• Milan Broz's avatar
    dm crypt: fix async split · 393b47ef
    Milan Broz authored
    When writing io, dm-crypt has to allocate a new cloned bio
    and encrypt the data into newly-allocated pages attached to this bio.
    In rare cases, because of hw restrictions (e.g. physical segment limit)
    or memory pressure, sometimes more than one cloned bio has to be used,
    each processing a different fragment of the original.
    
    Currently there is one waitqueue which waits for one fragment to finish
    and continues processing the next fragment.
    
    But when using asynchronous crypto this doesn't work, because several
    fragments may be processed asynchronously or in parallel and there is
    only one crypt context that cannot be shared between the bio fragments.
    The result may be corruption of the data contained in the encrypted bio.
    
    The patch fixes this by allocating new dm_crypt_io structs (with new
    crypto contexts) and running them independently.
    
    The fragments contains a pointer to the base dm_crypt_io struct to
    handle reference counting, so the base one is properly deallocated
    after all the fragments are finished.
    
    In a low memory situation, this only uses one additional object from the
    mempool.  If the mempool is empty, the next allocation simple waits for
    previous fragments to complete.
    Signed-off-by: default avatarMilan Broz <mbroz@redhat.com>
    Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
    393b47ef
dm-crypt.c 31 KB