public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
To: Gleb Natapov <gleb@redhat.com>
Cc: kvm@vger.kernel.org, Jun Nakajima <jun.nakajima@intel.com>,
	Yang Zhang <yang.z.zhang@intel.com>,
	pbonzini@redhat.com
Subject: Re: [PATCH v4 04/13] nEPT: Move common code to paging_tmpl.h
Date: Wed, 31 Jul 2013 16:02:49 +0800	[thread overview]
Message-ID: <51F8C4A9.4070502@linux.vnet.ibm.com> (raw)
In-Reply-To: <1374750001-28527-5-git-send-email-gleb@redhat.com>

On 07/25/2013 06:59 PM, Gleb Natapov wrote:
> From: Nadav Har'El <nyh@il.ibm.com>
> 
> For preparation, we just move gpte_access(), prefetch_invalid_gpte(),
> s_rsvd_bits_set(), protect_clean_gpte() and is_dirty_gpte() from mmu.c
> to paging_tmpl.h.
> 
> Signed-off-by: Nadav Har'El <nyh@il.ibm.com>
> Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
> Signed-off-by: Xinhao Xu <xinhao.xu@intel.com>
> Signed-off-by: Yang Zhang <yang.z.zhang@Intel.com>
> Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> ---
>  arch/x86/kvm/mmu.c         |   55 ------------------------------
>  arch/x86/kvm/paging_tmpl.h |   80 +++++++++++++++++++++++++++++++++++++-------
>  2 files changed, 68 insertions(+), 67 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 3a9493a..4c4274d 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -331,11 +331,6 @@ static int is_large_pte(u64 pte)
>  	return pte & PT_PAGE_SIZE_MASK;
>  }
> 
> -static int is_dirty_gpte(unsigned long pte)
> -{
> -	return pte & PT_DIRTY_MASK;
> -}
> -
>  static int is_rmap_spte(u64 pte)
>  {
>  	return is_shadow_present_pte(pte);
> @@ -2574,14 +2569,6 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
>  	mmu_free_roots(vcpu);
>  }
> 
> -static bool is_rsvd_bits_set(struct kvm_mmu *mmu, u64 gpte, int level)
> -{
> -	int bit7;
> -
> -	bit7 = (gpte >> 7) & 1;
> -	return (gpte & mmu->rsvd_bits_mask[bit7][level-1]) != 0;
> -}
> -
>  static pfn_t pte_prefetch_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn,
>  				     bool no_dirty_log)
>  {
> @@ -2594,26 +2581,6 @@ static pfn_t pte_prefetch_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn,
>  	return gfn_to_pfn_memslot_atomic(slot, gfn);
>  }
> 
> -static bool prefetch_invalid_gpte(struct kvm_vcpu *vcpu,
> -				  struct kvm_mmu_page *sp, u64 *spte,
> -				  u64 gpte)
> -{
> -	if (is_rsvd_bits_set(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL))
> -		goto no_present;
> -
> -	if (!is_present_gpte(gpte))
> -		goto no_present;
> -
> -	if (!(gpte & PT_ACCESSED_MASK))
> -		goto no_present;
> -
> -	return false;
> -
> -no_present:
> -	drop_spte(vcpu->kvm, spte);
> -	return true;
> -}
> -
>  static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu,
>  				    struct kvm_mmu_page *sp,
>  				    u64 *start, u64 *end)
> @@ -3501,18 +3468,6 @@ static void paging_free(struct kvm_vcpu *vcpu)
>  	nonpaging_free(vcpu);
>  }
> 
> -static inline void protect_clean_gpte(unsigned *access, unsigned gpte)
> -{
> -	unsigned mask;
> -
> -	BUILD_BUG_ON(PT_WRITABLE_MASK != ACC_WRITE_MASK);
> -
> -	mask = (unsigned)~ACC_WRITE_MASK;
> -	/* Allow write access to dirty gptes */
> -	mask |= (gpte >> (PT_DIRTY_SHIFT - PT_WRITABLE_SHIFT)) & PT_WRITABLE_MASK;
> -	*access &= mask;
> -}
> -
>  static bool sync_mmio_spte(struct kvm *kvm, u64 *sptep, gfn_t gfn,
>  			   unsigned access, int *nr_present)
>  {
> @@ -3530,16 +3485,6 @@ static bool sync_mmio_spte(struct kvm *kvm, u64 *sptep, gfn_t gfn,
>  	return false;
>  }
> 
> -static inline unsigned gpte_access(struct kvm_vcpu *vcpu, u64 gpte)
> -{
> -	unsigned access;
> -
> -	access = (gpte & (PT_WRITABLE_MASK | PT_USER_MASK)) | ACC_EXEC_MASK;
> -	access &= ~(gpte >> PT64_NX_SHIFT);
> -
> -	return access;
> -}
> -
>  static inline bool is_last_gpte(struct kvm_mmu *mmu, unsigned level, unsigned gpte)
>  {
>  	unsigned index;
> diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
> index 7769699..fb26ca9 100644
> --- a/arch/x86/kvm/paging_tmpl.h
> +++ b/arch/x86/kvm/paging_tmpl.h
> @@ -80,6 +80,31 @@ static gfn_t gpte_to_gfn_lvl(pt_element_t gpte, int lvl)
>  	return (gpte & PT_LVL_ADDR_MASK(lvl)) >> PAGE_SHIFT;
>  }
> 
> +static inline void FNAME(protect_clean_gpte)(unsigned *access, unsigned gpte)
> +{
> +	unsigned mask;
> +
> +	BUILD_BUG_ON(PT_WRITABLE_MASK != ACC_WRITE_MASK);
> +
> +	mask = (unsigned)~ACC_WRITE_MASK;
> +	/* Allow write access to dirty gptes */
> +	mask |= (gpte >> (PT_DIRTY_SHIFT - PT_WRITABLE_SHIFT)) & PT_WRITABLE_MASK;
> +	*access &= mask;
> +}
> +
> +static bool FNAME(is_rsvd_bits_set)(struct kvm_mmu *mmu, u64 gpte, int level)
> +{
> +	int bit7;
> +
> +	bit7 = (gpte >> 7) & 1;
> +	return (gpte & mmu->rsvd_bits_mask[bit7][level-1]) != 0;
> +}
> +
> +static inline int FNAME(is_present_gpte)(unsigned long pte)
> +{
> +	return is_present_gpte(pte);
> +}

It is adding a new function not just move and failed to mention it in the
change log. :)

