public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Yang Zhang <yang.zhang.wz@gmail.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: junkang.fjk@alibaba-inc.com
Subject: Re: [PATCH 1/2] KVM: x86: simplify handling of PKRU
Date: Thu, 24 Aug 2017 11:19:33 +0200	[thread overview]
Message-ID: <40adf946-79ad-87cd-8bfd-6db4dfdbefc3@redhat.com> (raw)
In-Reply-To: <8b7cd59e-05b9-e8c4-b686-8a3fda88c191@gmail.com>

On 24/08/2017 11:09, Yang Zhang wrote:
>> +    if (static_cpu_has(X86_FEATURE_OSPKE) &&
> 
> We expose protection key to VM without check whether OSPKE is enabled or
> not. Why not check guest's cpuid here which also can avoid unnecessary
> access to pkru?

Checking guest CPUID is pretty slow.  We could check CR4.PKE though.

Also, using static_cpu_has with OSPKE is probably wrong.  But if we do
check CR4.PKE, we can check X86_FEATURE_PKU instead, so something like

	if (static_cpu_has(X86_FEATURE_PKU) &&
	    kvm_read_cr4_bits(vcpu, X86_CR4_PKE) &&
	    vcpu->arch.pkru != vmx->host_pkru)

... but then, kvm_read_cr4_bits is also pretty slow---and we don't
really need it, since all CR4 writes cause a vmexit.  So for now I'd
stay with this patch, only s/static_cpu_has/boot_cpu_has/g.

Of course you can send improvements on top!

Paolo

>> +        vcpu->arch.pkru != vmx->host_pkru)
>> +        __write_pkru(vcpu->arch.pkru); 

  reply	other threads:[~2017-08-24  9:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 21:26 [PATCH 0/2] KVM, pkeys: fix handling of PKRU across migration Paolo Bonzini
2017-08-23 21:26 ` [PATCH 1/2] KVM: x86: simplify handling of PKRU Paolo Bonzini
2017-08-24  9:09   ` Yang Zhang
2017-08-24  9:19     ` Paolo Bonzini [this message]
2017-08-24 10:05       ` Yang Zhang
2017-08-24 10:14         ` Paolo Bonzini
2017-08-23 21:26 ` [PATCH 2/2] KVM, pkeys: do not use PKRU value in vcpu->arch.guest_fpu.state Paolo Bonzini

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=40adf946-79ad-87cd-8bfd-6db4dfdbefc3@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=junkang.fjk@alibaba-inc.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yang.zhang.wz@gmail.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