]> git.karo-electronics.de Git - karo-tx-linux.git/commit
vfio-mdev: Fix remove race
authorAlex Williamson <alex.williamson@redhat.com>
Fri, 30 Dec 2016 15:13:33 +0000 (08:13 -0700)
committerAlex Williamson <alex.williamson@redhat.com>
Fri, 30 Dec 2016 15:13:33 +0000 (08:13 -0700)
commit49550787a90b5bfa44d8dc424d11824dbe21473d
treefa32ae34a162eab3b96c2f1740aa64af822b5e5f
parent6c38c055cc4c0a5da31873d173b2de3085f43f33
vfio-mdev: Fix remove race

Using the mtty mdev sample driver we can generate a remove race by
starting one shell that continuously creates mtty devices and several
other shells all attempting to remove devices, in my case four remove
shells.  The fault occurs in mdev_remove_sysfs_files() where the
passed type arg is NULL, which suggests we've received a struct device
in mdev_device_remove() but it's in some sort of teardown state.  The
solution here is to make use of the accidentally unused list_head on
the mdev_device such that the mdev core keeps a list of all the mdev
devices.  This allows us to validate that we have a valid mdev before
we start removal, remove it from the list to prevent others from
working on it, and if the vendor driver refuses to remove, we can
re-add it to the list.

Cc: Kirti Wankhede <kwankhede@nvidia.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
drivers/vfio/mdev/mdev_core.c