On Sat, Nov 05, 2022 at 03:44:56PM -0700, Anthony DeRossi wrote: > In vfio_device_open(), vfio_container_device_register() is always called > when open_count == 1. On error, vfio_device_container_unregister() is > only called when open_count == 1 and close_device is set. This leaks a > registration for devices without a close_device implementation. > > In vfio_device_fops_release(), vfio_device_container_unregister() is > called unconditionally. This can cause a device to be unregistered > multiple times. > > Treating container device registration/unregistration uniformly (always > when open_count == 1) fixes both issues. > > Fixes: ce4b4657ff18 ("vfio: Replace the DMA unmapping notifier with a callback") > Signed-off-by: Anthony DeRossi <ajderossi@xxxxxxxxx> > --- > drivers/vfio/vfio_main.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) This seems to only effect the mbochs sample, but it looks OK Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx> This will generate conflicts with the iommufd treee, so please lets think about how to avoid them.. Jason