Skip to content
  • Stefan Hajnoczi's avatar
    e62da985
    aio-posix: fix race between epoll upgrade and aio_set_fd_handler() · e62da985
    Stefan Hajnoczi authored
    
    
    If another thread calls aio_set_fd_handler() while the IOThread event
    loop is upgrading from ppoll(2) to epoll(7) then we might miss new
    AioHandlers. The epollfd will not monitor the new AioHandler's fd,
    resulting in hangs.
    
    Take the AioHandler list lock while upgrading to epoll. This prevents
    AioHandlers from changing while epoll is being set up. If we cannot lock
    because we're in a nested event loop, then don't upgrade to epoll (it
    will happen next time we're not in a nested call).
    
    The downside to taking the lock is that the aio_set_fd_handler() thread
    has to wait until the epoll upgrade is finished, which involves many
    epoll_ctl(2) system calls. However, this scenario is rare and I couldn't
    think of another solution that is still simple.
    
    Reported-by: default avatarQing Wang <qinwang@redhat.com>
    Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2090998
    
    
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Fam Zheng <fam@euphon.net>
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20230323144859.1338495-1-stefanha@redhat.com>
    Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    e62da985
    aio-posix: fix race between epoll upgrade and aio_set_fd_handler()
    Stefan Hajnoczi authored
    
    
    If another thread calls aio_set_fd_handler() while the IOThread event
    loop is upgrading from ppoll(2) to epoll(7) then we might miss new
    AioHandlers. The epollfd will not monitor the new AioHandler's fd,
    resulting in hangs.
    
    Take the AioHandler list lock while upgrading to epoll. This prevents
    AioHandlers from changing while epoll is being set up. If we cannot lock
    because we're in a nested event loop, then don't upgrade to epoll (it
    will happen next time we're not in a nested call).
    
    The downside to taking the lock is that the aio_set_fd_handler() thread
    has to wait until the epoll upgrade is finished, which involves many
    epoll_ctl(2) system calls. However, this scenario is rare and I couldn't
    think of another solution that is still simple.
    
    Reported-by: default avatarQing Wang <qinwang@redhat.com>
    Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2090998
    
    
    Cc: Paolo Bonzini <pbonzini@redhat.com>
    Cc: Fam Zheng <fam@euphon.net>
    Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
    Message-Id: <20230323144859.1338495-1-stefanha@redhat.com>
    Reviewed-by: default avatarKevin Wolf <kwolf@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading