Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1892474lqo; Mon, 13 May 2024 01:14:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWrX/H+JELXijKJm17gH0VkK6BXBt89x2qJUhTVg8VMqz5kA5Lv7uvQ2DQWc/yCbDDtAPbVgE4xj1lH1A+WlBmCijPYx8xB2FGj0IgT/Q== X-Google-Smtp-Source: AGHT+IHS4/63I9g5EceVf3rt2/JMlyuO+CD+PmDPvWIDc4XSekABGNiSWL0nMICBh5x4kJ7AUySg X-Received: by 2002:a05:6a20:6f89:b0:1af:cdc5:dfbd with SMTP id adf61e73a8af0-1afde0d230cmr8332420637.14.1715588077000; Mon, 13 May 2024 01:14:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715588076; cv=pass; d=google.com; s=arc-20160816; b=UEGqrgGCApOj8c/aUEPH+qux51WE5aNcNjfHTUTOz2hFpOhAeTEi2ezb2XWRPDz5WK Mo3rgFiSV9lDZSWC3j5V8ZtVGtiCNuDYi/3JQCz7JNNPR+R3bkv5EVvGH45CEl+dHI0q gsHksJwNR8RMQv/hOQ3Nzm4lfEyt7Rv+y1/Etmt/8ADSFTWn7jniVYAPpXoSeG9xxkGF fdGCfLBLHJOjhEn94rz8XyHvQy1/RAnA5cfW4oGRvQ120kMpnYNu7n2l49yvrRGiWbkt +NcWlgvOFiWLvW0/r6woBuUNqfQSS0jGEd4kWvce7MDd1Io5WTXUVfDiEcsB/qm9b+k2 6fpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=f0QsI6eg5FRHjsJ3EXAYkOdUsRM9QF3yW2xylikNfdY=; fh=foOf/FwBCkHICfqvGRFkC647forVqeHBDXrQDPQPILo=; b=BcDC7l1lbq1S622HHbMJuEcpSWugVN0Hyyd/+Y5eGc6V4OmT1pOkLr+3q33YzKD/yt yp7HhTapdqAysIAP0KLIxNjJ3DBYKGCBUTDNuePsUkXwP1K9sYK8brUNaCeMVEuIqL4a f2KVrEgGwihwZZbDpRVNcgtOQIFphMYIyl2z5Zou4QXvKghZLSxXKKrDDA/cG8nlULlQ e5Qmygm772cZTA4OEfNNeOj1xvX6jrj2UxGOaOuLDJ/8ZNqqcEAQB8SUzJkQPSmfVeGk zYr+DPnyS/JXvY6zuNyhSYSg8MPC7Fgd8oFPcC4wcC/8WRN7dROkaXpQcIZkq0RMeARK KbMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mc6nznAe; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf3148bsi82332225ad.322.2024.05.13.01.14.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:14:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mc6nznAe; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-177330-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177330-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 8B5D52820C0 for ; Mon, 13 May 2024 08:14:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F2FFF1474A2; Mon, 13 May 2024 08:14:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mc6nznAe" Received: from mail-vs1-f52.google.com (mail-vs1-f52.google.com [209.85.217.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FE7F146D5C for ; Mon, 13 May 2024 08:14:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715588070; cv=none; b=pZx9nRZtqsPx/2T9ZT1h8iSJxyUKp9lc6XP6lNmWM6R6jHh3PM5RmkKjdcG8GWg2Kt8PsYqTS3AMFV7enHJaGux771aOOQsl5BP8zex+C6+GKntkl+HzWHvkqWwpLDm8SkULnOtbSt9gWU9GHgo5iahG8Apn/nO3q9jWZfliwlM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715588070; c=relaxed/simple; bh=12ml4wWfxQl4jhbhqgvB8GySKJX6FlqTruuxJO3r50s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=pKdpLN7xIhGltfOIQAZ02WP6/f+9I6+2dVLnFCCJ/SDcVgtQgbglUbo6HvIdo68+oGWa5GatA9u+VvHcnXFgs0YcHvrMYidCroQceSwm4fRHL0gFtjVS1guLh3fokrCAOxT7Ev6f4wYv9klEIMV9cjAAAIocM3UEKnCBVbuB+mo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mc6nznAe; arc=none smtp.client-ip=209.85.217.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-vs1-f52.google.com with SMTP id ada2fe7eead31-47efc592d9fso1149994137.0 for ; Mon, 13 May 2024 01:14:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715588067; x=1716192867; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=f0QsI6eg5FRHjsJ3EXAYkOdUsRM9QF3yW2xylikNfdY=; b=mc6nznAe164x80c7YoJMbtDNP7Os9yNeaBOuOgoZaxVmnTpTXhM7aXwA/BFq3OedU5 ozmMpKEAjtcIUyHUS2E8C5Qu9VOhR49+rPByIeMFdjknlTmKXJpUjLA0foRWY6F8M0sp 8nlnj6toixhcQdyJZcf+sKVX6kP2soHeskCQBs4a1kaysSECppmX5ikLPgM474QfHQ/N 7ancMeBGBARY+K26FXcTt899+m5rFU0XBWPg1brekvl4RbVG9n3wgzPk5/nvfoNZGMs0 SBvg/Js4n5la2qTIYka+5cqf1HqH2PRcgXeBWJ3aL1jtVKx09Y6wzpyDo1dfYYSLbKdJ rEUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715588067; x=1716192867; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f0QsI6eg5FRHjsJ3EXAYkOdUsRM9QF3yW2xylikNfdY=; b=lRs3pxihxoeL3Yeje/YKRDbWiinMBFLEHMaGT44+PziruW632vuliuFMjgAGXW1QiA 5fHwsql4VHuL1IUSaPpPbF3DSvjrMzuFHiC+/wKjh2BflBb893gb0azmt3gFd+38SGiT a4IJa207aTKluZ/fe00q9NeMCwMsQ+/Secw3JYBnErFeZ3MBfdRbddu7dujx0L+Hglrt 7C6FCfKPyT2DqBmrZnEn58Hd2/RuIn5TTD3qKjGfefPPK+EAPWhW35pjT1v6lCwrFo4J wdu2ICCiEc4boE0R5tW0WLZMjGv8hLMsezgnxAM31A/haTDEB42L4+CXGsiZAN920cq3 Qlog== X-Forwarded-Encrypted: i=1; AJvYcCVzZkSd5gO0HbNYONeBgNMF54pn93UD80roqFWFmag80Vg5DeR0+/AZ40rwTU6Pb688M93BYBC8VujsQ0PE+YkGhkTHi26bB077TRxv X-Gm-Message-State: AOJu0YxkeVjnDpsnXShAxYqMZj5YxEurTII/mZE9MKrvRFJNGH8Yc5+H 8ZhJTfW6cP1KdqYH6eVTTNz2SlZgGDxRkOPAUf1au2ytxBPlO1krl87G9DHJb0nzVX58OCPDOe2 dUZ8PuDcNi2jUYXznBFj8/0xV4VL+eZaL4R7g X-Received: by 2002:a05:6102:38ca:b0:47c:2c87:f019 with SMTP id ada2fe7eead31-48077db706cmr10268656137.5.1715588067255; Mon, 13 May 2024 01:14:27 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240510141921.883231-1-leitao@debian.org> <4d230bac-bdb0-4a01-8006-e95156965aa8@acm.org> <447ad732-3ff8-40bf-bd82-f7be66899cee@paulmck-laptop> <59ec96c2-52ce-4da1-92c3-9fe38053cd3d@paulmck-laptop> In-Reply-To: <59ec96c2-52ce-4da1-92c3-9fe38053cd3d@paulmck-laptop> From: Marco Elver Date: Mon, 13 May 2024 10:13:49 +0200 Message-ID: Subject: Re: [PATCH] block: Annotate a racy read in blk_do_io_stat() To: paulmck@kernel.org Cc: Bart Van Assche , Breno Leitao , Jens Axboe , "open list:BLOCK LAYER" , open list Content-Type: text/plain; charset="UTF-8" On Sat, 11 May 2024 at 02:41, Paul E. McKenney wrote: [...] > ------------------------------------------------------------------------ > > 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() "code generation must be protected" seems ambiguous, because protecting code generation could mean a lot of different things to different people. The more precise thing would be to write that "If the access must be atomic *and* KCSAN should ignore the access, use both ...". I've also had trouble in the past referring to "miscompilation" or similar, because that also entirely depends on the promised vs. expected semantics: if the code in question assumes for the access to be atomic, the compiler compiling the code in a way that the access is no longer atomic would be a "miscompilation". Although is it still a "miscompilation" if the compiler generated code according to specified language semantics (say according to our own LKMM) - and that's where opinions can diverge because it depends on which side we stand (compiler vs. our code). > + * and READ_ONCE(), for example, data_race(READ_ONCE(x)). Having more documentation sounds good to me, thanks for adding! This extra bit of documentation also exists in a longer form in access-marking.txt, correct? I wonder how it would be possible to refer to it, in case the reader wants to learn even more. Thanks, -- Marco