Skip to contentSkip to conversation

kvm: x86: check kvm_apic_sw_enabled() is enough

PATCH Wei Yang 3 participants 3 messages Jun 4, 2019 – Jun 6, 2019 2 messages not in the archive KVM

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Wei Yang

author
#1 lore raw

Ping...

Quoted 30 lines · Wei Yang

On delivering irq to apic, we iterate on vcpu and do the check like this:

   kvm_apic_present(vcpu)
   kvm_lapic_enabled(vpu)
       kvm_apic_present(vcpu) && kvm_apic_sw_enabled(vcpu->arch.apic)

Since we have already checked kvm_apic_present(), it is reasonable to replace kvm_lapic_enabled() with kvm_apic_sw_enabled().

---
arch/x86/kvm/irq_comm.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/irq_comm.c +1 -1
index 3cc3b2d130a0..188beb301cc5 100644
@@ -86,7 +86,7 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
 			if (r < 0)
 				r = 0;
 			r += kvm_apic_set_irq(vcpu, irq, dest_map);
-		} else if (kvm_lapic_enabled(vcpu)) {
+		} else if (kvm_apic_sw_enabled(vcpu->arch.apic)) {
 			if (!kvm_vector_hashing_enabled()) {
 				if (!lowest)
 					lowest = vcpu;
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw

Re: [PATCH 2/3] kvm: x86: use same convention to name apic_clear_vector()

Quoted 5 lines · Wei Yang

apic_clear_vector() is the counterpart of kvm_lapic_clear_vector(), while they have different naming convention.

Rename it and move together to arch/x86/kvm/lapic.h. Also fix one typo in comment by hand.

You mean "of kvm_lapic_set_vector()". Queued all three with only this change to the commit log, sorry for the delay.

Paolo

Quoted 77 lines
---
 arch/x86/kvm/lapic.c | 17 +++++++----------
 arch/x86/kvm/lapic.h |  5 +++++
 2 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/kvm/lapic.c +7 -10
index c4533d05c214..d8b3cbba8e29 100644
@@ -88,11 +88,6 @@ bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector)
 		apic_test_vector(vector, apic->regs + APIC_IRR);
 }
 
-static inline void apic_clear_vector(int vec, void *bitmap)
-{
-	clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
-}
-
 static inline int __apic_test_and_set_vector(int vec, void *bitmap)
 {
 	return __test_and_set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
@@ -445,12 +440,12 @@ static inline void apic_clear_irr(int vec, struct kvm_lapic *apic)
 
 	if (unlikely(vcpu->arch.apicv_active)) {
 		/* need to update RVI */
-		apic_clear_vector(vec, apic->regs + APIC_IRR);
+		kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR);
 		kvm_x86_ops->hwapic_irr_update(vcpu,
 				apic_find_highest_irr(apic));
 	} else {
 		apic->irr_pending = false;
-		apic_clear_vector(vec, apic->regs + APIC_IRR);
+		kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR);
 		if (apic_search_irr(apic) != -1)
 			apic->irr_pending = true;
 	}
@@ -1053,9 +1048,11 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 
 		if (apic_test_vector(vector, apic->regs + APIC_TMR) != !!trig_mode) {
 			if (trig_mode)
-				kvm_lapic_set_vector(vector, apic->regs + APIC_TMR);
+				kvm_lapic_set_vector(vector,
+						     apic->regs + APIC_TMR);
 			else
-				apic_clear_vector(vector, apic->regs + APIC_TMR);
+				kvm_lapic_clear_vector(vector,
+						       apic->regs + APIC_TMR);
 		}
 
 		if (vcpu->arch.apicv_active)
@@ -2278,7 +2275,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
 
 	/*
 	 * APIC is created enabled. This will prevent kvm_lapic_set_base from
-	 * thinking that APIC satet has changed.
+	 * thinking that APIC state has changed.
 	 */
 	vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE;
 	static_key_slow_inc(&apic_sw_disabled.key); /* sw disabled at reset */
