Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp587153lqo; Fri, 10 May 2024 08:41:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVISgm0AmS7wTgAUcDYw7YuqrokTyJJtRzfE43LkUKMcOobSMlwTVL6HKKo72P00b8Quuedbk55w/i/LBVj06ZTgBChUXOVT+VojZAuLQ== X-Google-Smtp-Source: AGHT+IFy+eY1JZqG9XOnnq/hueXM3t6upeRbcxKPRLGdMmckUiVYNVPaI2dhCQOOh1D59risOyzk X-Received: by 2002:a17:906:a408:b0:a59:ba2b:5921 with SMTP id a640c23a62f3a-a5a2d67f991mr200975266b.72.1715355692821; Fri, 10 May 2024 08:41:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715355692; cv=pass; d=google.com; s=arc-20160816; b=XIvYaRShwtgQHRCj3aVPayUdwGj4V7ZaOsaVov85X3WJy4X1m8AU98j6lvvoTrz/IL xGHgXhhpYE2EpP+ok1wLSYqNIBz7KEd/n041oBnxv79fWqSyUXrmQPN5fWKXb8VCYA21 vkHBd2puTcXV84XHc5XExcSch7bI8MYmKRfx3xdHywoJ/cNhQuHM8fvFyc/mOUeITxKk uXzhAKDBRRuiIstwdqER/nAUMhuD9cAOWt9mFebAhAukNx1Vk3QcN9cEUbwxWA/uUjq+ rtq9Unfo9b6SB7Z5Lq9o5zuqV01wlj1lxh0N1WiDLjqQkyIzFXx7aZpMtwTqJnbWTWFj bChw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=uSM70CK3DnfXwpCsA87RM/L5/sfT2b1MbitBqSqfgxU=; fh=7DmST56HsxvP98uw537w4U/fRJeJRCLY0PjmNSOZV9o=; b=mlhkNy817BsgQ89Atr9rCUY0O6pPNQf25j+tlke0pGHLqBg8R4hdQFMIzobX/wMyFi GeI+Tty30ttc6I2VHFp4Y94/ImgYRhLxPT7muIZH/qg35fxOlSHMC37GASIdTfIIu6go s257xQ0WjNMa04rVwUmhgaFAzEZIao89tw4o+5is2dENIW5pSJo/6tJ2mD1YJvwzhdJ0 nO5XBPp/Dgn+YbLYtgy15NCoTnor15/28dMu7+w82TVnG82+hXYm5fOQyxfUebIB8gL1 YbMmgNc3GME6oswtZGDJyP1IEaiA/2uHUbkvpUW7A+mg7Bd2xUCR2qb/azoYurxfF1DC smmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ILH92WRG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175969-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17be6874si202838066b.730.2024.05.10.08.41.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 08:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ILH92WRG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-175969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175969-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 72A4C1F215E1 for ; Fri, 10 May 2024 15:41:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8950B171647; Fri, 10 May 2024 15:41:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ILH92WRG" 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 AA91A171E72; Fri, 10 May 2024 15:41:08 +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=1715355668; cv=none; b=RtkkuzSBSlIuMIpI6tchId00mFiNp1ixdEn3DWkp2RDkfJoolQpSdgDMOmycidDTxSVu19/q72LtUgQxOevMbaCsEvQPcgRLYxhmZZr/2gY/nLL+VgbdvQWh+pqsjvUHVWm7mWP7NXIzFsBkeiwlEjL3/PQFg11qU/1rX9UOkdw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715355668; c=relaxed/simple; bh=LTm7mVVSrXVQxGvjvWX4FzLddQuu5y9GagjAYFS7UnE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EwOKQP0F8a8dhhYYm3KR1xfjTahdhKkvY578dUTJANDkhyqWMddBm2MGlEEH/kXtoHvqx9ZxtaDUrmGynMz93Qwo5yby4lQKdM9oJBnq5lseOKLZWs7xFuqyi5MvzIzBchBrvWcsEoPxshaHEYzXbdTRckFp7ZdFAtVY591qEAQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ILH92WRG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53594C113CC; Fri, 10 May 2024 15:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715355668; bh=LTm7mVVSrXVQxGvjvWX4FzLddQuu5y9GagjAYFS7UnE=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=ILH92WRGpndE4x0yfGD4wnPfYZ4rTISC0GlbkmceAWhVMsME2gQOqcgf/ilW0nt+w v3PgRBbqDB1BUfYWtw4vw13qLuy9/2fLBPsaEzd9sUusQNPTTnNxgc3SOBUpcbvk0w n4Wqru7CY/SKzBi29lMdglgHeGz3ZcGK88QSoEv3w38yOC0VsTEVdYBeGK+YpxRE/H gWeFh8QBdLUUo094YR0v+wlW6y3GKeVYYeYOhcE+e6jKMee4NpEsPyLY2Lfp/85BMB lkCGIXTA+fs89uOlcmGe1j1PkK+CYgLA9DbH7XR1KGdrd80DgfkFce1b7v+8cg1Txx c/ev8CR31bDKQ== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0576BCE08A1; Fri, 10 May 2024 08:41:08 -0700 (PDT) Date: Fri, 10 May 2024 08:41:07 -0700 From: "Paul E. McKenney" To: Bart Van Assche Cc: Breno Leitao , Jens Axboe , "open list:BLOCK LAYER" , open list Subject: Re: [PATCH] block: Annotate a racy read in blk_do_io_stat() Message-ID: Reply-To: paulmck@kernel.org References: <20240510141921.883231-1-leitao@debian.org> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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’t critical, let it race */ > > + return (data_race(rq->rq_flags) & RQF_IO_STAT) && !blk_rq_is_passthrough(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()? 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 it 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 accesses. Thanx, Paul