From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3211BC47E49 for ; Thu, 24 Oct 2019 17:09:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DBF742166E for ; Thu, 24 Oct 2019 17:09:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NDkinmJa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBF742166E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 694F96B0003; Thu, 24 Oct 2019 13:09:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 645A26B0006; Thu, 24 Oct 2019 13:09:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55B016B0007; Thu, 24 Oct 2019 13:09:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 35CE06B0003 for ; Thu, 24 Oct 2019 13:09:27 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id E122C181B0499 for ; Thu, 24 Oct 2019 17:09:26 +0000 (UTC) X-FDA: 76079314332.25.robin41_8ca3b49d7c246 X-HE-Tag: robin41_8ca3b49d7c246 X-Filterd-Recvd-Size: 6759 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 17:09:26 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id u13so2564898ote.0 for ; Thu, 24 Oct 2019 10:09:26 -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=RayDO/JqrYw+Xl3cArMo42XIqQFs2B2zGwLprGUGjAo+mIDapq4m4rm3MDpZU45oM7 FyEOG2dQprcbUPbb2f5QNZFKRA7atitulcpGEvwIi4+WgF9v9lE+UtqwrtQ3F7ieElmH TyfzkOs2BIW8zLG4abkmd8JG1329O8FL99vUDRIoX61p7VbXK7nHIWSZRhwGv3JCp7ur X0VAQGBJ/L5+G5ESmyBPOmcnR7IrklN/mwerUVyzC0ooqlSi2t9hjEuwFx2NaDxUcNkQ scU0cIb+co5OMCW3pZVvw1qkiUl9mGdHTzaA8WlDxv1ftEbqT9Yps/o9gfejjUgf4Nt9 32zQ== X-Gm-Message-State: APjAAAUzyFgcKwQcB6RMB/cDgGTuL5nEzYDtlNMYsN3ZK+L2c9PFgHcq BKVJYgfVjW9pIAPwL8zVzEfwbs7M3zlP1/oy4ixXlw== X-Google-Smtp-Source: APXvYqxSTwCL5fkShg1bnRE39/jq8VOLyg3rr+ufJxMetUClrNYquEzJIamome6gyOHHGkc4NQ4KND9V3edjNFM0B/4= 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" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.