From 658658e76c4a6a3b59a9d379e44892a6ff1e96e9 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 18 Jan 2022 17:08:42 +0000 Subject: [PATCH] hypervisor: kvm: Ignore -EINVAL from KVM_KVMCLOCK_CTRL ioctl() If the guest hasn't initialised a PV clock then the KVM_KVMCLOCK_CTRL ioctl will return -EINVAL. Therefore if running in the firmware or an OS that doesn't use the PV clock then we should ignore that error Tested by migrating a VM that has not yet booted into the Linux kernel (just in firmware) by specifying no disk image: e.g. target/debug/cloud-hypervisor --kernel ~/workloads/hypervisor-fw --api-socket /tmp/api --serial tty --console off Fixes: #3586 Signed-off-by: Rob Bradford --- hypervisor/src/kvm/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 07191b74a..8e5a3fda6 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -1051,9 +1051,16 @@ impl cpu::Vcpu for KvmVcpu { /// potential soft lockups when being resumed. /// fn notify_guest_clock_paused(&self) -> cpu::Result<()> { - self.fd - .kvmclock_ctrl() - .map_err(|e| cpu::HypervisorCpuError::NotifyGuestClockPaused(e.into())) + if let Err(e) = self.fd.kvmclock_ctrl() { + // Linux kernel returns -EINVAL if the PV clock isn't yet initialised + // which could be because we're still in firmware or the guest doesn't + // use KVM clock. + if e.errno() != libc::EINVAL { + return Err(cpu::HypervisorCpuError::NotifyGuestClockPaused(e.into())); + } + } + + Ok(()) } #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] fn vcpu_init(&self, kvi: &VcpuInit) -> cpu::Result<()> {