Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp528634ybb; Wed, 25 Mar 2020 04:46:13 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtTkPNwq3j236lG0WSo+fE+tDk3O6niT9wdTdb2f+2drgzyQgw3y5Mpmf9Sy2CI/8ABRW1k X-Received: by 2002:a9d:7f19:: with SMTP id j25mr2183652otq.129.1585136773260; Wed, 25 Mar 2020 04:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585136773; cv=none; d=google.com; s=arc-20160816; b=z9JC1/yNNoZRTEdmncjUpexmJ/rK/KlYJjJ8Q6Jq2wNI3ckjXq7XpuJP/A7Owqlrhw XFT0LLIiYtYM8SmETVM11HT5eVvJq1ByVswm6kNq+qEquTh6oJ6trLdMd4PMpUDmZ6Z7 Lb/IT4vFIJPawnoM3dQPKdF+r3TgsL1cIUQVuBkfvTyUGxCwZBh620tBdHLSiTWPvHSX RjOu7MMEV/FTxp5Yn75kaiUWdpRelLreEuOOQQ6VjIFC9Hv22hZOY+8X6ApygDEhmFvT x4mlyCIWBX6jf1T5N9AWtW2PwG+F/5VmkhSgwqiM5tpVdCzwz4TfVPpKwHO+PqlzgUo6 3Dlg== 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=Tm5Z+k+rBP6F88YL+wQ+Wpuiw3AdZUz7top8Qzt+Svc=; b=IzXlUBqwxGZ2G1Rc4IGNQmRm6CwkHhxHjmtOFQiq3VDj0j87CRogNGgBHcJlppS9+h gCjHQUqSIUx5pknehR8WHhACpJyx11HrSA+rUSuWA30Pj6bi/3WZWzNqZ5DVIV32auqv O9PZ25f3TwvvZq8KXtYphXQ+i6LpBnVSGzB8lYTxRAbVvh/XIYd2TW+tKX/3JdXPTJiV 9BpF9SYAWRWpz2wwZI2oRBnbDWYaYQ4DQL3Jw6ylvkR9+zKq5j1lTB9QzI3U72gPx+Sb CwB9RpwN2BzCZpnzKTlI2qAod1UBsJ6QE4OVv7txdPgbE+ZlLeef6W80/ihlsXYTQ4pK 8r8g== 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 g1si1426431otp.268.2020.03.25.04.46.01; Wed, 25 Mar 2020 04:46:13 -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 S1727346AbgCYLpk (ORCPT + 99 others); Wed, 25 Mar 2020 07:45:40 -0400 Received: from esgaroth.petrovitsch.at ([78.47.184.11]:4930 "EHLO esgaroth.tuxoid.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbgCYLpj (ORCPT ); Wed, 25 Mar 2020 07:45:39 -0400 X-Greylist: delayed 686 seconds by postgrey-1.27 at vger.kernel.org; Wed, 25 Mar 2020 07:45:39 EDT Received: from thorin.petrovitsch.priv.at (80-110-108-220.cgn.dynamic.surfer.at [80.110.108.220]) (authenticated bits=0) by esgaroth.tuxoid.at (8.15.2/8.15.2) with ESMTPSA id 02PBXCX5024904 (version=TLSv1 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 25 Mar 2020 12:33:13 +0100 Subject: Re: [PATCH v3] x86: Alias memset to __builtin_memset. To: Clement Courbet Cc: Nathan Chancellor , Kees Cook , Nick Desaulniers , Joe Perches , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com References: <20200323114207.222412-1-courbet@google.com> <20200324155907.97184-1-courbet@google.com> From: Bernd Petrovitsch Message-ID: Date: Wed, 25 Mar 2020 12:33:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200324155907.97184-1-courbet@google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-DCC-wuwien-Metrics: esgaroth.tuxoid.at 1290; Body=12 Fuz1=12 Fuz2=12 X-Virus-Scanned: clamav-milter 0.97 at esgaroth.tuxoid.at X-Virus-Status: Clean X-Spam-Status: No, score=0.0 required=5.0 tests=UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Report: * 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on esgaroth.tuxoid.at Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi all! Sry for being late at the party: On 24/03/2020 16:59, Clement Courbet wrote: [...] > --- > arch/x86/include/asm/string_64.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h > index 75314c3dbe47..9cfce0a840a4 100644 > --- a/arch/x86/include/asm/string_64.h > +++ b/arch/x86/include/asm/string_64.h > @@ -18,6 +18,15 @@ extern void *__memcpy(void *to, const void *from, size_t len); > void *memset(void *s, int c, size_t n); > void *__memset(void *s, int c, size_t n); > > +/* Recent compilers can generate much better code for known size and/or > + * fill values, and will fallback on `memset` if they fail. > + * We alias `memset` to `__builtin_memset` explicitly to inform the compiler to > + * perform this optimization even when -ffreestanding is used. > + */ > +#if !defined(CONFIG_FORTIFY_SOURCE) > +#define memset(s, c, count) __builtin_memset(s, c, count) To be on the safe side, the usual way to write macros is like #define memset(s, c, count) __builtin_memset((s), (c), (count)) as no one know what is passed as parameter to memset() and the extra pair of parentheses don't hurt. And similar below (and I fear there are more places). Or did I miss something in the Kernel? > +#endif > + > #define __HAVE_ARCH_MEMSET16 > static inline void *memset16(uint16_t *s, uint16_t v, size_t n) > { > @@ -74,6 +83,7 @@ int strcmp(const char *cs, const char *ct); > #undef memcpy > #define memcpy(dst, src, len) __memcpy(dst, src, len) #define memcpy(dst, src, len) __memcpy((dst), (src), (len)) > #define memmove(dst, src, len) __memmove(dst, src, len) #define memmove(dst, src, len) __memmove((dst), (src), (len)) > +#undef memset > #define memset(s, c, n) __memset(s, c, n) #define memset(s, c, n) __memset((s), (c), (n)) > > #ifndef __NO_FORTIFY > MfG, Bernd -- Bernd Petrovitsch Email : bernd@petrovitsch.priv.at LUGA : http://www.luga.at