Skip to contentSkip to conversation

KVM: apic: reuse smp_wmb() in kvm_make_request()

PATCH Superseded linmiaohe 3 participants 3 messages Feb 6, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

linmiaohe

author
#0 lore raw

PATCH 1/1 KVM: apic: reuse smp_wmb() in kvm_make_request()

From: Miaohe Lin <[email protected]>

There is already an smp_mb() barrier in kvm_make_request(). We reuse it here.

---
 arch/x86/kvm/lapic.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +6 -3
index eafc631d305c..ea871206a370 100644
@@ -1080,9 +1080,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 			result = 1;
 			/* assumes that there are only KVM_APIC_INIT/SIPI */
 			apic->pending_events = (1UL << KVM_APIC_INIT);
-			/* make sure pending_events is visible before sending
-			 * the request */
-			smp_wmb();
+			/*
+			 * Make sure pending_events is visible before sending
+			 * the request.
+			 * There is already an smp_wmb() in kvm_make_request(),
+			 * we reuse that barrier here.
+			 */
 			kvm_make_request(KVM_REQ_EVENT, vcpu);
 			kvm_vcpu_kick(vcpu);
 		}
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · linmiaohe

From: Miaohe Lin <[email protected]>

There is already an smp_mb() barrier in kvm_make_request(). We reuse it here.

---
 arch/x86/kvm/lapic.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +0 -0
index eafc631d305c..ea871206a370 100644
@@ -1080,9 +1080,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 			result = 1;
 			/* assumes that there are only KVM_APIC_INIT/SIPI */

arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, · line 1088

Quoted 10 lines
arch/x86/kvm/lapic.c +6 -3
 			apic->pending_events = (1UL << KVM_APIC_INIT);
-			/* make sure pending_events is visible before sending
-			 * the request */
-			smp_wmb();
+			/*
+			 * Make sure pending_events is visible before sending
+			 * the request.
+			 * There is already an smp_wmb() in kvm_make_request(),
+			 * we reuse that barrier here.
+			 */

Let me suggest an alternative wording,

"kvm_make_request() provides smp_wmb() so pending_events changes are guaranteed to be visible"

But there is nothing wrong with yours, it's just longer than it could be :-)

Quoted 3 lines
arch/x86/kvm/lapic.c +0 -0
 			kvm_make_request(KVM_REQ_EVENT, vcpu);
 			kvm_vcpu_kick(vcpu);
 		}
Signature · 1 line
Vitaly
#2 lore raw
Quoted 32 lines · Vitaly Kuznetsov
Quoted 17 lines · linmiaohe

From: Miaohe Lin <[email protected]>

There is already an smp_mb() barrier in kvm_make_request(). We reuse it here.

---
 arch/x86/kvm/lapic.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
arch/x86/kvm/lapic.c +0 -0
index eafc631d305c..ea871206a370 100644
@@ -1080,9 +1080,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 			result = 1;
 			/* assumes that there are only KVM_APIC_INIT/SIPI */

arch/x86/kvm/lapic.c static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, · line 1088

Quoted 10 lines
arch/x86/kvm/lapic.c +6 -3
 			apic->pending_events = (1UL << KVM_APIC_INIT);
-			/* make sure pending_events is visible before sending
-			 * the request */
-			smp_wmb();
+			/*
+			 * Make sure pending_events is visible before sending
+			 * the request.
+			 * There is already an smp_wmb() in kvm_make_request(),
+			 * we reuse that barrier here.
+			 */

Let me suggest an alternative wording,

Quoted 5 lines

"kvm_make_request() provides smp_wmb() so pending_events changes are guaranteed to be visible"

But there is nothing wrong with yours, it's just longer than it could be :-)

I usually lean in favor of more comments, but in thise case I'd vote to drop the comment altogether. There are lots of places that rely on the smp_wmb() in kvm_make_request() without a comment, e.g. the cases for APIC_DM_STARTUP and APIC_DM_REMRD in this same switch, kvm_inject_nmi(), etc... One might wonder what makes INIT special.

And on the flip side, APIC_DM_STARTUP is a good example of when a smp_wmb()/smp_rmb() is needed and commented correctly (though calling out the exactly location of the other half would be helpful).

Quoted 9 lines
Quoted 3 lines
arch/x86/kvm/lapic.c +0 -0
 			kvm_make_request(KVM_REQ_EVENT, vcpu);
 			kvm_vcpu_kick(vcpu);
 		}
Signature · 1 line
Vitaly