Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3260333img; Mon, 25 Mar 2019 06:58:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdnaou0xpr448WKoiqht/KCJ0OEHDWlMfkWy3gxvitq8oyU+F7qfOj0IuHI8gbSmEl8RKI X-Received: by 2002:a63:2045:: with SMTP id r5mr23079450pgm.394.1553522282034; Mon, 25 Mar 2019 06:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553522282; cv=none; d=google.com; s=arc-20160816; b=wDbf+JbPgVjGEyVdspVABq9UtCokfmtRB2V4CUDRF533ULwEW5BfwWCbE98zwW9vQk QHaoibHXgm8A751bzj2QqbkAgGnh80xBrJyrQNVze405Af3i/a/7GD+vYGavrCCyFuoL doq8iGUbQzw5b2p804yJQNuti049xz+RzLq1hrwBQjqbgVuFsQpFuWKjSJIaXNCUnUgu 8Pt/wOxs17ccyp02y8wFoNYgS3ToDM/1gy214XuXKwbN7HQS0cjwg65qjGIY2K53vqvK CzMzt1YcFd++6GFaDBz21HhbBx5Hs9GuMd2b6inxAtd5fYTPqG577G7KiJdXxI5Tyz8y HnrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=UofR6O96m3rMZey70IBgw9PyGN4PEE3VbsIh50PZcMQ=; b=Hsi+3bE5565UoTK/xtD+lfm+CjzBY2f8oLt2kfYBpIxrDGqn0Xxw7ebV1sDKnA5NEx WvRXpMDpW+CUrZJm0KbxIRTRpKj49uC720wy71cncb2Uxh0A/H0Oi+ZE9qtiDY4maieg g6Vz9sWiOpyzhA65TYv0zDscEBAwX9l6kVy9E0NxeiwuH+tRnfDOTvegT5I8nD8aAm8Y InzlblfABRr6Rw/qr04d1l7h8Q/BmiDU/lQJdJY1wSBlBme3ZfgPQDhdMSv/pHywY8CI tNMvw+s7WV8kCcSxD8QkTDu4U6fDG6lJqk5osHpHjatlz7slc8ywP35Mqyk2RKsE39+V 4kqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si1029066plp.201.2019.03.25.06.57.46; Mon, 25 Mar 2019 06:58:02 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728993AbfCYN5F (ORCPT + 99 others); Mon, 25 Mar 2019 09:57:05 -0400 Received: from www62.your-server.de ([213.133.104.62]:40188 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbfCYN5F (ORCPT ); Mon, 25 Mar 2019 09:57:05 -0400 Received: from [178.197.248.24] (helo=localhost) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1h8Q5p-00063d-6w; Mon, 25 Mar 2019 14:56:49 +0100 From: Daniel Borkmann To: tglx@linutronix.de Cc: linux-kernel@vger.kernel.org, mliska@suse.cz, Daniel Borkmann , "H . J . Lu" , David Woodhouse , Linus Torvalds , Jesper Dangaard Brouer , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Magnus Karlsson , Alexei Starovoitov , "David S . Miller" Subject: [PATCH] x86, retpolines: entirely disable switch jump tables when retpolines are enabled Date: Mon, 25 Mar 2019 14:56:20 +0100 Message-Id: <20190325135620.14882-1-daniel@iogearbox.net> X-Mailer: git-send-email 2.9.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25399/Mon Mar 25 08:46:48 2019) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit ce02ef06fcf7 ("x86, retpolines: Raise limit for generating indirect calls from switch-case") raised the limit under retpolines to 20 switch cases where gcc would only then start to emit jump tables, and therefore effectively disabling the emission of slow indirect calls in this area. After this has been brought to attention to gcc folks [0], Martin Liska has then fixed gcc to align with clang by avoiding to generate switch jump tables entirely under retpolines. This is taking effect in gcc starting from stable version 8.4.0. Given kernel supports compilation with older versions of gcc where the fix is not being available or backported anymore, we need to keep the extra KBUILD_CFLAGS around for some time and generally set the -fno-jump-tables to align with what more recent gcc is doing automatically today. More than 20 switch cases are not expected to be fast-path critical, but it would still be good to align with gcc behavior for versions < 8.4.0 in order to have consistency across supported gcc versions. vmlinux size is slightly growing by 0.27% for older gcc. This flag is only set to work around affected gcc, no change for clang. [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86952 Suggested-by: Martin Liska Signed-off-by: Daniel Borkmann Cc: H.J. Lu Cc: David Woodhouse Cc: Thomas Gleixner Cc: Linus Torvalds Cc: Jesper Dangaard Brouer Cc: Björn Töpel Cc: Magnus Karlsson Cc: Alexei Starovoitov Cc: David S. Miller --- arch/x86/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 2d8b9d8ca4f8..a587805c6687 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -219,8 +219,12 @@ ifdef CONFIG_RETPOLINE # Additionally, avoid generating expensive indirect jumps which # are subject to retpolines for small number of switch cases. # clang turns off jump table generation by default when under - # retpoline builds, however, gcc does not for x86. - KBUILD_CFLAGS += $(call cc-option,--param=case-values-threshold=20) + # retpoline builds, however, gcc does not for x86. This has + # only been fixed starting from gcc stable version 8.4.0 and + # onwards, but not for older ones. See gcc bug #86952. + ifndef CONFIG_CC_IS_CLANG + KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables) + endif endif archscripts: scripts_basic -- 2.17.1