linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
To: Paul Mackerras <paulus@ozlabs.org>,
	linuxppc-dev@ozlabs.org, kvm@vger.kernel.org,
	kvm-ppc@vger.kernel.org
Subject: Re: [PATCH 14/18] KVM: PPC: Book3S HV: MMU notifier callbacks for radix guests
Date: Mon, 23 Jan 2017 14:21:00 +1100	[thread overview]
Message-ID: <1485141660.8172.6.camel@gmail.com> (raw)
In-Reply-To: <1484212046-29591-15-git-send-email-paulus@ozlabs.org>

On Thu, 2017-01-12 at 20:07 +1100, Paul Mackerras wrote:
> This adapts our implementations of the MMU notifier callbacks
> (unmap_hva, unmap_hva_range, age_hva, test_age_hva, set_spte_hva)
> to call radix functions when the guest is using radix.  These
> implementations are much simpler than for HPT guests because we
> have only one PTE to deal with, so we don't need to traverse
> rmap chains.
> 
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
> ---
>  arch/powerpc/include/asm/kvm_book3s.h  |  6 ++++
>  arch/powerpc/kvm/book3s_64_mmu_hv.c    | 64 +++++++++++++++++++++++-
> ----------
>  arch/powerpc/kvm/book3s_64_mmu_radix.c | 54
> ++++++++++++++++++++++++++++
>  3 files changed, 103 insertions(+), 21 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_book3s.h
> b/arch/powerpc/include/asm/kvm_book3s.h
> index ff5cd5c..952cc4b 100644
> --- a/arch/powerpc/include/asm/kvm_book3s.h
> +++ b/arch/powerpc/include/asm/kvm_book3s.h
> @@ -192,6 +192,12 @@ extern int kvmppc_mmu_radix_xlate(struct
> kvm_vcpu *vcpu, gva_t eaddr,
>  extern void kvmppc_free_radix(struct kvm *kvm);
>  extern int kvmppc_radix_init(void);
>  extern void kvmppc_radix_exit(void);
> +extern int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
> +			unsigned long gfn);
> +extern int kvm_age_radix(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
> +			unsigned long gfn);
> +extern int kvm_test_age_radix(struct kvm *kvm, struct
> kvm_memory_slot *memslot,
> +			unsigned long gfn);
>  
>  /* XXX remove this export when load_last_inst() is generic */
>  extern int kvmppc_ld(struct kvm_vcpu *vcpu, ulong *eaddr, int size,
> void *ptr, bool data);
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 57690c2..fbb3de4 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -701,12 +701,13 @@ static void kvmppc_rmap_reset(struct kvm *kvm)
>  	srcu_read_unlock(&kvm->srcu, srcu_idx);
>  }
>  
> +typedef int (*hva_handler_fn)(struct kvm *kvm, struct
> kvm_memory_slot *memslot,
> +			      unsigned long gfn);
> +
>  static int kvm_handle_hva_range(struct kvm *kvm,
>  				unsigned long start,
>  				unsigned long end,
> -				int (*handler)(struct kvm *kvm,
> -					       unsigned long *rmapp,
> -					       unsigned long gfn))
> +				hva_handler_fn handler)
>  {
>  	int ret;
>  	int retval = 0;
> @@ -731,9 +732,7 @@ static int kvm_handle_hva_range(struct kvm *kvm,
>  		gfn_end = hva_to_gfn_memslot(hva_end + PAGE_SIZE -
> 1, memslot);
>  
>  		for (; gfn < gfn_end; ++gfn) {
> -			gfn_t gfn_offset = gfn - memslot->base_gfn;
> -
> -			ret = handler(kvm, &memslot-
> >arch.rmap[gfn_offset], gfn);
> +			ret = handler(kvm, memslot, gfn);
>  			retval |= ret;
>  		}
>  	}
> @@ -742,20 +741,21 @@ static int kvm_handle_hva_range(struct kvm
> *kvm,
>  }
>  
>  static int kvm_handle_hva(struct kvm *kvm, unsigned long hva,
> -			  int (*handler)(struct kvm *kvm, unsigned
> long *rmapp,
> -					 unsigned long gfn))
> +			  hva_handler_fn handler)
>  {
>  	return kvm_handle_hva_range(kvm, hva, hva + 1, handler);
>  }
>  
> -static int kvm_unmap_rmapp(struct kvm *kvm, unsigned long *rmapp,
> +static int kvm_unmap_rmapp(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
>  			   unsigned long gfn)
>  {
>  	struct revmap_entry *rev = kvm->arch.revmap;
>  	unsigned long h, i, j;
>  	__be64 *hptep;
>  	unsigned long ptel, psize, rcbits;
> +	unsigned long *rmapp;
>  
> +	rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
>  	for (;;) {
>  		lock_rmap(rmapp);
>  		if (!(*rmapp & KVMPPC_RMAP_PRESENT)) {
> @@ -816,26 +816,36 @@ static int kvm_unmap_rmapp(struct kvm *kvm,
> unsigned long *rmapp,
>  
>  int kvm_unmap_hva_hv(struct kvm *kvm, unsigned long hva)
>  {
> -	kvm_handle_hva(kvm, hva, kvm_unmap_rmapp);
> +	hva_handler_fn handler;
> +
> +	handler = kvm->arch.radix ? kvm_unmap_radix : 
kvm_is_radix() for consistency?
> kvm_unmap_rmapp;
> +	kvm_handle_hva(kvm, hva, handler);
>  	return 0;
>  }
>  
>  int kvm_unmap_hva_range_hv(struct kvm *kvm, unsigned long start,
> unsigned long end)
>  {
> -	kvm_handle_hva_range(kvm, start, end, kvm_unmap_rmapp);
> +	hva_handler_fn handler;
> +
> +	handler = kvm->arch.radix ? kvm_unmap_radix : 
ditto
> kvm_unmap_rmapp;
> +	kvm_handle_hva_range(kvm, start, end, handler);
>  	return 0;
>  }
>  
>  void kvmppc_core_flush_memslot_hv(struct kvm *kvm,
>  				  struct kvm_memory_slot *memslot)
>  {
> -	unsigned long *rmapp;
>  	unsigned long gfn;
>  	unsigned long n;
> +	unsigned long *rmapp;
>  
> -	rmapp = memslot->arch.rmap;
>  	gfn = memslot->base_gfn;
> -	for (n = memslot->npages; n; --n) {
> +	rmapp = memslot->arch.rmap;
> +	for (n = memslot->npages; n; --n, ++gfn) {
> +		if (kvm->arch.radix) {
ditto
> +			kvm_unmap_radix(kvm, memslot, gfn);
> +			continue;
> +		}
>  		/*
>  		 * Testing the present bit without locking is OK
> because
>  		 * the memslot has been marked invalid already, and
> hence
> @@ -843,20 +853,21 @@ void kvmppc_core_flush_memslot_hv(struct kvm
> *kvm,
>  		 * thus the present bit can't go from 0 to 1.
>  		 */
>  		if (*rmapp & KVMPPC_RMAP_PRESENT)
> -			kvm_unmap_rmapp(kvm, rmapp, gfn);
> +			kvm_unmap_rmapp(kvm, memslot, gfn);
>  		++rmapp;
> -		++gfn;
>  	}
>  }
>  
> -static int kvm_age_rmapp(struct kvm *kvm, unsigned long *rmapp,
> +static int kvm_age_rmapp(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
>  			 unsigned long gfn)
>  {
>  	struct revmap_entry *rev = kvm->arch.revmap;
>  	unsigned long head, i, j;
>  	__be64 *hptep;
>  	int ret = 0;
> +	unsigned long *rmapp;
>  
> +	rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
>   retry:
>  	lock_rmap(rmapp);
>  	if (*rmapp & KVMPPC_RMAP_REFERENCED) {
> @@ -904,17 +915,22 @@ static int kvm_age_rmapp(struct kvm *kvm,
> unsigned long *rmapp,
>  
>  int kvm_age_hva_hv(struct kvm *kvm, unsigned long start, unsigned
> long end)
>  {
> -	return kvm_handle_hva_range(kvm, start, end, kvm_age_rmapp);
> +	hva_handler_fn handler;
> +
> +	handler = kvm->arch.radix ? kvm_age_radix : kvm_age_rmapp;
ditto
> +	return kvm_handle_hva_range(kvm, start, end, handler);
>  }
>  
> -static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp,
> +static int kvm_test_age_rmapp(struct kvm *kvm, struct
> kvm_memory_slot *memslot,
>  			      unsigned long gfn)
>  {
>  	struct revmap_entry *rev = kvm->arch.revmap;
>  	unsigned long head, i, j;
>  	unsigned long *hp;
>  	int ret = 1;
> +	unsigned long *rmapp;
>  
> +	rmapp = &memslot->arch.rmap[gfn - memslot->base_gfn];
>  	if (*rmapp & KVMPPC_RMAP_REFERENCED)
>  		return 1;
>  
> @@ -940,12 +956,18 @@ static int kvm_test_age_rmapp(struct kvm *kvm,
> unsigned long *rmapp,
>  
>  int kvm_test_age_hva_hv(struct kvm *kvm, unsigned long hva)
>  {
> -	return kvm_handle_hva(kvm, hva, kvm_test_age_rmapp);
> +	hva_handler_fn handler;
> +
> +	handler = kvm->arch.radix ? kvm_test_age_radix : 
ditto
> kvm_test_age_rmapp;
> +	return kvm_handle_hva(kvm, hva, handler);
>  }
>  
>  void kvm_set_spte_hva_hv(struct kvm *kvm, unsigned long hva, pte_t
> pte)
>  {
> -	kvm_handle_hva(kvm, hva, kvm_unmap_rmapp);
> +	hva_handler_fn handler;
> +
> +	handler = kvm->arch.radix ? kvm_unmap_radix : 
ditto
> kvm_unmap_rmapp;
> +	kvm_handle_hva(kvm, hva, handler);
>  }
>  
>  static int vcpus_running(struct kvm *kvm)
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_radix.c
> b/arch/powerpc/kvm/book3s_64_mmu_radix.c
> index 865ea9b..69cabad 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_radix.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_radix.c
> @@ -463,6 +463,60 @@ int kvmppc_book3s_radix_page_fault(struct
> kvm_run *run, struct kvm_vcpu *vcpu,
>  	return ret;
>  }
>  
> +/* Called with kvm->lock held */
> +int kvm_unmap_radix(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
> +		    unsigned long gfn)
> +{
> +	pte_t *ptep;
> +	unsigned long gpa = gfn << PAGE_SHIFT;
> +	unsigned int shift;
> +
> +	ptep = __find_linux_pte_or_hugepte(kvm->arch.pgtable, gpa,
> +					   NULL, &shift);
> +	if (ptep && pte_present(*ptep)) {
> +		kvmppc_radix_update_pte(kvm, ptep, _PAGE_PRESENT, 0,
> +					gpa, shift);
> +		kvmppc_radix_tlbie_page(kvm, gpa, shift);
> +	}
> +	return 0;				
> +}
> +
> +/* Called with kvm->lock held */
> +int kvm_age_radix(struct kvm *kvm, struct kvm_memory_slot *memslot,
> +		  unsigned long gfn)
> +{
> +	pte_t *ptep;
> +	unsigned long gpa = gfn << PAGE_SHIFT;
> +	unsigned int shift;
> +	int ref = 0;
> +
> +	ptep = __find_linux_pte_or_hugepte(kvm->arch.pgtable, gpa,
> +					   NULL, &shift);
> +	if (ptep && pte_present(*ptep) && pte_young(*ptep)) {
> +		kvmppc_radix_update_pte(kvm, ptep, _PAGE_ACCESSED,
> 0,
> +					gpa, shift);
> +		/* XXX need to flush tlb here? */
> +		ref = 1;
> +	}
> +	return ref;
> +}
> +
> +/* Called with kvm->lock held */
> +int kvm_test_age_radix(struct kvm *kvm, struct kvm_memory_slot
> *memslot,
> +		       unsigned long gfn)
> +{
> +	pte_t *ptep;
> +	unsigned long gpa = gfn << PAGE_SHIFT;
> +	unsigned int shift;
> +	int ref = 0;
> +
> +	ptep = __find_linux_pte_or_hugepte(kvm->arch.pgtable, gpa,
> +					   NULL, &shift);
> +	if (ptep && pte_present(*ptep) && pte_young(*ptep))
> +		ref = 1;
> +	return ref;
> +}
> +
>  void kvmppc_free_radix(struct kvm *kvm)
>  {
>  	unsigned long ig, iu, im;

  reply	other threads:[~2017-01-23  3:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-12  9:07 [PATCH 00/18] Support for radix guest and host on POWER9 Paul Mackerras
2017-01-12  9:07 ` [PATCH 01/18] powerpc/64: Don't try to use radix MMU under a hypervisor Paul Mackerras
2017-01-12 16:48   ` Balbir Singh
2017-01-12  9:07 ` [PATCH 02/18] powerpc/64: Fixes for the ibm, client-architecture-support options Paul Mackerras
2017-01-12  9:07 ` [PATCH 03/18] powerpc/64: Always enable radix support for 64-bit Book 3S kernels Paul Mackerras
2017-01-12  9:07 ` [PATCH 04/18] powerpc/64: Enable use of radix MMU under hypervisor on POWER9 Paul Mackerras
2017-01-22  2:17   ` kbuild test robot
2017-01-12  9:07 ` [PATCH 05/18] powerpc/64: More definitions for POWER9 Paul Mackerras
2017-01-12  9:07 ` [PATCH 06/18] powerpc/64: Export pgtable_cache and pgtable_cache_add for KVM Paul Mackerras
2017-01-12  9:07 ` [PATCH 07/18] powerpc/64: Make type of partition table flush depend on partition type Paul Mackerras
2017-01-12  9:07 ` [PATCH 08/18] KVM: PPC: Book3S HV: Don't try to signal cpu -1 Paul Mackerras
2017-01-12  9:07 ` [PATCH 09/18] KVM: PPC: Book3S HV: Add userspace interfaces for POWER9 MMU Paul Mackerras
2017-01-12  9:07 ` [PATCH 10/18] KVM: PPC: Book3S HV: Set process table for HPT guests on POWER9 Paul Mackerras
2017-01-23  2:39   ` Suraj Jitindar Singh
2017-01-23  4:37     ` Paul Mackerras
2017-01-12  9:07 ` [PATCH 11/18] KVM: PPC: Book3S HV: Add basic infrastructure for radix guests Paul Mackerras
2017-01-12  9:07 ` [PATCH 12/18] KVM: PPC: Book3S HV: Modify guest entry/exit paths to handle " Paul Mackerras
2017-01-12  9:07 ` [PATCH 13/18] KVM: PPC: Book3S HV: Page table construction and page faults for " Paul Mackerras
2017-01-23  3:17   ` Suraj Jitindar Singh
2017-01-23  4:38     ` Paul Mackerras
2017-01-12  9:07 ` [PATCH 14/18] KVM: PPC: Book3S HV: MMU notifier callbacks " Paul Mackerras
2017-01-23  3:21   ` Suraj Jitindar Singh [this message]
2017-01-12  9:07 ` [PATCH 15/18] KVM: PPC: Book3S HV: Implement dirty page logging " Paul Mackerras
2017-01-12  9:07 ` [PATCH 16/18] KVM: PPC: Book3S HV: Make HPT-specific hypercalls return error in radix mode Paul Mackerras
2017-01-12  9:07 ` [PATCH 17/18] KVM: PPC: Book3S HV: Enable radix guest support Paul Mackerras
2017-01-23  3:31   ` Suraj Jitindar Singh
2017-01-12  9:07 ` [PATCH 18/18] KVM: PPC: Book3S HV: Use ASDR for HPT guests on POWER9 Paul Mackerras

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=1485141660.8172.6.camel@gmail.com \
    --to=sjitindarsingh@gmail.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=paulus@ozlabs.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;
as well as URLs for NNTP newsgroup(s).