Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3967472ybg; Fri, 25 Oct 2019 11:25:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqww497S7JXF6CYN+SH/UoYefYGk8l8VupxhcXc3RQs/NmkEjcUe0kcNkbBTKs1UFqDyOW47 X-Received: by 2002:aa7:c24c:: with SMTP id y12mr5435289edo.180.1572027904636; Fri, 25 Oct 2019 11:25:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572027904; cv=none; d=google.com; s=arc-20160816; b=A0HTH6k6w4f3fU+1FnC94XZtMCru3tZjutTEmMyQqJJCBiRN/WdWjaTOl5MKImh/5j cGiX1mzbuSS42+LvRy8rRJvLJKod19bdUjLq0qiS/t5e9w2GH/bqIRtCCcP5xBuTGPMp EXLPiq3KPEXHWFr6Bt+NSSVVDJti6QefBnw9IG6ClCbq0jomhvkjapUXxyRF4z6kfES0 iLY3r6FINNbKTNfWFKds7WPhQIf+2NDTJu7MmQnA5gd08egNWPputqc625m2wqDvOsTE Sb3H+qQ0J71fS/M4+6B1CdkHLURa2rsAhEA0INheQAF4NEm80fFTOlfg0KNQkdKm3Aty WuHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LW4UeTeDzuNPqIV02zMQFN/K1Ur44NII9oOTDJRv/K0=; b=xoJwVR+FrrZHsRSKIHARKbe24+RECIjhGpTtK8wdkZC1macg9OO/JPGCmBWSQKUjLz yvkuZ6yVAIp17HQPB4bL03p0KRolwKRcHbzHjWLFobfsdVMqJNme3epF4NZ8bwzRW1QC Jz/AsA88jwvz+6yichKyI6fvObTr+r8nHL13LA/NRBUFYK3LqrrA/i1iK1uIdDCRT8Ml n4SQOP/k03ZrxR2neEOnnyntcNJEQ6Yhg3MuVz+Md++MhxVGWVn9irj0FIAjxMH29Mvx e/hDzNRPoB1jcyfeX4kRoqDDrAbhrZPMuLD7WH3cRr5DAyvI9U93XMK+/LV4tfCvOffV OR4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NDkinmJa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w11si1775555eji.160.2019.10.25.11.24.40; Fri, 25 Oct 2019 11:25:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NDkinmJa; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436845AbfJXRJ0 (ORCPT + 99 others); Thu, 24 Oct 2019 13:09:26 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:46038 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405931AbfJXRJ0 (ORCPT ); Thu, 24 Oct 2019 13:09:26 -0400 Received: by mail-ot1-f68.google.com with SMTP id 41so21312800oti.12 for ; Thu, 24 Oct 2019 10:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LW4UeTeDzuNPqIV02zMQFN/K1Ur44NII9oOTDJRv/K0=; b=NDkinmJayQUfSCbDiVgdoNMU1yBcKSDEhSv8y0cmmLvNtNg35oWgX0eqE0kPaGmXa7 OXF8Hgj/LImoVhjP9MDk/qjwL3PrB7ufk3qntJLS9q1BBtFFDVrNklS3ulNRioaG/bt+ hYWyWFoh0VqrlftiW+50Q4bRj946rm1MjOt/J1LOdM4B8Slbz02GkqsdGS+fnTGpDeRt TCQWnaUisjsg/LSmxiyKwxR/y45jLAPWAnt7GhMJFhzXXnVLzl4VmQuU6/fFgjPvYX6w 6YZvf4rvNkFccuT6/XsXDBlLo+WoZqE/QJAXFjgt2p2QA0aeffVA0KXhtOHOgQq0scJY Dueg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LW4UeTeDzuNPqIV02zMQFN/K1Ur44NII9oOTDJRv/K0=; b=FwCsVMQVJqjmF3OsFGuv72A4VcX/Ah5DpTMAZSfvxMSZLVTo+KV7c+giZ3w4wT9J+d g6NGxibw9cmSSy1/5GdG+Rc+Q8WS0fcsIf28GlUrvqYq+7yimO0Ufl3aE2DUR192WhhW eiJWS6HGcETJN7w30pXDA2Aa1tXWP7PZfIDMMLEvSKWaphHInYF8TFp8EoW/aL6r+Mmj BodROR37G8Eol7TDqaYyRXSSIwP7mS8+ohRAX29wkNDCr9wpRmksuk71l8kzPJ55P6Qw iKSTAh2oPgXwbSnilmBQb/ffdzojf0q1mgs/nBD2eWnq6CENiOfvrNT+TBMpMD1lX1xa DDsw== X-Gm-Message-State: APjAAAUB+UGWV/6FcZnOykTTUDRUlju6ZzbDvmH17EDA7Cw2MX5MRsv/ ubTC61tEmvp8DOq8pswACz9hbxnGOsJH1vSVdNZkuQ== X-Received: by 2002:a05:6830:1693:: with SMTP id k19mr12897876otr.233.1571936964760; Thu, 24 Oct 2019 10:09:24 -0700 (PDT) MIME-Version: 1.0 References: <20191017141305.146193-1-elver@google.com> <20191017141305.146193-5-elver@google.com> <20191024122801.GD4300@lakrids.cambridge.arm.com> <20191024163545.GI4300@lakrids.cambridge.arm.com> In-Reply-To: <20191024163545.GI4300@lakrids.cambridge.arm.com> From: Marco Elver Date: Thu, 24 Oct 2019 19:09:12 +0200 Message-ID: Subject: Re: [PATCH v2 4/8] seqlock, kcsan: Add annotations for KCSAN To: Mark Rutland Cc: LKMM Maintainers -- Akira Yokosawa , Alan Stern , Alexander Potapenko , Andrea Parri , Andrey Konovalov , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Boqun Feng , Borislav Petkov , Daniel Axtens , Daniel Lustig , Dave Hansen , David Howells , Dmitry Vyukov , "H. Peter Anvin" , Ingo Molnar , Jade Alglave , Joel Fernandes , Jonathan Corbet , Josh Poimboeuf , Luc Maranget , Nicholas Piggin , "Paul E. McKenney" , Peter Zijlstra , Thomas Gleixner , Will Deacon , kasan-dev , linux-arch , "open list:DOCUMENTATION" , linux-efi@vger.kernel.org, Linux Kbuild mailing list , LKML , Linux Memory Management List , "the arch/x86 maintainers" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 24 Oct 2019 at 18:35, Mark Rutland wrote: > > On Thu, Oct 24, 2019 at 04:17:11PM +0200, Marco Elver wrote: > > On Thu, 24 Oct 2019 at 14:28, Mark Rutland wrote: > > > > > > On Thu, Oct 17, 2019 at 04:13:01PM +0200, Marco Elver wrote: > > > > Since seqlocks in the Linux kernel do not require the use of marked > > > > atomic accesses in critical sections, we teach KCSAN to assume such > > > > accesses are atomic. KCSAN currently also pretends that writes to > > > > `sequence` are atomic, although currently plain writes are used (their > > > > corresponding reads are READ_ONCE). > > > > > > > > Further, to avoid false positives in the absence of clear ending of a > > > > seqlock reader critical section (only when using the raw interface), > > > > KCSAN assumes a fixed number of accesses after start of a seqlock > > > > critical section are atomic. > > > > > > Do we have many examples where there's not a clear end to a seqlock > > > sequence? Or are there just a handful? > > > > > > If there aren't that many, I wonder if we can make it mandatory to have > > > an explicit end, or to add some helper for those patterns so that we can > > > reliably hook them. > > > > In an ideal world, all usage of seqlocks would be via seqlock_t, which > > follows a somewhat saner usage, where we already do normal begin/end > > markings -- with subtle exception to readers needing to be flat atomic > > regions, e.g. because usage like this: > > - fs/namespace.c:__legitimize_mnt - unbalanced read_seqretry > > - fs/dcache.c:d_walk - unbalanced need_seqretry > > > > But anything directly accessing seqcount_t seems to be unpredictable. > > Filtering for usage of read_seqcount_retry not following 'do { .. } > > while (read_seqcount_retry(..));' (although even the ones in while > > loops aren't necessarily predictable): > > > > $ git grep 'read_seqcount_retry' | grep -Ev 'seqlock.h|Doc|\* ' | grep > > -v 'while (' > > => about 1/3 of the total read_seqcount_retry usage. > > > > Just looking at fs/namei.c, I would conclude that it'd be a pretty > > daunting task to prescribe and migrate to an interface that forces > > clear begin/end. > > > > Which is why I concluded that for now, it is probably better to make > > KCSAN play well with the existing code. > > Thanks for the detailed explanation, it's very helpful. > > That all sounds reasonable to me -- could you fold some of that into the > commit message? Thanks, will do. (I hope to have v3 ready by some time next week.) -- Marco > Thanks, > Mark.