Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp42513pxx; Wed, 28 Oct 2020 17:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXQ1/TbgsX7COKvBiapVO+pAzfYkbHpQWzbKZ/QsQjZ/dPKxcYFWnDPOlL6ovD6TDJdbAZ X-Received: by 2002:a17:906:1a11:: with SMTP id i17mr1580135ejf.381.1603931709798; Wed, 28 Oct 2020 17:35:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931709; cv=none; d=google.com; s=arc-20160816; b=avHo3RfG3coDQpi8ynhloDION1PrU3OWBbdEE14BNaw4z7TILSM0meSNr4mqh/vcXZ vFNTbCovWQ1Qq6SnDfsh8ukZwOvj+V/xV3EjXGpK4oX330IeTCkptVcmiKK4NaTGj1Z1 ZGtElxCFU88q5Ly4iyiwEmmyd9X/3lg1tr0mBwKTNWZl2J7xm/BB4GwXrCxPArGk/QnP 7N4pf8YxR3MlsQGMJBeezQiJi6SDkUm/e6uaV9hl+njONjfZYjjZ5zJktO6tZtcdHgM7 mSg8xhI6oBdhSANarvccQCT0JpWeky+inOSV0gKo2r07SFlGF9DC8XXI/4BNIgwjBsc7 MyjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=sKDPcCe7oa+0J0gNWV/tekWlACOBrntdU1KnVcQjhMI=; b=G88q+o6CyNWGwFZZCBPcFbRkBVZIQGp4uZmLf/wEfeL+ANul3SkjOHPP9OzA2t8rgV +E7XLU4zCaIAj9V4ApfwiRHf09AToO4EDtWQnVns3vLP1qB8F0oDc98RsvplBPkqY7GY K60a3Ube0hqHu4InoAEtWISdE+0qRLaGZXt3xASnBbEY0Zv+vM0VPyu0iFOvvhnTTNA5 ez3vSBrs78b9Rl/WmETeFZx3Kga3as4hM9BsQIjHiVore6+SBQqKxTHAVxSORYv5ghok PpAADZOKtorCRrh+Hr34eL3Zwh/bLBJOPwxPxyq26Hn6J908wuocSVYQPX1tynjllX/V yVCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Szhzaduv; 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 s2si630241eju.121.2020.10.28.17.34.48; Wed, 28 Oct 2020 17:35:09 -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=Szhzaduv; 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 S1729551AbgJ1WCc (ORCPT + 99 others); Wed, 28 Oct 2020 18:02:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:50730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729512AbgJ1WCY (ORCPT ); Wed, 28 Oct 2020 18:02:24 -0400 Received: from e123331-lin.nice.arm.com (lfbn-nic-1-188-42.w2-15.abo.wanadoo.fr [2.15.37.42]) (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 4693D247FC; Wed, 28 Oct 2020 17:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603905317; bh=09phZTWmPiU017OVb0I9AGdf0nGRpJdaUisznwA8rFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SzhzaduvGQhnnQYFgwb52JDBHh3+ug90qZrxGFJGWQCM6lPNWMTHRifXXXtMs/v2Q zxNhne+WYa1DRL0xtHYkvDE0PcFjgU/OFrJFWRajRqSaTQhvTFd0PJWHJpUnu310IL T4i0vL8mexPWBhTWWF4yOI11+ZNi9tvcZhk5lGBw= From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, arnd@arndb.de, Ard Biesheuvel , Nick Desaulniers , Arvind Sankar , Randy Dunlap , Josh Poimboeuf , Thomas Gleixner , Alexei Starovoitov , Daniel Borkmann , Peter Zijlstra , Geert Uytterhoeven , Kees Cook Subject: [PATCH v2 1/2] bpf: don't rely on GCC __attribute__((optimize)) to disable GCSE Date: Wed, 28 Oct 2020 18:15:05 +0100 Message-Id: <20201028171506.15682-2-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201028171506.15682-1-ardb@kernel.org> References: <20201028171506.15682-1-ardb@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 3193c0836 ("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, it causes -fno-asynchronous-unwind-tables to be disregarded, resulting in .eh_frame info to be emitted for the function. This reverts commit 3193c0836, and instead, it disables the -fgcse optimization for the entire source file, but only when building for X86 using GCC with CONFIG_BPF_JIT_ALWAYS_ON disabled. Note that the original commit states that CONFIG_RETPOLINE=n triggers the issue, whereas CONFIG_RETPOLINE=y performs better without the optimization, so it is kept disabled in both cases. Fixes: 3193c0836 ("bpf: Disable GCC -fgcse optimization for ___bpf_prog_run()") Link: https://lore.kernel.org/lkml/CAMuHMdUg0WJHEcq6to0-eODpXPOywLot6UD2=GFHpzoj_hCoBQ@mail.gmail.com/ Signed-off-by: Ard Biesheuvel --- include/linux/compiler-gcc.h | 2 -- include/linux/compiler_types.h | 4 ---- kernel/bpf/Makefile | 6 +++++- kernel/bpf/core.c | 2 +- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index d1e3c6896b71..5deb37024574 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -175,5 +175,3 @@ #else #define __diag_GCC_8(s) #endif - -#define __no_fgcse __attribute__((optimize("-fno-gcse"))) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 6e390d58a9f8..ac3fa37a84f9 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -247,10 +247,6 @@ struct ftrace_likely_data { #define asm_inline asm #endif -#ifndef __no_fgcse -# define __no_fgcse -#endif - /* Are two types/vars the same type (ignoring qualifiers)? */ #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index bdc8cd1b6767..c1b9f71ee6aa 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile @@ -1,6 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := core.o -CFLAGS_core.o += $(call cc-disable-warning, override-init) +ifneq ($(CONFIG_BPF_JIT_ALWAYS_ON),y) +# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details +cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse +endif +CFLAGS_core.o += $(call cc-disable-warning, override-init) $(cflags-nogcse-yy) 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 -- 2.17.1