• NeilBrown's avatar
    Avoid dereferencing a 'request_queue' after last close. · 94007751
    NeilBrown authored
    On the last close of an 'md' device which as been stopped, the device
    is destroyed and in particular the request_queue is freed.  The free
    is done in a separate thread so it might happen a short time later.
    
    __blkdev_put calls bdev_inode_switch_bdi *after* ->release has been
    called.
    
    Since commit f758eeab
    bdev_inode_switch_bdi will dereference the 'old' bdi, which lives
    inside a request_queue, to get a spin lock.  This causes the last
    close on an md device to sometime take a spin_lock which lives in
    freed memory - which results in an oops.
    
    So move the called to bdev_inode_switch_bdi before the call to
    ->release.
    
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Wu Fengguang <fengguang.wu@intel.com>
    Acked-by: default avatarWu Fengguang <fengguang.wu@intel.com>
    Cc: stable@kernel.org
    Signed-off-by: default avatarNeilBrown <neilb@suse.de>
    94007751
block_dev.c 40.9 KB