Commit a78c8963 authored by Dariusz Stojaczyk's avatar Dariusz Stojaczyk Committed by Jim Harris
Browse files

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: default avatarDariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/396929


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 85a0a63e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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. */