Skip to content

Commit

Permalink
vfio/mbochs: Fix close when multiple device FDs are open
Browse files Browse the repository at this point in the history
mbochs_close() iterates over global device state and frees it. Currently
this is done every time a device FD is closed, but if multiple device FDs
are open this could corrupt other still active FDs.

Change this to use close_device() so it only runs on the last close.

Reviewed-by: Cornelia Huck <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alex Williamson <[email protected]>
  • Loading branch information
jgunthorpe authored and awilliam committed Aug 11, 2021
1 parent db44c17 commit 3cb2482
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions samples/vfio-mdev/mbochs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ static long mbochs_ioctl(struct vfio_device *vdev, unsigned int cmd,
return -ENOTTY;
}

static void mbochs_close(struct vfio_device *vdev)
static void mbochs_close_device(struct vfio_device *vdev)
{
struct mdev_state *mdev_state =
container_of(vdev, struct mdev_state, vdev);
Expand Down Expand Up @@ -1396,7 +1396,7 @@ static struct attribute_group *mdev_type_groups[] = {
};

static const struct vfio_device_ops mbochs_dev_ops = {
.release = mbochs_close,
.close_device = mbochs_close_device,
.read = mbochs_read,
.write = mbochs_write,
.ioctl = mbochs_ioctl,
Expand Down

0 comments on commit 3cb2482

Please sign in to comment.