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 A710ACA9EBC for ; Thu, 24 Oct 2019 16:36:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 87D2F21929 for ; Thu, 24 Oct 2019 16:36:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503457AbfJXQgN (ORCPT ); Thu, 24 Oct 2019 12:36:13 -0400 Received: from foss.arm.com ([217.140.110.172]:56142 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503452AbfJXQgI (ORCPT ); Thu, 24 Oct 2019 12:36:08 -0400 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) Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org 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.