Skip to contentSkip to conversation

svm/avic: Fix invalidate logical APIC id entry

PATCH Applied Suthikulpanit, Suravee 2 participants 3 messages Mar 26, 2019 – Apr 9, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm.c +2 -1
index 7a4ce1a22ca0..8a123bd0f591 100644
@@ -270,6 +270,7 @@ struct amd_svm_iommu_ir {
 };
 
 #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK	(0xFF)
+#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT			31
 #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK		(1 << 31)
 
 #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK	(0xFFULL)
@@ -4640,7 +4641,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);
+		clear_bit(AVIC_LOGICAL_ID_ENTRY_VALID_BIT, (unsigned long *)entry);
 }
 
 static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
Signature · 1 line
2.17.1
#1 lore raw

Ping

Quoted 32 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 | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm.c +2 -1
index 7a4ce1a22ca0..8a123bd0f591 100644
@@ -270,6 +270,7 @@ struct amd_svm_iommu_ir {
  };
 
  #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK	(0xFF)
+#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT			31
  #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK		(1 << 31)
 
  #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK	(0xFFULL)
@@ -4640,7 +4641,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);
+		clear_bit(AVIC_LOGICAL_ID_ENTRY_VALID_BIT, (unsigned long *)entry);
  }
 
  static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
maintainer Applied
#2 lore raw
In reply to Suthikulpanit, Suravee
Quoted 24 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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/svm.c +1 -0
index 7a4ce1a22ca0..8a123bd0f591 100644
@@ -270,6 +270,7 @@ struct amd_svm_iommu_ir {
 };
 
 #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK	(0xFF)
+#define AVIC_LOGICAL_ID_ENTRY_VALID_BIT			31
 #define AVIC_LOGICAL_ID_ENTRY_VALID_MASK		(1 << 31)
 
 #define AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK	(0xFFULL)

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

Quoted 8 lines
arch/x86/kvm/svm.c +1 -1
@@ -4640,7 +4641,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);
+		clear_bit(AVIC_LOGICAL_ID_ENTRY_VALID_BIT, (unsigned long *)entry);
 }
 
 static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)

Queued both this and the revert, thanks.

Paolo