linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm/svm: PKU not currently supported
@ 2019-12-19 15:23 John Allen
  2019-12-19 19:09 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 3+ messages in thread
From: John Allen @ 2019-12-19 15:23 UTC (permalink / raw)
  To: kvm; +Cc: linux-kernel, pbonzini, rkrcmar, John Allen

Current SVM implementation does not have support for handling PKU. Guests
running on a host with future AMD cpus that support the feature will read
garbage from the PKRU register and will hit segmentation faults on boot as
memory is getting marked as protected that should not be. Ensure that cpuid
from SVM does not advertise the feature.

Signed-off-by: John Allen <john.allen@amd.com>
---
 arch/x86/kvm/svm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 122d4ce3b1ab..f911aa1b41c8 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 		if (avic)
 			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
 		break;
+	case 0x7:
+		entry->ecx &= ~bit(X86_FEATURE_PKU);
 	case 0x80000001:
 		if (nested)
 			entry->ecx |= (1 << 2); /* Set SVM bit */
-- 
2.24.0


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

* Re: [PATCH] kvm/svm: PKU not currently supported
  2019-12-19 15:23 [PATCH] kvm/svm: PKU not currently supported John Allen
@ 2019-12-19 19:09 ` Vitaly Kuznetsov
  2019-12-19 19:49   ` John Allen
  0 siblings, 1 reply; 3+ messages in thread
From: Vitaly Kuznetsov @ 2019-12-19 19:09 UTC (permalink / raw)
  To: John Allen, kvm; +Cc: linux-kernel, pbonzini, rkrcmar, John Allen

John Allen <john.allen@amd.com> writes:

> Current SVM implementation does not have support for handling PKU. Guests
> running on a host with future AMD cpus that support the feature will read
> garbage from the PKRU register and will hit segmentation faults on boot as
> memory is getting marked as protected that should not be. Ensure that cpuid
> from SVM does not advertise the feature.
>
> Signed-off-by: John Allen <john.allen@amd.com>
> ---
>  arch/x86/kvm/svm.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 122d4ce3b1ab..f911aa1b41c8 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
>  		if (avic)
>  			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
>  		break;
> +	case 0x7:
> +		entry->ecx &= ~bit(X86_FEATURE_PKU);

Would it make more sense to introduce kvm_x86_ops->pku_supported() (and
return false for SVM and boot_cpu_has(X86_FEATURE_PKU) for vmx) so we
don't set the bit in the first place?

>  	case 0x80000001:
>  		if (nested)
>  			entry->ecx |= (1 << 2); /* Set SVM bit */

-- 
Vitaly


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

* Re: [PATCH] kvm/svm: PKU not currently supported
  2019-12-19 19:09 ` Vitaly Kuznetsov
@ 2019-12-19 19:49   ` John Allen
  0 siblings, 0 replies; 3+ messages in thread
From: John Allen @ 2019-12-19 19:49 UTC (permalink / raw)
  To: Vitaly Kuznetsov; +Cc: kvm, linux-kernel, pbonzini, rkrcmar

On Thu, Dec 19, 2019 at 08:09:57PM +0100, Vitaly Kuznetsov wrote:
> John Allen <john.allen@amd.com> writes:
> 
> > Current SVM implementation does not have support for handling PKU. Guests
> > running on a host with future AMD cpus that support the feature will read
> > garbage from the PKRU register and will hit segmentation faults on boot as
> > memory is getting marked as protected that should not be. Ensure that cpuid
> > from SVM does not advertise the feature.
> >
> > Signed-off-by: John Allen <john.allen@amd.com>
> > ---
> >  arch/x86/kvm/svm.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> > index 122d4ce3b1ab..f911aa1b41c8 100644
> > --- a/arch/x86/kvm/svm.c
> > +++ b/arch/x86/kvm/svm.c
> > @@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
> >  		if (avic)
> >  			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
> >  		break;
> > +	case 0x7:
> > +		entry->ecx &= ~bit(X86_FEATURE_PKU);
> 
> Would it make more sense to introduce kvm_x86_ops->pku_supported() (and
> return false for SVM and boot_cpu_has(X86_FEATURE_PKU) for vmx) so we
> don't set the bit in the first place?

Yes, I think you're right. I had initially planned to do it that way so I
already have a patch ready. I'll send it up pronto.

> 
> >  	case 0x80000001:
> >  		if (nested)
> >  			entry->ecx |= (1 << 2); /* Set SVM bit */
> 
> -- 
> Vitaly
> 

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

end of thread, other threads:[~2019-12-19 19:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-19 15:23 [PATCH] kvm/svm: PKU not currently supported John Allen
2019-12-19 19:09 ` Vitaly Kuznetsov
2019-12-19 19:49   ` John Allen

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).