OSDN Git Service

virtiofsd: prevent fv_queue_thread() vs virtio_loop() races
authorStefan Hajnoczi <stefanha@redhat.com>
Wed, 17 Jul 2019 15:05:57 +0000 (16:05 +0100)
committerDr. David Alan Gilbert <dgilbert@redhat.com>
Thu, 23 Jan 2020 16:41:37 +0000 (16:41 +0000)
commite7b337326d594b71b07cd6dbb332c49c122c80a4
treef927a9d9c5baee3d1d3968b10ef768a55a2124a3
parent620e9d8d9cee6df7fe71168dea950dba0cc21a4a
virtiofsd: prevent fv_queue_thread() vs virtio_loop() races

We call into libvhost-user from the virtqueue handler thread and the
vhost-user message processing thread without a lock.  There is nothing
protecting the virtqueue handler thread if the vhost-user message
processing thread changes the virtqueue or memory table while it is
running.

This patch introduces a read-write lock.  Virtqueue handler threads are
readers.  The vhost-user message processing thread is a writer.  This
will allow concurrency for multiqueue in the future while protecting
against fv_queue_thread() vs virtio_loop() races.

Note that the critical sections could be made smaller but it would be
more invasive and require libvhost-user changes.  Let's start simple and
improve performance later, if necessary.  Another option would be an
RCU-style approach with lighter-weight primitives.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
tools/virtiofsd/fuse_virtio.c