Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3219504imu; Mon, 28 Jan 2019 00:34:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN75LtmAqgrLP6VzGy3zoorzTscq/kPCl53TwMBakNqYQqCP0TXE2qoOmjD9qmFh7OdAZWvs X-Received: by 2002:a63:b105:: with SMTP id r5mr19074010pgf.442.1548664473531; Mon, 28 Jan 2019 00:34:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548664473; cv=none; d=google.com; s=arc-20160816; b=KiBB7QI1mNFgYjfXiOJG/P3OPbO7FDVIOfjvSaGnZVQ5/LF78l2lLCgnJC+2ezBEWx fNoZAAq3jf+kLgJnJqke7cYO7ceA9ZMtxDFy01Y7lE+tEeYX2DPiPzExaktHlkzFfize nwfbvA5++IUs9LtCUD7nacsGNFF0uBg5tnrQTB+3gClgB7OXgrwkgdx8N+02WFFDgVMV n2JxqvKZaDMDkN7VzuCj2+5O/eyu/81ikA7jUFoLetS46aaP2iOVV4k01WS50g2HDoeL awzvTtzYOq1FHbUxCVDcvQePuX4p7QmQOJ486ygfmL6opyKj5EY9uTRdlsmAD2DrTG4P aQqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vr/HMut0ktj2VJdSoSaKoFxNf82QpzugkR31+X8r3b0=; b=owLJg+YJIfWxNIM9BghZ1Z0iFPpWyuCu6ay8aqNYMterAMstGJGmdY0dizLLUb0BX+ eZvWRCMvma8Y2zf9FLNETgAanpy7jfs3DF80jw7PYl96KiDrhFJoUvn6it+QEkE9/nW2 M1hOnFybpvDGjYMTvp6oVDTzhHXQXqwD4fDHUHy0iUxlAQ0PJ/vW5cN5oK8zwT7ZrFXr qZtgunn/IXLA9yv6civKu4V+JSQHbneX4mZ7pNuL8NkcvtI7v9X8VAlHx0u63zp4p8E2 CTHYypmp7JpW4lfSnXTWweuxahdiYZDnePm3BI5dAP/ytr8vb3j+AzZD0j1arD5rMFqn IstQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TCwOTyue; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si35005197pls.162.2019.01.28.00.34.17; Mon, 28 Jan 2019 00:34:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=TCwOTyue; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726946AbfA1IeM (ORCPT + 99 others); Mon, 28 Jan 2019 03:34:12 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:43895 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbfA1IeL (ORCPT ); Mon, 28 Jan 2019 03:34:11 -0500 Received: by mail-io1-f66.google.com with SMTP id b23so12728602ios.10 for ; Mon, 28 Jan 2019 00:34:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vr/HMut0ktj2VJdSoSaKoFxNf82QpzugkR31+X8r3b0=; b=TCwOTyue9xncwPQFRgJFoohPMjIj4I3l+DEbqJbO3Sn4ypiAu8x8BtTUx4tr49Ae53 wy2+KylCncKRfOrptootOdCfqUneP3Rxagb0XZjcDsWlOL3ku+vy9etk42oPdP/A6r9U CdRbiNlP5L4JrPZmHd3MSvnKftmEcrllYpufnpx7SQ5LBgRGcsJ8QZC8vyQTFuyD1C0A 3aV4ZyGykREJWAtuE8+FBodCTiCLuEq7205Q3CM/My2HVL+aahVZj0dQmcl3eNy1aGFc dU4obVn6HEAO90JDJ6d2XaGREphS+lHKhSgBfSutuUua954ebtsz0EcXtMWipMbm+N+3 o0xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vr/HMut0ktj2VJdSoSaKoFxNf82QpzugkR31+X8r3b0=; b=qruLHvExMPI/7awjx9v4mBpCWGXqrpkNQ+IQIAcimlUYWZbI8egBBfsjSyTNyWmb9m P1lEecAF9rK3+pewDTwXM3aDLmcm769I4pN2BdvJPYKLKIWkGCo8abRkevt6QOH+MURb 9R9QP6FvLT2H0wNJH3X3sWy3/N1T0Nb+g/3kmjCOiUcgZd5R1y5XC1C/farFi1CTonCs g2IED8ScBDHJ8MXsD0sQhrbtjOdN0AExqpF7Fqx/wrFjimgYNwsD0z/OoJkYFDURDfc+ GkTJdeTuPUgKf7nN08TEx3ty28zxOB3HCt592BFkYnV6KxqPZ27oQDu2OPdbZZnQKD2P aeOg== X-Gm-Message-State: AHQUAuZfw7ppAUMMb8qhtu4fgrZEkxYPZkH35pIbcna9rD8w8yoYtpGL bxftnFDTySaK4znqKoOxQoVpdpQ/EIPCi/knpvTS8w== X-Received: by 2002:a5d:9456:: with SMTP id x22mr10205689ior.282.1548664450355; Mon, 28 Jan 2019 00:34:10 -0800 (PST) MIME-Version: 1.0 References: <20190121131816.GC17749@hirez.programming.kicks-ass.net> <20190122090456.GE13777@hirez.programming.kicks-ass.net> <2236FBA76BA1254E88B949DDB74E612BA4B944B3@IRSMSX102.ger.corp.intel.com> In-Reply-To: <2236FBA76BA1254E88B949DDB74E612BA4B944B3@IRSMSX102.ger.corp.intel.com> From: Dmitry Vyukov Date: Mon, 28 Jan 2019 09:33:58 +0100 Message-ID: Subject: Re: [PATCH] kcov: convert kcov.refcount to refcount_t To: "Reshetova, Elena" Cc: Peter Zijlstra , Alan Stern , Andrea Parri , Kees Cook , "Paul E. McKenney" , Will Deacon , Andrew Morton , Andrey Ryabinin , Anders Roxell , Mark Rutland , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Jan 27, 2019 at 7:41 PM Reshetova, Elena wrote: > > > On Mon, Jan 21, 2019 at 11:05:03AM -0500, Alan Stern wrote: > > > On Mon, 21 Jan 2019, Peter Zijlstra wrote: > > > > > > Any additional ordering; like the one you have above; are not strictly > > > > required for the proper functioning of the refcount. Rather, you rely on > > > > additional ordering and will need to provide this explicitly: > > > > > > > > > > > > if (refcount_dec_and_text(&x->rc)) { > > > > /* > > > > * Comment that explains what we order against.... > > > > */ > > > > smp_mb__after_atomic(); > > > > BUG_ON(!x->done*); > > > > free(x); > > > > } > > > > > > > > > > > > Also; these patches explicitly mention that refcount_t is weaker, > > > > specifically to make people aware of this difference. > > > > > > > > A full smp_mb() (or two) would also be much more expensive on a number > > > > of platforms and in the vast majority of the cases it is not required. > > > > > > How about adding smp_rmb() into refcount_dec_and_test()? That would > > > give acq+rel semantics, which seems to be what people will expect. And > > >it wouldn't be nearly as expensive as a full smp_mb(). > > > > Yes, that's a very good suggestion. > > > > I suppose we can add smp_acquire__after_ctrl_dep() on the true branch. > > Then it reall does become rel_acq. > > > > A wee something like so (I couldn't find an arm64 refcount, even though > > I have distinct memories of talk about it). > > > > This isn't compiled, and obviously needs comment/documentation updates > > to go along with it. > > > > --- > > arch/x86/include/asm/refcount.h | 9 ++++++++- > > lib/refcount.c | 7 ++++++- > > 2 files changed, 14 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h > > index dbaed55c1c24..6f7a1eb345b4 100644 > > --- a/arch/x86/include/asm/refcount.h > > +++ b/arch/x86/include/asm/refcount.h > > @@ -74,9 +74,16 @@ bool refcount_sub_and_test(unsigned int i, refcount_t *r) > > > > static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r) > > { > > - return GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl", > > + bool ret = GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl", > > > > REFCOUNT_CHECK_LT_ZERO, > > r- > > >refs.counter, e, "cx"); > > + > > + if (ret) { > > + smp_acquire__after_ctrl_dep(); > > + return true; > > + } > > + > > + return false; > > } > > Actually as I started to do this, any reason why the change here only for dec_and_test and not > for sub_and _test also? Should not the arch. specific logic follow the generic? I would say these should be exactly the same wrt semantics. dec_and_test is just syntactic sugar for 1 decrement. If we change dec_and_test, we should change sub_and_test the same way.