Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp447974ybg; Tue, 9 Jun 2020 04:59:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZY/KxRbqNinRZVplSztJP2rc5waxaGw5PHbkVPvZp27UCLFWgi3eWA5q9mLiLMVhX69GH X-Received: by 2002:aa7:cd6c:: with SMTP id ca12mr26869231edb.36.1591703963228; Tue, 09 Jun 2020 04:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591703963; cv=none; d=google.com; s=arc-20160816; b=XBUOY0KEUgoohPyQ+08dSvjS8JCBe+AseEkdcbsLSU6ZB4yaplNalyv44I+dfG+NRK UeOEma5C5y7QOVbwrdScs3C9CVIkkTgPJAjXQl4IemPL5GkgCnY9uqYxULaEMxYDt5Kl YFFY60MjGpB21wyaGAp0fZOvlOK4C7Ydo5dtdwlx2gm8TB/0ETjxmgayiUzm47DLZYBK 2FYaobDzWNk9ZAXwWIfgM0zvO+0NcpPl6FExhcYr+26TqjYWkdXLHBNXtktu13niIBKl ta9/Hcx69fkI+V6ePyM+MEJwx6J94ZL0OG1eocmPn/1IbbAn7m7NbnhXlaiN4PaNBnUQ dQkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=l4lmGyryxYChG1mnKH0ea07cHKOM/59Dg7Gbxe2csLY=; b=ecpJbOlTfcXfrcDwOxrgPFuUmXoZVI9+OyFpt99Tn+Gu28PHhXA/HEkD2W6Lb1Ixbp iYuvnlMZ4JKpKwrF6GkVlqOx8uQf8Jkmu7sIpB/zNZIEK2IQgHEfbgKjlzHuuHKZm8pR S/dVnsub7v3PYi121VaLBz3ULs0zwuX80DePjPUYEBRCy5YfUVPVV8mXPfTlzOJA0GJQ TtEbe9PWMzRSpn0cmltbj1s8zlg79jMRcE6bCeaiWa2IIOnQGMQDmCDdHWJFhWtReiei n9MqFsl+LxyywGpVworqtDI59PwWWcEaN4q+ZyO6ErO4WGmEq1FLVB5+OlAfoyXDphh4 JaLg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si1177357edv.523.2020.06.09.04.58.59; Tue, 09 Jun 2020 04:59:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729175AbgFILzo (ORCPT + 99 others); Tue, 9 Jun 2020 07:55:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:55612 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbgFILzk (ORCPT ); Tue, 9 Jun 2020 07:55:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5588EAAD0; Tue, 9 Jun 2020 11:55:42 +0000 (UTC) Subject: Re: [PATCH v5 00/18] Rework READ_ONCE() to improve codegen To: Marco Elver Cc: Borislav Petkov , Will Deacon , Peter Zijlstra , LKML , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar , Dmitry Vyukov , Nick Desaulniers References: <20200513124021.GB20278@willie-the-truck> <20200513165008.GA24836@willie-the-truck> <20200513174747.GB24836@willie-the-truck> <20200513212520.GC28594@willie-the-truck> <20200514110537.GC4280@willie-the-truck> <20200603185220.GA20613@zn.tnic> <20200603192353.GA180529@google.com> <87213fd1-950d-c2d5-4aa0-2f53ea3b505c@suse.cz> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: Date: Tue, 9 Jun 2020 13:55:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/8/20 9:56 PM, Marco Elver wrote: > On Mon, 8 Jun 2020 at 19:32, Martin Liška wrote: >> >> On 6/3/20 9:23 PM, Marco Elver wrote: >>> >>> >>> On Wed, 03 Jun 2020, Borislav Petkov wrote: >>> >>>> On Thu, May 14, 2020 at 12:05:38PM +0100, Will Deacon wrote: >>>>> Talking off-list, Clang >= 7 is pretty reasonable wrt inlining decisions >>>>> and the behaviour for __always_inline is: >>>>> >>>>> * An __always_inline function inlined into a __no_sanitize function is >>>>> not instrumented >>>>> * An __always_inline function inlined into an instrumented function is >>>>> instrumented >>>>> * You can't mark a function as both __always_inline __no_sanitize, because >>>>> __no_sanitize functions are never inlined >>>>> >>>>> GCC, on the other hand, may still inline __no_sanitize functions and then >>>>> subsequently instrument them. >>>> >>>> Yeah, about that: I've been looking for a way to trigger this so that >>>> I can show preprocessed source to gcc people. So do you guys have a >>>> .config or somesuch I can try? >>> >>> For example take this: >>> >>> int x; >>> >>> static inline __attribute__((no_sanitize_thread)) void do_not_sanitize(void) { >>> x++; >>> } >>> >>> void sanitize_this(void) { >>> do_not_sanitize(); >>> } >>> >>> Then >>> >>> gcc-10 -O3 -fsanitize=thread -o example.o -c example.c >>> objdump -D example.o >> >> Hello. >> >> Thank you for the example. It seems to me that Clang does not inline a no_sanitize_* function >> into one which is instrumented. Is it a documented behavior ([1] doesn't mention that)? >> If so, we can do the same in GCC. > > It is not explicitly mentioned in [1]. But the contract of > "no_sanitize" is "that a particular instrumentation or set of > instrumentations should not be applied". That contract is broken if a > function is instrumented, however that may happen. It sadly does > happen with GCC when a function is inlined. Presumably because the > sanitizer passes for TSAN/ASAN/MSAN run after the optimizer -- this > definitely can't change. Also because it currently gives us the > property that __always_inline functions are instrumented according to > the function they are inlined into (a property we want). > > The easy fix to no_sanitize seems to be to do what Clang does, and > never inline no_sanitize functions (with or without "inline" > attribute). always_inline functions should remain unchanged > (specifying no_sanitize on an always_inline function is an error). Hello. Works for me and I've just sent patch for that: https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547618.html > > Note this applies to all sanitizers (TSAN/ASAN/MSAN) and their > no_sanitize attribute that GCC has. Sure. > > The list of requirements were also summarized in more detail here: > https://lore.kernel.org/lkml/CANpmjNMTsY_8241bS7=XAfqvZHFLrVEkv_uM4aDUWE_kh3Rvbw@mail.gmail.com/ > > Hope that makes sense. (I also need to send a v2 for param > tsan-distinguish-volatile, but haven't gotten around to it yet -- > hopefully soon. The patch is approved now. And then we also need a param > tsan-instrument-func-entry-exit, which LLVM has for TSAN. One step at > a time though.) Yes, please send a patch for it. Martin > > Thanks, > -- Marco > > >> Thanks, >> Martin >> >> [1] https://clang.llvm.org/docs/AttributeReference.html#no-sanitize >> >>> >>> will show that do_not_sanitize() was inlined into sanitize_this() and is >>> instrumented. (With Clang this doesn't happen.) >>> >>> Hope this is enough. >>> >>> Thanks, >>> -- Marco >>> >>