• Alex Williamson's avatar
    vfio-mdev: Fix remove race · 49550787
    Alex Williamson authored
    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: default avatarAlex Williamson <alex.williamson@redhat.com>
    49550787
mdev_core.c 8.89 KB