On Tue, Feb 07, 2023 at 01:23:35PM +0000, Liu, Yi L wrote: > > From: Jason Gunthorpe <jgg@xxxxxxxxxx> > > Sent: Tuesday, February 7, 2023 9:20 PM > > > > On Tue, Feb 07, 2023 at 01:19:10PM +0000, Liu, Yi L wrote: > > > > From: Jason Gunthorpe <jgg@xxxxxxxxxx> > > > > Sent: Tuesday, February 7, 2023 9:13 PM > > > > > > > > On Tue, Feb 07, 2023 at 12:35:48AM +0000, Tian, Kevin wrote: > > > > > > From: Liu, Yi L <yi.l.liu@xxxxxxxxx> > > > > > > Sent: Monday, February 6, 2023 11:51 PM > > > > > > > > > > > > > From: Jason Gunthorpe <jgg@xxxxxxxxxx> > > > > > > > Sent: Monday, February 6, 2023 11:11 PM > > > > > > > > > > > > > > On Mon, Feb 06, 2023 at 10:09:52AM +0000, Tian, Kevin wrote: > > > > > > > > It's probably simpler if we always mark DMA owner with > > vfio_group > > > > > > > > for the group path, no matter vfio type1 or iommufd compat is > > used. > > > > > > > > This should avoid all the tricky corner cases between the two > > paths. > > > > > > > > > > > > > > Yes > > > > > > > > > > > > Then, we have two choices: > > > > > > > > > > > > 1) extend iommufd_device_bind() to allow a caller-specified DMA > > > > marker > > > > > > 2) claim DMA owner before calling iommufd_device_bind(), still > > need to > > > > > > extend iommufd_device_bind() to accept a flag to bypass DMA > > > > owner > > > > > > claim > > > > > > > > > > > > which one would be better? or do we have a third choice? > > > > > > > > > > > > > > > > first one > > > > > > > > Why can't this all be handled in vfio?? > > > > > > Are you preferring the second one? Surely VFIO can claim DMA owner > > > by itself. But it is the vfio iommufd compat mode, so it still needs to call > > > iommufd_device_bind(). And it should bypass DMA owner claim since > > > it's already done. > > > > No, I mean why can't vfio just call iommufd exactly once regardless of > > what mode it is running in? > > This seems to be moving the DMA owner claim out of iommufd_device_bind(). > Is it? Then either group and cdev can claim DMA owner with their own DMA > marker. No, it has nothing to do with DMA ownership Just keep a flag in vfio saying it is in group mode or device mode and act accordingly. The iommufd DMA owner check is *only* to be used for protecting against two unrelated drivers trying to claim the same device. Jason