Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3351638pxa; Tue, 18 Aug 2020 13:02:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA4crA56Rc1b5gZKIue1sSs4mrfY5tSjZZtOvl5bexpK6NFqs+wvMNRkdFfHhfMib+snTU X-Received: by 2002:a05:6402:16:: with SMTP id d22mr22186866edu.175.1597780939758; Tue, 18 Aug 2020 13:02:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597780939; cv=none; d=google.com; s=arc-20160816; b=vVO3py6OwurDjkAt9nSNitQi4Qytp5j9YjQIJ6a7TMJ/+G2IjFfXO5o3WomjkoC8bX vVPkhyzKQTdJS30azvJXgrlvONbRnQVLrvaPSHYiVz2MNkedKTqkzoc1SZKTq5Grj5Mf G2CXPXn2WWsRKrrAJ8Q0eqyVvrBbScSdasJpVjq03T4gXIWpWlSAnS3EXo5qTp6atK+9 hzPhlCbULMtdTJM+ZoWDpPLRYYikOw5KG3an7/JyEiw/e2Jub7zVdKrSpofwtTfpH/CY Odh4hmg+ipiHdhbT7XQTqD/P5JavCNJHvoKAGhd/y2iAe+Rl/IsRfQSWHKRJ+QBF0cqp G5HQ== 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=rqU4BC6tUsjcEJr/U162KnXra6DrJvlD2KShIytlY2w=; b=RaEynE9ePDYQNEr0qZ1+2HWQBZsyPxYxqWvO7HhwbxVctGjsJuG5jCHqEaNP7FgmOs 7LHgfcL0RjzitBjUc8O35DIMMI3fTwmTGqyt5sF4RY5/A4dZNb2MIUzAbaq4Zsxjpoyt fptvCmHJu3zrDa0bm0Qjdy1seRYbmU7C3PArwdzhTdYeGRLNlKL3pjaUba0ZlOo5YrZj nRbMHkkaTt4EjSooKJ7Xldi1afC27lNP5rXFf0OSXlY9ZswBzKLlG+Q6/eoQz0cI2IYK I2EeK0jKkX4Ox+LU3R8+44aKkVt7rUiZxEAct4j/s1zMxlS6xZGpkeW2n7+aw0dGnuP1 NHjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gZe6HvY1; 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 bx26si13996150edb.588.2020.08.18.13.01.55; Tue, 18 Aug 2020 13:02:19 -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=gZe6HvY1; 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 S1726837AbgHRT6l (ORCPT + 99 others); Tue, 18 Aug 2020 15:58:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726772AbgHRT6k (ORCPT ); Tue, 18 Aug 2020 15:58:40 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0FDFC061342 for ; Tue, 18 Aug 2020 12:58:39 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id h12so10235465pgm.7 for ; Tue, 18 Aug 2020 12:58:39 -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=rqU4BC6tUsjcEJr/U162KnXra6DrJvlD2KShIytlY2w=; b=gZe6HvY1Wn42oNIPkZd4GNzugvaoW6QAFKJSoN2USbuUhs41Zmmkn//dVKTG2hBMKx sqRaPKIoE6CHWVmyUXbOjRbQp7bxKJYri+lGyRLBCp9+FCMq3OSBhtJdR38FJvkNxY2G fUUbwsksChQSG1szN7bcyXVdhRqqIAVmg1dI17DlFtBdfl7ACmXH3tCYGXPIMOy7oa1D QNY+GXXaF2//a/9q4c/0+YsRQ8k5VOU8/+cheazCez+doO5RSykpudD0MY9/I0qq/D5K UmFgyuH0c5Rm5NOHG1YTL7fC0FWlxFrt1p5hz9/SREiX5H8ix8uuAq5L8+ItRqCXyNB5 8JMw== 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=rqU4BC6tUsjcEJr/U162KnXra6DrJvlD2KShIytlY2w=; b=L1VzH13LD7N0sLQICGyj/HMjxTz5YnX7dXU/3OoOilyHENzbrt4MIRhIG7sviuQHdC rSF413kqgl3I5f+eD5JTK0db1amkdIG98dixmAzKB4G1owxznQcDsQVvWRUpdEK2NbUq x7P1/Cv5gx26s9gkXHFf7XDhL0+/ivbgjyUICBriyX7EjThnRoE0VO5bqaah879PPZJP Zu1TpOXPR9TbXJkCnQi5eG82eCTIh1r2K7Yfif9uVHV1OANSQFl/Rb+JgLNCt9XtN7BG 0DIqHwbAznInQ3TjKB46w+9wGNVCfqfO4Q913hmgTFd1+vlZGBR/r7oe30xoUoodMPVx oE+g== X-Gm-Message-State: AOAM531K6Q+H613TQvqp1NA0n8/u5T/yWyrZpyzX1zohxMsvsFhFBe3v 4VsNXrw97WUaxa3ijSwktjoTp301eoprFkuSgHe1lA== X-Received: by 2002:aa7:96e5:: with SMTP id i5mr13553753pfq.108.1597780719010; Tue, 18 Aug 2020 12:58:39 -0700 (PDT) MIME-Version: 1.0 References: <20200817220212.338670-1-ndesaulniers@google.com> <76071c24-ec6f-7f7a-4172-082bd574d581@zytor.com> In-Reply-To: From: Nick Desaulniers Date: Tue, 18 Aug 2020 12:58:27 -0700 Message-ID: Subject: Re: [PATCH 0/4] -ffreestanding/-fno-builtin-* patches To: Linus Torvalds , Clement Courbet Cc: "H. Peter Anvin" , Masahiro Yamada , Andrew Morton , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Michal Marek , Linux Kbuild mailing list , LKML , Kees Cook , Tony Luck , Dmitry Vyukov , Michael Ellerman , Joe Perches , Joel Fernandes , Daniel Axtens , Arvind Sankar , Andy Shevchenko , Alexandru Ardelean , Yury Norov , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Ard Biesheuvel , "Paul E . McKenney" , Daniel Kiper , Bruce Ashfield , Marco Elver , Vamshi K Sthambamkadi , Andi Kleen , =?UTF-8?B?RMOhdmlkIEJvbHZhbnNrw70=?= , Eli Friedman 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, Aug 18, 2020 at 12:25 PM Nick Desaulniers wrote: > > On Tue, Aug 18, 2020 at 12:19 PM Linus Torvalds > wrote: > > > > On Tue, Aug 18, 2020 at 12:03 PM H. Peter Anvin wrote: > > > > > > I'm not saying "change the semantics", nor am I saying that playing > > > whack-a-mole *for a limited time* is unreasonable. But I would like to go back > > > to the compiler authors and get them to implement such a #pragma: "this > > > freestanding implementation *does* support *this specific library function*, > > > and you are free to call it." > > > > I'd much rather just see the library functions as builtins that always > > do the right thing (with the fallback being "just call the standard > > function"). > > > > IOW, there's nothing wrong with -ffreestanding if you then also have > > __builtin_memcpy() etc, and they do the sane compiler optimizations > > for memcpy(). > > > > What we want to avoid is the compiler making *assumptions* based on > > standard names, because we may implement some of those things > > differently. That's asking for trouble; please don't implement routines with identifiers from libc but with differing function signatures, and then proceed to *not* use -ffreestanding. You can't have it both ways (optimizations from *not* using -ffreestanding, then breaking all kinds of assumptions based on conventions used across userspace), at least not with the tools you currently have. > > > > And honestly, a compiler that uses 'bcmp' is just broken. WTH? It's > > the year 2020, we don't use bcmp. It's that simple. Fix your damn > > broken compiler and use memcmp. The argument that memcmp is more > > expensive than bcmp is garbage legacy thinking from four decades ago. > > > > It's likely the other way around, where people have actually spent > > time on memcmp, but not on bcmp. > > > > If somebody really *wants* to use bcmp, give them the "Get off my > > lawn" flag, I wrote a paper in college on the philosophy and symbolism in "Gran Torino." Would recommend (the movie, not the paper). > > and leave them alone. But never ever should "use bcmp" be > > any kind of default behavior. That's some batshit crazy stuff. > > > > Linus > > You'll have to ask Clement about that. I'm not sure I ever saw the > "faster bcmp than memcmp" implementation, but I was told "it exists" > when I asked for a revert when all of our kernel builds went red. Also, to Clement's credit, every patch I've ever seen from Clement is backed up by data; typically fleetwide profiles at Google. "we spend a lot of time in memcmp, particularly comparing the result against zero and no other value; hmm...how do we spend less time in memcmp...oh, well there's another library function with slightly different semantics we can call instead." I don't think anyone would consider the optimization batshit crazy given the number of cycles saved across the fleet. That an embedded project didn't provide an implementation, is a footnote that can be fixed in the embedded project, either by using -ffreestanding or -fno-builtin-bcmp, which is what this series proposes to do. -- Thanks, ~Nick Desaulniers