Message ID | 1584880325-10561-9-git-send-email-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | vfio: expose virtual Shared Virtual Addressing to VMs | expand |
> From: Liu, Yi L <yi.l.liu@intel.com> > Sent: Sunday, March 22, 2020 8:32 PM > > From: Liu Yi L <yi.l.liu@intel.com> > > Recent years, mediated device pass-through framework (e.g. vfio-mdev) > are used to achieve flexible device sharing across domains (e.g. VMs). are->is > Also there are hardware assisted mediated pass-through solutions from > platform vendors. e.g. Intel VT-d scalable mode which supports Intel > Scalable I/O Virtualization technology. Such mdevs are called IOMMU- > backed mdevs as there are IOMMU enforced DMA isolation for such mdevs. > In kernel, IOMMU-backed mdevs are exposed to IOMMU layer by aux- > domain > concept, which means mdevs are protected by an iommu domain which is > aux-domain of its physical device. Details can be found in the KVM "by an iommu domain which is auxiliary to the domain that the kernel driver primarily uses for DMA API" > presentation from Kevin Tian. IOMMU-backed equals to IOMMU-capable. > > https://events19.linuxfoundation.org/wp-content/uploads/2017/12/\ > Hardware-Assisted-Mediated-Pass-Through-with-VFIO-Kevin-Tian-Intel.pdf > > This patch supports NESTING IOMMU for IOMMU-backed mdevs by figuring > out the physical device of an IOMMU-backed mdev and then invoking > IOMMU > requests to IOMMU layer with the physical device and the mdev's aux > domain info. "and then calling into the IOMMU layer to complete the vSVA operations on the aux domain associated with that mdev" > > With this patch, vSVA (Virtual Shared Virtual Addressing) can be used > on IOMMU-backed mdevs. > > Cc: Kevin Tian <kevin.tian@intel.com> > CC: Jacob Pan <jacob.jun.pan@linux.intel.com> > CC: Jun Tian <jun.j.tian@intel.com> > Cc: Alex Williamson <alex.williamson@redhat.com> > Cc: Eric Auger <eric.auger@redhat.com> > Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > --- > drivers/vfio/vfio_iommu_type1.c | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c > b/drivers/vfio/vfio_iommu_type1.c > index 937ec3f..d473665 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -132,6 +132,7 @@ struct vfio_regions { > > struct domain_capsule { > struct iommu_domain *domain; > + struct vfio_group *group; > void *data; > }; > > @@ -148,6 +149,7 @@ static int vfio_iommu_for_each_dev(struct > vfio_iommu *iommu, > list_for_each_entry(d, &iommu->domain_list, next) { > dc.domain = d->domain; > list_for_each_entry(g, &d->group_list, next) { > + dc.group = g; > ret = iommu_group_for_each_dev(g->iommu_group, > &dc, fn); > if (ret) > @@ -2347,7 +2349,12 @@ static int vfio_bind_gpasid_fn(struct device *dev, > void *data) > struct iommu_gpasid_bind_data *gbind_data = > (struct iommu_gpasid_bind_data *) dc->data; > > - return iommu_sva_bind_gpasid(dc->domain, dev, gbind_data); > + if (dc->group->mdev_group) > + return iommu_sva_bind_gpasid(dc->domain, > + vfio_mdev_get_iommu_device(dev), gbind_data); > + else > + return iommu_sva_bind_gpasid(dc->domain, > + dev, gbind_data); > } > > static int vfio_unbind_gpasid_fn(struct device *dev, void *data) > @@ -2356,8 +2363,13 @@ static int vfio_unbind_gpasid_fn(struct device > *dev, void *data) > struct iommu_gpasid_bind_data *gbind_data = > (struct iommu_gpasid_bind_data *) dc->data; > > - return iommu_sva_unbind_gpasid(dc->domain, dev, > + if (dc->group->mdev_group) > + return iommu_sva_unbind_gpasid(dc->domain, > + vfio_mdev_get_iommu_device(dev), > gbind_data->hpasid); > + else > + return iommu_sva_unbind_gpasid(dc->domain, dev, > + gbind_data->hpasid); > } > > /** > @@ -2429,7 +2441,12 @@ static int vfio_cache_inv_fn(struct device *dev, > void *data) > struct iommu_cache_invalidate_info *cache_inv_info = > (struct iommu_cache_invalidate_info *) dc->data; > > - return iommu_cache_invalidate(dc->domain, dev, cache_inv_info); > + if (dc->group->mdev_group) > + return iommu_cache_invalidate(dc->domain, > + vfio_mdev_get_iommu_device(dev), cache_inv_info); > + else > + return iommu_cache_invalidate(dc->domain, > + dev, cache_inv_info); > } possibly above could be simplified, e.g. static struct device *vfio_get_iommu_device(struct vfio_group *group, struct device *dev) { if (group->mdev_group) return vfio_mdev_get_iommu_device(dev); else return dev; } Then use it to replace plain 'dev' in all three places. > > static long vfio_iommu_type1_ioctl(void *iommu_data, > -- > 2.7.4
> From: Tian, Kevin <kevin.tian@intel.com> > Sent: Monday, March 30, 2020 9:19 PM > To: Liu, Yi L <yi.l.liu@intel.com>; alex.williamson@redhat.com; > Subject: RE: [PATCH v1 8/8] vfio/type1: Add vSVA support for IOMMU-backed > mdevs > > > From: Liu, Yi L <yi.l.liu@intel.com> > > Sent: Sunday, March 22, 2020 8:32 PM > > > > From: Liu Yi L <yi.l.liu@intel.com> > > > > Recent years, mediated device pass-through framework (e.g. vfio-mdev) > > are used to achieve flexible device sharing across domains (e.g. VMs). > > are->is got it. > > Also there are hardware assisted mediated pass-through solutions from > > platform vendors. e.g. Intel VT-d scalable mode which supports Intel > > Scalable I/O Virtualization technology. Such mdevs are called IOMMU- > > backed mdevs as there are IOMMU enforced DMA isolation for such mdevs. > > In kernel, IOMMU-backed mdevs are exposed to IOMMU layer by aux- > > domain concept, which means mdevs are protected by an iommu domain > > which is aux-domain of its physical device. Details can be found in > > the KVM > > "by an iommu domain which is auxiliary to the domain that the kernel driver > primarily uses for DMA API" yep. > > presentation from Kevin Tian. IOMMU-backed equals to IOMMU-capable. > > > > https://events19.linuxfoundation.org/wp-content/uploads/2017/12/\ > > Hardware-Assisted-Mediated-Pass-Through-with-VFIO-Kevin-Tian-Intel.pdf > > > > This patch supports NESTING IOMMU for IOMMU-backed mdevs by figuring > > out the physical device of an IOMMU-backed mdev and then invoking > > IOMMU requests to IOMMU layer with the physical device and the mdev's > > aux domain info. > > "and then calling into the IOMMU layer to complete the vSVA operations on the aux > domain associated with that mdev" got it. > > > > With this patch, vSVA (Virtual Shared Virtual Addressing) can be used > > on IOMMU-backed mdevs. > > > > Cc: Kevin Tian <kevin.tian@intel.com> > > CC: Jacob Pan <jacob.jun.pan@linux.intel.com> > > CC: Jun Tian <jun.j.tian@intel.com> > > Cc: Alex Williamson <alex.williamson@redhat.com> > > Cc: Eric Auger <eric.auger@redhat.com> > > Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> > > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > > --- > > drivers/vfio/vfio_iommu_type1.c | 23 ++++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/vfio/vfio_iommu_type1.c > > b/drivers/vfio/vfio_iommu_type1.c index 937ec3f..d473665 100644 > > --- a/drivers/vfio/vfio_iommu_type1.c > > +++ b/drivers/vfio/vfio_iommu_type1.c > > @@ -132,6 +132,7 @@ struct vfio_regions { > > > > struct domain_capsule { > > struct iommu_domain *domain; > > + struct vfio_group *group; > > void *data; > > }; > > > > @@ -148,6 +149,7 @@ static int vfio_iommu_for_each_dev(struct > > vfio_iommu *iommu, > > list_for_each_entry(d, &iommu->domain_list, next) { > > dc.domain = d->domain; > > list_for_each_entry(g, &d->group_list, next) { > > + dc.group = g; > > ret = iommu_group_for_each_dev(g->iommu_group, > > &dc, fn); > > if (ret) > > @@ -2347,7 +2349,12 @@ static int vfio_bind_gpasid_fn(struct device > > *dev, void *data) > > struct iommu_gpasid_bind_data *gbind_data = > > (struct iommu_gpasid_bind_data *) dc->data; > > > > - return iommu_sva_bind_gpasid(dc->domain, dev, gbind_data); > > + if (dc->group->mdev_group) > > + return iommu_sva_bind_gpasid(dc->domain, > > + vfio_mdev_get_iommu_device(dev), gbind_data); > > + else > > + return iommu_sva_bind_gpasid(dc->domain, > > + dev, gbind_data); > > } > > > > static int vfio_unbind_gpasid_fn(struct device *dev, void *data) @@ > > -2356,8 +2363,13 @@ static int vfio_unbind_gpasid_fn(struct device > > *dev, void *data) > > struct iommu_gpasid_bind_data *gbind_data = > > (struct iommu_gpasid_bind_data *) dc->data; > > > > - return iommu_sva_unbind_gpasid(dc->domain, dev, > > + if (dc->group->mdev_group) > > + return iommu_sva_unbind_gpasid(dc->domain, > > + vfio_mdev_get_iommu_device(dev), > > gbind_data->hpasid); > > + else > > + return iommu_sva_unbind_gpasid(dc->domain, dev, > > + gbind_data->hpasid); > > } > > > > /** > > @@ -2429,7 +2441,12 @@ static int vfio_cache_inv_fn(struct device > > *dev, void *data) > > struct iommu_cache_invalidate_info *cache_inv_info = > > (struct iommu_cache_invalidate_info *) dc->data; > > > > - return iommu_cache_invalidate(dc->domain, dev, cache_inv_info); > > + if (dc->group->mdev_group) > > + return iommu_cache_invalidate(dc->domain, > > + vfio_mdev_get_iommu_device(dev), cache_inv_info); > > + else > > + return iommu_cache_invalidate(dc->domain, > > + dev, cache_inv_info); > > } > > possibly above could be simplified, e.g. > > static struct device *vfio_get_iommu_device(struct vfio_group *group, > struct device *dev) > { > if (group->mdev_group) > return vfio_mdev_get_iommu_device(dev); > else > return dev; > } > > Then use it to replace plain 'dev' in all three places. yes, better for reading. thanks. Regards, Yi Liu
On Sun, 22 Mar 2020 05:32:05 -0700 "Liu, Yi L" <yi.l.liu@intel.com> wrote: > From: Liu Yi L <yi.l.liu@intel.com> > > Recent years, mediated device pass-through framework (e.g. vfio-mdev) > are used to achieve flexible device sharing across domains (e.g. VMs). > Also there are hardware assisted mediated pass-through solutions from > platform vendors. e.g. Intel VT-d scalable mode which supports Intel > Scalable I/O Virtualization technology. Such mdevs are called IOMMU- > backed mdevs as there are IOMMU enforced DMA isolation for such mdevs. > In kernel, IOMMU-backed mdevs are exposed to IOMMU layer by aux-domain > concept, which means mdevs are protected by an iommu domain which is > aux-domain of its physical device. Details can be found in the KVM > presentation from Kevin Tian. IOMMU-backed equals to IOMMU-capable. > > https://events19.linuxfoundation.org/wp-content/uploads/2017/12/\ > Hardware-Assisted-Mediated-Pass-Through-with-VFIO-Kevin-Tian-Intel.pdf > > This patch supports NESTING IOMMU for IOMMU-backed mdevs by figuring > out the physical device of an IOMMU-backed mdev and then invoking IOMMU > requests to IOMMU layer with the physical device and the mdev's aux > domain info. > > With this patch, vSVA (Virtual Shared Virtual Addressing) can be used > on IOMMU-backed mdevs. > > Cc: Kevin Tian <kevin.tian@intel.com> > CC: Jacob Pan <jacob.jun.pan@linux.intel.com> > CC: Jun Tian <jun.j.tian@intel.com> > Cc: Alex Williamson <alex.williamson@redhat.com> > Cc: Eric Auger <eric.auger@redhat.com> > Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > --- > drivers/vfio/vfio_iommu_type1.c | 23 ++++++++++++++++++++--- > 1 file changed, 20 insertions(+), 3 deletions(-) > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > index 937ec3f..d473665 100644 > --- a/drivers/vfio/vfio_iommu_type1.c > +++ b/drivers/vfio/vfio_iommu_type1.c > @@ -132,6 +132,7 @@ struct vfio_regions { > > struct domain_capsule { > struct iommu_domain *domain; > + struct vfio_group *group; > void *data; > }; > > @@ -148,6 +149,7 @@ static int vfio_iommu_for_each_dev(struct vfio_iommu *iommu, > list_for_each_entry(d, &iommu->domain_list, next) { > dc.domain = d->domain; > list_for_each_entry(g, &d->group_list, next) { > + dc.group = g; > ret = iommu_group_for_each_dev(g->iommu_group, > &dc, fn); > if (ret) > @@ -2347,7 +2349,12 @@ static int vfio_bind_gpasid_fn(struct device *dev, void *data) > struct iommu_gpasid_bind_data *gbind_data = > (struct iommu_gpasid_bind_data *) dc->data; > > - return iommu_sva_bind_gpasid(dc->domain, dev, gbind_data); > + if (dc->group->mdev_group) > + return iommu_sva_bind_gpasid(dc->domain, > + vfio_mdev_get_iommu_device(dev), gbind_data); But we can't assume an mdev device is iommu backed, so this can call with NULL dev, which appears will pretty quickly segfault intel_svm_bind_gpasid. > + else > + return iommu_sva_bind_gpasid(dc->domain, > + dev, gbind_data); > } > > static int vfio_unbind_gpasid_fn(struct device *dev, void *data) > @@ -2356,8 +2363,13 @@ static int vfio_unbind_gpasid_fn(struct device *dev, void *data) > struct iommu_gpasid_bind_data *gbind_data = > (struct iommu_gpasid_bind_data *) dc->data; > > - return iommu_sva_unbind_gpasid(dc->domain, dev, > + if (dc->group->mdev_group) > + return iommu_sva_unbind_gpasid(dc->domain, > + vfio_mdev_get_iommu_device(dev), > gbind_data->hpasid); Same > + else > + return iommu_sva_unbind_gpasid(dc->domain, dev, > + gbind_data->hpasid); > } > > /** > @@ -2429,7 +2441,12 @@ static int vfio_cache_inv_fn(struct device *dev, void *data) > struct iommu_cache_invalidate_info *cache_inv_info = > (struct iommu_cache_invalidate_info *) dc->data; > > - return iommu_cache_invalidate(dc->domain, dev, cache_inv_info); > + if (dc->group->mdev_group) > + return iommu_cache_invalidate(dc->domain, > + vfio_mdev_get_iommu_device(dev), cache_inv_info); And again > + else > + return iommu_cache_invalidate(dc->domain, > + dev, cache_inv_info); > } > > static long vfio_iommu_type1_ioctl(void *iommu_data,
Hi Alex, > From: Alex Williamson <alex.williamson@redhat.com> > Sent: Friday, April 3, 2020 4:34 AM > To: Liu, Yi L <yi.l.liu@intel.com> > Subject: Re: [PATCH v1 8/8] vfio/type1: Add vSVA support for IOMMU-backed > mdevs > > On Sun, 22 Mar 2020 05:32:05 -0700 > "Liu, Yi L" <yi.l.liu@intel.com> wrote: > > > From: Liu Yi L <yi.l.liu@intel.com> > > > > Recent years, mediated device pass-through framework (e.g. vfio-mdev) > > are used to achieve flexible device sharing across domains (e.g. VMs). > > Also there are hardware assisted mediated pass-through solutions from > > platform vendors. e.g. Intel VT-d scalable mode which supports Intel > > Scalable I/O Virtualization technology. Such mdevs are called IOMMU- > > backed mdevs as there are IOMMU enforced DMA isolation for such mdevs. > > In kernel, IOMMU-backed mdevs are exposed to IOMMU layer by aux-domain > > concept, which means mdevs are protected by an iommu domain which is > > aux-domain of its physical device. Details can be found in the KVM > > presentation from Kevin Tian. IOMMU-backed equals to IOMMU-capable. > > > > https://events19.linuxfoundation.org/wp-content/uploads/2017/12/\ > > Hardware-Assisted-Mediated-Pass-Through-with-VFIO-Kevin-Tian-Intel.pdf > > > > This patch supports NESTING IOMMU for IOMMU-backed mdevs by figuring > > out the physical device of an IOMMU-backed mdev and then invoking IOMMU > > requests to IOMMU layer with the physical device and the mdev's aux > > domain info. > > > > With this patch, vSVA (Virtual Shared Virtual Addressing) can be used > > on IOMMU-backed mdevs. > > > > Cc: Kevin Tian <kevin.tian@intel.com> > > CC: Jacob Pan <jacob.jun.pan@linux.intel.com> > > CC: Jun Tian <jun.j.tian@intel.com> > > Cc: Alex Williamson <alex.williamson@redhat.com> > > Cc: Eric Auger <eric.auger@redhat.com> > > Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> > > Signed-off-by: Liu Yi L <yi.l.liu@intel.com> > > --- > > drivers/vfio/vfio_iommu_type1.c | 23 ++++++++++++++++++++--- > > 1 file changed, 20 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c > > index 937ec3f..d473665 100644 > > --- a/drivers/vfio/vfio_iommu_type1.c > > +++ b/drivers/vfio/vfio_iommu_type1.c > > @@ -132,6 +132,7 @@ struct vfio_regions { > > > > struct domain_capsule { > > struct iommu_domain *domain; > > + struct vfio_group *group; > > void *data; > > }; > > > > @@ -148,6 +149,7 @@ static int vfio_iommu_for_each_dev(struct vfio_iommu > *iommu, > > list_for_each_entry(d, &iommu->domain_list, next) { > > dc.domain = d->domain; > > list_for_each_entry(g, &d->group_list, next) { > > + dc.group = g; > > ret = iommu_group_for_each_dev(g->iommu_group, > > &dc, fn); > > if (ret) > > @@ -2347,7 +2349,12 @@ static int vfio_bind_gpasid_fn(struct device *dev, void > *data) > > struct iommu_gpasid_bind_data *gbind_data = > > (struct iommu_gpasid_bind_data *) dc->data; > > > > - return iommu_sva_bind_gpasid(dc->domain, dev, gbind_data); > > + if (dc->group->mdev_group) > > + return iommu_sva_bind_gpasid(dc->domain, > > + vfio_mdev_get_iommu_device(dev), gbind_data); > > But we can't assume an mdev device is iommu backed, so this can call > with NULL dev, which appears will pretty quickly segfault > intel_svm_bind_gpasid. I don't think the non-iommu backed mdev will not be in the iommu->domain_list. right? But, yeah, from this function p.o.v , it is still necessary to do a check. How about adding a check on the return of vfio_mdev_get_iommu_device(dev)? If iommu_device is fetch, the mdev should be iommu-backed. does it make sense? Regards, Yi Liu > > > + else > > + return iommu_sva_bind_gpasid(dc->domain, > > + dev, gbind_data); > > } > > > > static int vfio_unbind_gpasid_fn(struct device *dev, void *data) > > @@ -2356,8 +2363,13 @@ static int vfio_unbind_gpasid_fn(struct device *dev, > void *data) > > struct iommu_gpasid_bind_data *gbind_data = > > (struct iommu_gpasid_bind_data *) dc->data; > > > > - return iommu_sva_unbind_gpasid(dc->domain, dev, > > + if (dc->group->mdev_group) > > + return iommu_sva_unbind_gpasid(dc->domain, > > + vfio_mdev_get_iommu_device(dev), > > gbind_data->hpasid); > > Same > > > + else > > + return iommu_sva_unbind_gpasid(dc->domain, dev, > > + gbind_data->hpasid); > > } > > > > /** > > @@ -2429,7 +2441,12 @@ static int vfio_cache_inv_fn(struct device *dev, void > *data) > > struct iommu_cache_invalidate_info *cache_inv_info = > > (struct iommu_cache_invalidate_info *) dc->data; > > > > - return iommu_cache_invalidate(dc->domain, dev, cache_inv_info); > > + if (dc->group->mdev_group) > > + return iommu_cache_invalidate(dc->domain, > > + vfio_mdev_get_iommu_device(dev), cache_inv_info); > > And again > > > + else > > + return iommu_cache_invalidate(dc->domain, > > + dev, cache_inv_info); > > } > > > > static long vfio_iommu_type1_ioctl(void *iommu_data,
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 937ec3f..d473665 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -132,6 +132,7 @@ struct vfio_regions { struct domain_capsule { struct iommu_domain *domain; + struct vfio_group *group; void *data; }; @@ -148,6 +149,7 @@ static int vfio_iommu_for_each_dev(struct vfio_iommu *iommu, list_for_each_entry(d, &iommu->domain_list, next) { dc.domain = d->domain; list_for_each_entry(g, &d->group_list, next) { + dc.group = g; ret = iommu_group_for_each_dev(g->iommu_group, &dc, fn); if (ret) @@ -2347,7 +2349,12 @@ static int vfio_bind_gpasid_fn(struct device *dev, void *data) struct iommu_gpasid_bind_data *gbind_data = (struct iommu_gpasid_bind_data *) dc->data; - return iommu_sva_bind_gpasid(dc->domain, dev, gbind_data); + if (dc->group->mdev_group) + return iommu_sva_bind_gpasid(dc->domain, + vfio_mdev_get_iommu_device(dev), gbind_data); + else + return iommu_sva_bind_gpasid(dc->domain, + dev, gbind_data); } static int vfio_unbind_gpasid_fn(struct device *dev, void *data) @@ -2356,8 +2363,13 @@ static int vfio_unbind_gpasid_fn(struct device *dev, void *data) struct iommu_gpasid_bind_data *gbind_data = (struct iommu_gpasid_bind_data *) dc->data; - return iommu_sva_unbind_gpasid(dc->domain, dev, + if (dc->group->mdev_group) + return iommu_sva_unbind_gpasid(dc->domain, + vfio_mdev_get_iommu_device(dev), gbind_data->hpasid); + else + return iommu_sva_unbind_gpasid(dc->domain, dev, + gbind_data->hpasid); } /** @@ -2429,7 +2441,12 @@ static int vfio_cache_inv_fn(struct device *dev, void *data) struct iommu_cache_invalidate_info *cache_inv_info = (struct iommu_cache_invalidate_info *) dc->data; - return iommu_cache_invalidate(dc->domain, dev, cache_inv_info); + if (dc->group->mdev_group) + return iommu_cache_invalidate(dc->domain, + vfio_mdev_get_iommu_device(dev), cache_inv_info); + else + return iommu_cache_invalidate(dc->domain, + dev, cache_inv_info); } static long vfio_iommu_type1_ioctl(void *iommu_data,