Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3951363ybg; Fri, 25 Oct 2019 11:11:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuJTiULS+F2fGIQ5HN0IxnzLDYqsN0ODjECW1w8gRTrrnQqbY8afoOehfGN9Z+Vha5Ng5D X-Received: by 2002:a05:6402:336:: with SMTP id q22mr5566215edw.193.1572027068061; Fri, 25 Oct 2019 11:11:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572027068; cv=none; d=google.com; s=arc-20160816; b=WpUoaZq+0J/h8NUdmXDTGXPeaT3424YnPgvHzGoi30LxlD7/TcMDoEeMq4gMHX/PQ0 dE84KL4HNhbyHVXOP+kw33Wf019uH1ez5wx6yYSClaqBjQtGLxtms8EHEBaE+IpyJJTr nhpe+p9ly0kbStbfgBRb3qCfGFSuInaoGk+0L9BWip2v3eDqcZ03OKj7MjNDUncTQiyC xB9aIsEe4E7W3pkzLHcOW/Ubnl5Pj702PIyaRkXwIhzZhXG4FpnHiVaW3NeuRpcgVp6S v9hO2vrgxiJfPG5vr0oYPJTJXMoRfd+oG7yRo2LFg/ABDOlpBKtixWNDN+15e01zuKGr rpCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=SLG90vrRbLQUwAGkENlhgTDPP1LbndlcrswFZqOfJxA=; b=d2c1QokCMPbJRd4y5C+wcEWFlh+UewrBh2JC+DY5XC/HA/ImaUIeGTE/AnYXYeCjvp ednyzAEzkPhguNFupWnpjRjpVB4j+ZvgHc+IB8Ohq87OIchieSWUTnZ5i7vsnqchwk+b kRDM5e3G6xBpQTanXgyYwgx5cM0kBG6rd9us6nTPQfFZkZJ2YugYC7YUNPMZJohjmcLs 5OSeCC4oW5Q+AgoHFAaF6uECG9pTXhkbE4sL+7QJGKHj1cMqzvPSnyz6wveB7UbqxQBu xBS+a1tPqsvO958cfUzP7Hv+0jImEkZGqJMj4hm4pTAnrUARy/ivz58Ch2QzevjFKZyZ 2mPg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e11si1797890ejr.383.2019.10.25.11.10.44; Fri, 25 Oct 2019 11:11:08 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503367AbfJXQgQ (ORCPT + 99 others); Thu, 24 Oct 2019 12:36:16 -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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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.