From owner-svn-src-all@freebsd.org Sun Feb 16 16:07:40 2020 Return-Path: Delivered-To: svn-src-all@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 6FF3C239B35; Sun, 16 Feb 2020 16:07:40 +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) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48LBpg6pwGz4PlN; Sun, 16 Feb 2020 16:07:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id 01GG7UGG050149 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sun, 16 Feb 2020 18:07:33 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 01GG7UGG050149 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id 01GG7Ujr050148; Sun, 16 Feb 2020 18:07:30 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 16 Feb 2020 18:07:30 +0200 From: Konstantin Belousov To: Mateusz Guzik Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r357989 - head/sys/sys Message-ID: <20200216160730.GX4808@kib.kiev.ua> References: <202002160314.01G3Ete9074777@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202002160314.01G3Ete9074777@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: 48LBpg6pwGz4PlN X-Spamd-Bar: ----- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-5.99 / 15.00]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Feb 2020 16:07:40 -0000 On Sun, Feb 16, 2020 at 03:14:55AM +0000, Mateusz Guzik wrote: > Author: mjg > Date: Sun Feb 16 03:14:55 2020 > New Revision: 357989 > URL: https://svnweb.freebsd.org/changeset/base/357989 > > Log: > refcount: add missing release fence to refcount_release_if_gt I think you should update comment in refcount_release_last() to point to if_gt() as well. And probably annotate this fence with a pointer to acquire in release_last(). > > The CPU succeeding in releasing the not last reference can still have pending > stores to the object protected by the affected counter. This opens a time > window where another CPU can release the last reference and free the object, > resulting in use-after-free. On top of that this prevents the compiler from > generating more accesses to the object regardless of how atomic_fcmpset_rel_int > is implemented (of course as long as it provides the release semantic). > > Reviewed by: markj > > Modified: > head/sys/sys/refcount.h > > Modified: head/sys/sys/refcount.h > ============================================================================== > --- head/sys/sys/refcount.h Sun Feb 16 01:07:19 2020 (r357988) > +++ head/sys/sys/refcount.h Sun Feb 16 03:14:55 2020 (r357989) > @@ -198,7 +198,7 @@ refcount_release_if_gt(volatile u_int *count, u_int n) > return (false); > if (__predict_false(REFCOUNT_SATURATED(old))) > return (true); > - if (atomic_fcmpset_int(count, &old, old - 1)) > + if (atomic_fcmpset_rel_int(count, &old, old - 1)) > return (true); > } > }