From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yuanhan Liu Subject: Re: [PATCH] virtio: use volatile to get used->idx in the loop Date: Thu, 2 Jun 2016 16:52:15 +0800 Message-ID: <20160602085215.GU10038@yliu-dev.sh.intel.com> References: <1464106601-981-1-git-send-email-huawei.xie@intel.com> <20160530082258.GF5641@yliu-dev.sh.intel.com> <20160601060532.GK5641@yliu-dev.sh.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: "dev@dpdk.org" , "stephen@networkplumber.org" , "Ananyev, Konstantin" , "thomas.monjalon@6wind.com" To: "Xie, Huawei" Return-path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id C32F72C69 for ; Thu, 2 Jun 2016 10:52:12 +0200 (CEST) Content-Disposition: inline In-Reply-To: List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Thu, Jun 02, 2016 at 08:39:36AM +0000, Xie, Huawei wrote: > On 6/1/2016 2:03 PM, Yuanhan Liu wrote: > > On Wed, Jun 01, 2016 at 05:40:08AM +0000, Xie, Huawei wrote: > >> On 5/30/2016 4:20 PM, Yuanhan Liu wrote: > >>> On Wed, May 25, 2016 at 12:16:41AM +0800, Huawei Xie wrote: > >>>> There is no external function call or any barrier in the loop, > >>>> the used->idx would only be retrieved once. > >>>> > >>>> Signed-off-by: Huawei Xie > >>>> --- > >>>> drivers/net/virtio/virtio_ethdev.c | 3 ++- > >>>> 1 file changed, 2 insertions(+), 1 deletion(-) > >>>> > >>>> diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c > >>>> index c3fb628..f6d6305 100644 > >>>> --- a/drivers/net/virtio/virtio_ethdev.c > >>>> +++ b/drivers/net/virtio/virtio_ethdev.c > >>>> @@ -204,7 +204,8 @@ virtio_send_command(struct virtqueue *vq, struct virtio_pmd_ctrl *ctrl, > >>>> usleep(100); > >>>> } > >>>> > >>>> - while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) { > >>>> + while (vq->vq_used_cons_idx != > >>>> + *((volatile uint16_t *)(&vq->vq_ring.used->idx))) { > >>> I'm wondering maybe we could fix VIRTQUEUE_NUSED (which has no such > >>> qualifier) and use this macro here? > >>> > >>> If you check the reference of that macro, you might find similar > >>> issues, say, it is also used inside the while-loop of > >>> virtio_recv_mergeable_pkts(). > >>> > >>> --yliu > >>> > >>> > >> Yes, seems it has same issue though haven't confirmed with asm code. > > So, move the "volatile" qualifier to VIRTQUEUE_NUSED? > > > > --yliu > > > > Yes, anyway this is just intermediate fix. In next patch, will declare > the idx as volatile, and remove the qualifier in the macro. Hmm.., why we need an intermediate fix then, if we can come up with an ultimate fix very quickly? --yliu