iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
To: Alex Williamson
	<alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: "iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
	<iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: Re: [PATCH v4 2/3] vfio/iommu_type1: add new VFIO_TYPE1_NESTING_IOMMU IOMMU type
Date: Thu, 25 Sep 2014 16:07:14 +0100	[thread overview]
Message-ID: <20140925150714.GP20043@arm.com> (raw)
In-Reply-To: <1411582999.24563.110.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>

Hi Alex,

On Wed, Sep 24, 2014 at 07:23:19PM +0100, Alex Williamson wrote:
> On Wed, 2014-09-24 at 10:21 +0100, Will Deacon wrote:
> > VFIO allows devices to be safely handed off to userspace by putting
> > them behind an IOMMU configured to ensure DMA and interrupt isolation.
> > This enables userspace KVM clients, such as kvmtool and qemu, to further
> > map the device into a virtual machine.
> > 
> > With IOMMUs such as the ARM SMMU, it is then possible to provide SMMU
> > translation services to the guest operating system, which are nested
> > with the existing translation installed by VFIO. However, enabling this
> > feature means that the IOMMU driver must be informed that the VFIO domain
> > is being created for the purposes of nested translation.
> > 
> > This patch adds a new IOMMU type (VFIO_TYPE1_NESTING_IOMMU) to the VFIO
> > type-1 driver. The new IOMMU type acts identically to the
> > VFIO_TYPE1v2_IOMMU type, but additionally sets the DOMAIN_ATTR_NESTING
> > attribute on its IOMMU domains.

[...]

> > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> > index 0734fbe5b651..d15b00700a31 100644
> > --- a/drivers/vfio/vfio_iommu_type1.c
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -57,7 +57,8 @@ struct vfio_iommu {
> >  	struct list_head	domain_list;
> >  	struct mutex		lock;
> >  	struct rb_root		dma_list;
> > -	bool v2;
> > +	bool			v2;
> > +	bool			nesting;
> >  };
> >  
> >  struct vfio_domain {
> > @@ -671,7 +672,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
> >  	struct vfio_group *group, *g;
> >  	struct vfio_domain *domain, *d;
> >  	struct bus_type *bus = NULL;
> > -	int ret;
> > +	int ret, attr = 1;
> >  
> >  	mutex_lock(&iommu->lock);
> >  
> > @@ -705,6 +706,13 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
> >  		goto out_free;
> >  	}
> >  
> > +	if (iommu->nesting) {
> 
> nit, attr declaration could be moved here

Sure.

> > +		ret = iommu_domain_set_attr(domain->domain, DOMAIN_ATTR_NESTING,
> > +					    &attr);
> > +		if (ret)
> > +			goto out_domain;
> > +	}
> > +
> >  	ret = iommu_attach_group(domain->domain, iommu_group);
> >  	if (ret)
> >  		goto out_domain;
> > @@ -819,17 +827,25 @@ static void *vfio_iommu_type1_open(unsigned long arg)
> >  {
> >  	struct vfio_iommu *iommu;
> >  
> > -	if (arg != VFIO_TYPE1_IOMMU && arg != VFIO_TYPE1v2_IOMMU)
> > -		return ERR_PTR(-EINVAL);
> > -
> >  	iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
> >  	if (!iommu)
> >  		return ERR_PTR(-ENOMEM);
> >  
> > +	switch (arg) {
> > +	case VFIO_TYPE1_IOMMU:
> > +		break;
> > +	case VFIO_TYPE1_NESTING_IOMMU:
> > +		iommu->nesting = true;
> > +	case VFIO_TYPE1v2_IOMMU:
> > +		iommu->v2 = true;
> > +		break;
> > +	default:
> 
> Leaks iommu

Yikes, sorry about that. Will fix.

Will

  parent reply	other threads:[~2014-09-25 15:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24  9:21 [PATCH v4 0/3] Support for nesting IOMMUs in VFIO Will Deacon
     [not found] ` <1411550485-32483-1-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-09-24  9:21   ` [PATCH v4 1/3] iommu: introduce domain attribute for nesting IOMMUs Will Deacon
     [not found]     ` <1411550485-32483-2-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-09-25 14:32       ` Joerg Roedel
     [not found]         ` <20140925143233.GB8306-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2014-09-25 15:05           ` Will Deacon
2014-09-24  9:21   ` [PATCH v4 2/3] vfio/iommu_type1: add new VFIO_TYPE1_NESTING_IOMMU IOMMU type Will Deacon
     [not found]     ` <1411550485-32483-3-git-send-email-will.deacon-5wv7dgnIgG8@public.gmane.org>
2014-09-24 18:23       ` Alex Williamson
     [not found]         ` <1411582999.24563.110.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2014-09-25 15:07           ` Will Deacon [this message]
2014-09-24  9:21   ` [PATCH v4 3/3] iommu/arm-smmu: add support for DOMAIN_ATTR_NESTING attribute Will Deacon
2014-09-24 18:25   ` [PATCH v4 0/3] Support for nesting IOMMUs in VFIO Alex Williamson

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=20140925150714.GP20043@arm.com \
    --to=will.deacon-5wv7dgnigg8@public.gmane.org \
    --cc=alex.williamson-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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).