• Milan Broz's avatar
    loop: Flush possible running bios when loop device is released. · 14f27939
    Milan Broz authored
    When there are still queued bios and reference count
    drops to zero, loop device must flush all queued bios.
    
    Otherwise it can lead to situation that caller
    closes the device, but some bios are still running
    and endio() function call later OOpses when uses
    unallocated mempool.
    
    This happens for example when running dm-crypt over loop,
    here is typical oops backtrace:
    
     Oops: 0000 [#1] PREEMPT SMP
     EIP is at mempool_free+0x12/0x6b
    ...
     crypt_dec_pending+0x50/0x54 [dm_crypt]
     crypt_endio+0x9f/0xa7 [dm_crypt]
     crypt_endio+0x0/0xa7 [dm_crypt]
     bio_endio+0x2b/0x2e
     loop_thread+0x37a/0x3b1
     do_lo_send_aops+0x0/0x165
     autoremove_wake_function+0x0/0x33
     loop_thread+0x0/0x3b1
     kthread+0x3b/0x61
     kthread+0x0/0x61
     kernel_thread_helper+0x7/0x10
    
    (But crash is reproducible with different dm targets
    running over loop device too.)
    
    Patch fixes it by flushing the bios in release call,
    reusing the flush mechanism for switching backing store.
    Signed-off-by: default avatarMilan Broz <mbroz@redhat.com>
    Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
    14f27939
loop.c 39.1 KB