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