iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: Lu Baolu <baolu.lu@linux.intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	"Alex Williamson" <alex.williamson@redhat.com>
Cc: Jean-Philippe Brucker <jean-philippe@linaro.org>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Raj, Ashok" <ashok.raj@intel.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	Cornelia Huck <cohuck@redhat.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	Robin Murphy <robin.murphy@arm.com>
Subject: RE: [PATCH v6 5/5] vfio/type1: Use mdev bus iommu_ops for IOMMU callbacks
Date: Fri, 30 Oct 2020 06:16:28 +0000	[thread overview]
Message-ID: <MWHPR11MB1645DEBE7C0E7A61D22081DD8C150@MWHPR11MB1645.namprd11.prod.outlook.com> (raw)
In-Reply-To: <20201030045809.957927-6-baolu.lu@linux.intel.com>

> From: Lu Baolu <baolu.lu@linux.intel.com>
> Sent: Friday, October 30, 2020 12:58 PM
> 
> With the IOMMU driver registering iommu_ops for the mdev_bus, the
> IOMMU
> operations on an mdev could be done in the same way as any normal device
> (for example, PCI/PCIe). There's no need to distinguish an mdev from
> others for iommu operations. Remove the unnecessary code.

This is really a nice cleanup as the output of this change! :)

Thanks
Kevin

