On Fri, Mar 12, 2021 at 10:22:10AM +0100, Greg Kurz wrote: > A deadlock condition potentially exists if a vhost-user process needs > to request something to QEMU on the slave channel while processing a > vhost-user message. > > This doesn't seem to affect any vhost-user implementation so far, but > this is currently biting the upcoming enablement of DAX with virtio-fs. > The issue is being observed when the guest does an emergency reboot while > a mapping still exits in the DAX window, which is very easy to get with > a busy enough workload (e.g. as simulated by blogbench [1]) : > > - QEMU sends VHOST_USER_GET_VRING_BASE to virtiofsd. > > - In order to complete the request, virtiofsd then asks QEMU to remove > the mapping on the slave channel. > > All these dialogs are synchronous, hence the deadlock. > > As pointed out by Stefan Hajnoczi: > > When QEMU's vhost-user master implementation sends a vhost-user protocol > message, vhost_user_read() does a "blocking" read during which slave_fd > is not monitored by QEMU. > > The natural solution for this issue is an event loop. The main event > loop cannot be nested though since we have no guarantees that its > fd handlers are prepared for re-entrancy. > > Introduce a new event loop that only monitors the chardev I/O for now > in vhost_user_read() and push the actual reading to a one-shot handler. > A subsequent patch will teach the loop to monitor and process messages > from the slave channel as well. > > [1] https://github.com/jedisct1/Blogbench > > Suggested-by: Stefan Hajnoczi > Signed-off-by: Greg Kurz > --- > v2: - Document why a nested loop is needed in vhost_user_read() (Stefan) > --- > hw/virtio/vhost-user.c | 65 ++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 60 insertions(+), 5 deletions(-) Reviewed-by: Stefan Hajnoczi