Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2944408ybk; Tue, 12 May 2020 11:58:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaJ9WXylMbUh2n7kJH4ZTStNedWWcXL1HTFfhqZfWwqKjtoiuQ46gJkYWdf3uLIlJaCDKo X-Received: by 2002:a17:906:34c7:: with SMTP id h7mr2881504ejb.300.1589309926596; Tue, 12 May 2020 11:58:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589309926; cv=none; d=google.com; s=arc-20160816; b=WjdnJkfe31v6sN+DlI2yVrdDkLHpFsRnmaxfe/CteTj8fsSmBxxwOGs5DrLhxJ4vGB 8s1jY8Hz9axrUCC2vupK3hzxM1MCI89sF8hHNWAPJiSh+d5Q3VskmsABpLH2X4KLTbKD AlF0am0zcDhR4UEszTkaU+ap5wwmXy8NryQjRe/E4dJP5uOO/Dk+vSR9EIjYouNjpQle UQZjBqjaGOpq8STaR2ZAP+DlgJuLf+BbptdcPuLvkOB4DMiCMGJm1YGNc6/Ff16KAXJS saap6BQxD+713q3r9bKJDG3Q0ZUEL90wS0i8OU0qz253kJ8+S88PelBwlV+vfjTaGodd yiLg== 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=8/ib6+c7BKOFq4rzBPSiX9579nf57nKgi51prOVLeqM=; b=MBvfwjyNHnUe7ASlIS4RWfgsVudXrMNMDJR4FHBrmgr1u4iNB7eHIq3QIXUn+Zeqj5 /HBfXm7kknazAuOnt03kgPDjDRg+7GwDnvALUPnc5ul5Kf4YGDLLZL/FlPHzIyjUwIVG TKgf1dHL4KG5TFKEcLcqwKDX7CF1zwLRDWROu65UmozYze2HJpB/g2jrBbm00kO2eQOY yUO27hiV0zw6RCNmAkUxehJ03X1+N8/3mDZKSFD69Di8O7mIpTybXuQYG6NuWwWkPvvT 3UOk9AfYKQholKV14xt0XuAwbbB0v2YEPbsjVwAljGwz8rHWIyvDsH4M7fLb5i6O/GXK m8Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FcZ62UYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id x24si5412781edl.563.2020.05.12.11.58.23; Tue, 12 May 2020 11:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FcZ62UYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1730803AbgELSzs (ORCPT + 99 others); Tue, 12 May 2020 14:55:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725554AbgELSzr (ORCPT ); Tue, 12 May 2020 14:55:47 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C50A7C061A0C for ; Tue, 12 May 2020 11:55:47 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id a2so18979874oia.11 for ; Tue, 12 May 2020 11:55:47 -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=8/ib6+c7BKOFq4rzBPSiX9579nf57nKgi51prOVLeqM=; b=FcZ62UYqj1Uw6lvR03J/WQSC7U46eIoGLsLYjrBHxCf/M/FHYaJgDcl5gA/cF1utrS rfkru4WXu8OGZYcgyVCt8ye8MBGrzlUkmZH6m/OAnV6pKYYFe+QpAr+iHRW/LFW7Kj+9 sG9V6v26dklp1AJXIbooxCUjUhlmIko+KmvJvsLBoMLg+3viLP5T9hH++KpO2d17bs+R auvZq+dVgojLeJaXEreXfZC2ZkGqGWTAjETDUKVLwv+XWSDchaLPp1MbYxGKppv5DPTf 4FUJzauTU1k8FLeUdo+4ixoVv03YIoPLtqSYqv99JoZhwLIh5R9P8GbUX9rktXFJKxMx So7w== 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=8/ib6+c7BKOFq4rzBPSiX9579nf57nKgi51prOVLeqM=; b=A3K2qqP89pqeQW2y5RI24aXfziznnFBJOgmVAoU+hh5zFgYemsRDAH5I+ROFnvfUI3 1B+npZaWQiIf6cLC94Bjt08k7ph1sq+daNF45yMJFOIEXtDsOf5yW6lqXJG+YWvtRgf2 MZ0Nn3aoXUXYmYtsedPFEbQ6iJ1syNxgn3nEIUonp2O8eV7wJuwZzdiED81mllsNY0pd BGQ8xScGEHx8773WVyxR1THoQry1hQFoWBmyw9GnpXtsNG3+pOSIfI3Yn8HrMM10xxY/ dE8TqlVIrlf40VFNZ0LmGW1c6KkQjtpKZBIHH+Kc9Tb4KftREJp4vVEficuZzNMlssA9 HKgg== X-Gm-Message-State: AGi0PuZpZ3+YR/WAWj+xNdZgmmOytYKD7tiTI3ongQDVN1RLxGJLfWuv pnNae8LzRxqQTwMgSfoJ2iQH8Y+MpRURIDrlY/+Zcx45VdM= X-Received: by 2002:a05:6808:b36:: with SMTP id t22mr25095274oij.121.1589309746887; Tue, 12 May 2020 11:55:46 -0700 (PDT) MIME-Version: 1.0 References: <20200511204150.27858-1-will@kernel.org> <20200512081826.GE2978@hirez.programming.kicks-ass.net> In-Reply-To: From: Marco Elver Date: Tue, 12 May 2020 20:55:35 +0200 Message-ID: Subject: Re: [PATCH v5 00/18] Rework READ_ONCE() to improve codegen To: Peter Zijlstra Cc: Will Deacon , LKML , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar 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 Tue, 12 May 2020 at 19:53, Marco Elver wrote: > > On Tue, 12 May 2020 at 10:18, Peter Zijlstra wrote: > > > > On Mon, May 11, 2020 at 09:41:32PM +0100, Will Deacon wrote: > > > Hi folks, > > > > > > (trimmed CC list since v4 since this is largely just a rebase) > > > > > > This is version five of the READ_ONCE() codegen improvement series that > > > I've previously posted here: > > > > > > RFC: https://lore.kernel.org/lkml/20200110165636.28035-1-will@kernel.org > > > v2: https://lore.kernel.org/lkml/20200123153341.19947-1-will@kernel.org > > > v3: https://lore.kernel.org/lkml/20200415165218.20251-1-will@kernel.org > > > v4: https://lore.kernel.org/lkml/20200421151537.19241-1-will@kernel.org > > > > > > The main change since v4 is that this is now based on top of the KCSAN > > > changes queued in -tip (locking/kcsan) and therefore contains the patches > > > necessary to avoid breaking sparc32 as well as some cleanups to > > > consolidate {READ,WRITE}_ONCE() and data_race(). > > > > > > Other changes include: > > > > > > * Treat 'char' as distinct from 'signed char' and 'unsigned char' for > > > __builtin_types_compatible_p() > > > > > > * Add a compile-time assertion that the argument to READ_ONCE_NOCHECK() > > > points at something the same size as 'unsigned long' > > > > > > I'm happy for all of this to go via -tip, or I can take it via arm64. > > > > Looks good to me; Thanks! > > > > Acked-by: Peter Zijlstra (Intel) > > I just ran a bunch of KCSAN tests. While this series alone would have > passed the tests, there appears to be a problem with > __READ_ONCE/__WRITE_ONCE. I think they should already be using > 'data_race()', as otherwise we will get lots of false positives in > future. > > I noticed this when testing -tip/locking/kcsan, which breaks > unfortunately, because I see a bunch of spurious data races with > arch_atomic_{read,set} because "locking/atomics: Flip fallbacks and > instrumentation" changed them to use __READ_ONCE()/__WRITE_ONCE(). > From what I see, the intent was to not double-instrument, > unfortunately they are still double-instrumented because > __READ_ONCE/__WRITE_ONCE doesn't hide the access from KCSAN (nor KASAN > actually). I don't think we can use __no_sanitize_or_inline for the > arch_ functions, because we really want them to be __always_inline > (also to avoid calls to these functions in uaccess regions, which > objtool would notice). > > I think the easiest way to resolve this is to wrap the accesses in > __*_ONCE with data_race(). I just sent https://lkml.kernel.org/r/20200512183839.2373-1-elver@google.com -- note that, using __*_ONCE in arch_atomic_{read,set} will once again double-instrument with this. Overall there are 2 options: 1. provide __READ_ONCE/__WRITE_ONCE wrapped purely in data_race(), or 2. make __READ_ONCE/__WRITE_ONCE perform an atomic check so we may still catch races with plain accesses. The patch I sent does (2). It is inevitable that these will be used in places that we did not expect, purely to get around the type check, which is why I thought it might be the more conservative approach. Thoughts? Thanks, -- Marco