Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6309151imu; Mon, 21 Jan 2019 06:47:14 -0800 (PST) X-Google-Smtp-Source: ALg8bN555MV6qD2rZaPcb67WFGzFsPSN4vqeMdkHtXSTiqkVpvCFq4OqsTB6dub627zU2ak3Nngb X-Received: by 2002:a63:ff62:: with SMTP id s34mr28546575pgk.325.1548082034778; Mon, 21 Jan 2019 06:47:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548082034; cv=none; d=google.com; s=arc-20160816; b=b/uPvL6UvaBYtdW9JXFCCjQDmEnzFLMPn5q5rm14d9JbSXQhxsys5zur5TtqPSViNo 4HvEdNOCueZBMtGbnLEWEP/JvsxARR8Dp+D++g3w7BGVWPORIlyQ6bgS87u3QP7m1P7W neCsZOY2yJ/qWBajsUQeROpQsiBRgnBaNkARk97C/mAOzgv9C3+DsxFcsAtbZozrnlOc 2YZ3l/+K/aiqeJBeSD5TYVQ3C9588svlG/1EPUtCo5oyMJdo+GUEfB+zd7tMy2Qq37Mh 3To3Pkxdc6H71RXdc6F+32YhQhu76sQD/jg5m3/DBD4iqFtrQRS2iS8Gtw9BCK5P9/Mw cfHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=t71UswEWBFZkCe082TYkv1u+bc2P8dUcKTngMR/LjjU=; b=XPFilCHwozsPw/ew6vREoWY0Nq/+91vi2qvcl/n0+nQcIXRcAqnsGuuDInObPBOUfT mvREtGcgP0VFN/02vXgWa9sbWfhmh9+iMAzosR32/jnFwkU2tZ+/3X0quh+Jz9sUydSF /E6JgS3c+qDhsyPjUvfoy40GKfuODMHXiQe9k6sslc3kO7++OnTHlrpv62L1zPbjk8Dh 6rbNm9G6dqiOWS3+btMVgogSJtLohXAzdfSyxi5HyGEPxipvc2jFmCeUc4YbuzDo/8kQ zKEoydtHgT1+u1XevVAYmv9BFYTgcw+l5mOWZK/sdwnS+AwN0FUy4BCWHnVRcU4yd7bR DHQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="WAa/hXx6"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bj11si12679426plb.21.2019.01.21.06.46.59; Mon, 21 Jan 2019 06:47:14 -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=@amarulasolutions.com header.s=google header.b="WAa/hXx6"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729575AbfAUOo7 (ORCPT + 99 others); Mon, 21 Jan 2019 09:44:59 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:46946 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729279AbfAUOo7 (ORCPT ); Mon, 21 Jan 2019 09:44:59 -0500 Received: by mail-ed1-f66.google.com with SMTP id o10so16725522edt.13 for ; Mon, 21 Jan 2019 06:44:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=t71UswEWBFZkCe082TYkv1u+bc2P8dUcKTngMR/LjjU=; b=WAa/hXx6GW8lrjNRTKGp8NMMwpFxMm7O9y2g7JXZQo4ZfF3OHRojFxIwyQ1fPMW4Ie HIm8GtcbR97kTLu9y48f0sUAIxi9ZZum2YpJ9I9ZehzCV2O7A9DKIq3Dz8VdcC+Ruv3G cKZsZfiZshA0loGFCo/5/eNQGkhc9kROwVex8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t71UswEWBFZkCe082TYkv1u+bc2P8dUcKTngMR/LjjU=; b=MOZ+fE/bUiKxCdPVXkm0gG4rZjJfFqAddqf8iqD/4wRNGg6qBdC58S2qQ96WiNEnUC w9OPj/3dPqpENokeopXfgn9qJg5oVEWOUv4+wImYxy1kaaJ6LQuTXy220fbfh7ED/9oe TRJUf4f5JWcOL3NRtCYZ1CQMv3MhLwciW25X3ZCw9Tii8Ta/X4lptA7tvYVU4oRvM0E1 VpLAqVu6+IrsTZtdfMlAMFNkUDHCQ8NJSHMwwslVaqBCz/Bz3rzpZqFUQpNPmA8FXqD/ PRAWPBWHSAUcmGaHMS0mAaLvBpBnJLCV9s3qwOFxejDjzG5jcdeTnbU8HRQvD46vBNEQ X49w== X-Gm-Message-State: AJcUukchsEIiSHXc1tBXQRBrpCFjNz55og2QRVr6N1l31hh8bm0siWjQ rvXorEhI28tlYUBLM+wNxU8eWw== X-Received: by 2002:a17:906:4684:: with SMTP id a4-v6mr24600628ejr.24.1548081896851; Mon, 21 Jan 2019 06:44:56 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id d56sm9206090ede.76.2019.01.21.06.44.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 06:44:56 -0800 (PST) Date: Mon, 21 Jan 2019 15:44:46 +0100 From: Andrea Parri To: Dmitry Vyukov Cc: Elena Reshetova , Kees Cook , Peter Zijlstra , Alan Stern , "Paul E. McKenney" , Will Deacon , Andrew Morton , Andrey Ryabinin , Anders Roxell , Mark Rutland , LKML Subject: Re: [PATCH] kcov: convert kcov.refcount to refcount_t Message-ID: <20190121144446.GA8926@andrea> References: <1547634429-772-1-git-send-email-elena.reshetova@intel.com> <20190121114505.GA7307@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 21, 2019 at 01:29:11PM +0100, Dmitry Vyukov wrote: > On Mon, Jan 21, 2019 at 12:45 PM Andrea Parri > wrote: > > > > On Mon, Jan 21, 2019 at 10:52:37AM +0100, Dmitry Vyukov wrote: > > > > [...] > > > > > > Am I missing something or refcount_dec_and_test does not in fact > > > > provide ACQUIRE ordering? > > > > > > > > +case 5) - decrement-based RMW ops that return a value > > > > +----------------------------------------------------- > > > > + > > > > +Function changes: > > > > + atomic_dec_and_test() --> refcount_dec_and_test() > > > > + atomic_sub_and_test() --> refcount_sub_and_test() > > > > + no atomic counterpart --> refcount_dec_if_one() > > > > + atomic_add_unless(&var, -1, 1) --> refcount_dec_not_one(&var) > > > > + > > > > +Memory ordering guarantees changes: > > > > + fully ordered --> RELEASE ordering + control dependency > > > > > > > > I think that's against the expected refcount guarantees. When I > > > > privatize an atomic_dec_and_test I would expect that not only stores, > > > > but also loads act on a quiescent object. But loads can hoist outside > > > > of the control dependency. > > > > > > > > Consider the following example, is it the case that the BUG_ON can still fire? > > > > Can't it fire in an SC world? (wrong example, or a Monday morning? ;D) > > I don't see how. Maybe there is a stupid off-by-one, but overall > that's the example I wanted to show. refcount is 2, each thread sets > own done flag, drops refcount, last thread checks done flag of the > other thread. You're right: looking at the example again, I think that the BUG_ON() in your example can indeed trigger with a CTRL+RELEASE semantics (but _not with the fully-ordered semantics). I apologize for the confusion (it must have been _my Monday... ;-/). Andrea > > > > > > > struct X { > > > > refcount_t rc; // == 2 > > > > int done1, done2; // == 0 > > > > }; > > > > > > > > // thread 1: > > > > x->done1 = 1; > > > > if (refcount_dec_and_test(&x->rc)) > > > > BUG_ON(!x->done2); > > > > > > > > // thread 2: > > > > x->done2 = 1; > > > > if (refcount_dec_and_test(&x->rc)) > > > > BUG_ON(!x->done1);