linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: linuxppc-dev@lists.ozlabs.org, Paul Mackerras <paulus@samba.org>,
	kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH kernel v2 5/6] KVM: PPC: Move reusable bits of H_PUT_TCE handler to helpers
Date: Mon, 25 Jan 2016 11:18:06 +1100	[thread overview]
Message-ID: <20160125001806.GE27454@voom.redhat.com> (raw)
In-Reply-To: <20160125001236.GD27454@voom.redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4237 bytes --]

On Mon, Jan 25, 2016 at 11:12:36AM +1100, David Gibson wrote:
> On Thu, Jan 21, 2016 at 06:39:36PM +1100, Alexey Kardashevskiy wrote:
> > Upcoming multi-tce support (H_PUT_TCE_INDIRECT/H_STUFF_TCE hypercalls)
> > will validate TCE (not to have unexpected bits) and IO address
> > (to be within the DMA window boundaries).
> > 
> > This introduces helpers to validate TCE and IO address. The helpers are
> > exported as they compile into vmlinux (to work in realmode) and will be
> > used later by KVM kernel module in virtual mode.
> > 
> > Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> > ---
> > Changes:
> > v2:
> > * added note to the commit log about why new helpers are exported
> > * did not add a note that xxx_validate() validate TCEs for KVM (not for
> > host kernel DMA) as the helper names and file location tell what are
> > they for
> > ---
> >  arch/powerpc/include/asm/kvm_ppc.h  |  4 ++
> >  arch/powerpc/kvm/book3s_64_vio_hv.c | 92 ++++++++++++++++++++++++++++++++-----
> >  2 files changed, 84 insertions(+), 12 deletions(-)
> > 
> > diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
> > index 2241d53..9513911 100644
> > --- a/arch/powerpc/include/asm/kvm_ppc.h
> > +++ b/arch/powerpc/include/asm/kvm_ppc.h
> > @@ -166,6 +166,10 @@ extern int kvmppc_pseries_do_hcall(struct kvm_vcpu *vcpu);
> >  
> >  extern long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
> >  				struct kvm_create_spapr_tce *args);
> > +extern long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt,
> > +		unsigned long ioba, unsigned long npages);
> > +extern long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *tt,
> > +		unsigned long tce);
> >  extern long kvmppc_h_put_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
> >  			     unsigned long ioba, unsigned long tce);
> >  extern long kvmppc_h_get_tce(struct kvm_vcpu *vcpu, unsigned long liobn,
> > diff --git a/arch/powerpc/kvm/book3s_64_vio_hv.c b/arch/powerpc/kvm/book3s_64_vio_hv.c
> > index e142171..8cd3a95 100644
> > --- a/arch/powerpc/kvm/book3s_64_vio_hv.c
> > +++ b/arch/powerpc/kvm/book3s_64_vio_hv.c
> > @@ -36,6 +36,7 @@
> >  #include <asm/kvm_host.h>
> >  #include <asm/udbg.h>
> >  #include <asm/iommu.h>
> > +#include <asm/tce.h>
> >  
> >  #define TCES_PER_PAGE	(PAGE_SIZE / sizeof(u64))
> >  
> > @@ -64,18 +65,90 @@ static struct kvmppc_spapr_tce_table *kvmppc_find_table(struct kvm_vcpu *vcpu,
> >   * WARNING: This will be called in real-mode on HV KVM and virtual
> >   *          mode on PR KVM
> >   */
> > -static long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt,
> > +long kvmppc_ioba_validate(struct kvmppc_spapr_tce_table *stt,
> >  		unsigned long ioba, unsigned long npages)
> >  {
> > -	unsigned long mask = (1ULL << IOMMU_PAGE_SHIFT_4K) - 1;
> > +	unsigned long mask = IOMMU_PAGE_MASK_4K;
> >  	unsigned long idx = ioba >> IOMMU_PAGE_SHIFT_4K;
> >  	unsigned long size = stt->window_size >> IOMMU_PAGE_SHIFT_4K;
> >  
> > -	if ((ioba & mask) || (idx + npages > size))
> > +	if ((ioba & ~mask) || (idx + npages > size))
> >  		return H_PARAMETER;
> >  
> >  	return H_SUCCESS;
> >  }
> > +EXPORT_SYMBOL_GPL(kvmppc_ioba_validate);
> > +
> > +/*
> > + * Validates TCE address.
> > + * At the moment flags and page mask are validated.
> > + * As the host kernel does not access those addresses (just puts them
> > + * to the table and user space is supposed to process them), we can skip
> > + * checking other things (such as TCE is a guest RAM address or the page
> > + * was actually allocated).
> > + *
> > + * WARNING: This will be called in real-mode on HV KVM and virtual
> > + *          mode on PR KVM
> > + */
> > +long kvmppc_tce_validate(struct kvmppc_spapr_tce_table *stt,
> >  unsigned long tce)
> 
> It would be nice to write this in terms of kvmppc_ioba_validate() above.

Duh, sorry.  Realised shortly afterwards that's nonsense.  One is
looking at the IOBA, the other at the real address.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-01-25  0:43 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-21  7:39 [PATCH kernel v2 0/6] KVM: PPC: Add in-kernel multitce handling Alexey Kardashevskiy
2016-01-21  7:39 ` [PATCH kernel v2 1/6] KVM: PPC: Rework H_PUT_TCE/H_GET_TCE handlers Alexey Kardashevskiy
2016-01-22  0:42   ` David Gibson
2016-01-22  1:59     ` Alexey Kardashevskiy
2016-01-24 23:43       ` David Gibson
2016-02-11  4:11       ` Paul Mackerras
2016-01-21  7:39 ` [PATCH kernel v2 2/6] KVM: PPC: Use RCU for arch.spapr_tce_tables Alexey Kardashevskiy
2016-01-24 23:46   ` David Gibson
2016-01-21  7:39 ` [PATCH kernel v2 3/6] KVM: PPC: Account TCE-containing pages in locked_vm Alexey Kardashevskiy
2016-01-24 23:57   ` David Gibson
2016-01-21  7:39 ` [PATCH kernel v2 4/6] KVM: PPC: Replace SPAPR_TCE_SHIFT with IOMMU_PAGE_SHIFT_4K Alexey Kardashevskiy
2016-01-21  7:39 ` [PATCH kernel v2 5/6] KVM: PPC: Move reusable bits of H_PUT_TCE handler to helpers Alexey Kardashevskiy
2016-01-25  0:12   ` David Gibson
2016-01-25  0:18     ` David Gibson [this message]
2016-02-11  4:39   ` Paul Mackerras
2016-01-21  7:39 ` [PATCH kernel v2 6/6] KVM: PPC: Add support for multiple-TCE hcalls Alexey Kardashevskiy
2016-01-21  7:56   ` kbuild test robot
2016-01-21  8:09     ` Alexey Kardashevskiy
2016-01-25  0:44   ` David Gibson
2016-01-25  1:24     ` Alexey Kardashevskiy
2016-01-25  5:21       ` David Gibson
2016-02-11  5:32   ` Paul Mackerras
2016-02-12  4:54     ` Alexey Kardashevskiy
2016-02-12  5:52       ` 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=20160125001806.GE27454@voom.redhat.com \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.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).