> 
> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> ---
>  drivers/vfio/mdev/mdev_core.c    |  18 -----
>  drivers/vfio/mdev/mdev_driver.c  |   6 ++
>  drivers/vfio/mdev/mdev_private.h |   1 -
>  drivers/vfio/vfio_iommu_type1.c  | 128 +++----------------------------
>  include/linux/mdev.h             |  14 ----
>  5 files changed, 18 insertions(+), 149 deletions(-)
> 
> diff --git a/drivers/vfio/mdev/mdev_core.c
> b/drivers/vfio/mdev/mdev_core.c
> index 6b9ab71f89e7..f4fd5f237c49 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -386,24 +386,6 @@ int mdev_device_remove(struct device *dev)
>  	return 0;
>  }
> 
> -int mdev_set_iommu_device(struct device *dev, struct device
> *iommu_device)
> -{
> -	struct mdev_device *mdev = to_mdev_device(dev);
> -
> -	mdev->iommu_device = iommu_device;
> -
> -	return 0;
> -}
> -EXPORT_SYMBOL(mdev_set_iommu_device);
> -
> -struct device *mdev_get_iommu_device(struct device *dev)
> -{
> -	struct mdev_device *mdev = to_mdev_device(dev);
> -
> -	return mdev->iommu_device;
> -}
> -EXPORT_SYMBOL(mdev_get_iommu_device);
> -
>  static int __init mdev_init(void)
>  {
>  	return mdev_bus_register();
> diff --git a/drivers/vfio/mdev/mdev_driver.c
> b/drivers/vfio/mdev/mdev_driver.c
> index 0d3223aee20b..487402f16355 100644
> --- a/drivers/vfio/mdev/mdev_driver.c
> +++ b/drivers/vfio/mdev/mdev_driver.c
> @@ -18,6 +18,9 @@ static int mdev_attach_iommu(struct mdev_device
> *mdev)
>  	int ret;
>  	struct iommu_group *group;
> 
> +	if (iommu_present(&mdev_bus_type))
> +		return 0;
> +
>  	group = iommu_group_alloc();
>  	if (IS_ERR(group))
>  		return PTR_ERR(group);
> @@ -33,6 +36,9 @@ static int mdev_attach_iommu(struct mdev_device
> *mdev)
> 
>  static void mdev_detach_iommu(struct mdev_device *mdev)
>  {
> +	if (iommu_present(&mdev_bus_type))
> +		return;
> +
>  	iommu_group_remove_device(&mdev->dev);
>  	dev_info(&mdev->dev, "MDEV: detaching iommu\n");
>  }
> diff --git a/drivers/vfio/mdev/mdev_private.h
> b/drivers/vfio/mdev/mdev_private.h
> index 7d922950caaf..efe0aefdb52f 100644
> --- a/drivers/vfio/mdev/mdev_private.h
> +++ b/drivers/vfio/mdev/mdev_private.h
> @@ -31,7 +31,6 @@ struct mdev_device {
>  	void *driver_data;
>  	struct list_head next;
>  	struct kobject *type_kobj;
> -	struct device *iommu_device;
>  	bool active;
>  };
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c
> b/drivers/vfio/vfio_iommu_type1.c
> index bb2684cc245e..e231b7070ca5 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -100,7 +100,6 @@ struct vfio_dma {
>  struct vfio_group {
>  	struct iommu_group	*iommu_group;
>  	struct list_head	next;
> -	bool			mdev_group;	/* An mdev group */
>  	bool			pinned_page_dirty_scope;
>  };
> 
> @@ -1675,102 +1674,6 @@ static bool vfio_iommu_has_sw_msi(struct
> list_head *group_resv_regions,
>  	return ret;
>  }
> 
> -static struct device *vfio_mdev_get_iommu_device(struct device *dev)
> -{
> -	struct device *(*fn)(struct device *dev);
> -	struct device *iommu_device;
> -
> -	fn = symbol_get(mdev_get_iommu_device);
> -	if (fn) {
> -		iommu_device = fn(dev);
> -		symbol_put(mdev_get_iommu_device);
> -
> -		return iommu_device;
> -	}
> -
> -	return NULL;
> -}
> -
> -static int vfio_mdev_attach_domain(struct device *dev, void *data)
> -{
> -	struct iommu_domain *domain = data;
> -	struct device *iommu_device;
> -
> -	iommu_device = vfio_mdev_get_iommu_device(dev);
> -	if (iommu_device) {
> -		if (iommu_dev_feature_enabled(iommu_device,
> IOMMU_DEV_FEAT_AUX))
> -			return iommu_aux_attach_device(domain,
> iommu_device);
> -		else
> -			return iommu_attach_device(domain,
> iommu_device);
> -	}
> -
> -	return -EINVAL;
> -}
> -
> -static int vfio_mdev_detach_domain(struct device *dev, void *data)
> -{
> -	struct iommu_domain *domain = data;
> -	struct device *iommu_device;
> -
> -	iommu_device = vfio_mdev_get_iommu_device(dev);
> -	if (iommu_device) {
> -		if (iommu_dev_feature_enabled(iommu_device,
> IOMMU_DEV_FEAT_AUX))
> -			iommu_aux_detach_device(domain, iommu_device);
> -		else
> -			iommu_detach_device(domain, iommu_device);
> -	}
> -
> -	return 0;
> -}
> -
> -static int vfio_iommu_attach_group(struct vfio_domain *domain,
> -				   struct vfio_group *group)
> -{
> -	if (group->mdev_group)
> -		return iommu_group_for_each_dev(group->iommu_group,
> -						domain->domain,
> -						vfio_mdev_attach_domain);
> -	else
> -		return iommu_attach_group(domain->domain, group-
> >iommu_group);
> -}
> -
> -static void vfio_iommu_detach_group(struct vfio_domain *domain,
> -				    struct vfio_group *group)
> -{
> -	if (group->mdev_group)
> -		iommu_group_for_each_dev(group->iommu_group,
> domain->domain,
> -					 vfio_mdev_detach_domain);
> -	else
> -		iommu_detach_group(domain->domain, group-
> >iommu_group);
> -}
> -
> -static bool vfio_bus_is_mdev(struct bus_type *bus)
> -{
> -	struct bus_type *mdev_bus;
> -	bool ret = false;
> -
> -	mdev_bus = symbol_get(mdev_bus_type);
> -	if (mdev_bus) {
> -		ret = (bus == mdev_bus);
> -		symbol_put(mdev_bus_type);
> -	}
> -
> -	return ret;
> -}
> -
> -static int vfio_mdev_iommu_device(struct device *dev, void *data)
> -{
> -	struct device **old = data, *new;
> -
> -	new = vfio_mdev_get_iommu_device(dev);
> -	if (!new || (*old && *old != new))
> -		return -EINVAL;
> -
> -	*old = new;
> -
> -	return 0;
> -}
> -
>  /*
>   * This is a helper function to insert an address range to iova list.
>   * The list is initially created with a single entry corresponding to
> @@ -1999,7 +1902,7 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
>  	struct vfio_iommu *iommu = iommu_data;
>  	struct vfio_group *group;
>  	struct vfio_domain *domain, *d;
> -	struct bus_type *bus = NULL;
> +	struct bus_type *bus = NULL, *mdev_bus;
>  	int ret;
>  	bool resv_msi, msi_remap;
>  	phys_addr_t resv_msi_base = 0;
> @@ -2037,15 +1940,10 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
>  	if (ret)
>  		goto out_free;
> 
> -	if (vfio_bus_is_mdev(bus)) {
> -		struct device *iommu_device = NULL;
> -
> -		group->mdev_group = true;
> -
> -		/* Determine the isolation type */
> -		ret = iommu_group_for_each_dev(iommu_group,
> &iommu_device,
> -					       vfio_mdev_iommu_device);
> -		if (ret || !iommu_device) {
> +	mdev_bus = symbol_get(mdev_bus_type);
> +	if (mdev_bus) {
> +		if (bus == mdev_bus && !iommu_present(bus)) {
> +			symbol_put(mdev_bus_type);
>  			if (!iommu->external_domain) {
>  				INIT_LIST_HEAD(&domain->group_list);
>  				iommu->external_domain = domain;
> @@ -2070,8 +1968,6 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
> 
>  			return 0;
>  		}
> -
> -		bus = iommu_device->bus;
>  	}
> 
>  	domain->domain = iommu_domain_alloc(bus);
> @@ -2089,7 +1985,7 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
>  			goto out_domain;
>  	}
> 
> -	ret = vfio_iommu_attach_group(domain, group);
> +	ret = iommu_attach_group(domain->domain, iommu_group);
>  	if (ret)
>  		goto out_domain;
> 
> @@ -2157,15 +2053,15 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
>  	list_for_each_entry(d, &iommu->domain_list, next) {
>  		if (d->domain->ops == domain->domain->ops &&
>  		    d->prot == domain->prot) {
> -			vfio_iommu_detach_group(domain, group);
> -			if (!vfio_iommu_attach_group(d, group)) {
> +			iommu_detach_group(domain->domain,
> iommu_group);
> +			if (!iommu_attach_group(d->domain, iommu_group))
> {
>  				list_add(&group->next, &d->group_list);
>  				iommu_domain_free(domain->domain);
>  				kfree(domain);
>  				goto done;
>  			}
> 
> -			ret = vfio_iommu_attach_group(domain, group);
> +			ret = iommu_attach_group(domain->domain,
> iommu_group);
>  			if (ret)
>  				goto out_domain;
>  		}
> @@ -2202,7 +2098,7 @@ static int vfio_iommu_type1_attach_group(void
> *iommu_data,
>  	return 0;
> 
>  out_detach:
> -	vfio_iommu_detach_group(domain, group);
> +	iommu_detach_group(domain->domain, iommu_group);
>  out_domain:
>  	iommu_domain_free(domain->domain);
>  	vfio_iommu_iova_free(&iova_copy);
> @@ -2385,7 +2281,7 @@ static void vfio_iommu_type1_detach_group(void
> *iommu_data,
>  		if (!group)
>  			continue;
> 
> -		vfio_iommu_detach_group(domain, group);
> +		iommu_detach_group(domain->domain, iommu_group);
>  		update_dirty_scope = !group->pinned_page_dirty_scope;
>  		list_del(&group->next);
>  		kfree(group);
> @@ -2466,7 +2362,7 @@ static void vfio_release_domain(struct
> vfio_domain *domain, bool external)
>  	list_for_each_entry_safe(group, group_tmp,
>  				 &domain->group_list, next) {
>  		if (!external)
> -			vfio_iommu_detach_group(domain, group);
> +			iommu_detach_group(domain->domain, group-
> >iommu_group);
>  		list_del(&group->next);
>  		kfree(group);
>  	}
> diff --git a/include/linux/mdev.h b/include/linux/mdev.h
> index 0ce30ca78db0..f7aee86bd2b0 100644
> --- a/include/linux/mdev.h
> +++ b/include/linux/mdev.h
> @@ -12,20 +12,6 @@
> 
>  struct mdev_device;
> 
> -/*
> - * Called by the parent device driver to set the device which represents
> - * this mdev in iommu protection scope. By default, the iommu device is
> - * NULL, that indicates using vendor defined isolation.
> - *
> - * @dev: the mediated device that iommu will isolate.
> - * @iommu_device: a pci device which represents the iommu for @dev.
> - *
> - * Return 0 for success, otherwise negative error value.
> - */
> -int mdev_set_iommu_device(struct device *dev, struct device
> *iommu_device);
> -
> -struct device *mdev_get_iommu_device(struct device *dev);
> -
>  /**
>   * struct mdev_parent_ops - Structure to be registered for each parent
> device to
>   * register the device to mdev module.
> --
> 2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2020-10-30  6:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30  4:58 [PATCH v6 0/5] iommu aux-domain APIs extensions Lu Baolu
2020-10-30  4:58 ` [PATCH v6 1/5] vfio/mdev: Register mdev bus earlier during boot Lu Baolu
2020-10-30 17:02   ` Alex Williamson
2020-10-30  4:58 ` [PATCH v6 2/5] iommu: Use bus iommu ops for aux related callback Lu Baolu
2020-10-30  5:55   ` Tian, Kevin
2020-10-30 10:47     ` Jean-Philippe Brucker
2020-10-30  4:58 ` [PATCH v6 3/5] iommu/vt-d: Make some static functions global Lu Baolu
2020-10-30  4:58 ` [PATCH v6 4/5] iommu/vt-d: Add iommu_ops support for subdevice bus Lu Baolu
2020-10-30  6:13   ` Tian, Kevin
2020-10-30 20:56   ` Alex Williamson
2020-10-30  4:58 ` [PATCH v6 5/5] vfio/type1: Use mdev bus iommu_ops for IOMMU callbacks Lu Baolu
2020-10-30  6:16   ` Tian, Kevin [this message]
2020-10-30 21:06     ` Alex Williamson
2020-11-03  5:22       ` Lu Baolu
2020-11-12  2:31         ` Lu Baolu

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=MWHPR11MB1645DEBE7C0E7A61D22081DD8C150@MWHPR11MB1645.namprd11.prod.outlook.com \
    --to=kevin.tian@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=cohuck@redhat.com \
    --cc=dave.jiang@intel.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jean-philippe@linaro.org \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.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;
as well as URLs for NNTP newsgroup(s).