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=-2.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 E6DE0CA9EAF for ; Thu, 24 Oct 2019 16:36:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9E4E021906 for ; Thu, 24 Oct 2019 16:36:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E4E021906 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 48C8B6B0006; Thu, 24 Oct 2019 12:36:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 415396B0007; Thu, 24 Oct 2019 12:36:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3049E6B000A; Thu, 24 Oct 2019 12:36:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 0535A6B0006 for ; Thu, 24 Oct 2019 12:36:01 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id A093D180868EC for ; Thu, 24 Oct 2019 16:36:01 +0000 (UTC) X-FDA: 76079230122.12.book85_8be20726fa619 X-HE-Tag: book85_8be20726fa619 X-Filterd-Recvd-Size: 5080 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Oct 2019 16:36:01 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D418369; Thu, 24 Oct 2019 09:35:52 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 459D93F71F; Thu, 24 Oct 2019 09:35:48 -0700 (PDT) Date: Thu, 24 Oct 2019 17:35:46 +0100 From: Mark Rutland To: Marco Elver 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 Subject: Re: [PATCH v2 4/8] seqlock, kcsan: Add annotations for KCSAN Message-ID: <20191024163545.GI4300@lakrids.cambridge.arm.com> References: <20191017141305.146193-1-elver@google.com> <20191017141305.146193-5-elver@google.com> <20191024122801.GD4300@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) 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, 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, Mark.