From: Xiao Guangrong <guangrong.xiao@linux.intel.com>
To: Huaitong Han <huaitong.han@intel.com>,
pbonzini@redhat.com, gleb@kernel.org
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH V4 1/7] KVM, pkeys: expose CPUID/CR4 to guest
Date: Sun, 6 Mar 2016 15:15:49 +0800 [thread overview]
Message-ID: <56DBD925.1010807@linux.intel.com> (raw)
In-Reply-To: <1457177252-7577-2-git-send-email-huaitong.han@intel.com>
On 03/05/2016 07:27 PM, Huaitong Han wrote:
> X86_FEATURE_PKU is referred to as "PKU" in the hardware documentation:
> CPUID.7.0.ECX[3]:PKU. X86_FEATURE_OSPKE is software support for pkeys,
> enumerated with CPUID.7.0.ECX[4]:OSPKE, and it reflects the setting of
> CR4.PKE(bit 22).
>
> Signed-off-by: Huaitong Han <huaitong.han@intel.com>
> ---
> arch/x86/include/asm/kvm_host.h | 3 ++-
> arch/x86/kvm/cpuid.c | 21 +++++++++++++++++++--
> arch/x86/kvm/cpuid.h | 8 ++++++++
> arch/x86/kvm/x86.c | 9 ++++++---
> 4 files changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 44adbb8..2867626 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -83,7 +83,8 @@
> | X86_CR4_PSE | X86_CR4_PAE | X86_CR4_MCE \
> | X86_CR4_PGE | X86_CR4_PCE | X86_CR4_OSFXSR | X86_CR4_PCIDE \
> | X86_CR4_OSXSAVE | X86_CR4_SMEP | X86_CR4_FSGSBASE \
> - | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE | X86_CR4_SMAP))
> + | X86_CR4_OSXMMEXCPT | X86_CR4_VMXE | X86_CR4_SMAP \
> + | X86_CR4_PKE))
>
> #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index 6525e92..f058db5 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -81,6 +81,17 @@ int kvm_update_cpuid(struct kvm_vcpu *vcpu)
> apic->lapic_timer.timer_mode_mask = 1 << 17;
> }
>
> + best = kvm_find_cpuid_entry(vcpu, 7, 0);
> + if (!best)
> + return 0;
> +
> + /*Update OSPKE bit */
Missed a space here.
> + if (boot_cpu_has(X86_FEATURE_PKU) && best->function == 0x7) {
> + best->ecx &= ~F(OSPKE);
> + if (kvm_read_cr4_bits(vcpu, X86_CR4_PKE))
> + best->ecx |= F(OSPKE);
> + }
> +
> best = kvm_find_cpuid_entry(vcpu, 0xD, 0);
> if (!best) {
> vcpu->arch.guest_supported_xcr0 = 0;
> @@ -354,6 +365,9 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
> const u32 kvm_supported_word10_x86_features =
> F(XSAVEOPT) | F(XSAVEC) | F(XGETBV1) | f_xsaves;
>
> + /* cpuid 7.0.ecx*/
> + const u32 kvm_supported_word11_x86_features = F(PKU) | 0 /*OSPKE*/;
> +
> /* all calls to cpuid_count() should be made on the same cpu */
> get_cpu();
>
> @@ -431,10 +445,13 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
> cpuid_mask(&entry->ebx, 9);
> // TSC_ADJUST is emulated
> entry->ebx |= F(TSC_ADJUST);
> - } else
> + entry->ecx &= kvm_supported_word11_x86_features;
> + cpuid_mask(&entry->ecx, 13);
Can we use a meaningful name defined by cpuid_leafs instead of the raw number?
next prev parent reply other threads:[~2016-03-06 7:16 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-05 11:27 [PATCH V4 0/7] KVM, pkeys: add memory protection-key support Huaitong Han
2016-03-05 11:27 ` [PATCH V4 1/7] KVM, pkeys: expose CPUID/CR4 to guest Huaitong Han
2016-03-06 7:15 ` Xiao Guangrong [this message]
2016-03-06 23:20 ` Paolo Bonzini
2016-03-08 7:39 ` Xiao Guangrong
2016-03-08 7:58 ` Paolo Bonzini
2016-03-05 11:27 ` [PATCH V4 2/7] KVM, pkeys: disable pkeys for guests in non-paging mode Huaitong Han
2016-03-06 7:19 ` Xiao Guangrong
2016-03-08 12:09 ` Yang Zhang
2016-03-08 12:11 ` Paolo Bonzini
2016-03-08 13:02 ` Yang Zhang
2016-03-05 11:27 ` [PATCH V4 3/7] KVM, pkeys: update memeory permission bitmask for pkeys Huaitong Han
2016-03-06 7:42 ` Xiao Guangrong
2016-03-06 23:14 ` Paolo Bonzini
2016-03-08 7:35 ` Xiao Guangrong
2016-03-08 8:29 ` Paolo Bonzini
2016-03-08 9:19 ` Xiao Guangrong
2016-03-08 10:01 ` Paolo Bonzini
2016-03-09 5:03 ` Xiao Guangrong
2016-03-09 8:10 ` Paolo Bonzini
2016-03-05 11:27 ` [PATCH V4 4/7] KVM, pkeys: add pkeys support for permission_fault logic Huaitong Han
2016-03-06 8:00 ` Xiao Guangrong
2016-03-06 20:36 ` Paolo Bonzini
2016-03-06 23:29 ` Paolo Bonzini
2016-03-08 5:57 ` Xiao Guangrong
2016-03-05 11:27 ` [PATCH V4 5/7] KVM, pkeys: Add pkeys support for gva_to_gpa funcions Huaitong Han
2016-03-06 8:01 ` Xiao Guangrong
2016-03-06 21:33 ` Paolo Bonzini
2016-03-05 11:27 ` [PATCH V4 6/7] KVM, pkeys: add pkeys support for xsave state Huaitong Han
2016-03-06 8:27 ` Xiao Guangrong
2016-03-05 11:27 ` [PATCH V4 7/7] KVM, pkeys: disable PKU feature without ept Huaitong Han
2016-03-06 9:28 ` Xiao Guangrong
2016-03-06 20:32 ` Paolo Bonzini
2016-03-08 5:54 ` Xiao Guangrong
2016-03-08 8:47 ` Paolo Bonzini
2016-03-08 9:32 ` Xiao Guangrong
2016-03-08 10:02 ` Paolo Bonzini
2016-03-09 5:51 ` Xiao Guangrong
2016-03-09 6:37 ` Yang Zhang
2016-03-09 7:21 ` Xiao Guangrong
2016-03-09 7:41 ` Yang Zhang
2016-03-09 7:50 ` Xiao Guangrong
2016-03-09 8:00 ` Yang Zhang
2016-03-09 8:05 ` Xiao Guangrong
2016-03-09 8:18 ` Paolo Bonzini
2016-03-09 8:13 ` Paolo Bonzini
2016-03-09 6:24 ` Yang Zhang
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=56DBD925.1010807@linux.intel.com \
--to=guangrong.xiao@linux.intel.com \
--cc=gleb@kernel.org \
--cc=huaitong.han@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.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 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.