Skip to contentSkip to conversation

svm/avic: Fix invalidate logical APIC id entry

PATCH Superseded Suthikulpanit, Suravee 2 participants 3 messages Mar 22, 2019 – Mar 26, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 svm/avic: Fix invalidate logical APIC id entry

Only clear the valid bit when invalidate logical APIC id entry. The current logic clear the valid bit, but also set the rest of the bits (including reserved bits) to 1.

Fixes 98d90582be2e ('svm: Fix AVIC DFR and LDR handling')
---
 arch/x86/kvm/svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm.c +1 -1
index 7a4ce1a22ca0..f4fb766e474c 100644
@@ -4640,7 +4640,7 @@ static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
 	u32 *entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
 
 	if (entry)
-		WRITE_ONCE(*entry, (u32) ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK);
+		WRITE_ONCE(*entry, (u32)(*entry & ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK));
 }
 
 static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 15 lines · Suravee

Only clear the valid bit when invalidate logical APIC id entry. The current logic clear the valid bit, but also set the rest of the bits (including reserved bits) to 1.

Fixes 98d90582be2e ('svm: Fix AVIC DFR and LDR handling')
---
 arch/x86/kvm/svm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm.c +0 -0
index 7a4ce1a22ca0..f4fb766e474c 100644

arch/x86/kvm/svm.c static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu) · line 4643

Quoted 5 lines
arch/x86/kvm/svm.c +1 -1
@@ -4640,7 +4640,7 @@ static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
 	u32 *entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
 
 	if (entry)
-		WRITE_ONCE(*entry, (u32) ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK);
+		WRITE_ONCE(*entry, (u32)(*entry & ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK));

I'm not sure how important this is, but this change creates a tiny time window between reading from *entry and writing there. Should we use atomic bitops instead?

Quoted 3 lines
arch/x86/kvm/svm.c +0 -0
 }
 
 static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
Signature · 1 line
Vitaly
#2 lore raw
Quoted 19 lines · Vitaly Kuznetsov
Quoted 17 lines · Suravee

Only clear the valid bit when invalidate logical APIC id entry. The current logic clear the valid bit, but also set the rest of the bits (including reserved bits) to 1.

Fixes 98d90582be2e ('svm: Fix AVIC DFR and LDR handling')
---
  arch/x86/kvm/svm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm.c +0 -0
index 7a4ce1a22ca0..f4fb766e474c 100644
@@ -4640,7 +4640,7 @@ static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
  	u32 *entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
 
Quoted 7 lines

arch/x86/kvm/svm.c static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu) · line 4643

Quoted 3 lines
arch/x86/kvm/svm.c +1 -1
  	if (entry)
-		WRITE_ONCE(*entry, (u32) ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK);
+		WRITE_ONCE(*entry, (u32)(*entry & ~AVIC_LOGICAL_ID_ENTRY_VALID_MASK));

I'm not sure how important this is, but this change creates a tiny time window between reading from *entry and writing there. Should we use atomic bitops instead?

Sure. That is also simpler. I'll send out V2 w/ clear_bit() instead.

Suravee

Quoted 5 lines
Quoted 4 lines
arch/x86/kvm/svm.c +0 -0
  }
 
  static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)