Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp614374lqo; Fri, 10 May 2024 09:21:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXR1hq46MVo013uaL0fBwvciCPDD4Cehg6wIo5kw5V/WWuaEIQkUz7RpGVWo6xXf3Ep1Ob6uC4ZZL2AVMhzPGZGHHBP+YgheiARuFdRug== X-Google-Smtp-Source: AGHT+IECXOmQOYDNiEf0RJd6aJIp4+dLa1sPjwBXLfU8wQGGC5nQwa4FyOX4ZvtHD8Vre7c2Q3JN X-Received: by 2002:a05:6870:ac21:b0:23d:697:e8fd with SMTP id 586e51a60fabf-24172f6b5b4mr3496643fac.40.1715358086782; Fri, 10 May 2024 09:21:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715358086; cv=pass; d=google.com; s=arc-20160816; b=ZQ88UD9aYCRWrLVKnpDDBbylKKSFc8ABVOPPPFCR174C4mW60eNtzlICuzXSEQjq4u QpEYFEGxWKHBqY9Dh+YtheYTvY5k5Tj24qXH/zRtD4uQ0LW2bsVE0rjd9xGtOSripNqR wGNXu32mTkxV6ji+Z6qMhxcQD4VSb0xHHdMjra0azrTJNz032ArixLcfYmbyOyALFzn0 P4SWyVa6a19KRdG9TW/X45Xl0R806s2WPt1d5dGZ34XAZExd5hg3GsA9vytX7fAFl2ua xq41glqO1B35O3Z1IcSLvOKNdozOg9HSJDys5AYK8uh4xxeBTDfxpBgg0NiQ6snHQU9R MXTA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=QOddt5IKXRCkImqqK6vka+M2kOA6v8rGcyELCFfSJJc=; fh=7FJ3l8KvpQ+Kj5t8yo/dDSv0aH58x0ZtTr7XBQR1Pp8=; b=SoaSrfTfMJqpTM4zw6psmBb1qs+kQ7bGlQos1ZsrWGz0zesu16JlPP8E1Gd30dw0zt jHRMjMsHmdUUmSXtOlMAwVLltmIUsxerho85SJJL1txBAkfhKHdZef4ycQDBSW+NV5Ue 1kAYnIAzzx6iyWtdvhtTbt/QMRyFux6tUFxjYqo1W/LbESoMEkg6Fp352GXbEY7ecrzQ 4ksQrgFFn5pm9D+A3iuNLrnFUg6YocticcN7IwPukO8AjlkKlX2b2/y+bVEGXk/hamis g+lXDnJYo2v6mXKT2IhBDwO8UF0Uv3SEGQr1pp1G1kIQZPP3icVJd8Waf8x8jbRNDxBk +4sQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@acm.org header.s=mr01 header.b=n18lc6a2; arc=pass (i=1 spf=pass spfdomain=acm.org dkim=pass dkdomain=acm.org dmarc=pass fromdomain=acm.org); spf=pass (google.com: domain of linux-kernel+bounces-176004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=acm.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df56d485fsi39457751cf.679.2024.05.10.09.21.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 09:21:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@acm.org header.s=mr01 header.b=n18lc6a2; arc=pass (i=1 spf=pass spfdomain=acm.org dkim=pass dkdomain=acm.org dmarc=pass fromdomain=acm.org); spf=pass (google.com: domain of linux-kernel+bounces-176004-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176004-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=acm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6FFBE1C235CC for ; Fri, 10 May 2024 16:21:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9F95172BDB; Fri, 10 May 2024 16:21:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b="n18lc6a2" Received: from 008.lax.mailroute.net (008.lax.mailroute.net [199.89.1.11]) (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 A14181E502; Fri, 10 May 2024 16:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.89.1.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715358072; cv=none; b=MBKleKfZrNIlgmnnD4WqTrb9KCpKdo7dq549Y63WfZe/jc+UMTO3FLX0cO2PXaToR1XaFySjOSL2W9XXlH8+BwqyKCEC/vv971jVyt/MqLFjiD1F4zJRXrxjuAodC+u9R2xbzImSOOhEQPpGcwg7ioq90XHZGiqFUYaWCiyQeeA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715358072; c=relaxed/simple; bh=9eVFeI4MVw3d17iTqq4yVn7+uRkW7sAAFJQNg15myGY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZXo1YSGQuzBGkIL/f9n9N/o3bikuwX5QaaeIm/625sX6tHGzSly7Zj8/l2MOPink+UlqMzMemcVXTQf2oEl206DZ3VIrx95bL9Kf7V0wpuQeMcyJ8FIkOEi9PQUgCtNYD2K0rO1NX8ylxdk6GdF1zWhQKIn9l0CH3v8OGu/qPgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass (2048-bit key) header.d=acm.org header.i=@acm.org header.b=n18lc6a2; arc=none smtp.client-ip=199.89.1.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Received: from localhost (localhost [127.0.0.1]) by 008.lax.mailroute.net (Postfix) with ESMTP id 4VbYz43zB0z6Cnk8y; Fri, 10 May 2024 16:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :user-agent:mime-version:date:date:message-id:received:received; s=mr01; t=1715358062; x=1717950063; bh=QOddt5IKXRCkImqqK6vka+M2 kOA6v8rGcyELCFfSJJc=; b=n18lc6a2Ps6drLfgczpjOnaevfy+D88JeI39N2ox QBRLMO/rQ2SwBx61cyyY5IP6wC5INT6BNaGFgVEzyZH3af3BQ10jnH7orkfoYvUM 0vbMiKZtBqKk/2RrRuki24FzIdJR+aVrmvLinHcZFwtvHVRtfWnVHesK3H+kQVoE UnXTgfZzs/jP0Z8PTzFklx2q/xCRH1FrdsINOULe370AVemgXBQE5PeokfJTlYWt cv4tORr9LR9NbX7UTC4dDzTjwaxXkQCdGyeWmoNWbmjsyrOe9CWfyVcX7d0saUOO GEYNPbmB7LP9CBfuwfmNBcnYIk7TNWUAKgqNUbwVBnPR7Q== X-Virus-Scanned: by MailRoute Received: from 008.lax.mailroute.net ([127.0.0.1]) by localhost (008.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id A3-vK-S9u8rf; Fri, 10 May 2024 16:21:02 +0000 (UTC) Received: from [192.168.3.219] (c-73-231-117-72.hsd1.ca.comcast.net [73.231.117.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 008.lax.mailroute.net (Postfix) with ESMTPSA id 4VbYz05VYwz6Cnk8s; Fri, 10 May 2024 16:21:00 +0000 (UTC) Message-ID: Date: Fri, 10 May 2024 09:20:58 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] block: Annotate a racy read in blk_do_io_stat() To: paulmck@kernel.org Cc: Breno Leitao , Jens Axboe , "open list:BLOCK LAYER" , open list References: <20240510141921.883231-1-leitao@debian.org> Content-Language: en-US From: Bart Van Assche In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On 5/10/24 8:41 AM, Paul E. McKenney wrote: > On Fri, May 10, 2024 at 07:28:41AM -0700, Bart Van Assche wrote: >> On 5/10/24 07:19, Breno Leitao wrote: >>> diff --git a/block/blk.h b/block/blk.h >>> index d9f584984bc4..57a1d73a0718 100644 >>> --- a/block/blk.h >>> +++ b/block/blk.h >>> @@ -353,7 +353,8 @@ int blk_dev_init(void); >>> */ >>> static inline bool blk_do_io_stat(struct request *rq) >>> { >>> - return (rq->rq_flags & RQF_IO_STAT) && !blk_rq_is_passthrough(rq); >>> + /* Disk stats reading isn=E2=80=99t critical, let it race */ >>> + return (data_race(rq->rq_flags) & RQF_IO_STAT) && !blk_rq_is_passth= rough(rq); >>> } >>> void update_io_ticks(struct block_device *part, unsigned long now,= bool end); >> >> Why to annotate this race with data_race() instead of READ_ONCE()? Are >> there any cases in which it is better to use data_race() than >> READ_ONCE()? >=20 > We use this pattern quite a bit in RCU. For example, suppose that we > have a variable that is accessed only under a given lock, except that i= t > is also locklessly accessed for diagnostics or statistics. Then having > unmarked (normal C language) accesses under the lock and data_race() > for that statistics enables KCSAN to flag other (buggy) lockless access= es. Can using data_race() instead of READ_ONCE() result in incorrect code generation, e.g. the compiler emitting a read twice and reading two different values? Thanks, Bart.