Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions src/vmm/src/devices/virtio/iovec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,26 @@ impl IoVecBuffer {
slice = slice.subslice(0, len)?;
}

let bytes_read = loop {
match loop {
match dst.write_volatile(&slice) {
Err(VolatileMemoryError::IOError(err))
if err.kind() == ErrorKind::Interrupted =>
{
continue
}
Ok(bytes_read) => break bytes_read,
Err(volatile_memory_error) => return Err(volatile_memory_error),
if err.kind() == ErrorKind::Interrupted => {}
result => break result,
}
};
total_bytes_read += bytes_read;
} {
Ok(bytes_read) => {
total_bytes_read += bytes_read;

if bytes_read < slice.len() {
break;
if bytes_read < slice.len() {
break;
}
len -= bytes_read;
}
// exit successfully if we previously managed to write some bytes
Err(_) if total_bytes_read > 0 => break,
// this captures the `volatile_memory_error` from the above loop
Err(err) => return Err(err),
}
len -= bytes_read;
}

Ok(total_bytes_read)
Expand Down Expand Up @@ -299,23 +302,26 @@ impl IoVecBufferMut {
slice = slice.subslice(0, len)?;
}

let bytes_read = loop {
match loop {
match src.read_volatile(&mut slice) {
Err(VolatileMemoryError::IOError(err))
if err.kind() == ErrorKind::Interrupted =>
{
continue
}
Ok(bytes_read) => break bytes_read,
Err(volatile_memory_error) => return Err(volatile_memory_error),
if err.kind() == ErrorKind::Interrupted => {}
result => break result,
}
};
total_bytes_read += bytes_read;
} {
Ok(bytes_read) => {
total_bytes_read += bytes_read;

if bytes_read < slice.len() {
break;
if bytes_read < slice.len() {
break;
}
len -= bytes_read;
}
// exit successfully if we previously managed to write some bytes
Err(_) if total_bytes_read > 0 => break,
// this captures the `volatile_memory_error` from the above loop
Err(err) => return Err(err),
}
len -= bytes_read;
}

Ok(total_bytes_read)
Expand Down
3 changes: 3 additions & 0 deletions src/vmm/src/logger/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ pub struct VcpuMetrics {
pub exit_mmio_write: SharedIncMetric,
/// Number of errors during this VCPU's run.
pub failures: SharedIncMetric,
/// Number of times that the `KVM_KVMCLOCK_CTRL` ioctl failed.
pub kvmclock_ctrl_fails: SharedIncMetric,
/// Provides Min/max/sum for KVM exits handling input IO.
pub exit_io_in_agg: LatencyAggregateMetrics,
/// Provides Min/max/sum for KVM exits handling output IO.
Expand All @@ -798,6 +800,7 @@ impl VcpuMetrics {
exit_mmio_read: SharedIncMetric::new(),
exit_mmio_write: SharedIncMetric::new(),
failures: SharedIncMetric::new(),
kvmclock_ctrl_fails: SharedIncMetric::new(),
exit_io_in_agg: LatencyAggregateMetrics::new(),
exit_io_out_agg: LatencyAggregateMetrics::new(),
exit_mmio_read_agg: LatencyAggregateMetrics::new(),
Expand Down
12 changes: 12 additions & 0 deletions src/vmm/src/vstate/vcpu/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,15 @@ impl KvmVcpu {
self.fd.set_tsc_khz(tsc_freq).map_err(SetTscError)
}

/// Calls KVM_KVMCLOCK_CTRL to avoid guest soft lockup watchdog panics on resume.
/// See https://docs.kernel.org/virt/kvm/api.html .
pub fn kvmclock_ctrl(&self) {
if let Err(err) = self.fd.kvmclock_ctrl() {
METRICS.vcpu.kvmclock_ctrl_fails.inc();
warn!("KVM_KVMCLOCK_CTRL call failed {}", err);
}
}

/// Use provided state to populate KVM internal state.
pub fn restore_state(&self, state: &VcpuState) -> Result<(), KvmVcpuError> {
// Ordering requirements:
Expand Down Expand Up @@ -621,6 +630,9 @@ impl KvmVcpu {
self.fd
.set_vcpu_events(&state.vcpu_events)
.map_err(KvmVcpuError::VcpuSetVcpuEvents)?;

self.kvmclock_ctrl();

Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/host_tools/fcmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def validate_fc_metrics(metrics):
"exit_mmio_read",
"exit_mmio_write",
"failures",
"kvmclock_ctrl_fails",
{"exit_io_in_agg": latency_agg_metrics_fields},
{"exit_io_out_agg": latency_agg_metrics_fields},
{"exit_mmio_read_agg": latency_agg_metrics_fields},
Expand Down