> From: Liu, Yi L <yi.l.liu@xxxxxxxxx> > Sent: Monday, February 13, 2023 11:14 PM > > for counting the devices that are opened via the cdev path. This count > is increased and decreased by the cdev path. The group path checks it > to achieve exclusion with the cdev path. With this, only one path (group > path or cdev path) will claim DMA ownership. This avoids scenarios in > which devices within the same group may be opened via different paths. please move vfio_device_claim/release_group() from patch 14 into this patch to make the exclusiveness part complete. > > Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx> > --- > drivers/vfio/group.c | 5 +++++ > drivers/vfio/vfio.h | 1 + > 2 files changed, 6 insertions(+) > > diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c > index 9f3f6f0e4942..f3f5f4589cdd 100644 > --- a/drivers/vfio/group.c > +++ b/drivers/vfio/group.c > @@ -403,6 +403,11 @@ static int vfio_group_fops_open(struct inode *inode, > struct file *filep) > goto out_unlock; > } > > + if (group->cdev_device_open_cnt) { > + ret = -EBUSY; > + goto out_unlock; > + } > + > /* > * Do we need multiple instances of the group open? Seems not. > */ > diff --git a/drivers/vfio/vfio.h b/drivers/vfio/vfio.h > index 6f063e31d08a..7a77fb12bd2c 100644 > --- a/drivers/vfio/vfio.h > +++ b/drivers/vfio/vfio.h > @@ -84,6 +84,7 @@ struct vfio_group { > struct blocking_notifier_head notifier; > struct iommufd_ctx *iommufd; > spinlock_t kvm_ref_lock; > + unsigned int cdev_device_open_cnt; > }; > > int vfio_device_set_group(struct vfio_device *device, > -- > 2.34.1