Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5078131ybb; Tue, 24 Mar 2020 10:32:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsv9GnMOg0qFPgfkBvwn5OX+YK5XEtDPshtcXMQczxVpgO98QOID1XilWeKxJtXpLMvUbwU X-Received: by 2002:aca:210c:: with SMTP id 12mr4081664oiz.0.1585071132344; Tue, 24 Mar 2020 10:32:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585071132; cv=none; d=google.com; s=arc-20160816; b=ivnluJvqwPUbZB7BAYOzmRyD2pRaxPH0JQgi24vzhl/x+kiSesfcjxIJWqiz94Kr+Z yHvAWgefenZpRrIBtLbs1E51gy2rut4LJBXPgL67FJJvfvJEvCawLXEpZw+uZy3nIaQh l1EdYLZAjuju1hpwXv5wfTgDnLGq47sbf52maSGN3VrZ1qx0K+J55IbrEvdZ0r6LCeqJ Uw/CNC835GvUcUSJrZEb2hpAR9KSnIWXt8+bHjmkJABmCUhputbsWMp+ogHyzWFxi2B/ YV4PHRXPCOm8zkFwk4GHoiaIi8+u4GHaT7i8bOsQU1DrtJLAUg3wrG7l0bQzpH4m13sL Rhrw== 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=kq+FYdniWIla4pk5nZSbH7cg3uuV8JkCybEVH1HaxnI=; b=euOVVKXlVZ5pBehRjbD756pxJLwIIgzxWtgEa6L+i4dTM4vQ+e2Q8ljM/7c4f1HYVm gPF7l1hxceG1etQ0FRJ/tUaQZHQYkfgMSLKSasURjhBpA0V85J0UUNfNdidmXU4Vt1y7 usHoa28OvdMFqbYnWi+WHORFGrmPGCTDcEG2/4bGkPvNbu2Ze7s9ZOiTwxtBRzbs0zLK X3tIOVYdUUX9PLSHhp5BlqZ/oyjFbJKkSBVzsZihdwTod1sJ0VyHolDBucxYjv80hPTy fr1ImUJgS/crHaGFw3Y9sFnKQVH+tcGrmZPnVnbcHPn9K0TZ7sOtGct800WJqwvVjYrD +GhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=m46TPzI0; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si9596140otq.75.2020.03.24.10.31.58; Tue, 24 Mar 2020 10:32:12 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=m46TPzI0; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727314AbgCXRaB (ORCPT + 99 others); Tue, 24 Mar 2020 13:30:01 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38632 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727223AbgCXRaB (ORCPT ); Tue, 24 Mar 2020 13:30:01 -0400 Received: by mail-pf1-f193.google.com with SMTP id z25so5298195pfa.5 for ; Tue, 24 Mar 2020 10:30:00 -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=kq+FYdniWIla4pk5nZSbH7cg3uuV8JkCybEVH1HaxnI=; b=m46TPzI0nrj30YVTG7qLQejHAv7snUYYtbN2Pdjv2gzb4sBZajt9MO/hkb9Y9uEqWh qa4JiXYKikVNjVFlogSQb4lcN4+OycFM6og456ZiK4VuXHyVK6vqVD2IKbLZp8L+8udE g9nOq7xk0uimdDmZPVa1XV3YcU9UW6FUrEcffLo6Hs8fuCImxoDAP7YN+xrZanoeKywK BwlDpHyNkycj77W9BZUyAl3PfnbNNyz+lMse/iogu/pe8JseEPhAovXxnHBUXZuRRgsT rvPZQbC1wQiPwpphWmzKrmz4CdeUHnHGry/FMvkA+OdWCdXpFVwCnM2O20JyX1CiODsb Juqw== 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=kq+FYdniWIla4pk5nZSbH7cg3uuV8JkCybEVH1HaxnI=; b=fepIUG9yE4gIT7MWkF0DRFOZyPD74yhabYM8mPvfharAHA/nsUQRDe//Sd+LVR0q4i peD9YmLbWujun9q4TdCGs3fVczbu9ubho3JtZ39CnG+/rd6qKvBAGvjGWvKMyzH6dUbc FXtVXVV2IhzdrgsYlLM0uHyAWfeh19obeGHRzPmT/la+9c2QRMO3g/bkHvq6kbNqbQof mwiFhbs9kgbL8hZuAP28tFKjXudOgf7G1Kxk+A8zRPElaWKVYQx4SuILTl2jIHyarLo8 mxiTPEYORwQT00nuQEmCX3DG+WMmJd/+dxL6juxrPxplOUI1DZmkR/Duf7WefH3gx3xa J+jA== X-Gm-Message-State: ANhLgQ0jFFxNgJSJByFJ9tp5sjflcbS2ksB0vcIdnjh/7fHQO8Cd1NB5 VhOWzfprgVQlzV2GCRoHOBik+J3mXuXclzG99L2k3g== X-Received: by 2002:a63:4e22:: with SMTP id c34mr29126500pgb.263.1585070999349; Tue, 24 Mar 2020 10:29:59 -0700 (PDT) MIME-Version: 1.0 References: <20200323114207.222412-1-courbet@google.com> <20200324140639.70079-1-courbet@google.com> In-Reply-To: <20200324140639.70079-1-courbet@google.com> From: Nick Desaulniers Date: Tue, 24 Mar 2020 10:29:47 -0700 Message-ID: Subject: Re: [PATCH] x86: Alias memset to __builtin_memset. To: Clement Courbet Cc: Nathan Chancellor , Kees Cook , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , LKML , clang-built-linux 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, Mar 24, 2020 at 7:06 AM Clement Courbet wrote: > > Thanks for the comments. Answers below. > > > This ifdef is unnecessary > > This needs to be within #ifndef CONFIG_FORTIFY_SOURCE > > Thanks, fixed. > > > shouldn't this just be done universally ? > > It looks like every architecture does its own magic with memory > functions. I'm not very familiar with how the linux kernel is > organized, do you have a pointer for where this would go if enabled > globally ? > > > Who's adding it for 64b? > > Any idea where it's coming from in your > > build? Maybe a local modification to be removed? > > Actually this is from our local build configuration. Apparently this Not sure we should modify this for someone's downstream tree to work around an issue they introduced. If you want to file a bug internally, I'd be happy to comment on it. Does __builtin_memset detect support for `rep stosb`, then patch the kernel to always use it or not? The kernel is limited in that we use -mno-sse and friends to avoid saving/restoring vector registers on context switch unless kernel_fpu_{begin|end}() is called, which the compiler doesn't insert for memcpy's. Did you verify what this change does for other compilers? > is needed to build on some architectures that redefine common > symbols, but the authors seemed to feel strongly that this should be Sounds like a linkage error or issue with symbol visibility; I don't see how -ffreestanding should have any bearing on that. > on for all architectures. I've reached out to the authors for an > extended rationale. > On the other hand I think that there is no reason to prevent people > from building with freestanding if we can easily allow them to. I disagree. The codegen in the kernel is very tricky to get right; it's somewhat an embedded system, yet provides many symbols that would have been provided by libc, yet it doesn't use vector operations for the general case. Adding -ffreestanding to optimize one hot memset in one function is using a really big hammer to solve the wrong problem. -- Thanks, ~Nick Desaulniers