All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
@ 2024-12-11 17:29 Sean Christopherson
  2024-12-11 18:14 ` Tom Lendacky
  2024-12-19  2:40 ` Sean Christopherson
  0 siblings, 2 replies; 5+ messages in thread
From: Sean Christopherson @ 2024-12-11 17:29 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: kvm, linux-kernel, Simon Pilkington, Tom Lendacky

Drop KVM's arbitrary behavior of making DE_CFG.LFENCE_SERIALIZE read-only
for the guest, as rejecting writes can lead to guest crashes, e.g. Windows
in particular doesn't gracefully handle unexpected #GPs on the WRMSR, and
nothing in the AMD manuals suggests that LFENCE_SERIALIZE is read-only _if
it exists_.

KVM only allows LFENCE_SERIALIZE to be set, by the guest or host, if the
underlying CPU has X86_FEATURE_LFENCE_RDTSC, i.e. if LFENCE is guaranteed
to be serializing.  So if the guest sets LFENCE_SERIALIZE, KVM will provide
the desired/correct behavior without any additional action (the guest's
value is never stuffed into hardware).  And having LFENCE be serializing
even when it's not _required_ to be is a-ok from a functional perspective.

Fixes: 74a0e79df68a ("KVM: SVM: Disallow guest from changing userspace's MSR_AMD64_DE_CFG value")
Fixes: d1d93fa90f1a ("KVM: SVM: Add MSR-based feature support for serializing LFENCE")
Reported-by: Simon Pilkington <simonp.git@mailbox.org>
Closes: https://lore.kernel.org/all/52914da7-a97b-45ad-86a0-affdf8266c61@mailbox.org
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/svm.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index dd15cc635655..21dacd312779 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -3201,15 +3201,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
 		if (data & ~supported_de_cfg)
 			return 1;
 
-		/*
-		 * Don't let the guest change the host-programmed value.  The
-		 * MSR is very model specific, i.e. contains multiple bits that
-		 * are completely unknown to KVM, and the one bit known to KVM
-		 * is simply a reflection of hardware capabilities.
-		 */
-		if (!msr->host_initiated && data != svm->msr_decfg)
-			return 1;
-
 		svm->msr_decfg = data;
 		break;
 	}

base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4
-- 
2.47.0.338.g60cca15819-goog


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

* Re: [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
  2024-12-11 17:29 [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits Sean Christopherson
@ 2024-12-11 18:14 ` Tom Lendacky
  2024-12-19  2:40 ` Sean Christopherson
  1 sibling, 0 replies; 5+ messages in thread
From: Tom Lendacky @ 2024-12-11 18:14 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Simon Pilkington

On 12/11/24 11:29, Sean Christopherson wrote:
> Drop KVM's arbitrary behavior of making DE_CFG.LFENCE_SERIALIZE read-only
> for the guest, as rejecting writes can lead to guest crashes, e.g. Windows
> in particular doesn't gracefully handle unexpected #GPs on the WRMSR, and
> nothing in the AMD manuals suggests that LFENCE_SERIALIZE is read-only _if
> it exists_.
> 
> KVM only allows LFENCE_SERIALIZE to be set, by the guest or host, if the
> underlying CPU has X86_FEATURE_LFENCE_RDTSC, i.e. if LFENCE is guaranteed
> to be serializing.  So if the guest sets LFENCE_SERIALIZE, KVM will provide
> the desired/correct behavior without any additional action (the guest's
> value is never stuffed into hardware).  And having LFENCE be serializing
> even when it's not _required_ to be is a-ok from a functional perspective.
> 
> Fixes: 74a0e79df68a ("KVM: SVM: Disallow guest from changing userspace's MSR_AMD64_DE_CFG value")
> Fixes: d1d93fa90f1a ("KVM: SVM: Add MSR-based feature support for serializing LFENCE")
> Reported-by: Simon Pilkington <simonp.git@mailbox.org>
> Closes: https://lore.kernel.org/all/52914da7-a97b-45ad-86a0-affdf8266c61@mailbox.org
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Sean Christopherson <seanjc@google.com>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  arch/x86/kvm/svm/svm.c | 9 ---------
>  1 file changed, 9 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index dd15cc635655..21dacd312779 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3201,15 +3201,6 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr)
>  		if (data & ~supported_de_cfg)
>  			return 1;
>  
> -		/*
> -		 * Don't let the guest change the host-programmed value.  The
> -		 * MSR is very model specific, i.e. contains multiple bits that
> -		 * are completely unknown to KVM, and the one bit known to KVM
> -		 * is simply a reflection of hardware capabilities.
> -		 */
> -		if (!msr->host_initiated && data != svm->msr_decfg)
> -			return 1;
> -
>  		svm->msr_decfg = data;
>  		break;
>  	}
> 
> base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4

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

