From: Lu Baolu <baolu.lu@linux.intel.com>
To: Auger Eric <eric.auger@redhat.com>,
Joerg Roedel <joro@8bytes.org>,
David Woodhouse <dwmw2@infradead.org>,
Alex Williamson <alex.williamson@redhat.com>,
Kirti Wankhede <kwankhede@nvidia.com>
Cc: baolu.lu@linux.intel.com, kevin.tian@intel.com,
ashok.raj@intel.com, tiwei.bie@intel.com,
Jean-Philippe Brucker <jean-philippe.brucker@arm.com>,
sanjay.k.kumar@intel.com, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, yi.y.sun@intel.com,
jacob.jun.pan@intel.com, kvm@vger.kernel.org
Subject: Re: [PATCH v4 7/8] vfio/type1: Add domain at(de)taching group helpers
Date: Mon, 26 Nov 2018 11:05:04 +0800 [thread overview]
Message-ID: <13a8bda6-1e66-66b9-6670-70d1b71ab50a@linux.intel.com> (raw)
In-Reply-To: <b5f5eda1-2dbf-dd7e-3b68-bfd9e5099c06@redhat.com>
Hi,
On 11/23/18 10:13 PM, Auger Eric wrote:
> Hi Lu,
>
> On 11/5/18 8:34 AM, Lu Baolu wrote:
>> This adds helpers to attach or detach a domain to a
>> group. This will replace iommu_attach_group() which
>> only works for pci devices.
> s/pci/non mdev?
... which doesn't work for mdev devices.
>>
>> If a domain is attaching to a group which includes the
>> mediated devices, it should attach to the iommu device
>> (a pci device which represents the mdev in iommu scope)
>> instead. The added helper supports attaching domain to
>> groups for both pci and mdev devices.
>>
>> Cc: Ashok Raj <ashok.raj@intel.com>
>> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
>> Cc: Kevin Tian <kevin.tian@intel.com>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
>> ---
>> drivers/vfio/vfio_iommu_type1.c | 114 ++++++++++++++++++++++++++++++--
>> 1 file changed, 107 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
>> index d9fd3188615d..178264b330e7 100644
>> --- a/drivers/vfio/vfio_iommu_type1.c
>> +++ b/drivers/vfio/vfio_iommu_type1.c
>> @@ -91,6 +91,7 @@ struct vfio_dma {
>> struct vfio_group {
>> struct iommu_group *iommu_group;
>> struct list_head next;
>> + bool mdev_group; /* An mdev group */
>> };
>>
>> /*
>> @@ -1327,6 +1328,105 @@ static bool vfio_iommu_has_sw_msi(struct iommu_group *group, phys_addr_t *base)
>> return ret;
>> }
>>
>> +static struct device *vfio_mdev_get_iommu_device(struct device *dev)
>> +{
>> + struct device *(*fn)(struct device *dev);
>> + struct device *iommu_parent;
>> +
>> + fn = symbol_get(mdev_get_iommu_device);
>> + if (fn) {
>> + iommu_parent = fn(dev);
>> + symbol_put(mdev_get_iommu_device);
>> +
>> + return iommu_parent;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static int vfio_mdev_set_domain(struct device *dev, struct iommu_domain *domain)
>> +{
>> + int (*fn)(struct device *dev, void *domain);
>> + int ret;
>> +
>> + fn = symbol_get(mdev_set_iommu_domain);
>> + if (fn) {
>> + ret = fn(dev, domain);
>> + symbol_put(mdev_set_iommu_domain);
>> +
>> + return ret;
>> + }
>> +
>> + return -EINVAL;
>> +}
>> +
>> +static int vfio_mdev_attach_domain(struct device *dev, void *data)
>> +{
>> + struct iommu_domain *domain = data;
>> + struct device *iommu_device;
>> + int ret;
>> +
>> + ret = vfio_mdev_set_domain(dev, domain);
>> + if (ret)
>> + return ret;
>> +
>> + iommu_device = vfio_mdev_get_iommu_device(dev);
>> + if (iommu_device) {
>> + bool aux_mode = false;
>> +
>> + iommu_get_dev_attr(iommu_device,
>> + IOMMU_DEV_ATTR_AUXD_ENABLED, &aux_mode);
> Don' you need to test the returned value before using aux_mode?
Yes. Good catch.
>> + if (aux_mode)
>> + return iommu_attach_device_aux(domain, iommu_device);
>> + else
>> + return iommu_attach_device(domain, iommu_device);
> if for some reason the above ops fail, don't you want to call
> vfio_mdev_set_domain(dev, NULL)
Yes. Good catch.
>
>> + }
>> +
>> + return -EINVAL;
>> +}
>> +
>> +static int vfio_mdev_detach_domain(struct device *dev, void *data)
>> +{
>> + struct iommu_domain *domain = data;
>> + struct device *iommu_device;
>> +
>> + vfio_mdev_set_domain(dev, NULL);
>> + iommu_device = vfio_mdev_get_iommu_device(dev);
>> + if (iommu_device) {
>> + bool aux_mode = false;
>> +
>> + iommu_get_dev_attr(iommu_device,
>> + IOMMU_DEV_ATTR_AUXD_ENABLED, &aux_mode);
> same here
Will fix it.
>> + if (aux_mode)
>> + iommu_detach_device_aux(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 int vfio_iommu_type1_attach_group(void *iommu_data,
>> struct iommu_group *iommu_group)
>> {
>> @@ -1402,7 +1502,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
>> goto out_domain;
>> }
>>
>> - ret = iommu_attach_group(domain->domain, iommu_group);
>> + ret = vfio_iommu_attach_group(domain, group);
>> if (ret)
>> goto out_domain;
>>
>> @@ -1434,8 +1534,8 @@ 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) {
>> - iommu_detach_group(domain->domain, iommu_group);
>> - if (!iommu_attach_group(d->domain, iommu_group)) {
>> + vfio_iommu_detach_group(domain, group);
>> + if (!vfio_iommu_attach_group(d, group)) {
>> list_add(&group->next, &d->group_list);
>> iommu_domain_free(domain->domain);
>> kfree(domain);
>> @@ -1443,7 +1543,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
>> return 0;
>> }
>>
>> - ret = iommu_attach_group(domain->domain, iommu_group);
>> + ret = vfio_iommu_attach_group(domain, group);
>> if (ret)
>> goto out_domain;
>> }
>> @@ -1469,7 +1569,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
>> return 0;
>>
>> out_detach:
>> - iommu_detach_group(domain->domain, iommu_group);
>> + vfio_iommu_detach_group(domain, group);
>> out_domain:
>> iommu_domain_free(domain->domain);
>> out_free:
>> @@ -1560,7 +1660,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data,
>> if (!group)
>> continue;
>>
>> - iommu_detach_group(domain->domain, iommu_group);
>> + vfio_iommu_detach_group(domain, group);
>> list_del(&group->next);
>> kfree(group);
>> /*
>> @@ -1625,7 +1725,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)
>> - iommu_detach_group(domain->domain, group->iommu_group);
>> + vfio_iommu_detach_group(domain, group);
>> list_del(&group->next);
>> kfree(group);
>> }
>>
> Thanks
>
> Eric
>
Best regards,
Lu Baolu
next prev parent reply other threads:[~2018-11-26 3:08 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-05 7:34 [PATCH v4 0/8] vfio/mdev: IOMMU aware mediated device Lu Baolu
2018-11-05 7:34 ` [PATCH v4 1/8] iommu: Add APIs for multiple domains per device Lu Baolu
2018-11-23 10:50 ` Auger Eric
2018-11-26 2:04 ` Lu Baolu
2018-11-05 7:34 ` [PATCH v4 2/8] iommu/vt-d: Add multiple domains per device query Lu Baolu
2018-11-23 10:49 ` Auger Eric
2018-11-26 2:10 ` Lu Baolu
2018-11-05 7:34 ` [PATCH v4 3/8] iommu/vt-d: Enable/disable multiple domains per device Lu Baolu
2018-11-05 7:34 ` [PATCH v4 4/8] iommu/vt-d: Attach/detach domains in auxiliary mode Lu Baolu
2018-11-23 10:49 ` Auger Eric
2018-11-26 2:37 ` Lu Baolu
2018-11-05 7:34 ` [PATCH v4 5/8] iommu/vt-d: Return ID associated with an auxiliary domain Lu Baolu
2018-11-05 7:34 ` [PATCH v4 6/8] vfio/mdev: Add iommu place holders in mdev_device Lu Baolu
2018-11-05 14:51 ` Christoph Hellwig
2018-11-05 23:33 ` Lu Baolu
2018-11-06 23:53 ` Alex Williamson
2018-11-07 1:48 ` Lu Baolu
2018-11-15 21:31 ` Kirti Wankhede
2018-11-16 1:20 ` Lu Baolu
2018-11-16 8:57 ` Christoph Hellwig
2018-11-17 2:37 ` Lu Baolu
2018-11-20 20:52 ` Kirti Wankhede
2018-11-21 8:45 ` Christoph Hellwig
2018-12-03 16:27 ` Kirti Wankhede
2018-11-05 7:34 ` [PATCH v4 7/8] vfio/type1: Add domain at(de)taching group helpers Lu Baolu
2018-11-23 14:13 ` Auger Eric
2018-11-26 3:05 ` Lu Baolu [this message]
2018-11-05 7:34 ` [PATCH v4 8/8] vfio/type1: Handle different mdev isolation type Lu Baolu
2018-11-23 14:23 ` Auger Eric
2018-11-26 3:09 ` Lu Baolu
2018-12-04 3:46 ` [PATCH v4 0/8] vfio/mdev: IOMMU aware mediated device Xu Zaibo
2018-12-04 6:20 ` Lu Baolu
2018-12-04 6:50 ` Xu Zaibo
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=13a8bda6-1e66-66b9-6670-70d1b71ab50a@linux.intel.com \
--to=baolu.lu@linux.intel.com \
--cc=alex.williamson@redhat.com \
--cc=ashok.raj@intel.com \
--cc=dwmw2@infradead.org \
--cc=eric.auger@redhat.com \
--cc=iommu@lists.linux-foundation.org \
--cc=jacob.jun.pan@intel.com \
--cc=jean-philippe.brucker@arm.com \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sanjay.k.kumar@intel.com \
--cc=tiwei.bie@intel.com \
--cc=yi.y.sun@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;
as well as URLs for NNTP newsgroup(s).