Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp257551pxx; Thu, 29 Oct 2020 01:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzswf7u+T9544zKAS6u2FKfRbpU4fZnHMJQjAoVChjy2GqWF0gF5UZ4KyT+cB/tZdvx1wds X-Received: by 2002:a17:906:ce27:: with SMTP id sd7mr2802226ejb.264.1603960935771; Thu, 29 Oct 2020 01:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603960935; cv=none; d=google.com; s=arc-20160816; b=f3CXTB7Kf4a0fGK8q80/xs2NBFcM+D9lPKWm07Pp3iUquHaHkyW+bywwQLQAw1Culm v4IyXiK5G5Xzlc8rgOIxuPW+k+awU+XDbQj8nwNz/Onale6FM4AsTEL/RPqXMttMTB7R GHMl8Pan5f7LONbvtVPryc0eLvWd5y10lwdJNY4ARJgj/31OkeqNxi1ZPNmznELPawxG aO4OIZS/eY0XlRlA2Xwjrfpip5IUjkuXv2t5dhs1Y8tPeP8c2ky8jnvVkPcM2sbbLYJZ vqNvyw35CdMhpXW1a+QWvap382/VXoiH9y+qnd2krzyYqmDy6zfcIEKWNeDONuEKrqBN 6H/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hcgvGBdP+QdcEES8Cp/sDeqMnU3n66qJ1iT720kIQJ8=; b=wHI6X7emPYXITM3HKK5hQoe0R6ogdiEkVegKLBl9X6eQCVCcCL6b3CkOrD0oR4ygiK Sd1nHd76andT7Tu4arBMMfmtmT6DFT2DViqQp4EaEkZ9HLhd9MIiHkD9NxYZ0mXpl/wH IffDhcIfEjdNcPxPD7JKI6p7O3J4H17StwcfGICmMQCoDGoZr0ZI2YhwpiyHphUchILX 8teP4V/AsSteyvlWBUSnz3/f0+Dhk8bnhFUdZK3Eg0OTVmqLBhDFjtASfYxMGKSjZkNJ uRtjWu2YffHptcGZsS7GuZHJTIKNclvf4I8Z5PXQoRYHpKJtkP/KnrRWZf/+RDaQRcVj ce+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NNPg4Gyi; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si1304277ejf.129.2020.10.29.01.41.54; Thu, 29 Oct 2020 01:42:15 -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=@kernel.org header.s=default header.b=NNPg4Gyi; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404019AbgJ2BAU (ORCPT + 99 others); Wed, 28 Oct 2020 21:00:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:60510 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731537AbgJ1WR2 (ORCPT ); Wed, 28 Oct 2020 18:17:28 -0400 Received: from mail-oi1-f175.google.com (mail-oi1-f175.google.com [209.85.167.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2607724179; Wed, 28 Oct 2020 06:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603867920; bh=WgbuHj01IFnS0Vj48OP8wcJkPWzOiL5aoOn7vv03c4g=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=NNPg4GyiaHS1i8YK/6d3Ckx2fUsPyrZolq6BMElDKh7cfUVDosbIfW12QK+vL+3Kd 90FAjPPv8CPN34Y3SeKxY2aVd6D401txJox5nWy0s9v4LQw9oZxF+IfPGDLt/Bay4+ AyYYXe5PX3WYPdt0X23xtq825ajjbyl79Fcus1aM= Received: by mail-oi1-f175.google.com with SMTP id w191so3973402oif.2; Tue, 27 Oct 2020 23:52:00 -0700 (PDT) X-Gm-Message-State: AOAM533YKS/WyiUjXcVLHyXR1N37RwJoMua/A4hLKMkR2t7ASPACcoud A6HYGkJtYxyCgtPkwDREsi55ZfE7ZswPqRRPt80= X-Received: by 2002:aca:5c82:: with SMTP id q124mr4120751oib.33.1603867919159; Tue, 27 Oct 2020 23:51:59 -0700 (PDT) MIME-Version: 1.0 References: <20201027205723.12514-1-ardb@kernel.org> <72f0dd64-9f65-cbd0-873a-684540912847@iogearbox.net> In-Reply-To: <72f0dd64-9f65-cbd0-873a-684540912847@iogearbox.net> From: Ard Biesheuvel Date: Wed, 28 Oct 2020 07:51:47 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] bpf: don't rely on GCC __attribute__((optimize)) to disable GCSE To: Daniel Borkmann Cc: Linux Kernel Mailing List , "open list:BPF JIT for MIPS (32-BIT AND 64-BIT)" , "open list:BPF JIT for MIPS (32-BIT AND 64-BIT)" , Arnd Bergmann , Nick Desaulniers , Arvind Sankar , Randy Dunlap , Josh Poimboeuf , Thomas Gleixner , Alexei Starovoitov , Peter Zijlstra , Geert Uytterhoeven , Kees Cook Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 28 Oct 2020 at 00:04, Daniel Borkmann wrote: > > On 10/27/20 9:57 PM, Ard Biesheuvel wrote: > > Commit 3193c0836f203 ("bpf: Disable GCC -fgcse optimization for > > ___bpf_prog_run()") introduced a __no_fgcse macro that expands to a > > function scope __attribute__((optimize("-fno-gcse"))), to disable a > > GCC specific optimization that was causing trouble on x86 builds, and > > was not expected to have any positive effect in the first place. > > > > However, as the GCC manual documents, __attribute__((optimize)) > > is not for production use, and results in all other optimization > > options to be forgotten for the function in question. This can > > cause all kinds of trouble, but in one particular reported case, > > Looks like there are couple more as well aside from __no_fgcse, are you > also planning to fix them? > > arch/powerpc/kernel/setup.h:14:#define __nostackprotector __attribute__((__optimize__("no-stack-protector"))) > tools/include/linux/compiler-gcc.h:37:#define __no_tail_call __attribute__((optimize("no-optimize-sibling-calls"))) > No, but we can notify the respective maintainers. > > it causes -fno-asynchronous-unwind-tables to be disregarded, > > resulting in .eh_frame info to be emitted for the function > > inadvertently. > > Would have been useful to add a pointer to the original discussion with > Link tag. > > Link: https://lore.kernel.org/lkml/CAMuHMdUg0WJHEcq6to0-eODpXPOywLot6UD2=GFHpzoj_hCoBQ@mail.gmail.com/ > Agreed. > > This reverts commit 3193c0836f203, and instead, it disables the -fgcse > > optimization for the entire source file, but only when building for > > X86. > > > > Cc: Nick Desaulniers > > Cc: Arvind Sankar > > Cc: Randy Dunlap > > Cc: Josh Poimboeuf > > Cc: Thomas Gleixner > > Cc: Alexei Starovoitov > > Cc: Daniel Borkmann > > Cc: Peter Zijlstra (Intel) > > Cc: Geert Uytterhoeven > > Cc: Kees Cook > > Fixes: 3193c0836f203 ("bpf: Disable GCC -fgcse optimization for ___bpf_prog_run()") > > Signed-off-by: Ard Biesheuvel > [...] > > diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile > > index bdc8cd1b6767..02b58f44c479 100644 > > --- a/kernel/bpf/Makefile > > +++ b/kernel/bpf/Makefile > > @@ -1,6 +1,8 @@ > > # SPDX-License-Identifier: GPL-2.0 > > obj-y := core.o > > -CFLAGS_core.o += $(call cc-disable-warning, override-init) > > +# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details > > +cflags-core-$(CONFIG_X86) := -fno-gcse > > +CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-core-y) > > Also, this needs to be guarded behind !CONFIG_RETPOLINE and !CONFIG_BPF_JIT_ALWAYS_ON > in particular the latter since only in this case interpreter is compiled in ... most > distros have the CONFIG_BPF_JIT_ALWAYS_ON set these days for x86. > Is that a new requirement? Because before this patch, -fno-gcse was applied unconditionally. > Do you have an analysis for the commit log on what else this penalizes in core.c if > it's now for the entire translation unit? > No, I simply observed the regression this caused on non-x86 architectures, and proposed a way to fix it. Do you have any concerns in particular regarding other things in core.c? Would you prefer ___bpf_prog_run() to be moved into a separate .c file? > > obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o bpf_iter.o map_iter.o task_iter.o prog_iter.o > > obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o > > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > > index 9268d77898b7..55454d2278b1 100644 > > --- a/kernel/bpf/core.c > > +++ b/kernel/bpf/core.c > > @@ -1369,7 +1369,7 @@ u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr) > > * > > * Decode and execute eBPF instructions. > > */ > > -static u64 __no_fgcse ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack) > > +static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack) > > { > > #define BPF_INSN_2_LBL(x, y) [BPF_##x | BPF_##y] = &&x##_##y > > #define BPF_INSN_3_LBL(x, y, z) [BPF_##x | BPF_##y | BPF_##z] = &&x##_##y##_##z > > >