Skip to contentSkip to conversation

KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space

PATCH Applied Nicolas Saenz Julienne 3 participants 3 messages Oct 17, 2023 – Oct 18, 2023

Subsystems (5)
Stable branch x86 KVM KVM x86 +1 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 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.

Fixes 1f4b34f825e8 ("kvm/x86: Hyper-V SynIC timers")

---

Changes since v2:
- reword commit message/subject.

Changes since v1:
- Cover all 'stimer->config.enable' updates.

 arch/x86/kvm/hyperv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/kvm/hyperv.c +6 -4
index 7c2dac6824e2..238afd7335e4 100644
@@ -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);
Signature · 1 line
2.40.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 37 lines · Nicolas Saenz Julienne

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.

Fixes 1f4b34f825e8 ("kvm/x86: Hyper-V SynIC timers")

---

Changes since v2:
- reword commit message/subject.

Changes since v1:
- Cover all 'stimer->config.enable' updates.

 arch/x86/kvm/hyperv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/kvm/hyperv.c +0 -3
index 7c2dac6824e2..238afd7335e4 100644
@@ -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)

arch/x86/kvm/hyperv.c static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, · line 738

Quoted 10 lines
arch/x86/kvm/hyperv.c +6 -1
-		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);

LGTM, thanks!

Signature · 1 line
Vitaly
maintainer Applied
#2 lore raw
In reply to Nicolas Saenz Julienne
Quoted 12 lines · Nicolas Saenz Julienne

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.

Quoted 1 line

[...]

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: hyper-v: Don't auto-enable stimer on write from user-space

      https://github.com/kvm-x86/linux/commit/d6800af51c76

--
https://github.com/kvm-x86/linux/tree/next