From: Lu Baolu <baolu.lu@linux.intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: baolu.lu@linux.intel.com, Cornelia Huck <cohuck@redhat.com>,
Joerg Roedel <joro@8bytes.org>,
Robin Murphy <robin.murphy@arm.com>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Kevin Tian <kevin.tian@intel.com>,
Ashok Raj <ashok.raj@intel.com>,
Dave Jiang <dave.jiang@intel.com>, Liu Yi L <yi.l.liu@intel.com>,
Zeng Xin <xin.zeng@intel.com>,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org
Subject: Re: [PATCH 1/1] vfio/type1: Add subdev_ioasid callback to vfio_iommu_driver_ops
Date: Tue, 17 Nov 2020 22:39:55 +0800 [thread overview]
Message-ID: <c4526653-2e0d-2f9a-66ad-b3dba284a4d3@linux.intel.com> (raw)
In-Reply-To: <20201116125631.2d043fcd@w520.home>
Hi Alex,
On 2020/11/17 3:56, Alex Williamson wrote:
> On Thu, 12 Nov 2020 10:24:07 +0800
> Lu Baolu<baolu.lu@linux.intel.com> wrote:
>
>> Add API for getting the ioasid of a subdevice (vfio/mdev). This calls
>> into the backend IOMMU module to get the actual value or error number
>> if ioasid for subdevice is not supported. The physical device driver
>> implementations which rely on the vfio/mdev framework for mediated
>> device user level access could typically consume this interface like
>> below:
>>
>> struct device *dev = mdev_dev(mdev);
>> unsigned int pasid;
>> int ret;
>>
>> ret = vfio_subdev_ioasid(dev, &pasid);
>> if (ret < 0)
>> return ret;
>>
>> /* Program device context with pasid value. */
>> ....
>
> Seems like an overly specific callback. We already export means for
> you to get a vfio_group, test that a device is an mdev, and get the
> iommu device from an mdev. So you can already test whether a given
> device is an mdev with an iommu backing device that supports aux
> domains. The only missing piece seems to be that you can't get the
> domain for a group in order to retrieve the pasid. So why aren't we
> exporting a callback that given a vfio_group provides the iommu domain?
Make sense! Thanks for your guidance. :-)
So what we want to export in vfio.c is
struct iommu_domain *vfio_group_get_domain(struct vfio_group *group)
What the callers need to do are:
unsigned int pasid;
struct vfio_group *vfio_group;
struct iommu_domain *iommu_domain;
struct device *dev = mdev_dev(mdev);
struct device *iommu_device = mdev_get_iommu_device(dev);
if (!iommu_device ||
!iommu_dev_feature_enabled(iommu_device, IOMMU_DEV_FEAT_AUX))
return -EINVAL;
vfio_group = vfio_group_get_external_user_from_dev(dev);
if (IS_ERR_OR_NULL(vfio_group))
return -EFAULT;
iommu_domain = vfio_group_get_domain(vfio_group);
if (IS_ERR_OR_NULL(iommu_domain)) {
vfio_group_put_external_user(vfio_group);
return -EFAULT;
}
pasid = iommu_aux_get_pasid(iommu_domain, iommu_device);
if (pasid < 0) {
vfio_group_put_external_user(vfio_group);
return -EFAULT;
}
/* Program device context with pasid value. */
...
/* After use of this pasid */
/* Clear the pasid value in device context */
...
vfio_group_put_external_user(vfio_group);
Do I understand your points correctly?
Best regards,
baolu
prev parent reply other threads:[~2020-11-17 14:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 2:24 [PATCH 1/1] vfio/type1: Add subdev_ioasid callback to vfio_iommu_driver_ops Lu Baolu
2020-11-16 19:56 ` Alex Williamson
2020-11-17 14:39 ` Lu Baolu [this message]
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=c4526653-2e0d-2f9a-66ad-b3dba284a4d3@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@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=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=xin.zeng@intel.com \
--cc=yi.l.liu@intel.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