The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <stable@xxxxxxxxxxxxxxx>. To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.19.y git checkout FETCH_HEAD git cherry-pick -x d6800af51c76b6dae20e6023bbdc9b3da3ab5121 # <resolve conflicts, build, test, etc.> git commit -s git send-email --to '<stable@xxxxxxxxxxxxxxx>' --in-reply-to '2023112012-decency-frying-1e27@gregkh' --subject-prefix 'PATCH 4.19.y' HEAD^.. Possible dependencies: d6800af51c76 ("KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space") 013cc6ebbf41 ("x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init") 87a8d795b2f1 ("x86/hyper-v: Stop caring about EOI for direct stimers") 8644f771e07c ("x86/kvm/hyper-v: direct mode for synthetic timers") 6a058a1eadc3 ("x86/kvm/hyper-v: use stimer config definition from hyperv-tlfs.h") 0aa67255f54d ("x86/hyper-v: move synic/stimer control structures definitions to hyperv-tlfs.h") 7deec5e0df74 ("x86: kvm: hyperv: don't retry message delivery for periodic timers") 3a0e7731724f ("x86: kvm: hyperv: simplify SynIC message delivery") f21dd494506a ("KVM: x86: hyperv: optimize sparse VP set processing") e6b6c483ebe9 ("KVM: x86: hyperv: fix 'tlb_lush' typo") 214ff83d4473 ("KVM: x86: hyperv: implement PV IPI send hypercalls") 2cefc5feb80c ("KVM: x86: hyperv: optimize kvm_hv_flush_tlb() for vp_index == vcpu_idx case") 0b0a31badb2d ("KVM: x86: hyperv: valid_bank_mask should be 'u64'") a812297c4fd9 ("KVM: x86: hyperv: optimize 'all cpus' case in kvm_hv_flush_tlb()") aa069a996951 ("KVM: PPC: Book3S HV: Add a VM capability to enable nested virtualization") 9d67121a4fce ("Merge remote-tracking branch 'remotes/powerpc/topic/ppc-kvm' into kvm-ppc-next") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From d6800af51c76b6dae20e6023bbdc9b3da3ab5121 Mon Sep 17 00:00:00 2001 From: Nicolas Saenz Julienne <nsaenz@xxxxxxxxxx> Date: Tue, 17 Oct 2023 15:51:02 +0000 Subject: [PATCH] KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space Don't apply the stimer's counter side effects when modifying its value from user-space, as this may trigger spurious interrupts. For example: - 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. - The VM is live migrated. - 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. Cc: stable@xxxxxxxxxxxxxxx Fixes: 1f4b34f825e8 ("kvm/x86: Hyper-V SynIC timers") Signed-off-by: Nicolas Saenz Julienne <nsaenz@xxxxxxxxxx> Reviewed-by: Vitaly Kuznetsov <vkuznets@xxxxxxxxxx> Link: https://lore.kernel.org/r/20231017155101.40677-1-nsaenz@xxxxxxxxxx Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 7c2dac6824e2..238afd7335e4 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -727,10 +727,12 @@ static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, stimer_cleanup(stimer); stimer->count = count; - if (stimer->count == 0) - stimer->config.enable = 0; - else if (stimer->config.auto_enable) - stimer->config.enable = 1; + if (!host) { + if (stimer->count == 0) + stimer->config.enable = 0; + else if (stimer->config.auto_enable) + stimer->config.enable = 1; + } if (stimer->config.enable) stimer_mark_pending(stimer, false);