• M
    dm cache: fix bugs when a GFP_NOWAIT allocation fails · 69f2ec11
    Mikulas Patocka 提交于
    commit 13bd677a472d534bf100bab2713efc3f9e3f5978 upstream.
    
    GFP_NOWAIT allocation can fail anytime - it doesn't wait for memory being
    available and it fails if the mempool is exhausted and there is not enough
    memory.
    
    If we go down this path:
      map_bio -> mg_start -> alloc_migration -> mempool_alloc(GFP_NOWAIT)
    we can see that map_bio() doesn't check the return value of mg_start(),
    and the bio is leaked.
    
    If we go down this path:
      map_bio -> mg_start -> mg_lock_writes -> alloc_prison_cell ->
      dm_bio_prison_alloc_cell_v2 -> mempool_alloc(GFP_NOWAIT) ->
      mg_lock_writes -> mg_complete
    the bio is ended with an error - it is unacceptable because it could
    cause filesystem corruption if the machine ran out of memory
    temporarily.
    
    Change GFP_NOWAIT to GFP_NOIO, so that the mempool code will properly
    wait until memory becomes available. mempool_alloc with GFP_NOIO can't
    fail, so remove the code paths that deal with allocation failure.
    
    Cc: stable@vger.kernel.org
    Signed-off-by: NMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: NMike Snitzer <snitzer@redhat.com>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    69f2ec11
dm-cache-target.c 82.5 KB