* Re: [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
  2024-12-11 17:29 [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits Sean Christopherson
  2024-12-11 18:14 ` Tom Lendacky
@ 2024-12-19  2:40 ` Sean Christopherson
  2024-12-19 12:47   ` Paolo Bonzini
  1 sibling, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2024-12-19  2:40 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini
  Cc: kvm, linux-kernel, Simon Pilkington, Tom Lendacky

On Wed, 11 Dec 2024 09:29:52 -0800, Sean Christopherson wrote:
> Drop KVM's arbitrary behavior of making DE_CFG.LFENCE_SERIALIZE read-only
> for the guest, as rejecting writes can lead to guest crashes, e.g. Windows
> in particular doesn't gracefully handle unexpected #GPs on the WRMSR, and
> nothing in the AMD manuals suggests that LFENCE_SERIALIZE is read-only _if
> it exists_.
> 
> KVM only allows LFENCE_SERIALIZE to be set, by the guest or host, if the
> underlying CPU has X86_FEATURE_LFENCE_RDTSC, i.e. if LFENCE is guaranteed
> to be serializing.  So if the guest sets LFENCE_SERIALIZE, KVM will provide
> the desired/correct behavior without any additional action (the guest's
> value is never stuffed into hardware).  And having LFENCE be serializing
> even when it's not _required_ to be is a-ok from a functional perspective.
> 
> [...]

Applied to kvm-x86 fixes, thanks!

[1/1] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
      https://github.com/kvm-x86/linux/commit/2778c9a4687d

--
https://github.com/kvm-x86/linux/tree/next

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

* Re: [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
  2024-12-19  2:40 ` Sean Christopherson
@ 2024-12-19 12:47   ` Paolo Bonzini
  2024-12-19 15:20     ` Sean Christopherson
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2024-12-19 12:47 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm, linux-kernel, Simon Pilkington, Tom Lendacky

On 12/19/24 03:40, Sean Christopherson wrote:
> On Wed, 11 Dec 2024 09:29:52 -0800, Sean Christopherson wrote:
>> Drop KVM's arbitrary behavior of making DE_CFG.LFENCE_SERIALIZE read-only
>> for the guest, as rejecting writes can lead to guest crashes, e.g. Windows
>> in particular doesn't gracefully handle unexpected #GPs on the WRMSR, and
>> nothing in the AMD manuals suggests that LFENCE_SERIALIZE is read-only _if
>> it exists_.
>>
>> KVM only allows LFENCE_SERIALIZE to be set, by the guest or host, if the
>> underlying CPU has X86_FEATURE_LFENCE_RDTSC, i.e. if LFENCE is guaranteed
>> to be serializing.  So if the guest sets LFENCE_SERIALIZE, KVM will provide
>> the desired/correct behavior without any additional action (the guest's
>> value is never stuffed into hardware).  And having LFENCE be serializing
>> even when it's not _required_ to be is a-ok from a functional perspective.
>>
>> [...]
> 
> Applied to kvm-x86 fixes, thanks!
> 
> [1/1] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
>        https://github.com/kvm-x86/linux/commit/2778c9a4687d

Oh, I missed this!  I assume you're going to send me a pull request 
today or tomorrow?

Paolo


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

* Re: [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
  2024-12-19 12:47   ` Paolo Bonzini
@ 2024-12-19 15:20     ` Sean Christopherson
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Christopherson @ 2024-12-19 15:20 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, linux-kernel, Simon Pilkington, Tom Lendacky

On Thu, Dec 19, 2024, Paolo Bonzini wrote:
> On 12/19/24 03:40, Sean Christopherson wrote:
> > On Wed, 11 Dec 2024 09:29:52 -0800, Sean Christopherson wrote:
> > > Drop KVM's arbitrary behavior of making DE_CFG.LFENCE_SERIALIZE read-only
> > > for the guest, as rejecting writes can lead to guest crashes, e.g. Windows
> > > in particular doesn't gracefully handle unexpected #GPs on the WRMSR, and
> > > nothing in the AMD manuals suggests that LFENCE_SERIALIZE is read-only _if
> > > it exists_.
> > > 
> > > KVM only allows LFENCE_SERIALIZE to be set, by the guest or host, if the
> > > underlying CPU has X86_FEATURE_LFENCE_RDTSC, i.e. if LFENCE is guaranteed
> > > to be serializing.  So if the guest sets LFENCE_SERIALIZE, KVM will provide
> > > the desired/correct behavior without any additional action (the guest's
> > > value is never stuffed into hardware).  And having LFENCE be serializing
> > > even when it's not _required_ to be is a-ok from a functional perspective.
> > > 
> > > [...]
> > 
> > Applied to kvm-x86 fixes, thanks!
> > 
> > [1/1] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits
> >        https://github.com/kvm-x86/linux/commit/2778c9a4687d
> 
> Oh, I missed this!  I assume you're going to send me a pull request today or
> tomorrow?

Yep, I'll get it to you today.

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

end of thread, other threads:[~2024-12-19 15:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11 17:29 [PATCH] KVM: SVM: Allow guest writes to set MSR_AMD64_DE_CFG bits Sean Christopherson
2024-12-11 18:14 ` Tom Lendacky
2024-12-19  2:40 ` Sean Christopherson
2024-12-19 12:47   ` Paolo Bonzini
2024-12-19 15:20     ` Sean Christopherson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.