• Mikulas Patocka's avatar
    dm sysfs: fix a module unload race · 43057146
    Mikulas Patocka authored
    commit 2995fa78 upstream.
    
    This reverts commit be35f486 ("dm: wait until embedded kobject is
    released before destroying a device") and provides an improved fix.
    
    The kobject release code that calls the completion must be placed in a
    non-module file, otherwise there is a module unload race (if the process
    calling dm_kobject_release is preempted and the DM module unloaded after
    the completion is triggered, but before dm_kobject_release returns).
    
    To fix this race, this patch moves the completion code to dm-builtin.c
    which is always compiled directly into the kernel if BLK_DEV_DM is
    selected.
    
    The patch introduces a new dm_kobject_holder structure, its purpose is
    to keep the completion and kobject in one place, so that it can be
    accessed from non-module code without the need to export the layout of
    struct mapped_device to that code.
    Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
    [bwh: Backported to 3.2:
     - Adjust context
     - Remove paranoid check of container_of() result in dm_get_from_kobject(),
       which would now be incorrect
     - Include <linux/export.h> in dm-builtin.c, included indirectly upstream]
    Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
    43057146
dm.c 60.9 KB