• Benjamin LaHaise's avatar
    aio: fix reqs_available handling · b1fd18c3
    Benjamin LaHaise authored
    commit d856f32a upstream.
    
    As reported by Dan Aloni, commit f8567a38 ("aio: fix aio request
    leak when events are reaped by userspace") introduces a regression when
    user code attempts to perform io_submit() with more events than are
    available in the ring buffer.  Reverting that commit would reintroduce a
    regression when user space event reaping is used.
    
    Fixing this bug is a bit more involved than the previous attempts to fix
    this regression.  Since we do not have a single point at which we can
    count events as being reaped by user space and io_getevents(), we have
    to track event completion by looking at the number of events left in the
    event ring.  So long as there are as many events in the ring buffer as
    there have been completion events generate, we cannot call
    put_reqs_available().  The code to check for this is now placed in
    refill_reqs_available().
    
    A test program from Dan and modified by me for verifying this bug is available
    at http://www.kvack.org/~bcrl/20140824-aio_bug.c .
    Reported-by: default avatarDan Aloni <dan@kernelim.com>
    Signed-off-by: default avatarBenjamin LaHaise <bcrl@kvack.org>
    Acked-by: default avatarDan Aloni <dan@kernelim.com>
    Cc: Kent Overstreet <kmo@daterainc.com>
    Cc: Mateusz Guzik <mguzik@redhat.com>
    Cc: Petr Matousek <pmatouse@redhat.com>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    b1fd18c3
aio.c 41.8 KB