From 6f482b8856303f6a186e88aa0a98b428fd704ef2 Mon Sep 17 00:00:00 2001 From: Conghui Chen Date: Wed, 27 Feb 2019 05:36:21 +0800 Subject: [PATCH] dm: virtio: add memory barrier before notify FE Without memory barrier, the change of used ring index could not immediately detected by FE, this would bring some problems. For virtio-blk FE driver, when it receives an interrupt, and confirms the used ring index has changed, it will first set ring flags with VRING_AVAIL_F_NO_INTERRUPT, then get buffer from virtqueue, after process this request, it will mask VRING_AVAIL_F_NO_INTERRUPT, and get used ring index again before return. If used ring changes, it will process it. At the same time, BE will read this flags before each notify, if VRING_AVAIL_F_NO_INTERRUPT was set, BE will not inject interrupt. Without memory barrier, before FE mask VRING_AVAIL_F_NO_INTERRUPT, BE has finished notify without interrupt, then FE mask VRING_AVAIL_F_NO_INTERRUPT, and get used ring index but failed (index has changed from BE side). FE will return from interrupt handler function, and wait for next interrupt which was not injected by BE. Thus, this will cause kernel hung. Tracked-On: #2732 Signed-off-by: Conghui Chen Signed-off-by: Yin Fengwei Acked-by: Wang Yu --- devicemodel/hw/pci/virtio/virtio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/devicemodel/hw/pci/virtio/virtio.c b/devicemodel/hw/pci/virtio/virtio.c index 62f603559..dcc212961 100644 --- a/devicemodel/hw/pci/virtio/virtio.c +++ b/devicemodel/hw/pci/virtio/virtio.c @@ -35,6 +35,7 @@ #include "pci_core.h" #include "virtio.h" #include "timer.h" +#include /* * Functions for dealing with generalized "virtual devices" as @@ -611,6 +612,9 @@ vq_endchains(struct virtio_vq_info *vq, int used_all_avail) * In any case, though, if NOTIFY_ON_EMPTY is set and the * entire avail was processed, we need to interrupt always. */ + + atomic_thread_fence(); + base = vq->base; old_idx = vq->save_used; vq->save_used = new_idx = vq->used->idx;