Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A41CC433F5 for ; Mon, 29 Nov 2021 18:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349478AbhK2SOq (ORCPT ); Mon, 29 Nov 2021 13:14:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345648AbhK2SMo (ORCPT ); Mon, 29 Nov 2021 13:12:44 -0500 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37AE4C03AD7E for ; Mon, 29 Nov 2021 06:43:12 -0800 (PST) Received: by mail-oi1-x22d.google.com with SMTP id s139so34957579oie.13 for ; Mon, 29 Nov 2021 06:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3mz1HPmHbMNrW+p+9eQAxOprfgUAji2Y3fPOhA732u0=; b=UYFA5+Kj7tvA2GXd53dZLzAwlSi6l7w/hTEzJ3H8A+QSaBrwkIe8WweXjIbXj3BELl eEBahNbVY5hxEA+m1Zsm/zHAH7vuo7iO9Gl/UAaFYO0N+uctB9MXeGvMxWld668gE72X ZpkrPa3wLVOeRFpp9PUS3nuus8d3b2MdtaCDRllfNTF1MiJRcjnyweEdXOB+gejWKaba rstv4lNGXUjQ1y0SH14O3YJdiUm9YqCn1bXP5QKKI+H7z3Pivs8/wkzEzplwbBGSVRfD q6IFlC/cNjnDA+eV1n9jQaWwaWtoxvLRocDUtogezJf9caNQXvpLif2bT2/FBaAkE/GO 4eeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3mz1HPmHbMNrW+p+9eQAxOprfgUAji2Y3fPOhA732u0=; b=X8DCWHQ1Pt9kkJcn58Jmff9QRxdDnyFc62z+MeHU0H3c5o9/cT3B0Vz1H2NeTGoQaF bJrlXbt5ijjVOSoeCLWCTjccDxVaNxb2Z4DvIArii+lgyuasbVS78aUnQUTeHlU4fkWn HTCSJH/wSsNDVepnnBnxUHWy27LwkTgjibGuGWk/V1BvOsLpVlnRW2H8bn7LV4VElun6 ivy+HvUi8j+fwQ4IHy/FuOEITPQWFvDirNlwrylgbq6OkO1vFNaVTmQMU6tVYqc3oFVc RL9jPMZM4+veS9bgPlYFCqvJVGS8ySC5WMStDfb4Ld3QxxgT7YvGmdC1qSaq7syD9SFU zSHA== X-Gm-Message-State: AOAM531ECYqRIBAGgeNeyXm+RE3m8yZtXqJAfKtXhoOh7h0ggSfRZr7Y BaWh4crz+J0QN1bTpMLeROTU2ZOQFXpXwrhO8Z71mQ== X-Google-Smtp-Source: ABdhPJxzBms38b97VrAR+iOn0cM/VBioe+AWcYnISh3nXwb94CqvfvGOQZiwp9KrhWts1M5WTIvE6H8tN6RT2BjBeuQ= X-Received: by 2002:a05:6808:1903:: with SMTP id bf3mr41684658oib.7.1638196991401; Mon, 29 Nov 2021 06:43:11 -0800 (PST) MIME-Version: 1.0 References: <20211118081027.3175699-1-elver@google.com> <20211118081027.3175699-4-elver@google.com> In-Reply-To: From: Marco Elver Date: Mon, 29 Nov 2021 15:42:59 +0100 Message-ID: Subject: Re: [PATCH v2 03/23] kcsan: Avoid checking scoped accesses from nested contexts To: Boqun Feng Cc: "Paul E. McKenney" , Alexander Potapenko , Borislav Petkov , Dmitry Vyukov , Ingo Molnar , Josh Poimboeuf , Mark Rutland , Peter Zijlstra , Thomas Gleixner , Waiman Long , Will Deacon , kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 Nov 2021 at 15:27, Boqun Feng wrote: [...] > > This case is also possible: > > > > static int v; > > static int x; > > int foo(..) > > { > > ASSERT_EXCLUSIVE_ACCESS_SCOPED(v); > > x++; // preempted during watchpoint for 'v' after checking x++ > > } > > > > Here, all we need is for the scoped access to be checked after x++, end > > up with a watchpoint for it, then enter scheduler code, which then > > checked 'v', sees the conflicting watchpoint, and reports a nonsensical > > race again. > > > > Just to be clear, in both examples, the assumption is that 'v' is a > variable that scheduler code doesn't access, right? Because if scheduler > code does access 'v', then it's a problem that KCSAN should report. Yes, > I don't know any variable that scheduler exports, just to make sure > here. Right. We might miss such cases where an ASSERT_EXCLUSIVE*_SCOPED() could have pointed out a legitimate race with a nested context that share ctx, like in scheduler, where the only time to detect it is if some state change later in the scope makes a concurrent access possible from that point in the scope. I'm willing to bet that there's an extremely small chance we'll ever encounter such a case (famous last words ;-)), i.e. the initial check_access() in kcsan_begin_scoped_access() wouldn't detect it nor would the problem manifest as a regular data race. Thanks, -- Marco