From a78c896369330f0cfec6150734f35bffdab56b0b Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Mon, 29 Jan 2018 17:32:00 +0100 Subject: [PATCH] vhost: add a memory barrier after incrementing used->idx Ensure the used->idx changes are visible to the guest at the time of interrupt. Change-Id: I245b91c7fbe2e21600aa94d8314271ea5b987343 Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/396929 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Jim Harris --- lib/vhost/vhost.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c index d4dafd13a..11df11001 100644 --- a/lib/vhost/vhost.c +++ b/lib/vhost/vhost.c @@ -286,9 +286,17 @@ spdk_vhost_vq_used_ring_enqueue(struct spdk_vhost_dev *vdev, struct spdk_vhost_v used->ring[last_idx].id = id; used->ring[last_idx].len = len; - spdk_wmb(); + /* Ensure the used ring is updated before we increment used->idx. */ + spdk_smp_wmb(); * (volatile uint16_t *) &used->idx = vring->last_used_idx; + /* Ensure all our used ring changes are visible to the guest at the time + * of interrupt. + * TODO: this is currently an sfence on x86. For other architectures we + * will most likely need an smp_mb(), but smp_mb() is an overkill for x86. + */ + spdk_wmb(); + virtqueue->used_req_cnt++; /* We need to signal every last_used_idx overflow. */