Skip to contentSkip to conversation

KVM: X86: Do not yield to self

PATCH In review Wanpeng Li 2 participants 3 messages Apr 8, 2021 – Apr 9, 2021

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/1 KVM: X86: Do not yield to self

From: Wanpeng Li <[email protected]>

If the target is self we do not need to yield, we can avoid malicious guest to play this.

---
Rebased on https://lore.kernel.org/kvm/[email protected]/

 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kvm/x86.c +4 -0
index 43c9f9b..260650f 100644
@@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
 	if (!target)
 		goto no_yield;
 
+	/* yield to self */
+	if (vcpu->vcpu_id == target->vcpu_id)
+		goto no_yield;
+
 	if (!READ_ONCE(target->ready))
 		goto no_yield;
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 17 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

If the target is self we do not need to yield, we can avoid malicious guest to play this.

---
Rebased on https://lore.kernel.org/kvm/[email protected]/

 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kvm/x86.c +0 -0
index 43c9f9b..260650f 100644

arch/x86/kvm/x86.c static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id) · line 8233

Quoted 4 lines
arch/x86/kvm/x86.c +1 -0
@@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
 	if (!target)
 		goto no_yield;
 
+	/* yield to self */

If you're going to bother with a comment, maybe elaborate a bit, e.g.

	/* Ignore requests to yield to self. */
Quoted 9 lines
arch/x86/kvm/x86.c +3 -0
+	if (vcpu->vcpu_id == target->vcpu_id)
+		goto no_yield;
+
 	if (!READ_ONCE(target->ready))
 		goto no_yield;
 
Signature · 1 line
2.7.4
author
#2 lore raw
Quoted 22 lines · Sean Christopherson
Quoted 20 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

If the target is self we do not need to yield, we can avoid malicious guest to play this.

---
Rebased on https://lore.kernel.org/kvm/[email protected]/

 arch/x86/kvm/x86.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/x86/kvm/x86.c +0 -0
index 43c9f9b..260650f 100644
@@ -8230,6 +8230,10 @@ static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id)
      if (!target)
              goto no_yield;
 
Quoted 5 lines

arch/x86/kvm/x86.c static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id) · line 8233

Quoted 1 line
arch/x86/kvm/x86.c +1 -0
+     /* yield to self */

If you're going to bother with a comment, maybe elaborate a bit, e.g.

        /* Ignore requests to yield to self. */

Looks good, thanks.

Wanpeng