From: Babu Moger <babu.moger@amd.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>,
Jim Mattson <jmattson@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H . Peter Anvin" <hpa@zytor.com>,
Paolo Bonzini <pbonzini@redhat.com>,
the arch/x86 maintainers <x86@kernel.org>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Joerg Roedel <joro@8bytes.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
mchehab+samsung@kernel.org, changbin.du@intel.com,
Nadav Amit <namit@vmware.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
yang.shi@linux.alibaba.com,
Anthony Steinhauser <asteinhauser@google.com>,
anshuman.khandual@arm.com, Jan Kiszka <jan.kiszka@siemens.com>,
Andrew Morton <akpm@linux-foundation.org>,
steven.price@arm.com, rppt@linux.vnet.ibm.com, peterx@redhat.com,
Dan Williams <dan.j.williams@intel.com>,
Arjun Roy <arjunroy@google.com>,
logang@deltatee.com, Thomas Hellstrom <thellstrom@vmware.com>,
Andrea Arcangeli <aarcange@redhat.com>,
justin.he@arm.com, robin.murphy@arm.com, ira.weiny@intel.com,
Kees Cook <keescook@chromium.org>,
Juergen Gross <jgross@suse.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
pawan.kumar.gupta@linux.intel.com, "Yu,
Fenghua" <fenghua.yu@intel.com>,
vineela.tummalapalli@intel.com, yamada.masahiro@socionext.com,
sam@ravnborg.org, acme@redhat.com, linux-doc@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
kvm list <kvm@vger.kernel.org>
Subject: Re: [PATCH v3 3/3] KVM: x86: Move MPK feature detection to common code
Date: Tue, 12 May 2020 15:04:49 -0500 [thread overview]
Message-ID: <4a9cc633-f530-8d43-3b8c-b83822597506@amd.com> (raw)
In-Reply-To: <20200512172800.GB12100@linux.intel.com>
On 5/12/20 12:28 PM, Sean Christopherson wrote:
> On Tue, May 12, 2020 at 09:58:19AM -0700, Jim Mattson wrote:
>> On Tue, May 12, 2020 at 8:12 AM Babu Moger <babu.moger@amd.com> wrote:
>>>
>>>
>>>
>>> On 5/11/20 6:51 PM, Jim Mattson wrote:
>>>> On Mon, May 11, 2020 at 4:33 PM Babu Moger <babu.moger@amd.com> wrote:
>>>>>
>>>>> Both Intel and AMD support (MPK) Memory Protection Key feature.
>>>>> Move the feature detection from VMX to the common code. It should
>>>>> work for both the platforms now.
>>>>>
>>>>> Signed-off-by: Babu Moger <babu.moger@amd.com>
>>>>> ---
>>>>> arch/x86/kvm/cpuid.c | 4 +++-
>>>>> arch/x86/kvm/vmx/vmx.c | 4 ----
>>>>> 2 files changed, 3 insertions(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>>>>> index 901cd1fdecd9..3da7d6ea7574 100644
>>>>> --- a/arch/x86/kvm/cpuid.c
>>>>> +++ b/arch/x86/kvm/cpuid.c
>>>>> @@ -278,6 +278,8 @@ void kvm_set_cpu_caps(void)
>>>>> #ifdef CONFIG_X86_64
>>>>> unsigned int f_gbpages = F(GBPAGES);
>>>>> unsigned int f_lm = F(LM);
>>>>> + /* PKU is not yet implemented for shadow paging. */
>>>>> + unsigned int f_pku = tdp_enabled ? F(PKU) : 0;
>>>>
>>>> I think we still want to require that OSPKE be set on the host before
>>>> exposing PKU to the guest.
>>>>
>>>
>>> Ok I can add this check.
>>>
>>> + unsigned int f_pku = tdp_enabled && F(OSPKE)? F(PKU) : 0;
>>
>> That doesn't do what you think it does. F(OSPKE) is a non-zero
>> constant, so that conjunct is always true.
>
> My vote would be to omit f_pku and adjust the cap directly, e.g.
Sure. I am fine with this. Thanks
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 6828be99b9083..998c902df9e57 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -326,7 +326,7 @@ void kvm_set_cpu_caps(void)
> );
>
> kvm_cpu_cap_mask(CPUID_7_ECX,
> - F(AVX512VBMI) | F(LA57) | 0 /*PKU*/ | 0 /*OSPKE*/ | F(RDPID) |
> + F(AVX512VBMI) | F(LA57) | F(PKU) | 0 /*OSPKE*/ | F(RDPID) |
> F(AVX512_VPOPCNTDQ) | F(UMIP) | F(AVX512_VBMI2) | F(GFNI) |
> F(VAES) | F(VPCLMULQDQ) | F(AVX512_VNNI) | F(AVX512_BITALG) |
> F(CLDEMOTE) | F(MOVDIRI) | F(MOVDIR64B) | 0 /*WAITPKG*/
> @@ -334,6 +334,8 @@ void kvm_set_cpu_caps(void)
> /* Set LA57 based on hardware capability. */
> if (cpuid_ecx(7) & F(LA57))
> kvm_cpu_cap_set(X86_FEATURE_LA57);
> + if (!tdp_enabled || !boot_cpu_has(OSPKE))
> + kvm_cpu_cap_clear(X86_FEATURE_PKU);
>
> kvm_cpu_cap_mask(CPUID_7_EDX,
> F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) |
>
prev parent reply other threads:[~2020-05-12 20:05 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-11 23:32 [PATCH v3 0/3] arch/x86: Enable MPK feature on AMD Babu Moger
2020-05-11 23:32 ` [PATCH v3 1/3] arch/x86: Rename config X86_INTEL_MEMORY_PROTECTION_KEYS to generic x86 Babu Moger
2020-05-11 23:44 ` Dave Hansen
2020-05-12 14:57 ` Babu Moger
2020-05-12 15:19 ` Dave Hansen
2020-05-12 15:45 ` Babu Moger
2020-05-11 23:33 ` [PATCH v3 2/3] KVM: x86: Move pkru save/restore to x86.c Babu Moger
2020-05-12 16:39 ` Jim Mattson
2020-05-12 17:17 ` Babu Moger
2020-05-13 6:47 ` Paolo Bonzini
2020-05-11 23:33 ` [PATCH v3 3/3] KVM: x86: Move MPK feature detection to common code Babu Moger
2020-05-11 23:51 ` Jim Mattson
2020-05-12 15:12 ` Babu Moger
2020-05-12 16:58 ` Jim Mattson
2020-05-12 17:28 ` Sean Christopherson
2020-05-12 20:04 ` Babu Moger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4a9cc633-f530-8d43-3b8c-b83822597506@amd.com \
--to=babu.moger@amd.com \
--cc=aarcange@redhat.com \
--cc=acme@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=andrew.cooper3@citrix.com \
--cc=anshuman.khandual@arm.com \
--cc=arjunroy@google.com \
--cc=asteinhauser@google.com \
--cc=bigeasy@linutronix.de \
--cc=bp@alien8.de \
--cc=changbin.du@intel.com \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=fenghua.yu@intel.com \
--cc=hpa@zytor.com \
--cc=ira.weiny@intel.com \
--cc=jan.kiszka@siemens.com \
--cc=jgross@suse.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=justin.he@arm.com \
--cc=keescook@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=luto@kernel.org \
--cc=mchehab+samsung@kernel.org \
--cc=mingo@redhat.com \
--cc=namit@vmware.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=robin.murphy@arm.com \
--cc=rppt@linux.vnet.ibm.com \
--cc=sam@ravnborg.org \
--cc=sean.j.christopherson@intel.com \
--cc=steven.price@arm.com \
--cc=tglx@linutronix.de \
--cc=thellstrom@vmware.com \
--cc=vineela.tummalapalli@intel.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
--cc=yamada.masahiro@socionext.com \
--cc=yang.shi@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).