From owner-svn-src-stable-12@freebsd.org Fri Sep 4 13:09:57 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0DBC53C1F28; Fri, 4 Sep 2020 13:09:57 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4BjdLr1YRwz4279; Fri, 4 Sep 2020 13:09:55 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 084D9kvY017845 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 4 Sep 2020 16:09:49 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 084D9kvY017845 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 084D9kI4017844; Fri, 4 Sep 2020 16:09:46 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Fri, 4 Sep 2020 16:09:46 +0300 From: Konstantin Belousov To: Marcin Wojtas Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: Re: svn commit: r365326 - stable/12/sys/sys Message-ID: <20200904130946.GG94807@kib.kiev.ua> References: <202009041122.084BMIYn040628@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202009041122.084BMIYn040628@repo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4BjdLr1YRwz4279 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Sep 2020 13:09:57 -0000 On Fri, Sep 04, 2020 at 11:22:18AM +0000, Marcin Wojtas wrote: > Author: mw > Date: Fri Sep 4 11:22:18 2020 > New Revision: 365326 > URL: https://svnweb.freebsd.org/changeset/base/365326 > > Log: > MFC: r346593 > > Add barrier in buf ring peek function to prevent race in ARM and ARM64. > > Obtained from: Semihalf > Sponsored by: Amazon, Inc. > > Modified: > stable/12/sys/sys/buf_ring.h > Directory Properties: > stable/12/ (props changed) > > Modified: stable/12/sys/sys/buf_ring.h > ============================================================================== > --- stable/12/sys/sys/buf_ring.h Fri Sep 4 04:31:56 2020 (r365325) > +++ stable/12/sys/sys/buf_ring.h Fri Sep 4 11:22:18 2020 (r365326) > @@ -310,14 +310,23 @@ buf_ring_peek_clear_sc(struct buf_ring *br) > if (!mtx_owned(br->br_lock)) > panic("lock not held on single consumer dequeue"); > #endif > - /* > - * I believe it is safe to not have a memory barrier > - * here because we control cons and tail is worst case > - * a lagging indicator so we worst case we might > - * return NULL immediately after a buffer has been enqueued > - */ > + > if (br->br_cons_head == br->br_prod_tail) > return (NULL); > + > +#if defined(__arm__) || defined(__aarch64__) > + /* > + * The barrier is required there on ARM and ARM64 to ensure, that > + * br->br_ring[br->br_cons_head] will not be fetched before the above > + * condition is checked. > + * Without the barrier, it is possible, that buffer will be fetched > + * before the enqueue will put mbuf into br, then, in the meantime, the > + * enqueue will update the array and the br_prod_tail, and the > + * conditional check will be true, so we will return previously fetched > + * (and invalid) buffer. > + */ > + atomic_thread_fence_acq(); > +#endif Putting the semantic of the change aside, why did you added the fence (it is a fence, not barrier as stated in the comment) only to arm* ? If it is needed, it is needed for all arches. > > #ifdef DEBUG_BUFRING > /*