On Thu, May 30, 2019 at 07:59:14PM +0800, Jason Wang wrote:
On 2019/5/30 äå6:10, Stefano Garzarella wrote:What about checking 'the_virtio_vsock' in the worker functions in a RCU
On Thu, May 30, 2019 at 05:46:18PM +0800, Jason Wang wrote:
On 2019/5/29 äå6:58, Stefano Garzarella wrote:Okay, I'm going this way.
On Wed, May 29, 2019 at 11:22:40AM +0800, Jason Wang wrote:Yes, that's my point.
On 2019/5/28 äå6:56, Stefano Garzarella wrote:Both virtio_transport_send_pkt() and vsock_transport_cancel_pkt() can
@@ -690,6 +693,9 @@ static void virtio_vsock_remove(struct virtio_device *vdev)Some questions after a quick glance:
vsock->event_run = false;
+ /* Flush all pending works */
/* Flush all device writes and interrupts, device will not use any
* more buffers.
@@ -726,6 +732,11 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
/* Delete virtqueues and flush outstanding callbacks if any */
+ /* Other works can be queued before 'config->del_vqs()', so we flush
+ * all works before to free the vsock object to avoid use after free.
1) It looks to me that the work could be queued from the path of
vsock_transport_cancel_pkt() . Is that synchronized here?
queue work from the upper layer (socket).
Setting the_virtio_vsock to NULL, should synchronize, but after a careful look
a rare issue could happen:
we are setting the_virtio_vsock to NULL at the start of .remove() and we
are freeing the object pointed by it at the end of .remove(), so
virtio_transport_send_pkt() or vsock_transport_cancel_pkt() may still be
running, accessing the object that we are freed.
Should I use something like RCU to prevent this issue?RCU is probably a way to go. (Like what vhost_transport_send_pkt() did).
virtio_transport_send_pkt() and vsock_transport_cancel_pkt()
vsock = rcu_dereference(the_virtio_vsock_mutex);
My only doubt is:...I mean could we simply do flush after reset once and without tx_rx/rx_run
Could there be a better approach?
2) If we decide to flush after dev_vqs(), is tx_run/rx_run/event_run stillThe main reason of tx_run/rx_run/event_run is to prevent that a worker
needed? It looks to me we've already done except that we need flush rx_work
in the end since send_pkt_work can requeue rx_work.
function is running while we are calling config->reset().
E.g. if an interrupt comes between virtio_vsock_flush_works() and
config->reset(), it can queue new works that can access the device while
we are in config->reset().
IMHO they are still needed.
What do you think?
is it safe to call config->reset() while a worker function could access
I had this doubt reading the Michael's advice and looking at
virtnet_remove() where there are these lines before the config->reset():
/* Make sure no work handler is accessing the device. */
Good point. Then I agree with you. But if we can use the RCU to detect the
detach of device from socket for these, it would be even better.
In this way, I can remove the rx_run/tx_run/event_run.
Do you think it's cleaner?
Thank you very much,