From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linhaifeng Subject: Re: [PATCH] vhost: flush used->idx update before reading avail->flags Date: Fri, 24 Apr 2015 09:01:15 +0800 Message-ID: <553995DB.4000801@huawei.com> References: <1429720392-25345-1-git-send-email-huawei.xie@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Cc: mst-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org To: Huawei Xie , Return-path: In-Reply-To: <1429720392-25345-1-git-send-email-huawei.xie-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" On 2015/4/23 0:33, Huawei Xie wrote: > update of used->idx and read of avail->flags could be reordered. > memory fence should be used to ensure the order, otherwise guest could see a stale used->idx value after it toggles the interrupt suppression flag. > > Signed-off-by: Huawei Xie > --- > lib/librte_vhost/vhost_rxtx.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c > index 510ffe8..6afba35 100644 > --- a/lib/librte_vhost/vhost_rxtx.c > +++ b/lib/librte_vhost/vhost_rxtx.c > @@ -178,6 +178,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id, > *(volatile uint16_t *)&vq->used->idx += count; > vq->last_used_idx = res_end_idx; > > + /* flush used->idx update before we read avail->flags. */ > + rte_mb(); > + > /* Kick the guest if necessary. */ > if (!(vq->avail->flags & VRING_AVAIL_F_NO_INTERRUPT)) > eventfd_write((int)vq->callfd, 1); > If not add memory fence what would happen? Packets loss or interrupt loss?How to test it ?