Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp834925lqo; Fri, 10 May 2024 17:41:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4SZVIxdvzF9f0Gfv+HpL94SwCs0pJi2JlrV018U5qChwauAdzZw7W5lAHhlzBwpRywbEGkKbj0JT9QkajSCW9x0ngAD85JMKuZK3ScA== X-Google-Smtp-Source: AGHT+IE8+PNZlfuyXZMx1tJtNp8vBwPqJBtouPDqgtAEiYUhIkp5Y9h4EqBOONnLLTqiABx/DOD4 X-Received: by 2002:a05:6a21:3d85:b0:1a7:52fa:7d6b with SMTP id adf61e73a8af0-1afde197988mr4644818637.43.1715388074386; Fri, 10 May 2024 17:41:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715388074; cv=pass; d=google.com; s=arc-20160816; b=voM7TD98Yn0tJ2d8xlWmOUlVjk3JGc9/mxtwOF265H2IQo9pJ5sMYnySUKBp7bXs58 MUGENYjeH71bJATvAf5IIH+NJl09B81EPkX1Xjgtokz8lLCXg+9njN1NhNfFD5FKS23G F7Ffh0x2MkqzH44CboLxg7//MLVHJ1Rxo5WyOaq0ZHyO32UZ6kDhE+dBQO/bwYbXBc4d vLdxkLdKrP0c07A3vCBi1GdXqesjQTLu3RnSv3y8WqpFOBnK84BsM7DePwOE1KOfVH5l +NhbSbO9f/7KNq0RvUVUGf8F/FeVDm+EUMgm3Ht1BcVqPVQ+GCui85VVplfRSLVbbP6a i7tg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=o9T9WVMXjttt0WRwPtjMlCuJUXl9O4urLsHekuNCF0M=; fh=vYVgPCnUodSTCEVjh4OuCJUL93JWUs8huFBwVsrzMUQ=; b=oVTe6HOGwJQxlbToEY8+irl+2kaMExchMJA4YCWpG+2wSzO4/t+QTnHeC6TugoZT14 SI4x5mZFXUuX3Rg3v1clKlpWleYas+DntLpILDjpimsjTYzp/3L1gn07/dTPPX3NKu1V hI/dV/QRpd+RUUxIOUjY1AzjEht4MkS6x1cKHUyeulhvgu+qDY25AFolRvWkS7i3YiTv 6BQSrUA0oQ6Lvl1/NOX8Xojhqs6OlIoEKMp3VbnoJLF8XzaECxc2FvLhtEbGl9mtSkfX TweCgJbplk1rxdcQFT2BIz9/vL8arI4LHDF1CCkvdJobDe+LhQL1J0FrobrHtq3GspjY vT8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhlojpax; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176321-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b6711629fasi4755086a91.80.2024.05.10.17.41.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 17:41:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mhlojpax; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-176321-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176321-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0141A28542F for ; Sat, 11 May 2024 00:41:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95C308F5C; Sat, 11 May 2024 00:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mhlojpax" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC2D2A48; Sat, 11 May 2024 00:41:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388065; cv=none; b=REn9RGliXvcDXZJU4nibjgGlPVkrAMxKABb2QuCwSVsJ4jA+fs2XiQFxJ8Fbp7El4JDFzYszmTII86PW0KNZ6c+cou3eZ+gAnWBrzpJ61gtN7h10cweeNKFUvVFDpMaQ+pEGSNdTeupI9YLKEYGRRgDxJY3dDut6jEd47k/vZRY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715388065; c=relaxed/simple; bh=pIPPzYuAehENWnP6ADisG/tghpPKOf9MUXmBw/VMOEQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=p3x8XCnP90iyfuxD/hQ2NSDCeCk+tucwkaqBg9ei2CZmO+W9NecaO+TCoHSaiyRPNfowPce1VnX4fImN/SSbr4+etjJP2X3+rU+IFqlcSOoAg//VgZjuN3tAMMAuh42aZb5q1TjXVKrKE3mFatEYCcnMMqDhR9J6DHPtMQTN2ug= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mhlojpax; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CD2C113CC; Sat, 11 May 2024 00:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715388065; bh=pIPPzYuAehENWnP6ADisG/tghpPKOf9MUXmBw/VMOEQ=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=mhlojpaxwDiEI7cVAv+KhylgYHCK8rn6AO8HBpz9r/RbSBIUGDCiNBJvOPt7IhenY KpZ/NqGgc1JwmPwQicLtoWhlqg74IX93QVcgH9BcLTFobQ7YycXx4B6qWXELWi2TPo Snu2pGrowb0YNq73itfO9a5AweYpnjkiaWpDj27VT7WyIy6Z4HwBgIT/9u8GcOB1BN k8DIsxoGm980Upn0P+zkrPcS0Zsaq0RiF6dZX2PKR9uHVfcaQKKSDnbWgBo70FhaN8 SNSaF1qwTpV+oiI24Lm+4NE6ty+4h/qAVOFDVDf+4nwMlbVGzNPbgmUGwDtvIkMZUy 0cak9LyyrwgZQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id B49C6CE095C; Fri, 10 May 2024 17:41:04 -0700 (PDT) Date: Fri, 10 May 2024 17:41:04 -0700 From: "Paul E. McKenney" To: Bart Van Assche Cc: Breno Leitao , Jens Axboe , "open list:BLOCK LAYER" , open list , Marco Elver Subject: Re: [PATCH] block: Annotate a racy read in blk_do_io_stat() Message-ID: <59ec96c2-52ce-4da1-92c3-9fe38053cd3d@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20240510141921.883231-1-leitao@debian.org> <4d230bac-bdb0-4a01-8006-e95156965aa8@acm.org> <447ad732-3ff8-40bf-bd82-f7be66899cee@paulmck-laptop> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, May 10, 2024 at 04:22:58PM -0700, Bart Van Assche wrote: > On 5/10/24 3:35 PM, Paul E. McKenney wrote: > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > > index c00cc6c0878a1..78593b40fe7e9 100644 > > --- a/include/linux/compiler.h > > +++ b/include/linux/compiler.h > > @@ -194,9 +194,18 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > > * This data_race() macro is useful for situations in which data races > > * should be forgiven. One example is diagnostic code that accesses > > * shared variables but is not a part of the core synchronization design. > > + * For example, if accesses to a given variable are protected by a lock, > > + * except for diagnostic code, then the accesses under the lock should > > + * be plain C-language accesses and those in the diagnostic code should > > + * use data_race(). This way, KCSAN will complain if buggy lockless > > + * accesses to that variable are introduced, even if the buggy accesses > > + * are protected by READ_ONCE() or WRITE_ONCE(). > > + * > > + * This macro *does not* affect normal code generation, but is a hint to > > + * tooling that data races here are to be ignored. If code generation must > > + * be protected *and* KCSAN should ignore the access, use both data_race() > > + * and READ_ONCE(), for example, data_race(READ_ONCE(x)). > > * > > - * This macro *does not* affect normal code generation, but is a hint > > - * to tooling that data races here are to be ignored. > > */ > > This patch changes the end of the comment from "*/" into "*\n*/". > That's probably unintended? Otherwise this patch looks good to me. Good eyes, thank you! How about like this instead? Thanx, Paul ------------------------------------------------------------------------ commit 930cb5f711443d8044e88080ee21b0a5edda33bd Author: Paul E. McKenney Date: Fri May 10 15:36:57 2024 -0700 kcsan: Add example to data_race() kerneldoc header Although the data_race() kerneldoc header accurately states what it does, some of the implications and usage patterns are non-obvious. Therefore, add a brief locking example and also state how to have KCSAN ignore accesses while also preventing the compiler from folding, spindling, or otherwise mutilating the access. [ paulmck: Apply Bart Van Assche feedback. ] Reported-by: Bart Van Assche Signed-off-by: Paul E. McKenney Cc: Marco Elver Cc: Breno Leitao Cc: Jens Axboe diff --git a/include/linux/compiler.h b/include/linux/compiler.h index c00cc6c0878a1..9249768ec7a26 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -194,9 +194,17 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, * This data_race() macro is useful for situations in which data races * should be forgiven. One example is diagnostic code that accesses * shared variables but is not a part of the core synchronization design. + * For example, if accesses to a given variable are protected by a lock, + * except for diagnostic code, then the accesses under the lock should + * be plain C-language accesses and those in the diagnostic code should + * use data_race(). This way, KCSAN will complain if buggy lockless + * accesses to that variable are introduced, even if the buggy accesses + * are protected by READ_ONCE() or WRITE_ONCE(). * - * This macro *does not* affect normal code generation, but is a hint - * to tooling that data races here are to be ignored. + * This macro *does not* affect normal code generation, but is a hint to + * tooling that data races here are to be ignored. If code generation must + * be protected *and* KCSAN should ignore the access, use both data_race() + * and READ_ONCE(), for example, data_race(READ_ONCE(x)). */ #define data_race(expr) \ ({ \