Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp692647pxx; Wed, 28 Oct 2020 14:40:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT6r6oBrmjSTAx+OYXutaaI770PVxxf5+AOjb/yY/QGw9Li4ZZZuRrpJLqAda6osx99Nqo X-Received: by 2002:a17:906:3b8f:: with SMTP id u15mr1067682ejf.348.1603921252503; Wed, 28 Oct 2020 14:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603921252; cv=none; d=google.com; s=arc-20160816; b=Rh+YGUJrkuR4x4qGMxYSRglXaVbPqZx7g6l+K3JoxvtbrjAU9UCpIqkW5PoJoRpFSF mMTe9H4ZPLwOB7W9FTsOtxgrDo+rC644CSwRnAGGKVh012BBhTzQqwkjv9PyD4BrVgfq uREaP4zg9FvTfhcZ8gWEyxg1wM+0Ax5AgonOvmK9JVXLTifvuQ5KRpGNZpj0zPKkF7Mo jzHeppaKAN6vZnjY7KulLIICLDMMhhheUgWCL7rkH2Jd/h9Z7KP0ZcZQoNrTYF4oOrbN l9tSEcdXHxirKqfa0xzlzNWahjqjpw9Pgs4yEJPKkfFQrCo9FgXTrg5h6y0zA4Gj2TQ+ l14A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=S1BBekDGMjHruJ5RijGn0vmZZ79dEq41DNsq/siKp5I=; b=DUXjJpNfR7WneiIy9uoiqNyA1P92vGKteMf9n7EALq/Ufp8zn5nC3WCljdW8NHZjzM TQk53vznP2R05G6jtn2VEN8HxnRd0lRd9+hMbPmBBRA8QgrxQaPYRhlUxeVw9X8J5cv/ Qd1jPtKCexsUyeqzleJdMA3jj7I1CGYKeRvRbpJEm8lfaqw224se/mah2H3EHIKFFYtZ bEjTECMNkSRcMKOn8W9tG7Q/7BYGADOxsUuVbHDauReK2KiaLBYcsABzI9mAvsxqN5gs pHDNis7J2NLM64MiAqhZfMA89B5ta8p10a1YTg+U7bEn9dHGE5vc2Ksz3z0a9sS3va0H fxYA== 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 e16si409493ejc.699.2020.10.28.14.40.30; Wed, 28 Oct 2020 14:40:52 -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 S1832667AbgJ0XEc (ORCPT + 99 others); Tue, 27 Oct 2020 19:04:32 -0400 Received: from www62.your-server.de ([213.133.104.62]:38368 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1832658AbgJ0XEc (ORCPT ); Tue, 27 Oct 2020 19:04:32 -0400 Received: from sslproxy06.your-server.de ([78.46.172.3]) by www62.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1kXY0w-0002mG-Dd; Wed, 28 Oct 2020 00:04:26 +0100 Received: from [178.196.57.75] (helo=pc-9.home) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kXY0w-000MGw-4i; Wed, 28 Oct 2020 00:04:26 +0100 Subject: Re: [PATCH] bpf: don't rely on GCC __attribute__((optimize)) to disable GCSE To: Ard Biesheuvel , linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, arnd@arndb.de, Nick Desaulniers , Arvind Sankar , Randy Dunlap , Josh Poimboeuf , Thomas Gleixner , Alexei Starovoitov , Peter Zijlstra , Geert Uytterhoeven , Kees Cook References: <20201027205723.12514-1-ardb@kernel.org> From: Daniel Borkmann Message-ID: <72f0dd64-9f65-cbd0-873a-684540912847@iogearbox.net> Date: Wed, 28 Oct 2020 00:04:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <20201027205723.12514-1-ardb@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.102.4/25970/Tue Oct 27 13:18:55 2020) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"))) > 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/ > 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. 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? > 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 >