From: "Tian, Kevin" <kevin.tian@intel.com>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: "jgg@nvidia.com" <jgg@nvidia.com>,
"Liu, Yi L" <yi.l.liu@intel.com>,
"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2 3/3] iommufd/device: Change iommufd_hw_pagetable_has_group to device centric
Date: Mon, 30 Jan 2023 00:44:48 +0000 [thread overview]
Message-ID: <BN9PR11MB52769DF1D9C9C06C88CC13408CD39@BN9PR11MB5276.namprd11.prod.outlook.com> (raw)
In-Reply-To: <Y9ZMulxEyGvnvW0X@Asurada-Nvidia>
> From: Nicolin Chen <nicolinc@nvidia.com>
> Sent: Sunday, January 29, 2023 6:39 PM
>
> On Sun, Jan 29, 2023 at 09:37:00AM +0000, Tian, Kevin wrote:
> > External email: Use caution opening links or attachments
> >
> >
> > > From: Nicolin Chen <nicolinc@nvidia.com>
> > > Sent: Sunday, January 29, 2023 5:18 AM
> > >
> > > -static bool iommufd_hw_pagetable_has_group(struct
> > > iommufd_hw_pagetable *hwpt,
> > > - struct iommu_group *group)
> > > +static bool iommufd_hw_pagetable_has_device(struct
> > > iommufd_hw_pagetable *hwpt,
> > > + struct device *dev)
> > > {
> > > - struct iommufd_device *cur_dev;
> > > -
> > > - list_for_each_entry(cur_dev, &hwpt->devices, devices_item)
> > > - if (cur_dev->group == group)
> > > - return true;
> > > - return false;
> > > + /*
> > > + * iommu_get_domain_for_dev() returns an iommu_group->domain
> > > ptr, if it
> > > + * is the same domain as the hwpt->domain, it means that this hwpt
> > > has
> > > + * the iommu_group/device.
> > > + */
> > > + return hwpt->domain == iommu_get_domain_for_dev(dev);
> > > }
> >
> > Here we could have three scenarios:
> >
> > 1) the device is attached to blocked domain;
> > 2) the device is attached to hwpt->domain;
> > 3) the device is attached to another hwpt->domain;
> >
> > if this function returns false then iommufd_device_do_attach() will attach
> > the device to the specified hwpt. But then it's wrong for 3).
> >
> > Has 3) been denied in earlier path? If yes at least a WARN_ON for
> > case 3) makes sense here.
>
> The case #3 means the device is already attached to some other
> domain? Then vfio_iommufd_physical_attach_ioas returns -EBUSY
> at the sanity of vdev->iommufd_attached. And the case #3 feels
> like a domain replacement use case to me. So probably not that
> necessary to add a wARN_ON?
>
You are right. I thought about the cdev case where the device is
not attached in vfio but has a valid domain due to attach status
of other devices in the group. But even in this case it's user's
responsibility to not break group boundary. So yes it's just a
domain replacement and WARN_ON is not required.
next prev parent reply other threads:[~2023-01-30 0:45 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 21:18 [PATCH v2 0/3] iommufd: Remove iommufd_hw_pagetable_has_group Nicolin Chen
2023-01-28 21:18 ` [PATCH v2 1/3] iommufd: Add devices_users to track the hw_pagetable usage by device Nicolin Chen
2023-01-29 9:23 ` Tian, Kevin
2023-01-29 9:30 ` Nicolin Chen
2023-01-29 9:39 ` Tian, Kevin
2023-01-30 2:22 ` Liu, Yi L
2023-01-30 15:02 ` Jason Gunthorpe
2023-01-30 19:27 ` Nicolin Chen
2023-01-30 19:50 ` Jason Gunthorpe
2023-01-30 20:04 ` Nicolin Chen
2023-01-30 20:35 ` Jason Gunthorpe
2023-01-30 20:53 ` Nicolin Chen
2023-02-01 7:48 ` Nicolin Chen
2023-02-02 9:12 ` Nicolin Chen
2023-02-07 4:19 ` Liu, Yi L
2023-02-01 6:57 ` Nicolin Chen
2023-02-01 7:56 ` Nicolin Chen
2023-02-01 15:53 ` Jason Gunthorpe
2023-02-01 17:46 ` Nicolin Chen
2023-02-01 18:37 ` Jason Gunthorpe
2023-02-01 19:25 ` Nicolin Chen
2023-02-01 20:00 ` Jason Gunthorpe
2023-02-01 21:18 ` Nicolin Chen
2023-02-02 7:28 ` Nicolin Chen
2023-02-02 15:03 ` Jason Gunthorpe
2023-02-07 4:27 ` Liu, Yi L
2023-01-28 21:18 ` [PATCH v2 2/3] iommufd/device: Make hwpt_list list_add/del symmetric Nicolin Chen
2023-01-29 9:24 ` Tian, Kevin
2023-01-29 9:31 ` Nicolin Chen
2023-01-30 14:59 ` Jason Gunthorpe
2023-01-30 19:03 ` Nicolin Chen
2023-01-30 19:07 ` Jason Gunthorpe
2023-01-30 19:38 ` Nicolin Chen
2023-01-28 21:18 ` [PATCH v2 3/3] iommufd/device: Change iommufd_hw_pagetable_has_group to device centric Nicolin Chen
2023-01-29 9:37 ` Tian, Kevin
2023-01-29 10:38 ` Nicolin Chen
2023-01-30 0:44 ` Tian, Kevin [this message]
2023-01-30 10:22 ` Nicolin Chen
2023-02-01 3:07 ` Tian, Kevin
2023-02-01 6:49 ` Baolu Lu
2023-02-01 6:59 ` Tian, Kevin
2023-02-01 7:20 ` Nicolin Chen
2023-02-02 6:32 ` Tian, Kevin
2023-02-02 6:36 ` Nicolin Chen
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=BN9PR11MB52769DF1D9C9C06C88CC13408CD39@BN9PR11MB5276.namprd11.prod.outlook.com \
--to=kevin.tian@intel.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolinc@nvidia.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;
as well as URLs for NNTP newsgroup(s).