kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xiao Guangrong <guangrong.xiao@linux.intel.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: huaitong.han@intel.com
Subject: Re: [RFC PATCH 1/2] KVM: MMU: precompute page fault error code
Date: Thu, 10 Mar 2016 22:01:32 +0800	[thread overview]
Message-ID: <56E17E3C.30407@linux.intel.com> (raw)
In-Reply-To: <1457437538-65867-2-git-send-email-pbonzini@redhat.com>



On 03/08/2016 07:45 PM, Paolo Bonzini wrote:
> For the next patch, we will want to filter PFERR_FETCH_MASK away early,
> and not pass it to permission_fault if neither NX nor SMEP are enabled.
> Prepare for the change.

Why it is needed? It is much easier to drop PFEC.F in
update_permission_bitmask().

>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   arch/x86/kvm/mmu.c         |  2 +-
>   arch/x86/kvm/paging_tmpl.h | 26 +++++++++++++++-----------
>   2 files changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 2463de0b935c..e57f7be061e3 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -3883,7 +3883,7 @@ static void update_permission_bitmask(struct kvm_vcpu *vcpu,
>   			u = bit & ACC_USER_MASK;
>
>   			if (!ept) {
> -				/* Not really needed: !nx will cause pte.nx to fault */
> +				/* Not really needed: if !nx, ff will always be zero */
>   				x |= !mmu->nx;
>   				/* Allow supervisor writes if !cr0.wp */
>   				w |= !is_write_protection(vcpu) && !uf;
> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
> index 6013f3685ef4..285858d3223b 100644
> --- a/arch/x86/kvm/paging_tmpl.h
> +++ b/arch/x86/kvm/paging_tmpl.h
> @@ -272,13 +272,24 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
>   	gpa_t pte_gpa;
>   	int offset;
>   	const int write_fault = access & PFERR_WRITE_MASK;
> -	const int user_fault  = access & PFERR_USER_MASK;
> -	const int fetch_fault = access & PFERR_FETCH_MASK;
> -	u16 errcode = 0;
> +	u16 errcode;
>   	gpa_t real_gpa;
>   	gfn_t gfn;
>
>   	trace_kvm_mmu_pagetable_walk(addr, access);
> +
> +	/*
> +	 * Do not modify PFERR_FETCH_MASK in access.  It is used later in the call to
> +	 * mmu->translate_gpa and, when nested virtualization is in use, the X or NX
> +	 * bit of nested page tables always applies---even if NX and SMEP are disabled
> +	 * in the guest.
> +	 *
> +	 * TODO: cache the result of the NX and SMEP test in struct kvm_mmu?
> +	 */
> +	errcode = access;
> +	if (!(mmu->nx || kvm_read_cr4_bits(vcpu, X86_CR4_SMEP)))
> +		errcode &= ~PFERR_FETCH_MASK;
> +

PFEC.P might be set since it is copied from @access.

And the workload is moved from rare path to the common path...

>   retry_walk:
>   	walker->level = mmu->root_level;
>   	pte           = mmu->get_cr3(vcpu);
> @@ -389,9 +400,7 @@ retry_walk:
>
>   	if (unlikely(!accessed_dirty)) {
>   		ret = FNAME(update_accessed_dirty_bits)(vcpu, mmu, walker, write_fault);
> -		if (unlikely(ret < 0))
> -			goto error;
> -		else if (ret)
> +		if (ret > 0)
>   			goto retry_walk;

So it returns normally even if update_accessed_dirty_bits() failed.

  reply	other threads:[~2016-03-10 14:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-08 11:45 [RFC PATCH 0/2] KVM: MMU: return page fault error code from permission_fault Paolo Bonzini
2016-03-08 11:45 ` [RFC PATCH 1/2] KVM: MMU: precompute page fault error code Paolo Bonzini
2016-03-10 14:01   ` Xiao Guangrong [this message]
2016-03-10 14:07     ` Paolo Bonzini
2016-03-08 11:45 ` [RFC PATCH 2/2] KVM: MMU: return page fault error code from permission_fault Paolo Bonzini
2016-03-10 14:03   ` Xiao Guangrong
2016-03-10 14:04     ` 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=56E17E3C.30407@linux.intel.com \
    --to=guangrong.xiao@linux.intel.com \
    --cc=huaitong.han@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@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 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).