> +
>  static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
>  			       pt_element_t __user *ptep_user, unsigned index,
>  			       pt_element_t orig_pte, pt_element_t new_pte)
> @@ -103,6 +128,36 @@ static int FNAME(cmpxchg_gpte)(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu,
>  	return (ret != orig_pte);
>  }
> 
> +static bool FNAME(prefetch_invalid_gpte)(struct kvm_vcpu *vcpu,
> +				  struct kvm_mmu_page *sp, u64 *spte,
> +				  u64 gpte)
> +{
> +	if (FNAME(is_rsvd_bits_set)(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL))
> +		goto no_present;
> +
> +	if (!FNAME(is_present_gpte)(gpte))
> +		goto no_present;
> +
> +	if (!(gpte & PT_ACCESSED_MASK))
> +		goto no_present;
> +
> +	return false;
> +
> +no_present:
> +	drop_spte(vcpu->kvm, spte);
> +	return true;
> +}
> +
> +static inline unsigned FNAME(gpte_access)(struct kvm_vcpu *vcpu, u64 gpte)
> +{
> +	unsigned access;
> +
> +	access = (gpte & (PT_WRITABLE_MASK | PT_USER_MASK)) | ACC_EXEC_MASK;
> +	access &= ~(gpte >> PT64_NX_SHIFT);
> +
> +	return access;
> +}
> +
>  static int FNAME(update_accessed_dirty_bits)(struct kvm_vcpu *vcpu,
>  					     struct kvm_mmu *mmu,
>  					     struct guest_walker *walker,
> @@ -123,7 +178,8 @@ static int FNAME(update_accessed_dirty_bits)(struct kvm_vcpu *vcpu,
>  			trace_kvm_mmu_set_accessed_bit(table_gfn, index, sizeof(pte));
>  			pte |= PT_ACCESSED_MASK;
>  		}
> -		if (level == walker->level && write_fault && !is_dirty_gpte(pte)) {
> +		if (level == walker->level && write_fault &&
> +				!(pte & PT_DIRTY_MASK)) {

Why use the raw code instead of the function? Since it is the only user of
this function, so drop the function?

Others look good to me.

Reviewed-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>


  reply	other threads:[~2013-07-31  8:02 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-25 10:59 [PATCH v4 00/13] Nested EPT Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 01/13] nEPT: Support LOAD_IA32_EFER entry/exit controls for L1 Gleb Natapov
2013-07-29  8:32   ` Paolo Bonzini
2013-07-29 13:12     ` Gleb Natapov
2013-07-29 14:13       ` Paolo Bonzini
2013-07-25 10:59 ` [PATCH v4 02/13] nEPT: Fix cr3 handling in nested exit and entry Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 03/13] nEPT: Fix wrong test in kvm_set_cr3 Gleb Natapov
2013-07-29  8:36   ` Paolo Bonzini
2013-07-29 10:43     ` Gleb Natapov
2013-07-31  8:02   ` Xiao Guangrong
2013-07-25 10:59 ` [PATCH v4 04/13] nEPT: Move common code to paging_tmpl.h Gleb Natapov
2013-07-31  8:02   ` Xiao Guangrong [this message]
2013-07-31  8:36     ` Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 05/13] nEPT: make guest's A/D bits depends on guest's paging mode Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 06/13] nEPT: Add EPT tables support to paging_tmpl.h Gleb Natapov
2013-07-29  9:48   ` Paolo Bonzini
2013-07-29 11:33     ` Gleb Natapov
2013-07-29 11:55       ` Paolo Bonzini
2013-07-29 12:24         ` Gleb Natapov
2013-07-29 13:19           ` Paolo Bonzini
2013-07-29 13:27             ` Gleb Natapov
2013-07-29 14:15               ` Paolo Bonzini
2013-07-29 16:14                 ` Gleb Natapov
2013-07-29 16:28                   ` Paolo Bonzini
2013-07-29 16:43                     ` Gleb Natapov
2013-07-29 17:06                       ` Paolo Bonzini
2013-07-29 17:11                         ` Gleb Natapov
2013-07-30 10:03   ` Paolo Bonzini
2013-07-30 11:56     ` Gleb Natapov
2013-07-30 12:13       ` Paolo Bonzini
2013-07-30 14:22         ` Gleb Natapov
2013-07-30 14:36           ` Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 07/13] nEPT: Redefine EPT-specific link_shadow_page() Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 08/13] nEPT: Nested INVEPT Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 09/13] nEPT: Add nEPT violation/misconfigration support Gleb Natapov
2013-07-29  8:59   ` Paolo Bonzini
2013-07-29 10:52     ` Gleb Natapov
2013-07-29 10:59       ` Paolo Bonzini
2013-07-29 11:43         ` Gleb Natapov
2013-07-29 12:05           ` Paolo Bonzini
2013-07-29 12:34             ` Gleb Natapov
2013-07-29 13:11               ` Paolo Bonzini
2013-07-29 13:20                 ` Gleb Natapov
2013-07-29 14:12                   ` Paolo Bonzini
2013-07-29 16:24                     ` Gleb Natapov
2013-07-29 16:36                       ` Paolo Bonzini
2013-07-29 16:54                         ` Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 10/13] nEPT: MMU context for nested EPT Gleb Natapov
2013-07-25 10:59 ` [PATCH v4 11/13] nEPT: Advertise EPT to L1 Gleb Natapov
2013-07-29  9:21   ` Paolo Bonzini
2013-07-29 11:11     ` Gleb Natapov
2013-07-29 11:33       ` Paolo Bonzini
2013-07-29 11:35         ` Gleb Natapov
2013-07-25 11:00 ` [PATCH v4 12/13] nEPT: Some additional comments Gleb Natapov
2013-07-25 11:00 ` [PATCH v4 13/13] nEPT: Miscelleneous cleanups Gleb Natapov

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=51F8C4A9.4070502@linux.vnet.ibm.com \
    --to=xiaoguangrong@linux.vnet.ibm.com \
    --cc=gleb@redhat.com \
    --cc=jun.nakajima@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=yang.z.zhang@intel.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