From: Lai Jiangshan <laijs@linux.alibaba.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: Re: [PATCH] KVM: MMU: shadow nested paging does not have PKU
Date: Sat, 27 Nov 2021 09:21:29 +0800 [thread overview]
Message-ID: <2091ec8e-299a-8b3d-596e-75cf4b68fde1@linux.alibaba.com> (raw)
In-Reply-To: <20211126132131.26077-1-pbonzini@redhat.com>
On 2021/11/26 21:21, Paolo Bonzini wrote:
> Initialize the mask for PKU permissions as if CR4.PKE=0, avoiding
> incorrect interpretations of the nested hypervisor's page tables.
I think the AMD64 volume2 Architecture Programmer’s Manual does not
specify it, but it seems that for a sane NPT walk, PKU should not work
in NPT.
I once planed to set
cr0 = X86_CR0_PG | X86_CR0_WP;
cr4 = cr4 & ~(X86_CR4_SMEP | X86_CR4_SMAP | X86_CR4_PKE);
It adds X86_CR0_WP and removes smep smap just because it is always usermode
access, and it has no meaning for CR0_WP, smep, smap. Setting it like this
ways can reduce the role combination.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/mmu/mmu.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
> index 5942e9c6dd6e..a33b5361bc67 100644
> --- a/arch/x86/kvm/mmu/mmu.c
> +++ b/arch/x86/kvm/mmu/mmu.c
> @@ -4855,7 +4855,7 @@ void kvm_init_shadow_npt_mmu(struct kvm_vcpu *vcpu, unsigned long cr0,
> struct kvm_mmu *context = &vcpu->arch.guest_mmu;
> struct kvm_mmu_role_regs regs = {
> .cr0 = cr0,
> - .cr4 = cr4,
> + .cr4 = cr4 & ~X86_CR4_PKE,
> .efer = efer,
> };
> union kvm_mmu_role new_role;
> @@ -4919,7 +4919,7 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly,
> context->direct_map = false;
>
> update_permission_bitmask(context, true);
> - update_pkru_bitmask(context);
> + context->pkru_mask = 0;
It is not worth to optimize it since update_pkru_bitmask() will also just
set context->pkru_mask = 0 and then return.
> reset_rsvds_bits_mask_ept(vcpu, context, execonly);
> reset_ept_shadow_zero_bits_mask(vcpu, context, execonly);
> }
>
next prev parent reply other threads:[~2021-11-27 1:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-26 13:21 [PATCH] KVM: MMU: shadow nested paging does not have PKU Paolo Bonzini
2021-11-27 1:21 ` Lai Jiangshan [this message]
2021-11-27 10:25 ` Paolo Bonzini
2021-11-29 19:08 ` Tom Lendacky
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=2091ec8e-299a-8b3d-596e-75cf4b68fde1@linux.alibaba.com \
--to=laijs@linux.alibaba.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=stable@vger.kernel.org \
/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