kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks
@ 2021-01-15 22:03 Sean Christopherson
  2021-01-15 22:03 ` [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path Sean Christopherson
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-01-15 22:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, luferry

Resurrect a patch[*] from over a year ago to avoid RDMSR in a fairly hot
path in KVM's posted interrupt support.  Note, in my response to that
patch, I suggested checking x2apic_supported() as well as x2apic_mode.  I
have no idea why I suggested that; unless I'm missing something,
x2apic_mode can never be set if x2apic_supported() is false.

[*] https://lkml.kernel.org/r/20190723130608.26528-1-luferry@163.com/

Sean Christopherson (2):
  x86/apic: Export x2apic_mode for use by KVM in "warm" path
  KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state

 arch/x86/kernel/apic/apic.c    | 1 +
 arch/x86/kvm/vmx/posted_intr.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path
  2021-01-15 22:03 [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Sean Christopherson
@ 2021-01-15 22:03 ` Sean Christopherson
  2021-01-15 22:03 ` [PATCH 2/2] KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state Sean Christopherson
  2021-01-18 18:24 ` [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-01-15 22:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, luferry

Export x2apic_mode so that KVM can query whether x2APIC is active
without having to incur the RDMSR in x2apic_enabled().  When Posted
Interrupts are in use for a guest with an assigned device, KVM ends up
checking for x2APIC at least once every time a vCPU halts.  KVM could
obviously snapshot x2apic_enabled() to avoid the RDMSR, but that's
rather silly given that x2apic_mode holds the exact info needed by KVM.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kernel/apic/apic.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 6bd20c0de8bc..dea2b44966ca 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1743,6 +1743,7 @@ void apic_ap_setup(void)
 
 #ifdef CONFIG_X86_X2APIC
 int x2apic_mode;
+EXPORT_SYMBOL_GPL(x2apic_mode);
 
 enum {
 	X2APIC_OFF,
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state
  2021-01-15 22:03 [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Sean Christopherson
  2021-01-15 22:03 ` [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path Sean Christopherson
@ 2021-01-15 22:03 ` Sean Christopherson
  2021-01-18 18:24 ` [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Sean Christopherson @ 2021-01-15 22:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel, luferry

Use x2apic_mode instead of x2apic_enabled() when adjusting the
destination ID during Posted Interrupt updates.  This avoids the costly
RDMSR that is hidden behind x2apic_enabled().

Reported-by: luferry <luferry@163.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/vmx/posted_intr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
index f02962dcc72c..4831bc44ce66 100644
--- a/arch/x86/kvm/vmx/posted_intr.c
+++ b/arch/x86/kvm/vmx/posted_intr.c
@@ -54,7 +54,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
 
 		dest = cpu_physical_id(cpu);
 
-		if (x2apic_enabled())
+		if (x2apic_mode)
 			new.ndst = dest;
 		else
 			new.ndst = (dest << 8) & 0xFF00;
@@ -104,7 +104,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu)
 
 		dest = cpu_physical_id(vcpu->cpu);
 
-		if (x2apic_enabled())
+		if (x2apic_mode)
 			new.ndst = dest;
 		else
 			new.ndst = (dest << 8) & 0xFF00;
@@ -174,7 +174,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu)
 		 */
 		dest = cpu_physical_id(vcpu->pre_pcpu);
 
-		if (x2apic_enabled())
+		if (x2apic_mode)
 			new.ndst = dest;
 		else
 			new.ndst = (dest << 8) & 0xFF00;
-- 
2.30.0.284.gd98b1dd5eaa7-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks
  2021-01-15 22:03 [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Sean Christopherson
  2021-01-15 22:03 ` [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path Sean Christopherson
  2021-01-15 22:03 ` [PATCH 2/2] KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state Sean Christopherson
@ 2021-01-18 18:24 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2021-01-18 18:24 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel, luferry

On 15/01/21 23:03, Sean Christopherson wrote:
> Resurrect a patch[*] from over a year ago to avoid RDMSR in a fairly hot
> path in KVM's posted interrupt support.  Note, in my response to that
> patch, I suggested checking x2apic_supported() as well as x2apic_mode.  I
> have no idea why I suggested that; unless I'm missing something,
> x2apic_mode can never be set if x2apic_supported() is false.
> 
> [*] https://lkml.kernel.org/r/20190723130608.26528-1-luferry@163.com/
> 
> Sean Christopherson (2):
>    x86/apic: Export x2apic_mode for use by KVM in "warm" path
>    KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state
> 
>   arch/x86/kernel/apic/apic.c    | 1 +
>   arch/x86/kvm/vmx/posted_intr.c | 6 +++---
>   2 files changed, 4 insertions(+), 3 deletions(-)
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-18 18:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15 22:03 [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Sean Christopherson
2021-01-15 22:03 ` [PATCH 1/2] x86/apic: Export x2apic_mode for use by KVM in "warm" path Sean Christopherson
2021-01-15 22:03 ` [PATCH 2/2] KVM: VMX: Use x2apic_mode to avoid RDMSR when querying PI state Sean Christopherson
2021-01-18 18:24 ` [PATCH 0/2] KVM: VMX: Avoid RDMSRs in PI x2APIC checks Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).