linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Fix always skip to boost kernel lock holder candidate for SEV-ES guests
@ 2021-04-22  8:34 Wanpeng Li
  2021-04-22 10:34 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Wanpeng Li @ 2021-04-22  8:34 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

Commit f1c6366e3043 ("KVM: SVM: Add required changes to support intercepts under 
SEV-ES") prevents hypervisor accesses guest register state when the guest is 
running under SEV-ES. The initial value of vcpu->arch.guest_state_protected
is false, it will not be updated in preemption notifiers after this commit which 
means that the kernel spinlock lock holder will always be skipped to boost. Let's 
fix it by always treating preempted is in the guest kernel mode, false positive 
is better than skip completely.

Fixes: f1c6366e3043 (KVM: SVM: Add required changes to support intercepts under SEV-ES)
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/x86.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d696a9f..e52ca09 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11151,6 +11151,9 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
 
 bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
 {
+	if (vcpu->arch.guest_state_protected)
+		return true;
+
 	return vcpu->arch.preempted_in_kernel;
 }
 
-- 
2.7.4


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

* Re: [PATCH] KVM: X86: Fix always skip to boost kernel lock holder candidate for SEV-ES guests
  2021-04-22  8:34 [PATCH] KVM: X86: Fix always skip to boost kernel lock holder candidate for SEV-ES guests Wanpeng Li
@ 2021-04-22 10:34 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-04-22 10:34 UTC (permalink / raw)
  To: Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 22/04/21 10:34, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> Commit f1c6366e3043 ("KVM: SVM: Add required changes to support intercepts under
> SEV-ES") prevents hypervisor accesses guest register state when the guest is
> running under SEV-ES. The initial value of vcpu->arch.guest_state_protected
> is false, it will not be updated in preemption notifiers after this commit which
> means that the kernel spinlock lock holder will always be skipped to boost. Let's
> fix it by always treating preempted is in the guest kernel mode, false positive
> is better than skip completely.
> 
> Fixes: f1c6366e3043 (KVM: SVM: Add required changes to support intercepts under SEV-ES)
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
>   arch/x86/kvm/x86.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d696a9f..e52ca09 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11151,6 +11151,9 @@ bool kvm_arch_dy_has_pending_interrupt(struct kvm_vcpu *vcpu)
>   
>   bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
>   {
> +	if (vcpu->arch.guest_state_protected)
> +		return true;
> +
>   	return vcpu->arch.preempted_in_kernel;
>   }
>   
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2021-04-22 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22  8:34 [PATCH] KVM: X86: Fix always skip to boost kernel lock holder candidate for SEV-ES guests Wanpeng Li
2021-04-22 10:34 ` 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).