From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id C95571B114; Tue, 11 Dec 2018 19:33:55 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B679307D865; Tue, 11 Dec 2018 18:33:55 +0000 (UTC) Received: from [10.36.112.28] (ovpn-112-28.ams2.redhat.com [10.36.112.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7BFA060C44; Tue, 11 Dec 2018 18:33:50 +0000 (UTC) To: Ilya Maximets , dev@dpdk.org Cc: Tiwei Bie , Zhihong Wang , jfreimann@redhat.com, stable@dpdk.org References: <20181205150926.4895-1-i.maximets@samsung.com> From: Maxime Coquelin Message-ID: Date: Tue, 11 Dec 2018 19:33:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181205150926.4895-1-i.maximets@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 11 Dec 2018 18:33:55 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] vhost: fix double read of descriptor flags X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Dec 2018 18:33:56 -0000 On 12/5/18 4:09 PM, Ilya Maximets wrote: > Flags could be updated in a separate process leading to the > inconsistent check. > > Additionally, read marked as 'volatile' to highlight the shared > nature of the variable and avoid such issues in the future. > > Fixes: d3211c98c456 ("vhost: add helpers for packed virtqueues") > Cc: stable@dpdk.org > > Signed-off-by: Ilya Maximets > --- > lib/librte_vhost/vhost.h | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h > index 5218f1b12..84cbee2b6 100644 > --- a/lib/librte_vhost/vhost.h > +++ b/lib/librte_vhost/vhost.h > @@ -393,8 +393,10 @@ vq_is_packed(struct virtio_net *dev) > static inline bool > desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter) > { > - return wrap_counter == !!(desc->flags & VRING_DESC_F_AVAIL) && > - wrap_counter != !!(desc->flags & VRING_DESC_F_USED); > + uint16_t flags = *((volatile uint16_t *) &desc->flags); > + > + return wrap_counter == !!(flags & VRING_DESC_F_AVAIL) && > + wrap_counter != !!(flags & VRING_DESC_F_USED); > } > > #define VHOST_LOG_PAGE 4096 > Applied to dpdk-next-virtio. Thanks, Maxime