arch/x86/kvm/lapic.h +5 -0
index ff6ef9c3d760..339ee029be6e 100644
@@ -127,6 +127,11 @@ void kvm_lapic_exit(void);
 #define VEC_POS(v) ((v) & (32 - 1))
 #define REG_POS(v) (((v) >> 5) << 4)
 
+static inline void kvm_lapic_clear_vector(int vec, void *bitmap)
+{
+	clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
+}
+
 static inline void kvm_lapic_set_vector(int vec, void *bitmap)
 {
 	set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
#4 lore raw

Re: [PATCH 2/3] kvm: x86: use same convention to name apic_clear_vector()

Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Wei Yang

apic_clear_vector() is the counterpart of kvm_lapic_clear_vector(), while they have different naming convention.

Rename it and move together to arch/x86/kvm/lapic.h. Also fix one typo in comment by hand.

You mean "of kvm_lapic_set_vector()". Queued all three with only this change to the commit log, sorry for the delay.

Thanks :-)

Quoted 79 lines

Paolo

Quoted 77 lines
---
 arch/x86/kvm/lapic.c | 17 +++++++----------
 arch/x86/kvm/lapic.h |  5 +++++
 2 files changed, 12 insertions(+), 10 deletions(-)
arch/x86/kvm/lapic.c +7 -10
index c4533d05c214..d8b3cbba8e29 100644
@@ -88,11 +88,6 @@ bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector)
 		apic_test_vector(vector, apic->regs + APIC_IRR);
 }
 
-static inline void apic_clear_vector(int vec, void *bitmap)
-{
-	clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
-}
-
 static inline int __apic_test_and_set_vector(int vec, void *bitmap)
 {
 	return __test_and_set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
@@ -445,12 +440,12 @@ static inline void apic_clear_irr(int vec, struct kvm_lapic *apic)
 
 	if (unlikely(vcpu->arch.apicv_active)) {
 		/* need to update RVI */
-		apic_clear_vector(vec, apic->regs + APIC_IRR);
+		kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR);
 		kvm_x86_ops->hwapic_irr_update(vcpu,
 				apic_find_highest_irr(apic));
 	} else {
 		apic->irr_pending = false;
-		apic_clear_vector(vec, apic->regs + APIC_IRR);
+		kvm_lapic_clear_vector(vec, apic->regs + APIC_IRR);
 		if (apic_search_irr(apic) != -1)
 			apic->irr_pending = true;
 	}
@@ -1053,9 +1048,11 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
 
 		if (apic_test_vector(vector, apic->regs + APIC_TMR) != !!trig_mode) {
 			if (trig_mode)
-				kvm_lapic_set_vector(vector, apic->regs + APIC_TMR);
+				kvm_lapic_set_vector(vector,
+						     apic->regs + APIC_TMR);
 			else
-				apic_clear_vector(vector, apic->regs + APIC_TMR);
+				kvm_lapic_clear_vector(vector,
+						       apic->regs + APIC_TMR);
 		}
 
 		if (vcpu->arch.apicv_active)
@@ -2278,7 +2275,7 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
 
 	/*
 	 * APIC is created enabled. This will prevent kvm_lapic_set_base from
-	 * thinking that APIC satet has changed.
+	 * thinking that APIC state has changed.
 	 */
 	vcpu->arch.apic_base = MSR_IA32_APICBASE_ENABLE;
 	static_key_slow_inc(&apic_sw_disabled.key); /* sw disabled at reset */
arch/x86/kvm/lapic.h +5 -0
index ff6ef9c3d760..339ee029be6e 100644
@@ -127,6 +127,11 @@ void kvm_lapic_exit(void);
 #define VEC_POS(v) ((v) & (32 - 1))
 #define REG_POS(v) (((v) >> 5) << 4)
 
+static inline void kvm_lapic_clear_vector(int vec, void *bitmap)
+{
+	clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
+}
+
 static inline void kvm_lapic_set_vector(int vec, void *bitmap)
 {
 	set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec));
Signature · 2 lines
Wei Yang
Help you, Help me