public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: hyper-v: Don't auto-enable stimer during deserialization
@ 2023-10-16  9:52 Nicolas Saenz Julienne
  2023-10-16 12:14 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Saenz Julienne @ 2023-10-16  9:52 UTC (permalink / raw)
  To: kvm
  Cc: vkuznets, seanjc, pbonzini, tglx, mingo, bp, dave.hansen, x86,
	hpa, graf, rkagan, linux-kernel, Nicolas Saenz Julienne

By not honoring the 'stimer->config.enable' state during stimer
deserialization we might introduce spurious timer interrupts. For
example through the following events:
 - The stimer is configured in auto-enable mode.
 - The stimer's count is set and the timer enabled.
 - The stimer expires, an interrupt is injected.
 - We live migrate the VM.
 - The stimer config and count are deserialized, auto-enable is ON, the
   stimer is re-enabled.
 - The stimer expires right away, and injects an unwarranted interrupt.

So let's not change the stimer's enable state if the MSR write comes
from user-space.

Fixes: 1f4b34f825e8 ("kvm/x86: Hyper-V SynIC timers")
Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>
---
 arch/x86/kvm/hyperv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c
index 7c2dac6824e2..9f1deb6aa131 100644
--- a/arch/x86/kvm/hyperv.c
+++ b/arch/x86/kvm/hyperv.c
@@ -729,7 +729,7 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
 	stimer->count = count;
 	if (stimer->count == 0)
 		stimer->config.enable = 0;
-	else if (stimer->config.auto_enable)
+	else if (stimer->config.auto_enable && !host)
 		stimer->config.enable = 1;
 
 	if (stimer->config.enable)
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-16 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-16  9:52 [PATCH] KVM: x86: hyper-v: Don't auto-enable stimer during deserialization Nicolas Saenz Julienne
2023-10-16 12:14 ` Vitaly Kuznetsov
2023-10-16 12:42   ` Nicolas Saenz Julienne
2023-10-16 16:27     ` Sean Christopherson
2023-10-16 17:04       ` Nicolas Saenz Julienne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox