From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750993AbeABVMm (ORCPT + 1 other); Tue, 2 Jan 2018 16:12:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55578 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750726AbeABVMk (ORCPT ); Tue, 2 Jan 2018 16:12:40 -0500 Date: Tue, 2 Jan 2018 22:12:30 +0100 From: Stefano Brivio To: Nicolai Stange Cc: "David S. Miller" , Alexey Kuznetsov , Hideaki YOSHIFUJI , Mohamed Ghannam , Michal Kubecek , Miroslav Benes , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] net: ipv4: emulate READ_ONCE() on ->hdrincl bit-field in raw_sendmsg() Message-ID: <20180102221230.452019a9@elisabeth> In-Reply-To: <20180102163020.32473-1-nstange@suse.de> References: <20180102163020.32473-1-nstange@suse.de> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 02 Jan 2018 21:12:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi, On Tue, 2 Jan 2018 17:30:20 +0100 Nicolai Stange wrote: > [...] > > diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c > index 5b9bd5c33d9d..e84290c28c0c 100644 > --- a/net/ipv4/raw.c > +++ b/net/ipv4/raw.c > @@ -513,16 +513,18 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) > int err; > struct ip_options_data opt_copy; > struct raw_frag_vec rfv; > - int hdrincl; > + int hdrincl, __hdrincl; > > err = -EMSGSIZE; > if (len > 0xFFFF) > goto out; > > /* hdrincl should be READ_ONCE(inet->hdrincl) > - * but READ_ONCE() doesn't work with bit fields > + * but READ_ONCE() doesn't work with bit fields. > + * Emulate it by doing the READ_ONCE() from an intermediate int. > */ > - hdrincl = inet->hdrincl; > + __hdrincl = inet->hdrincl; > + hdrincl = READ_ONCE(__hdrincl); I guess you don't actually need to use a third variable. What about doing READ_ONCE() on hdrincl itself after the first assignment? Perhaps something like the patch below -- applies to net.git, yields same binary output as your version with gcc 6, looks IMHO more straightforward: diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 125c1eab3eaa..8c2f783a95fc 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -519,10 +519,12 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (len > 0xFFFF) goto out; - /* hdrincl should be READ_ONCE(inet->hdrincl) - * but READ_ONCE() doesn't work with bit fields + /* hdrincl should be READ_ONCE(inet->hdrincl) but READ_ONCE() doesn't + * work with bit fields. Emulate it by adding a further sequence point. */ hdrincl = inet->hdrincl; + hdrincl = READ_ONCE(hdrincl); + /* * Check the flags. */ -- Stefano