From patchwork Mon Oct 23 21:17:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559082vqx; Mon, 23 Oct 2023 14:18:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfjK8HEKhzssXXG27Xjj7p/cejEP34PVfi60sthKfDUgMyvZwJwjAr3C+qZJGOCdZ3B6Q3 X-Received: by 2002:a92:d3d0:0:b0:357:a14e:17cf with SMTP id c16-20020a92d3d0000000b00357a14e17cfmr10305126ilh.19.1698095893519; Mon, 23 Oct 2023 14:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095893; cv=none; d=google.com; s=arc-20160816; b=yMZbigyGt2Ou4q4ofqnZ45Oa5BvBhFaN/u4g/lWE41KWYJbatxJSLYPFSuSI6k4IEa ETkNsSTlSgr006J4yDYTVXlzy0gnIPKy+1UqRsuL+0GjHxvbs2w0K3LPRC9gSsa+6QBR oNRBP4qVJXWfZMGJzaWAfpsW11MLyctum6AknjXIuDCNlhHd3kUL29otTm0yrC0WWdCM QK1aR3J789uIYOcD4srf9ML6yi0Mhcl2uzvkHcguoYs1KM07TYwOTCVCvOcf2hApcBl2 lNLSFar29Yjg2GLbbCzd78ZX6DDmOMw37fsp6hP51PHrA50iMH+/1hrQTk3CaANP+buK IeTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MozeFj7AsxNvK40iWKEorOKKdXplrF78HG0tGDcuTc0=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=p73p7HoLxFS8WjoVRMcLQJjND/K8xxWI3zmEYxm3y77JDsK/CgBZFLyyFSIxb2EjuU m3sZ27Rl+NbHET9L4EeTPOEnTtS+FdnyRn9a0YUwS5/rJJTgSxjrVNEsFe8j8wyM2Eey 5sOzqcXoJTNrkX3QKi2nGIk+Dkg4zqUPnJ4aKn/wU8T9wZXEAwBuVFhgJxULiqdKUarK DlV6Jrb11GXE+fAQBPs5pFBmz/vwlP+8z8OIjE5jBXDUUpCjtzFxyBgxIotte/q0KPhq O6xa04GMrsuZ3VvVbSwqm4nNenOYnjfShw0+8P4EjMeso3qDk9UlR1x3OJF19Q8Z2ANu rdHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mPMlRFjR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id t13-20020a65554d000000b005b4ef61bfc7si94698pgr.596.2023.10.23.14.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mPMlRFjR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B2E7480A9142; Mon, 23 Oct 2023 14:18:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231536AbjJWVRo (ORCPT + 27 others); Mon, 23 Oct 2023 17:17:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229657AbjJWVRl (ORCPT ); Mon, 23 Oct 2023 17:17:41 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30F7B10A for ; Mon, 23 Oct 2023 14:17:39 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-5ac376d311aso13125157b3.1 for ; Mon, 23 Oct 2023 14:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095858; x=1698700658; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MozeFj7AsxNvK40iWKEorOKKdXplrF78HG0tGDcuTc0=; b=mPMlRFjRGMnGvJ5YGVNKgI7/9Cpr6OAO30MHnQIFWoZd2kuDqUXTRmwDHeEcVQigBO yAsfSXuKXzgkDvhYShOeIZWsMumWvEyBdL6LyEp9IEDIWh2e/FPpDg4LxrN42W1Dlz18 8fzI2x9YiHlREACG+kd0MjX50JDzEIMhK4D/mEgbM4ZpSbR2Twt+ZRKZKS3glL5+/tbZ TfXQSDkz1Va7PjRtWFzvAqevUL77ruiv13S6xVC35rSojFeD9jGsCsKZq6CK4C51o/jo 3kbWzi7hL/putZTi2jXhfHR5VR9BAD1Kx/qamT2ZLaKPtPuhWPncofhfH70MzLYfJj2n v9ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095858; x=1698700658; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MozeFj7AsxNvK40iWKEorOKKdXplrF78HG0tGDcuTc0=; b=kvxcgLelmYj524Jc0UtVc8ly7dEbugsaXsWV1eHKRPcauifU3Vlq/044ifT6spy1g7 baR0BC7W4FiKdSz3j/f/cG0ThjCHvYSQFF7lKURXyPYO2DV7qw2Y+Dr1perUd9zpYUaz wcyzs49q5V27k8JpYMXkLJ1yIhY4GPqDQygAKhA9iiZhi3uGNYj+halpR/h0lFmfl+0R 0XW2PYSbRH+PxW21MTNrUaTtIZgbtF1LXrvCDEbd4kt4LpVsDrc4Re7X10B1wcut0YOI 0EwW/nD2pMJbiKyGJJCMh1PjRhu5VLZB+adRoELVIiBAqDuTsGOvoytJ6PukrIc37Yua mqcw== X-Gm-Message-State: AOJu0YzwBbFZ8cXzJTMirdQsT7hQE0u5+WSxfiTgFxXLHaSlh0BHAFQY Uozlc+A4pkRPuDdDGEC4zweIZGay+g== X-Received: by 2002:a0d:f741:0:b0:59b:5696:c33 with SMTP id h62-20020a0df741000000b0059b56960c33mr10450976ywf.46.1698095857963; Mon, 23 Oct 2023 14:17:37 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:37 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 1/9] x86/stackprotector/32: Remove stack protector test script Date: Mon, 23 Oct 2023 17:17:22 -0400 Message-ID: <20231023211730.40566-2-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582599252165198 X-GMAIL-MSGID: 1780582599252165198 Test for compiler support directly in Kconfig. Signed-off-by: Brian Gerst --- arch/x86/Kconfig | 2 +- scripts/gcc-x86_32-has-stack-protector.sh | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100755 scripts/gcc-x86_32-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 5ef081aa12ac..039872be1630 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -411,7 +411,7 @@ config PGTABLE_LEVELS config CC_HAS_SANE_STACKPROTECTOR bool default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(CC) $(CLANG_FLAGS)) if 64BIT - default $(success,$(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(CC) $(CLANG_FLAGS)) + default $(cc-option,-mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard) help We have to make sure stack protector is unconditionally disabled if the compiler produces broken code or if it does not let us control diff --git a/scripts/gcc-x86_32-has-stack-protector.sh b/scripts/gcc-x86_32-has-stack-protector.sh deleted file mode 100755 index 825c75c5b715..000000000000 --- a/scripts/gcc-x86_32-has-stack-protector.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -# This requires GCC 8.1 or better. Specifically, we require -# -mstack-protector-guard-reg, added by -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81708 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -fstack-protector -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs" From patchwork Mon Oct 23 21:17:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1558946vqx; Mon, 23 Oct 2023 14:17:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkreiYLOIi6TamnaLTmUVj1/GZpDy7UE4dgxZOnmEUgSZ199Id601L8ZlA3KTKdc8XPPcj X-Received: by 2002:a17:902:c404:b0:1c7:8345:f377 with SMTP id k4-20020a170902c40400b001c78345f377mr10310268plk.29.1698095874742; Mon, 23 Oct 2023 14:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095874; cv=none; d=google.com; s=arc-20160816; b=Y/1cHjv/Ik5vpNtNzzK5ScyIRMHm9JHkmJ1LadgBubQ6azJlmM5G8OJIJabteM66OA HS6eGhbvDA+avDwA4u7ST4G6YIp/MXUfBK2niykT+tzLCVNP7r2QI50b28X2RmgARDPN 6wx/dCPDeg2oNUNRq42Pn03qI0P6YyAOnTQOKf2yot+9CIlGGR6B9f0MD60hPQKPCKu4 57M7yi41At8eBvnNgXHPmguZB/LoQzah1o9ACkddGtraPFOik3Rucf6RXFoWo0SzuHT2 5Pamx7fOn3keLit9i0BsFiFM0140gLWXg6g2NTAqEoEj8EiEp7X/LlMF5bi1iuCBNx1h WVNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lsKN0vAWTPkRoeR+0eW+M/Vw4EKK+fkuLodskFQx/7g=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=lR5kr0dPXBSjPZWVSjHoJTw5qmBqfhV0LLqw7Iy6vKIvSi2WWr+LiZjhEfG5QW7050 Ih78mXg08f28F6vONGS23tOOUj7dQKe1JedLw1tCjvNRcBpsUhQdTQD1L73y6ZpAiL3b dssVMZngUkdJR9rx0PHpc2cUUDgJD2bxHairwUO0d7pYY8aeJWbX342zJcgk8BBQBbg4 NkAtNKQg6FzavgDe4NvPAaTdL1D+dpalp6B12kMRHVqogpZYpSIIzFuZAqBk2I7NVdE8 cTG6eHLzsDf6rIaCMRzQtQnWYHmj2j4K837TSzj2O1dS+ZfA2/K56CaDKcPZHr7Cq+Rd KFHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="gb/vSNEg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l14-20020a170903244e00b001ca33bba8ecsi7634498pls.371.2023.10.23.14.17.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="gb/vSNEg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 13A5080C035C; Mon, 23 Oct 2023 14:17:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231686AbjJWVRr (ORCPT + 27 others); Mon, 23 Oct 2023 17:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231396AbjJWVRl (ORCPT ); Mon, 23 Oct 2023 17:17:41 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7C3DD for ; Mon, 23 Oct 2023 14:17:40 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id 46e09a7af769-6ce2cf67be2so2554492a34.2 for ; Mon, 23 Oct 2023 14:17:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095859; x=1698700659; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lsKN0vAWTPkRoeR+0eW+M/Vw4EKK+fkuLodskFQx/7g=; b=gb/vSNEg2Q3s9/RrpcxJ/PtZ+1dOQPa4zedcpnbt85vl6tkTXAscaEzDw4hBWiF26O yiAdYXpvedx6LZkLrQRPBlD/iuoyg+5uy8Qp0NCiB0AAaDvROCn5FpL1p2d6KU9JLiRh bd5Ymt3CHFzb1Il5M/JJCYLBr26SAKYsRFCpwPfXQuJ56xvpsxy74IsN3nGTxxu0mkXs F0vNG/wZAADbvRTWHdllufTyTZO2qOgPp+lUNhYM+vs26DuZjCqg/gJVIVck7eCcWjnE 1zzeL+LJrAZ8o6iF9gHxuvxwfu1Lpcy8bcnWmfi9MQRk5sbMvcX3/mkLX5aR/l05RGD6 KpoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095859; x=1698700659; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lsKN0vAWTPkRoeR+0eW+M/Vw4EKK+fkuLodskFQx/7g=; b=MwQQ8CYUTLQzQCWa/6nXyYj1HrnkRRrss7BzXUfIOZWFi3PskjmJ3VQCxhinAqXxCj s6e16O8glXNdeKsN89W4pYv1nmSfHFcF0iHXsZ3PMTthjvu/Wf2Z3WLd3jNFvl0qQZDX RAKc1UgFpBHkSeLOj9xv8iVFmTDByh/v2r+Y/M9LxLVy+2utn9ysQgq31fj3hBombVj9 oJTSQhFXbtx528HNIef+E6YuEdMLJADEKYkfEo87FajwGK/vo4ad1nYta/Li+uXN9yvk WOI6nVC6a1EnO0TX0EAP74e/PZC9WL/Wb7vMdZE8GseJxOXXkuv9DfqyTVqXjEh/AJLG QcNA== X-Gm-Message-State: AOJu0YzEakWl3WAte0wf8AX+4aEQfa2r6bBUzMsw+FmGaywD7mEkIe7r djdda5+P0zr4M74GmTTds3P3ajmZTw== X-Received: by 2002:a05:6830:2b23:b0:6be:fe1e:c13 with SMTP id l35-20020a0568302b2300b006befe1e0c13mr14809191otv.0.1698095859110; Mon, 23 Oct 2023 14:17:39 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:38 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 2/9] x86/boot: Disable stack protector for early boot code Date: Mon, 23 Oct 2023 17:17:23 -0400 Message-ID: <20231023211730.40566-3-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:17:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582579909160152 X-GMAIL-MSGID: 1780582579909160152 On 64-bit, this will prevent crashes when the canary access is changed from %gs:40 to %gs:__stack_chk_guard(%rip). RIP-relative addresses from the identity-mapped early boot code will target the wrong address with zero-based percpu. KASLR could then shift that address to an unmapped page causing a crash on boot. This early boot code runs well before userspace is active and does not need stack protector enabled. Signed-off-by: Brian Gerst --- arch/x86/kernel/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 0000325ab98f..aff619054e17 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -39,6 +39,8 @@ KMSAN_SANITIZE_nmi.o := n KCOV_INSTRUMENT_head$(BITS).o := n KCOV_INSTRUMENT_sev.o := n +CFLAGS_head32.o := -fno-stack-protector +CFLAGS_head64.o := -fno-stack-protector CFLAGS_irq.o := -I $(srctree)/$(src)/../include/asm/trace obj-y += head_$(BITS).o From patchwork Mon Oct 23 21:17:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157117 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559246vqx; Mon, 23 Oct 2023 14:18:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeXIcdIpHhTzPv/v2yL/kw8Im2I4sfLGEvFzy5WAsiercLGLdc2ywSJbjwLeXf1L0rLiDq X-Received: by 2002:a62:f246:0:b0:691:27b:15b4 with SMTP id y6-20020a62f246000000b00691027b15b4mr17461538pfl.5.1698095914815; Mon, 23 Oct 2023 14:18:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095914; cv=none; d=google.com; s=arc-20160816; b=oXmctdxW5gxzxnJETBnsfMAgsqmOHb+Mt1kTjzFtWScwlJ5FThqjGMwRymlDNlj5iG LK+05pM6DieZE91DtQYXQdB3xC5hUBjScWS85HJuZlAeB0XXnR9DB94i/GLDIsz7aCy0 FY7ExKmEHZkzb3A/5De+j2SW1JD0vmtENtfw9VZFI9URrs7T3cOJTi2pK4v1jq4OrqqC KYDc2t3icE4jJYuSR+GjoGf2nPgpLi8A9gEcFsBskhqQ5uXqKtAqhuCwgU7jcnFt8/4U IJoMSG+eaeaBKFZ9Fa21OnU1cAupVZx7KZqIUfLvn4NWjUzNhSV08DESy7TYDOY8R8Y4 pXJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Uj8LskhtlqyoaBwqcGX6oYCEo+qAf73XDhhIGhkA9po=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=sJyzoytMEFI/So/KklypXGjJZAWAY+s41cMWbkkT7nWbwvkh5aOuTU8a5drWaS7rY5 kKcl/IfkZjAJpeO9KxiQAh3aLCXEVOMUlFFjbmvdjQfbTim/lzmu1SQ+uEUHRMUzGVFC P3d6OSOl2/tFEBHzzBpEB2/r6vipmg/49AT+EF7h1jQRozg23JVLuhN8E5DHcWs1v39t pEShtPDOuQWSWLWItMH71B8WR1ivoYmhPzUeFZgBVSQaOes5JZPatbOuMpGjt9Ps+rSF PXxqZnXL2YxOFVkPqx1G7p/7dg20HmGLljnFNTWMqflo3AHjm7AF67o0/vX512TlaTdy zbVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=da0XDlBn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y63-20020a638a42000000b005aad9763d8bsi6877108pgd.422.2023.10.23.14.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=da0XDlBn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 9E8CD80A8510; Mon, 23 Oct 2023 14:18:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjJWVRz (ORCPT + 27 others); Mon, 23 Oct 2023 17:17:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbjJWVRo (ORCPT ); Mon, 23 Oct 2023 17:17:44 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D434DD for ; Mon, 23 Oct 2023 14:17:41 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5a7a80a96dbso39579967b3.0 for ; Mon, 23 Oct 2023 14:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095860; x=1698700660; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uj8LskhtlqyoaBwqcGX6oYCEo+qAf73XDhhIGhkA9po=; b=da0XDlBnIRWBC5U4tmQvJfeBs/1U5+gK9CqR3YJXbM18L3qRk0990gYZU2lJOUql+2 pJuVkwXxE+5eszQ+J3RYuhv+nr18h1sJpSKwAhV3uHD6CyzbNrdxK5XM+hBrQxXDgK0z tfkju8M0TIMp+/Di4H8VK7BUDH4nrj+QccglUN51OcFqny34hZi9joSSAyo+UveeFrhh bQn3f+zn4lbuH3fAVfvComkhLbMUA20LmG0j7zYumUiYKMX76CO/1Wq9/gycHju9Za4v 0VmA6LJ1N1psorbmkGmuYsb1UgHqCPwn+S9lN21+2+6zU6kC+kVyF+y3WepSMhuFbbjq 908g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095860; x=1698700660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uj8LskhtlqyoaBwqcGX6oYCEo+qAf73XDhhIGhkA9po=; b=BM8/HbLjpIgfFgRMxmYMimYkWYXkpzAw0a0prPgm+fJqZlt2/pfCfmVIgX9zGRObYW ckunVbjzssSDXPBakc6BKbDR4BS5tKDL77zxuOp/SSfxyJPT3l7+69I1r1ntTbCROulX yxoh86HmaJiJLSt300R+7NKz8M1Mf8p6CKD1iQmKtBiaM5EVKJZPRmgkxBKm5rcKsiNk /5d/Do5RuI6Di45rwJu4SqFka8vjhUj4iRf8ZSTbX3Gv7p67ypEMJx3G/uCoaQVXbBTD +Gt+e6uslzW78wILlM8/Pt0+pioj9U9Bkx1oUHv9t2hjaBqEeB5jMLfO8XQoAKaQw9Ak Z4/g== X-Gm-Message-State: AOJu0YzK3BBiQDmy21kh60oos4mhIzm3E6cHV6IlgD5xWHsDZmA8EbNM /uYjVPFI5HKyJ0dlyPjmSXPJO6+6uA== X-Received: by 2002:a81:52cc:0:b0:5a7:af4f:59ad with SMTP id g195-20020a8152cc000000b005a7af4f59admr10395622ywb.0.1698095860215; Mon, 23 Oct 2023 14:17:40 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:39 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 3/9] x86/stackprotector/64: Convert stack protector to normal percpu variable Date: Mon, 23 Oct 2023 17:17:24 -0400 Message-ID: <20231023211730.40566-4-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582621866740540 X-GMAIL-MSGID: 1780582621866740540 Older versions of GCC fixed the location of the stack protector canary at %gs:40. This constraint forced the percpu section to be linked at virtual address 0 so that the canary could be the first data object in the percpu section. Supporting the zero-based percpu section requires additional code to handle relocations for RIP-relative references to percpu data, extra complexity to kallsyms, and workarounds for linker bugs due to the use of absolute symbols. Since version 8.1, GCC has options to configure the location of the canary value. This allows the canary to be turned into a normal percpu variable and removes the constraint that the percpu section be zero-based. Signed-off-by: Brian Gerst --- arch/x86/Kconfig | 5 ++- arch/x86/Makefile | 19 +++++++----- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/processor.h | 15 +-------- arch/x86/include/asm/stackprotector.h | 37 +++++------------------ arch/x86/kernel/asm-offsets_64.c | 6 ---- arch/x86/kernel/cpu/common.c | 4 +-- scripts/gcc-x86_64-has-stack-protector.sh | 4 --- 8 files changed, 24 insertions(+), 68 deletions(-) delete mode 100755 scripts/gcc-x86_64-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 039872be1630..c95e0ce557da 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -410,12 +410,11 @@ config PGTABLE_LEVELS config CC_HAS_SANE_STACKPROTECTOR bool - default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(CC) $(CLANG_FLAGS)) if 64BIT + default $(cc-option,-mstack-protector-guard-reg=gs -mstack-protector-guard-symbol=__stack_chk_guard) if 64BIT default $(cc-option,-mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard) help We have to make sure stack protector is unconditionally disabled if - the compiler produces broken code or if it does not let us control - the segment on 32-bit kernels. + the compiler does not allow control of the segment and symbol. menu "Processor type and features" diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 22e41d9dbc23..169f086997ec 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -111,13 +111,7 @@ ifeq ($(CONFIG_X86_32),y) # temporary until string.h is fixed KBUILD_CFLAGS += -ffreestanding - ifeq ($(CONFIG_STACKPROTECTOR),y) - ifeq ($(CONFIG_SMP),y) - KBUILD_CFLAGS += -mstack-protector-guard-reg=fs -mstack-protector-guard-symbol=__stack_chk_guard - else - KBUILD_CFLAGS += -mstack-protector-guard=global - endif - endif + percpu_seg := fs else BITS := 64 UTS_MACHINE := x86_64 @@ -167,6 +161,17 @@ else KBUILD_CFLAGS += -mcmodel=kernel KBUILD_RUSTFLAGS += -Cno-redzone=y KBUILD_RUSTFLAGS += -Ccode-model=kernel + + percpu_seg := gs +endif + +ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + KBUILD_CFLAGS += -mstack-protector-guard-reg=$(percpu_seg) \ + -mstack-protector-guard-symbol=__stack_chk_guard + else + KBUILD_CFLAGS += -mstack-protector-guard=global + endif endif # diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 1a88ad8a7b48..cddcc236aaae 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -190,7 +190,7 @@ SYM_FUNC_START(__switch_to_asm) #ifdef CONFIG_STACKPROTECTOR movq TASK_stack_canary(%rsi), %rbx - movq %rbx, PER_CPU_VAR(fixed_percpu_data + FIXED_stack_canary) + movq %rbx, PER_CPU_VAR(__stack_chk_guard) #endif /* diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index ae81a7191c1c..04371f60e3c6 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -394,16 +394,7 @@ struct irq_stack { #ifdef CONFIG_X86_64 struct fixed_percpu_data { - /* - * GCC hardcodes the stack canary as %gs:40. Since the - * irq_stack is the object at %gs:0, we reserve the bottom - * 48 bytes of the irq stack for the canary. - * - * Once we are willing to require -mstack-protector-guard-symbol= - * support for x86_64 stackprotector, we can get rid of this. - */ char gs_base[40]; - unsigned long stack_canary; }; DECLARE_PER_CPU_FIRST(struct fixed_percpu_data, fixed_percpu_data) __visible; @@ -418,11 +409,7 @@ extern asmlinkage void entry_SYSCALL32_ignore(void); /* Save actual FS/GS selectors and bases to current->thread */ void current_save_fsgs(void); -#else /* X86_64 */ -#ifdef CONFIG_STACKPROTECTOR -DECLARE_PER_CPU(unsigned long, __stack_chk_guard); -#endif -#endif /* !X86_64 */ +#endif /* X86_64 */ struct perf_event; diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h index 00473a650f51..33abbd29ea26 100644 --- a/arch/x86/include/asm/stackprotector.h +++ b/arch/x86/include/asm/stackprotector.h @@ -2,26 +2,13 @@ /* * GCC stack protector support. * - * Stack protector works by putting predefined pattern at the start of + * Stack protector works by putting a predefined pattern at the start of * the stack frame and verifying that it hasn't been overwritten when - * returning from the function. The pattern is called stack canary - * and unfortunately gcc historically required it to be at a fixed offset - * from the percpu segment base. On x86_64, the offset is 40 bytes. + * returning from the function. The pattern is called the stack canary + * and is a unique value for each task. * - * The same segment is shared by percpu area and stack canary. On - * x86_64, percpu symbols are zero based and %gs (64-bit) points to the - * base of percpu area. The first occupant of the percpu area is always - * fixed_percpu_data which contains stack_canary at the appropriate - * offset. On x86_32, the stack canary is just a regular percpu - * variable. - * - * Putting percpu data in %fs on 32-bit is a minor optimization compared to - * using %gs. Since 32-bit userspace normally has %fs == 0, we are likely - * to load 0 into %fs on exit to usermode, whereas with percpu data in - * %gs, we are likely to load a non-null %gs on return to user mode. - * - * Once we are willing to require GCC 8.1 or better for 64-bit stackprotector - * support, we can remove some of this complexity. + * GCC is configured to read the stack canary value from the __stack_chk_guard + * per-cpu variable, which is changed on task switch. */ #ifndef _ASM_STACKPROTECTOR_H @@ -36,6 +23,8 @@ #include +DECLARE_PER_CPU(unsigned long, __stack_chk_guard); + /* * Initialize the stackprotector canary value. * @@ -51,25 +40,13 @@ static __always_inline void boot_init_stack_canary(void) { unsigned long canary = get_random_canary(); -#ifdef CONFIG_X86_64 - BUILD_BUG_ON(offsetof(struct fixed_percpu_data, stack_canary) != 40); -#endif - current->stack_canary = canary; -#ifdef CONFIG_X86_64 - this_cpu_write(fixed_percpu_data.stack_canary, canary); -#else this_cpu_write(__stack_chk_guard, canary); -#endif } static inline void cpu_init_stack_canary(int cpu, struct task_struct *idle) { -#ifdef CONFIG_X86_64 - per_cpu(fixed_percpu_data.stack_canary, cpu) = idle->stack_canary; -#else per_cpu(__stack_chk_guard, cpu) = idle->stack_canary; -#endif } #else /* STACKPROTECTOR */ diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c index bb65371ea9df..590b6cd0eac0 100644 --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c @@ -54,11 +54,5 @@ int main(void) BLANK(); #undef ENTRY - BLANK(); - -#ifdef CONFIG_STACKPROTECTOR - OFFSET(FIXED_stack_canary, fixed_percpu_data, stack_canary); - BLANK(); -#endif return 0; } diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b14fc8c1c953..f9c8bd27b642 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2103,15 +2103,13 @@ void syscall_init(void) X86_EFLAGS_AC|X86_EFLAGS_ID); } -#else /* CONFIG_X86_64 */ +#endif /* CONFIG_X86_64 */ #ifdef CONFIG_STACKPROTECTOR DEFINE_PER_CPU(unsigned long, __stack_chk_guard); EXPORT_PER_CPU_SYMBOL(__stack_chk_guard); #endif -#endif /* CONFIG_X86_64 */ - /* * Clear all 6 debug registers: */ diff --git a/scripts/gcc-x86_64-has-stack-protector.sh b/scripts/gcc-x86_64-has-stack-protector.sh deleted file mode 100755 index 75e4e22b986a..000000000000 --- a/scripts/gcc-x86_64-has-stack-protector.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m64 -O0 -mcmodel=kernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" From patchwork Mon Oct 23 21:17:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157113 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1558986vqx; Mon, 23 Oct 2023 14:17:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoBckTtJpHT098fvEvvaKLHg5TQg1XocCR3540ifze7qERnpI3SmiHw9pxqXvN3lR8wlB2 X-Received: by 2002:a05:6359:6c11:b0:168:e8f8:c5cb with SMTP id tc17-20020a0563596c1100b00168e8f8c5cbmr1932221rwb.0.1698095879222; Mon, 23 Oct 2023 14:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095879; cv=none; d=google.com; s=arc-20160816; b=GRJO01uKyBpbjV5bQqPg589x/LYCoOrQNz5gAQCDTMjvP0L2P8rt/JYDMDmWcaTp1R MP08GAVYYeUghDT5mXxeCwE/XdqtuXmSrXHWtPwVBG8yZpj1H9vfspE7ZIyTFJUho0rV qHcFU5hu3exzMZM6swqTFre1KJMcJcGB3gBBYdlkuGborUnzVW9atrVm7dyvfv6ZttYL HbNLJ60XGaGFsd+OaLJDdPvRXwGJ4G+0JLwr/KR3l67qMcnw3rWMKQ2KiuqZ0JMtTubw fYUm32NAoyyGJmLZJP74zGxrsnW5Y6GZ1evd3nzr0EmBJlvhsnwN5BCz7rSd4P3cqJRt moow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sFuYnGAQUTzuREgXlsOmxY7LqCUSpomHGIDzZdL7lBI=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=p4ue4OzANYibFmzWccPDROYpx28TAZwjwKzfA4B8JJhdA8v9QYmsA3k+zuo7fzZzJo 7QeZ3G7N5ywByC3EgH4TArF8yG2qtJq7/kQtgPFUTJpHd6kLN7WhunwC1jGoIlsCVl4A UeGILDCD2KLJM4og5Yf/6ebIR00dLjSkmK4Itn3v3oC69ECH/m25dzZpwcqmK9MV8pRd nSBSlFQbNWOl46wEpDHVDuTSaITBwljO5r0QDZ46LYfYt57lbxRaxHH8d18DQjJ/X7vE iLaYezeRiAxjikMW3UiwW8j48RrgWndGBcwOZU4KvESgn5z/hITV52ajqd01Kolpl+a5 OsMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P4PQPayO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w25-20020a637b19000000b005b02d7bb426si6874361pgc.282.2023.10.23.14.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=P4PQPayO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4446880C037F; Mon, 23 Oct 2023 14:17:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232167AbjJWVRv (ORCPT + 27 others); Mon, 23 Oct 2023 17:17:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjJWVRp (ORCPT ); Mon, 23 Oct 2023 17:17:45 -0400 Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF39D7C for ; Mon, 23 Oct 2023 14:17:42 -0700 (PDT) Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5a92782615dso24179747b3.2 for ; Mon, 23 Oct 2023 14:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095861; x=1698700661; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sFuYnGAQUTzuREgXlsOmxY7LqCUSpomHGIDzZdL7lBI=; b=P4PQPayOy5mvjI6ghbg+pj3G6y5hprocXmeV4LxsEpZDhdm7/6ub6M+eXO2BUd/Xpt 3Ln7EmPArt3UWfsBRk+Da04J2Km4KvZ7qQCRvE4wB2/9MiPEjg5OTEoVu26tlIL6/rce lyUgaS1YmfEGXL3OvJs3r3uExM4bFN76m0Ytrzg6t4Ng4D+PzLU+r2UenxAjqcKlyI4h yEiTsKh2tkcj6jySBYatz9fi7j9njv43Oqz9wT/DNKjLvH5sIt4ifRKqi/5cUxbl4dL1 a5Nmmu9CB04wsMeIv4LaGYbgzvXN7rc3C4yl+klFwZ3YuccLdZW5nVjkE8SsngSkc/eg hd3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095861; x=1698700661; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sFuYnGAQUTzuREgXlsOmxY7LqCUSpomHGIDzZdL7lBI=; b=irrA7AqwILursA3F2Y6eC8wMMeaYXU2lgsqfnrjQgOPE8M2oB53GHG7YQIYP5fPyCh WZYVrL6y5myDmoZCawjlyWgPYx2uH/k72NLq3DUanBfGKFtSzzENmRFaWEAGzghyYblv STHHv7pta5Au437s+fFAP6siNiJ8KUeIIkj7UiK0VkAzCRjH5y+PvBL/h1yjUo/nDQfC NnYk+sbL5PsplqMeBt2tTssViRUbwcSR99YAFqbK8WPUd5lKdJrZiKk2iEJRBoFN60Mw xeDEnUM3qFjqX2FNeZ365Q0PpKvpddRmLizE7eKvjAJSyj78Zis6RbS3FVrS/h3NYpZ1 8G7A== X-Gm-Message-State: AOJu0YwHkzAiKracwMZjNWLBM7opnJH0wIo2H2uuriW43SuBq4DWo4tw Vhq/d46qUXg3zgAAUp5zfdUfUFRAkw== X-Received: by 2002:a05:690c:fd1:b0:5a7:ccf3:7163 with SMTP id dg17-20020a05690c0fd100b005a7ccf37163mr12181250ywb.15.1698095861316; Mon, 23 Oct 2023 14:17:41 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:40 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 4/9] x86/percpu/64: Remove fixed_percpu_data Date: Mon, 23 Oct 2023 17:17:25 -0400 Message-ID: <20231023211730.40566-5-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:17:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582585027976439 X-GMAIL-MSGID: 1780582585027976439 Now that the stack protector canary value is a normal percpu variable, fixed_percpu_data is unused and can be removed. Signed-off-by: Brian Gerst --- arch/x86/include/asm/processor.h | 13 +++++-------- arch/x86/kernel/cpu/common.c | 4 ---- arch/x86/kernel/head_64.S | 12 ++++++------ arch/x86/kernel/vmlinux.lds.S | 6 ------ arch/x86/tools/relocs.c | 1 - arch/x86/xen/xen-head.S | 12 ++++++++---- 6 files changed, 19 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 04371f60e3c6..48c31b8e3e72 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -393,16 +393,13 @@ struct irq_stack { } __aligned(IRQ_STACK_SIZE); #ifdef CONFIG_X86_64 -struct fixed_percpu_data { - char gs_base[40]; -}; - -DECLARE_PER_CPU_FIRST(struct fixed_percpu_data, fixed_percpu_data) __visible; -DECLARE_INIT_PER_CPU(fixed_percpu_data); - static inline unsigned long cpu_kernelmode_gs_base(int cpu) { - return (unsigned long)per_cpu(fixed_percpu_data.gs_base, cpu); +#ifdef CONFIG_SMP + return per_cpu_offset(cpu); +#else + return 0; +#endif } extern asmlinkage void entry_SYSCALL32_ignore(void); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index f9c8bd27b642..a44fd3ad460e 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2051,10 +2051,6 @@ DEFINE_PER_CPU_ALIGNED(struct pcpu_hot, pcpu_hot) = { EXPORT_PER_CPU_SYMBOL(pcpu_hot); #ifdef CONFIG_X86_64 -DEFINE_PER_CPU_FIRST(struct fixed_percpu_data, - fixed_percpu_data) __aligned(PAGE_SIZE) __visible; -EXPORT_PER_CPU_SYMBOL_GPL(fixed_percpu_data); - static void wrmsrl_cstar(unsigned long val) { /* diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 3dcabbc49149..f2453eb38417 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -72,9 +72,14 @@ SYM_CODE_START_NOALIGN(startup_64) /* Setup GSBASE to allow stack canary access for C code */ movl $MSR_GS_BASE, %ecx - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx +#ifdef CONFIG_SMP + leaq __per_cpu_load(%rip), %rdx movl %edx, %eax shrq $32, %rdx +#else + xorl %eax, %eax + xorl %edx, %edx +#endif wrmsr call startup_64_setup_env @@ -345,15 +350,10 @@ SYM_INNER_LABEL(secondary_startup_64_no_verify, SYM_L_GLOBAL) /* Set up %gs. * - * The base of %gs always points to fixed_percpu_data. If the - * stack protector canary is enabled, it is located at %gs:40. * Note that, on SMP, the boot cpu uses init data section until * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx -#ifndef CONFIG_SMP - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx -#endif movl %edx, %eax shrq $32, %rdx wrmsr diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 54a5596adaa6..c87dc8de2084 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -509,14 +509,8 @@ SECTIONS */ #define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load INIT_PER_CPU(gdt_page); -INIT_PER_CPU(fixed_percpu_data); INIT_PER_CPU(irq_stack_backing_store); -#ifdef CONFIG_SMP -. = ASSERT((fixed_percpu_data == 0), - "fixed_percpu_data is not at start of per-cpu area"); -#endif - #ifdef CONFIG_CPU_UNRET_ENTRY . = ASSERT((retbleed_return_thunk & 0x3f) == 0, "retbleed_return_thunk not cacheline-aligned"); #endif diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index d30949e25ebd..3ccd9d4fcf9c 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -811,7 +811,6 @@ static void percpu_init(void) * __per_cpu_load * * The "gold" linker incorrectly associates: - * init_per_cpu__fixed_percpu_data * init_per_cpu__gdt_page */ static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index a0ea285878db..9ce0d9d268bb 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -53,14 +53,18 @@ SYM_CODE_START(startup_xen) /* Set up %gs. * - * The base of %gs always points to fixed_percpu_data. If the - * stack protector canary is enabled, it is located at %gs:40. * Note that, on SMP, the boot cpu uses init data section until * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx - movq $INIT_PER_CPU_VAR(fixed_percpu_data),%rax - cdq +#ifdef CONFIG_SMP + leaq __per_cpu_load(%rip), %rdx + movl %edx, %eax + shrq $32, %rdx +#else + xorl %eax, %eax + xorl %edx, %edx +#endif wrmsr mov %rsi, %rdi From patchwork Mon Oct 23 21:17:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559155vqx; Mon, 23 Oct 2023 14:18:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJL9YzEdlpEiStnBhdQip/uYxMS+rDjKCQBvnaSC7XBtt2vqhiGNfwYdsfpsB9YFnDkWPT X-Received: by 2002:a05:6a20:3c93:b0:13d:8876:4c97 with SMTP id b19-20020a056a203c9300b0013d88764c97mr854380pzj.16.1698095903349; Mon, 23 Oct 2023 14:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095903; cv=none; d=google.com; s=arc-20160816; b=lNPjQ2uW0fAqfydvfqyuaEjqTKjYw+KsA9OohqGBKGgZxGJJiPv7uigAVw4YA5c4Ga /SSCIpun/JrepWSvnBYSNGNSFJYk/29/P6tktB4EElk3J3qRAI+UZ6UREleUsstIytB6 uRQPmORd3fumwQtBicFSAR9luNzi0twGXvfnvIZ6FdposCpf+QRr4PFlMZm0bGB9Yh05 eFjdExw+J8hXWoJivzRbZ6ae7FtUg1DcQ0oHEBWsQzcPcM/WGgG8gLtcMY15y8XiRW57 0aOowSBzSmr4Ygft/9he0RlZQETmPW9oRJ28O8Hy8vHeS4QqvyMlovLa2RMQQKK6la/o Mn9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cKtCKkTSYC7hZ3rLuwOCTXUI3GkJ5ijCz5zkNO2WTMs=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=eipBnBfX9UVYRqIjPmgaTQkDXiOg4OLP9M34Do1Xn1azYkQREuj6Jb9u2qd2M1XK3k PSYwdf2ruJ39EysjDFsavBZXJtm4Zf//2LVeUIpJvGaMZCEDUHUY0t0v9aCo5sbCOvGm CZjaFnA58EvOTCKha2K7ivAGVFHLN/boGu4xKgMUAkn/qswCsUlLWs+JaoXFHJvhfzT1 IQlv+NYHMV2Cr5tSbcV94D1lrGtK4nZLxHJIz0AmzQQcrT372/gA7E5jiZVx0ZBSSNoR Ya62sKrtwGXis5I40bJLkUMiqcfwZivmGoPnRrIJBBc5guZI9vTyKM4KUTleL/IGEQXz CHMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=drm7NLvQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id bq21-20020a056a02045500b005b7c45b1f95si7503556pgb.555.2023.10.23.14.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=drm7NLvQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1BE87805EB30; Mon, 23 Oct 2023 14:18:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjJWVR7 (ORCPT + 27 others); Mon, 23 Oct 2023 17:17:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjJWVRq (ORCPT ); Mon, 23 Oct 2023 17:17:46 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 912FC10C0 for ; Mon, 23 Oct 2023 14:17:43 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-5a7e5dc8573so38040987b3.0 for ; Mon, 23 Oct 2023 14:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095862; x=1698700662; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cKtCKkTSYC7hZ3rLuwOCTXUI3GkJ5ijCz5zkNO2WTMs=; b=drm7NLvQ2F3JJl62iCQscBlIJ5zJXHFmCha6Na5ZmgNuujszmJ03pBWgUChG4DZ7Tg DTbOVzI7K6vO7yJjxD96oLFAgU8Wek4eMGa58vfb1j0FABD3zfgM9vJXoQ342KtgXOKQ l2YqWDZsJxrTPKt93OEr0dip9dWKU7sFb2orA5P9piwARYKDtSX2SqkhLykGfM/rV8yW 3wexc34/7xJCOK1GnBjMdlWZORLxyvP+eB3wTFFU9Cspu75bn10Z7bYvmhPc4qJgCmRf cy78w47pwy9qWqifljqm5AVnTSUTEDSjFR68opZZCF85pVpGyLla5vt5MCIsXYpsB4XD Cwsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095862; x=1698700662; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cKtCKkTSYC7hZ3rLuwOCTXUI3GkJ5ijCz5zkNO2WTMs=; b=QPYKhnHFuyXZhjhSWU2DSO7KHgbXMOnpwaXr9MjJSTjaFol/n9ZdVgg0/h5+j0TqHx xFumQ3eNXiO/1wO94++vfHRsjWwKH5ONbVNpekcynGwx9U3r9rDoNA8ODpV6upZismH0 mr8pU08mqae8wF2o0NGvcKJ1DG+mkGUgIpTHYeMU3PqnAgTmbHEKh7M+ICp0JN7IDrM2 A/ZgPkeDvYcFM0J5NJ6igAPdytYBGRJukXXhoAZe4vegxSu40MQNBcShNOt65AXtvhd8 OLW+dT7CBAnrwt7+E8ZJqLSuzi+Udi/ejCq4mx4r55f7fISijOz2uXH4N2RexiZbLUI0 QCYg== X-Gm-Message-State: AOJu0YzLd9EAxXyVbr4+hb+pOGbyZJ7mD95LX1enJ5XMEN6H8vb53XvJ r22RcT2RyRadWbvlaGvBd41X9zeILw== X-Received: by 2002:a0d:d804:0:b0:59b:d872:5ca8 with SMTP id a4-20020a0dd804000000b0059bd8725ca8mr12323788ywe.22.1698095862341; Mon, 23 Oct 2023 14:17:42 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:42 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 5/9] x86/percpu/64: Use relative percpu offsets Date: Mon, 23 Oct 2023 17:17:26 -0400 Message-ID: <20231023211730.40566-6-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582610080580294 X-GMAIL-MSGID: 1780582610080580294 The percpu section is currently linked at virtual address 0, because older compilers hardcoded the stack protector canary value at a fixed offset from the start of the GS segment. Now that the canary is a normal percpu variable, the percpu section can be linked normally. This means that x86-64 will calculate percpu offsets like most other architectures, as the delta between the initial percpu address and the dynamically allocated memory. Signed-off-by: Brian Gerst --- arch/x86/kernel/head_64.S | 6 ------ arch/x86/kernel/setup_percpu.c | 12 ++---------- arch/x86/kernel/vmlinux.lds.S | 24 +----------------------- arch/x86/tools/relocs.c | 10 +++------- arch/x86/xen/xen-head.S | 6 ------ init/Kconfig | 2 +- 6 files changed, 7 insertions(+), 53 deletions(-) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index f2453eb38417..b35f74e58dd7 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -72,14 +72,8 @@ SYM_CODE_START_NOALIGN(startup_64) /* Setup GSBASE to allow stack canary access for C code */ movl $MSR_GS_BASE, %ecx -#ifdef CONFIG_SMP - leaq __per_cpu_load(%rip), %rdx - movl %edx, %eax - shrq $32, %rdx -#else xorl %eax, %eax xorl %edx, %edx -#endif wrmsr call startup_64_setup_env diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index 2c97bf7b56ae..8707dd07b9ce 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c @@ -23,18 +23,10 @@ #include #include -#ifdef CONFIG_X86_64 -#define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load) -#else -#define BOOT_PERCPU_OFFSET 0 -#endif - -DEFINE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET; +DEFINE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off); EXPORT_PER_CPU_SYMBOL(this_cpu_off); -unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init = { - [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET, -}; +unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init; EXPORT_SYMBOL(__per_cpu_offset); /* diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index c87dc8de2084..8d8eb4d9ff9d 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -102,12 +102,6 @@ jiffies = jiffies_64; PHDRS { text PT_LOAD FLAGS(5); /* R_E */ data PT_LOAD FLAGS(6); /* RW_ */ -#ifdef CONFIG_X86_64 -#ifdef CONFIG_SMP - percpu PT_LOAD FLAGS(6); /* RW_ */ -#endif - init PT_LOAD FLAGS(7); /* RWE */ -#endif note PT_NOTE FLAGS(0); /* ___ */ } @@ -223,21 +217,7 @@ SECTIONS __init_begin = .; /* paired with __init_end */ } -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP) - /* - * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the - * output PHDR, so the next output section - .init.text - should - * start another segment - init. - */ - PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu) - ASSERT(SIZEOF(.data..percpu) < CONFIG_PHYSICAL_START, - "per-CPU data too large - increase CONFIG_PHYSICAL_START") -#endif - INIT_TEXT_SECTION(PAGE_SIZE) -#ifdef CONFIG_X86_64 - :init -#endif /* * Section for code used exclusively before alternatives are run. All @@ -367,9 +347,7 @@ SECTIONS EXIT_DATA } -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP) PERCPU_SECTION(INTERNODE_CACHE_BYTES) -#endif . = ALIGN(PAGE_SIZE); @@ -507,7 +485,7 @@ SECTIONS * Per-cpu symbols which need to be offset from __per_cpu_load * for the boot processor. */ -#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load +#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) INIT_PER_CPU(gdt_page); INIT_PER_CPU(irq_stack_backing_store); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 3ccd9d4fcf9c..01efbfdd3eb3 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -815,12 +815,7 @@ static void percpu_init(void) */ static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) { - int shndx = sym_index(sym); - - return (shndx == per_cpu_shndx) && - strcmp(symname, "__init_begin") && - strcmp(symname, "__per_cpu_load") && - strncmp(symname, "init_per_cpu_", 13); + return 0; } @@ -1043,7 +1038,8 @@ static int cmp_relocs(const void *va, const void *vb) static void sort_relocs(struct relocs *r) { - qsort(r->offset, r->count, sizeof(r->offset[0]), cmp_relocs); + if (r->count) + qsort(r->offset, r->count, sizeof(r->offset[0]), cmp_relocs); } static int write32(uint32_t v, FILE *f) diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 9ce0d9d268bb..c1d9c92b417a 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -57,14 +57,8 @@ SYM_CODE_START(startup_xen) * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx -#ifdef CONFIG_SMP - leaq __per_cpu_load(%rip), %rdx - movl %edx, %eax - shrq $32, %rdx -#else xorl %eax, %eax xorl %edx, %edx -#endif wrmsr mov %rsi, %rdi diff --git a/init/Kconfig b/init/Kconfig index 6d35728b94b2..1af31b23e376 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1718,7 +1718,7 @@ config KALLSYMS_ALL config KALLSYMS_ABSOLUTE_PERCPU bool depends on KALLSYMS - default X86_64 && SMP + default n config KALLSYMS_BASE_RELATIVE bool From patchwork Mon Oct 23 21:17:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157116 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559208vqx; Mon, 23 Oct 2023 14:18:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQZoSI4fZmVJ75SODDwXS+23iZ/ZiCcMVH5uXLGjgsJWmirtH24T0WrP6FOg61kEqoxG4/ X-Received: by 2002:a17:90a:aa8d:b0:27e:22b:dce5 with SMTP id l13-20020a17090aaa8d00b0027e022bdce5mr10221141pjq.27.1698095910917; Mon, 23 Oct 2023 14:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095910; cv=none; d=google.com; s=arc-20160816; b=MDp/s5KHXtqkdnvLpflhQaGK/xzVfJHlFZHRXM2JxackFiOotv6uDmG04QTcqfW4kk Oy/YvDk5sUq6wUgaJ+FC314YfpzA0jSv54dguOozCT7IpomN9tSN65jpaekXa+KUvQaY Xprlm9FHcTANuBYDSuBUJgutgtu1+IfFqBS+x3AWRBGdMzxEtsUVnj8+LkDfCPTKD6Fo dBoD09+iqswvSTqvltVqNPZ1aN+Na021TRT/mEs9LqCDQ96fm6miBHMejzksGm8xPE3m oo/XKYRWplaEiHatDNSP9P3myj/pbJMWYHR5aDi/Y6PM9SFeuujDfszC+ZaW4ptKoews D3Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=db30fLrdyUYnUnirSu1qpKhiubFgmXt1L06pmuCbQb8=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=T0Z8v7icNbzvGi0Hoz/ZaRoGzh2J7o3KZvbRV4LPBYbMLtqg2yXKeZk36U+JMQVcye tNxR8vwubgZVsZcftN+f158R1AZVogv6fmE5JJ/GaniuO3w3O/VDG0NaP56m6vNoNO8m Ljda9hv3J/cZBXltQJbropulIfhSMVlN/zsSNlhx01ggzt96zw/fJkgK+7vU4b83nQAH Xws9wL7PdqG/MIM86HZFYYM0RkH/XjrEq4ZmEdDHKN6GepHzwGZ/B+tKTAXrVtzj0POU iN7ei4uGaS6SSW8Zr+kZmwyTUiz56O0fm11hPsHxgo7FpiLIfxO353bShfTmMJ7ZL09K vBXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cBbIDMW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id go14-20020a17090b03ce00b002773152a294si6135740pjb.80.2023.10.23.14.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=cBbIDMW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C3961809A793; Mon, 23 Oct 2023 14:18:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231452AbjJWVSE (ORCPT + 27 others); Mon, 23 Oct 2023 17:18:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjJWVRr (ORCPT ); Mon, 23 Oct 2023 17:17:47 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 848DB10C8 for ; Mon, 23 Oct 2023 14:17:44 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6ce2add34c9so2652788a34.1 for ; Mon, 23 Oct 2023 14:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095863; x=1698700663; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=db30fLrdyUYnUnirSu1qpKhiubFgmXt1L06pmuCbQb8=; b=cBbIDMW4c7V+g8J2rhDDm5GgKaQOQFcrGuBk3rJgY54g8AabElJ3x9yQG7GdEHNrTs y9PZ4IAJKVi7a6Er81RIH4ZncY5vgnZptURHMaE5mY5Ov7PEu0fHGsFlAbkrKDGyG/Be /og3BLcP+VLa5R2gQ/s5fxd6e19jFt3zkuOSiLKtEh1DNwF8p7AMfOa1pemjsSxYaFBz emddY2o/I69d6LnDuvhT73e41+74P10Ie89s/HHTuWLcIKnE7p3VmgmWvJv0z0PLCMeF K+PPsclPMyG8kUjw78/EudykyF4IbxhmUd6WPTxSrZ6pcS097w6IEAbVJhN7ye9eznnx y5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095863; x=1698700663; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=db30fLrdyUYnUnirSu1qpKhiubFgmXt1L06pmuCbQb8=; b=boE493DxMmiJml/wPCwNMFI9hU/jnvGWvizKJy8/rD9tsGjBLasw4d2R66Nb1RQkEr Couzyd9BFCRkoUID+EQNZIAanlYnXDe2h06cZPM8IX6Z0XglF3oC08wYWOzJWlkBlq3U srXeYb4sO9Ny3Qab78l/5/PgLx4ixMu5WJWznSDn1C3ntsVu5ktTuYp43o+/Upc7I4XH RnwJHR4NrpPDOjvMrN1d6PjHdOi5bwu/2EVpZmaR4CIyuiahCZBQR2SlCRa4/EKPHjHU +YrX0ENIp1HWzLyNWhkSNuO7906uXlCnO02mlbK4YX08XJ7ntn8TOmdpF+no0vJAnCiG wGAg== X-Gm-Message-State: AOJu0YyJKRVw5ZERAK3yfRTutU7SVnXTqn5HJDThj4HoRV/6Vx55n3gr 9mP8vdBEgPVAUr/fWr93ucaLeY14sw== X-Received: by 2002:a05:6830:4103:b0:6c4:9423:a350 with SMTP id w3-20020a056830410300b006c49423a350mr12166059ott.3.1698095863396; Mon, 23 Oct 2023 14:17:43 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:43 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 6/9] x86/boot/64: Remove inverse relocations Date: Mon, 23 Oct 2023 17:17:27 -0400 Message-ID: <20231023211730.40566-7-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:21 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582617547668178 X-GMAIL-MSGID: 1780582617547668178 Now that the percpu section is not at a fixed virtual address, inverse relocations, which were needed to offset the effects of relocation on RIP-relative percpu references, are no longer needed. Signed-off-by: Brian Gerst --- arch/x86/boot/compressed/misc.c | 14 +--- arch/x86/tools/relocs.c | 126 +------------------------------- 2 files changed, 2 insertions(+), 138 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c index b99e08e6815b..2de345a236c0 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -221,7 +221,7 @@ static void handle_relocations(void *output, unsigned long output_len, /* * Process relocations: 32 bit relocations first then 64 bit after. - * Three sets of binary relocations are added to the end of the kernel + * Two sets of binary relocations are added to the end of the kernel * before compression. Each relocation table entry is the kernel * address of the location which needs to be updated stored as a * 32-bit value which is sign extended to 64 bits. @@ -231,8 +231,6 @@ static void handle_relocations(void *output, unsigned long output_len, * kernel bits... * 0 - zero terminator for 64 bit relocations * 64 bit relocation repeated - * 0 - zero terminator for inverse 32 bit relocations - * 32 bit inverse relocation repeated * 0 - zero terminator for 32 bit relocations * 32 bit relocation repeated * @@ -249,16 +247,6 @@ static void handle_relocations(void *output, unsigned long output_len, *(uint32_t *)ptr += delta; } #ifdef CONFIG_X86_64 - while (*--reloc) { - long extended = *reloc; - extended += map; - - ptr = (unsigned long)extended; - if (ptr < min_addr || ptr > max_addr) - error("inverse 32-bit relocation outside of kernel!\n"); - - *(int32_t *)ptr -= delta; - } for (reloc--; *reloc; reloc--) { long extended = *reloc; extended += map; diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 01efbfdd3eb3..7feb63179b62 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -28,7 +28,6 @@ struct relocs { static struct relocs relocs16; static struct relocs relocs32; #if ELF_BITS == 64 -static struct relocs relocs32neg; static struct relocs relocs64; #define FMT PRIu64 #else @@ -84,7 +83,6 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = { "__initramfs_start|" "(jiffies|jiffies_64)|" #if ELF_BITS == 64 - "__per_cpu_load|" "init_per_cpu__.*|" "__end_rodata_hpage_align|" #endif @@ -281,33 +279,6 @@ static const char *sym_name(const char *sym_strtab, Elf_Sym *sym) return name; } -static Elf_Sym *sym_lookup(const char *symname) -{ - int i; - for (i = 0; i < shnum; i++) { - struct section *sec = &secs[i]; - long nsyms; - char *strtab; - Elf_Sym *symtab; - Elf_Sym *sym; - - if (sec->shdr.sh_type != SHT_SYMTAB) - continue; - - nsyms = sec->shdr.sh_size/sizeof(Elf_Sym); - symtab = sec->symtab; - strtab = sec->link->strtab; - - for (sym = symtab; --nsyms >= 0; sym++) { - if (!sym->st_name) - continue; - if (strcmp(symname, strtab + sym->st_name) == 0) - return sym; - } - } - return 0; -} - #if BYTE_ORDER == LITTLE_ENDIAN #define le16_to_cpu(val) (val) #define le32_to_cpu(val) (val) @@ -750,75 +721,8 @@ static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel, } } -/* - * The .data..percpu section is a special case for x86_64 SMP kernels. - * It is used to initialize the actual per_cpu areas and to provide - * definitions for the per_cpu variables that correspond to their offsets - * within the percpu area. Since the values of all of the symbols need - * to be offsets from the start of the per_cpu area the virtual address - * (sh_addr) of .data..percpu is 0 in SMP kernels. - * - * This means that: - * - * Relocations that reference symbols in the per_cpu area do not - * need further relocation (since the value is an offset relative - * to the start of the per_cpu area that does not change). - * - * Relocations that apply to the per_cpu area need to have their - * offset adjusted by by the value of __per_cpu_load to make them - * point to the correct place in the loaded image (because the - * virtual address of .data..percpu is 0). - * - * For non SMP kernels .data..percpu is linked as part of the normal - * kernel data and does not require special treatment. - * - */ -static int per_cpu_shndx = -1; -static Elf_Addr per_cpu_load_addr; - -static void percpu_init(void) -{ - int i; - for (i = 0; i < shnum; i++) { - ElfW(Sym) *sym; - if (strcmp(sec_name(i), ".data..percpu")) - continue; - - if (secs[i].shdr.sh_addr != 0) /* non SMP kernel */ - return; - - sym = sym_lookup("__per_cpu_load"); - if (!sym) - die("can't find __per_cpu_load\n"); - - per_cpu_shndx = i; - per_cpu_load_addr = sym->st_value; - return; - } -} - #if ELF_BITS == 64 -/* - * Check to see if a symbol lies in the .data..percpu section. - * - * The linker incorrectly associates some symbols with the - * .data..percpu section so we also need to check the symbol - * name to make sure that we classify the symbol correctly. - * - * The GNU linker incorrectly associates: - * __init_begin - * __per_cpu_load - * - * The "gold" linker incorrectly associates: - * init_per_cpu__gdt_page - */ -static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) -{ - return 0; -} - - static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, const char *symname) { @@ -829,12 +733,6 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, if (sym->st_shndx == SHN_UNDEF) return 0; - /* - * Adjust the offset if this reloc applies to the percpu section. - */ - if (sec->shdr.sh_info == per_cpu_shndx) - offset += per_cpu_load_addr; - switch (r_type) { case R_X86_64_NONE: /* NONE can be ignored. */ @@ -843,33 +741,21 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, case R_X86_64_PC32: case R_X86_64_PLT32: /* - * PC relative relocations don't need to be adjusted unless - * referencing a percpu symbol. + * PC relative relocations don't need to be adjusted. * * NB: R_X86_64_PLT32 can be treated as R_X86_64_PC32. */ - if (is_percpu_sym(sym, symname)) - add_reloc(&relocs32neg, offset); break; case R_X86_64_PC64: /* * Only used by jump labels */ - if (is_percpu_sym(sym, symname)) - die("Invalid R_X86_64_PC64 relocation against per-CPU symbol %s\n", - symname); break; case R_X86_64_32: case R_X86_64_32S: case R_X86_64_64: - /* - * References to the percpu area don't need to be adjusted. - */ - if (is_percpu_sym(sym, symname)) - break; - if (shn_abs) { /* * Whitelisted absolute symbols do not require @@ -1083,7 +969,6 @@ static void emit_relocs(int as_text, int use_real_mode) /* Order the relocations for more efficient processing */ sort_relocs(&relocs32); #if ELF_BITS == 64 - sort_relocs(&relocs32neg); sort_relocs(&relocs64); #else sort_relocs(&relocs16); @@ -1115,13 +1000,6 @@ static void emit_relocs(int as_text, int use_real_mode) /* Now print each relocation */ for (i = 0; i < relocs64.count; i++) write_reloc(relocs64.offset[i], stdout); - - /* Print a stop */ - write_reloc(0, stdout); - - /* Now print each inverse 32-bit relocation */ - for (i = 0; i < relocs32neg.count; i++) - write_reloc(relocs32neg.offset[i], stdout); #endif /* Print a stop */ @@ -1172,8 +1050,6 @@ void process(FILE *fp, int use_real_mode, int as_text, read_strtabs(fp); read_symtabs(fp); read_relocs(fp); - if (ELF_BITS == 64) - percpu_init(); if (show_absolute_syms) { print_absolute_symbols(); return; From patchwork Mon Oct 23 21:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559372vqx; Mon, 23 Oct 2023 14:18:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRYxx14Uv8kVn0wB6HR0DJUSlbHU1EFvEQoBFjPTJEvy9NmjnKjaiZBtOsQaYFE5skkIoH X-Received: by 2002:a17:90a:19c5:b0:27d:1f9f:a57f with SMTP id 5-20020a17090a19c500b0027d1f9fa57fmr10082811pjj.32.1698095931843; Mon, 23 Oct 2023 14:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095931; cv=none; d=google.com; s=arc-20160816; b=QYmTpZvCKa/Y9r7Gi36ci7hH5FVlBJpSFxQQoQcWC8DoXvV6k7E2DVhR/Lq++sZ4xY Filk4tAU3IkRzvDBQ+bfwuYCAjEtqZxSEpZcy+u1clYTmv0F+jap6FDelQpusv7zWdyW fhZwjbHPRKKAqmd3eGMPVXg8xpetjZ0ivJ8xpWi+4BvE/V9cE/vlPxXyXSykPcEVZcgr PDwDa+Uw7I3whLjJCi5Djf/g+17/+dy7NBHuhrrdzUdN6siM8iGIlsJssd9TuuP4iixq fiBKjW0dBphCPGDk1cc46hrReuGave1TkE1KOHkKln2rOLHiV3x1l5H/8yZcBmrAX6bz sp9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h6iz2ek/tD2gffzEDkFQST98O3SckhijZstJ7BN63Is=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=D6Oc4m2BBrLJ8kmzNShalp1X/1dWLnDEMcAdDZxQtlkV7YYTcmqbe7vQlg1EnKB4Ni cE1w7ZL7CReJ+NJ1DJ+Kins2dZCrx2m9ZvLtLBdY2cWI9eepfOpR/aggMio55/60/XA9 RcepcB8h9WwYky1rTPDqUk8164GBO/mJwJRuDtGmNgi/xHeY/1szOM1l/ImGo4TBdhEG aODgZ+LZh6vjULAjLIpPQTk24o/WqRHjH7jfUSw3L7Q3ePxj2Kf3UDqmrp3CC1alKnyF aaBHSWxj5HX6lcgdw6fBWfY42RGDeYY9zwS3PyRWOjjZSJuuSGyoFKk7K5NQ2tPeM2QJ vGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W6pthclQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id lx12-20020a17090b4b0c00b0027dbf69ec11si7515952pjb.160.2023.10.23.14.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=W6pthclQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 94FEC80A6EC7; Mon, 23 Oct 2023 14:18:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233298AbjJWVSI (ORCPT + 27 others); Mon, 23 Oct 2023 17:18:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232051AbjJWVRv (ORCPT ); Mon, 23 Oct 2023 17:17:51 -0400 Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D32C2110 for ; Mon, 23 Oct 2023 14:17:45 -0700 (PDT) Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-5a7af20c488so38972517b3.1 for ; Mon, 23 Oct 2023 14:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095864; x=1698700664; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=h6iz2ek/tD2gffzEDkFQST98O3SckhijZstJ7BN63Is=; b=W6pthclQay7W24/niWlwnGJlaW+Ae2GitU6YPUonc9cqj+MqITGsluJp38wrKJwRD0 Wxekt4eXiWKj+abcJCW8r99nrU0Eo88rhRnQcHL9HglmHuTjUvRcQ+RltKKVWVweCPPt LIDi8oe3MAb001blfaacovBfGrDNmVF0h4ztumZHHwoi5WG7umOzcbBXxWySPYDQPg54 dA6ahS4IQUX8eo5wiYjKt9SXY0dNKImdfOGuDOPVhJZqOQAaqQOB1kFxV77Opr+PNtQ1 PfKSgLoqzOLavyYCIEvZxgj/6d02RWnby1sf6Q+1jVxoJMbAvr8JPgEGmtgAkbWmClVA kw0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095864; x=1698700664; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=h6iz2ek/tD2gffzEDkFQST98O3SckhijZstJ7BN63Is=; b=MvkQINHzVXRzUtfDtZD/SuMZLrptkbB9+PGC6Pn7MdgVRh2R9N5bCW+ytu2FanzqOJ mVO1dp1rLDqPSkAKuNUvVrGYS4PXfs2j2Xy4+LUbg5Jq73Gt7rLcFsBhllK586wYzyqg Rgj2s5B8QMPHJBII64i8pF3dgWhcssPlW2NTYhKrU7JvHtVlW2uHNr2GAH8rBbizQII2 yRevi89AemdMf0bLdVbVQJF/YWjePrW4eu+2TnHGPGKFCME9I+sKu/m5gayxOvyqrsBN CR1wk4+ETGPF49Vq/0XDYKQQV65WDYvmypliMPZmktT2nPLgeiYuz9aSQTpagbQHFRop L27Q== X-Gm-Message-State: AOJu0Yz3gmKSNYWosHMe3Rrg27me79ywPAtFJW+yr54CDIkx7o5Icnz6 AlppmKBJtq9GOBViy7Q9xlBHOcC5oA== X-Received: by 2002:a0d:db45:0:b0:5a7:ba17:584b with SMTP id d66-20020a0ddb45000000b005a7ba17584bmr11342232ywe.1.1698095864474; Mon, 23 Oct 2023 14:17:44 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:44 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 7/9] x86/percpu/64: Remove INIT_PER_CPU macros Date: Mon, 23 Oct 2023 17:17:28 -0400 Message-ID: <20231023211730.40566-8-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:42 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582639599137675 X-GMAIL-MSGID: 1780582639599137675 The load and link addresses of percpu variables are now the same, so these macros are no longer necessary. Signed-off-by: Brian Gerst --- arch/x86/include/asm/percpu.h | 22 ---------------------- arch/x86/kernel/irq_64.c | 1 - arch/x86/kernel/vmlinux.lds.S | 7 ------- arch/x86/tools/relocs.c | 1 - 4 files changed, 31 deletions(-) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index bbcc1ca737f0..11f50ab32d0e 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -20,12 +20,6 @@ #define PER_CPU_VAR(var) __percpu(var)__percpu_rel -#ifdef CONFIG_X86_64_SMP -#define INIT_PER_CPU_VAR(var) init_per_cpu__##var -#else -#define INIT_PER_CPU_VAR(var) var -#endif - #else /* ...!ASSEMBLY */ #include @@ -96,22 +90,6 @@ #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x -/* - * Initialized pointers to per-cpu variables needed for the boot - * processor need to use these macros to get the proper address - * offset from __per_cpu_load on SMP. - * - * There also must be an entry in vmlinux_64.lds.S - */ -#define DECLARE_INIT_PER_CPU(var) \ - extern typeof(var) init_per_cpu_var(var) - -#ifdef CONFIG_X86_64_SMP -#define init_per_cpu_var(var) init_per_cpu__##var -#else -#define init_per_cpu_var(var) var -#endif - /* For arch-specific code, we can use direct single-insn ops (they * don't give an lvalue though). */ diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c index fe0c859873d1..30424f9876bc 100644 --- a/arch/x86/kernel/irq_64.c +++ b/arch/x86/kernel/irq_64.c @@ -26,7 +26,6 @@ #include DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __visible; -DECLARE_INIT_PER_CPU(irq_stack_backing_store); #ifdef CONFIG_VMAP_STACK /* diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 8d8eb4d9ff9d..089d164164e8 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -481,13 +481,6 @@ SECTIONS "kernel image bigger than KERNEL_IMAGE_SIZE"); #ifdef CONFIG_X86_64 -/* - * Per-cpu symbols which need to be offset from __per_cpu_load - * for the boot processor. - */ -#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) -INIT_PER_CPU(gdt_page); -INIT_PER_CPU(irq_stack_backing_store); #ifdef CONFIG_CPU_UNRET_ENTRY . = ASSERT((retbleed_return_thunk & 0x3f) == 0, "retbleed_return_thunk not cacheline-aligned"); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 7feb63179b62..931d90aa814c 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -83,7 +83,6 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = { "__initramfs_start|" "(jiffies|jiffies_64)|" #if ELF_BITS == 64 - "init_per_cpu__.*|" "__end_rodata_hpage_align|" #endif "__vvar_page|" From patchwork Mon Oct 23 21:17:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559304vqx; Mon, 23 Oct 2023 14:18:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEAg0buGYl9LX/nqGzapNnIlYGQwjmpiQf1B4tpmtvUmCen5h8FI32W6mUlS/uXvovWS/8H X-Received: by 2002:a05:6a00:99e:b0:6be:265:1bf5 with SMTP id u30-20020a056a00099e00b006be02651bf5mr9297025pfg.24.1698095922406; Mon, 23 Oct 2023 14:18:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095922; cv=none; d=google.com; s=arc-20160816; b=pudA+XzFwE9qadtvl9i2icNcwKxEnSE6Z4JjDxkA7UZWL/IkV4fL3I+mnCgYUOPdh+ wi5XWXJsnSOZoJW7lXgQiVuTBTHRS+j4NPFaOGx8wKpzgAe1Mto1jAu0+JsEFpWgFCq8 ZVpbmOC92imd+uepaJhksRlCXe5hGy6Nzn5JF1zYauSzVl7sqbTmO3agJ2GdAPAz0CPX VzBCHMj2LCCj3F8EEQEF1saMj52E5aRx1IrZpRQKERg+v0MDkmR21gbxVjNmwunxKPUX a6Z7ax1gsUcpedKbWXOqhzF/4beTASXad0vBaOCCdE9Su/4n8j7DHeYyMfTnwHgF/1yE 7M6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4b6n2hqqBemYL89ZXVDSUOUI69G9HFJxSx2FZy1kuzU=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=t8Mxaf6cEeTlGMO6jEpY+NMUMdfJ2xHIRXsQqAespyHVTBob+Cv8QWHN+nPJnvjaiA 4SXrPHeVj7STGT7Ui9MwA2wum5oCAVzqr40kDBpmzllBFJXwOoP1PrUQKDMB/9lroGht s14zYehMRmjJcoonU7vosfWHrILCJvU9gISubjMoBgdRmNjB42QzDGWvlEqXVS3Z0/I3 9eTvtAqEYQbvMHVWdebZDUOyqDOyzMqKtSwETUDiU4zLQ45InOtwNOGsLfstiEjc0EyY aa1QYb6IIO3K8BkNS2va5Yaooqa/jP2aFoMvtnGwEex6Vvt826f0sgo/Lq3TDGiJQSQl 4Tbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=giHvaqdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id d14-20020a056a00198e00b006933e8fec67si7322662pfl.227.2023.10.23.14.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=giHvaqdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5664E805EB36; Mon, 23 Oct 2023 14:18:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233316AbjJWVSM (ORCPT + 27 others); Mon, 23 Oct 2023 17:18:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjJWVRx (ORCPT ); Mon, 23 Oct 2023 17:17:53 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D36A510DD for ; Mon, 23 Oct 2023 14:17:46 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5a7afd45199so39490117b3.0 for ; Mon, 23 Oct 2023 14:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095865; x=1698700665; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4b6n2hqqBemYL89ZXVDSUOUI69G9HFJxSx2FZy1kuzU=; b=giHvaqdde3hdtFYvqMzTd/cxO2SQJun+/TVVAOSrBGnOzVvF1JIpaint6Wg4wOd5ux s8W4FvMWaaRGLF/vI9W91sMQh3mkxN7tYodk1Om9tRsNaMJ5Ej/mldahEsKq7hRl+pQT B2Ob1z/IOJAbC0kIbIJsrHy4rFAhd84WL6VpsXe/TUZNqwQPyrrwZAymQxhJEDjSAZZS U7kz1Ox3g5v+Qtx1wOakEOvR2wE2sLIyOAGmgCksooZyb6Xpy/T/F/ZdclDO1PZr/G44 jmXKVe6x4C9GlNhFJkillowng/+7Hka6z+/5bh3gbUzGFK0jbVZtAXgbaWXUrl8CpgHW bxYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095865; x=1698700665; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4b6n2hqqBemYL89ZXVDSUOUI69G9HFJxSx2FZy1kuzU=; b=iNWKNjcp6P0yi1IcXtIWUlBLpCH/N1/DivR4qB0EibSroCweaZRm6cSB4P5eDDmkpB 8TkXhD4vkBleoOlOMAr3qG0WxhBcPRo8TBc5ehrSZ49Il6ZE5AxfbDaKE93cJ1+XmLjt gyKwSSGLYSffQJp6bUwOYNWxnbcMiwIPYxncz5z+cUh6jL/2Taatq1YmtY7DHVePeyLQ /SvqvLkXwTCcPEWRmH7X+Z0rh/jBILxlmg9alMLccURkG57Z7MSz7e56G+bUxSvidbOJ /UNq+58cMDIqHFfgHouw7WA0A8qKe23tFvOw8AUssjehH6Rz8i0kn7ELeOfVp6W691cf VBrA== X-Gm-Message-State: AOJu0YypOw9IeOsNhGKlv7MBXAbP2BCpoN1XCt9IPg3NWWVHF9LhDBg+ VeUOam+h7H1ZaqnPQnwD7GHCbpLIZw== X-Received: by 2002:a81:5216:0:b0:58e:a9d3:bf98 with SMTP id g22-20020a815216000000b0058ea9d3bf98mr11236696ywb.27.1698095865584; Mon, 23 Oct 2023 14:17:45 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:45 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 8/9] percpu: Remove PER_CPU_FIRST_SECTION Date: Mon, 23 Oct 2023 17:17:29 -0400 Message-ID: <20231023211730.40566-9-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582630183717191 X-GMAIL-MSGID: 1780582630183717191 x86-64 was the only user. Signed-off-by: Brian Gerst --- include/asm-generic/vmlinux.lds.h | 1 - include/linux/percpu-defs.h | 12 ------------ 2 files changed, 13 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 67d8dd2f1bde..23d8acc72760 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1032,7 +1032,6 @@ */ #define PERCPU_INPUT(cacheline) \ __per_cpu_start = .; \ - *(.data..percpu..first) \ . = ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . = ALIGN(cacheline); \ diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h index ec3573119923..b9ddee91e6c7 100644 --- a/include/linux/percpu-defs.h +++ b/include/linux/percpu-defs.h @@ -26,13 +26,11 @@ #define PER_CPU_SHARED_ALIGNED_SECTION "..shared_aligned" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" #endif -#define PER_CPU_FIRST_SECTION "..first" #else #define PER_CPU_SHARED_ALIGNED_SECTION "" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" -#define PER_CPU_FIRST_SECTION "" #endif @@ -114,16 +112,6 @@ #define DEFINE_PER_CPU(type, name) \ DEFINE_PER_CPU_SECTION(type, name, "") -/* - * Declaration/definition used for per-CPU variables that must come first in - * the set of variables. - */ -#define DECLARE_PER_CPU_FIRST(type, name) \ - DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) - -#define DEFINE_PER_CPU_FIRST(type, name) \ - DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) - /* * Declaration/definition used for per-CPU variables that must be cacheline * aligned under SMP conditions so that, whilst a particular instance of the From patchwork Mon Oct 23 21:17:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 157120 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1559407vqx; Mon, 23 Oct 2023 14:18:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOPeQErN0cE+QefdV/0SwqMnWSCHtKHB7UcefkePvhwal2Ktr6XFLde44Hm2AEprttITMc X-Received: by 2002:a05:6a21:66c9:b0:14e:3ba7:2933 with SMTP id ze9-20020a056a2166c900b0014e3ba72933mr628371pzb.54.1698095937274; Mon, 23 Oct 2023 14:18:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698095937; cv=none; d=google.com; s=arc-20160816; b=gYhBxVLt/oeavnxD7MqLJzBwyALN2jojZ91LeHYTlBZPCAR1xb+2RKHUb8IjRdmIfq bxiqsTRRDwFC+2uZ+5q4RGZ4Pi7yrofvY5TUxFJNLZgWuaVrR2XRXWr1z7KuUcobFUA/ yqYwL+UsvNYt/stuOmDa5VWQfkK4zMWaA32inE20OIV6aRtyR/YjvIBgjagp5V2TjqVR ODMFVedmP4pa0fSVuakeVjudVZedEm6Q57QKQ8ukUJZFBq35NkTuCdLHwIidMd9zZBZX 5aFWhUlDX7COAtqBoTbo5Z+MDrjaE/P6IvxzQGDJsOkQAwNnSr5JScPX4i8zmU2EE46U 2xmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uEKMOhNXhzYoW+58HZlorWdy0xM6bOeFhfp+J2ei5Pk=; fh=kGpLZLNLRje3BV+NP+TIHFvhQuUJy2o1P7WKpXu8DOs=; b=iduBLeEbFzzBeYBuhL2m6+x1BY0zhG6tjcd7vxPk2Fvelm4HWQpCxWLwrsWVibXZtb vQlHODN37tF3nG18lhKeDing38USrBqeWJABdMCIVpMNUmj09oXIJOKZGfpsiPrxqW5m QBuhTI8Reh1slx17TylQTDQuwx768/XbkVtoUybgQnuk+/oN7IouuWeF45/eWJFYAKrJ fBTtWW4Ooldoa06lCqfvp5SRDo28pbNmPppudQf46bOc14en/ZXSfNDqFAtFVlYnPZrQ rZ6HQWqVpI8I/4fhnCBA5rp2JAUvw6bQAgY6u12FtUZWFlWhCdsoarW+m6Yhk8K8EFF+ 8MNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f5v1bg2w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b005b883b7116fsi6202816pgb.414.2023.10.23.14.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:18:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=f5v1bg2w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 964EA809148E; Mon, 23 Oct 2023 14:18:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232704AbjJWVSX (ORCPT + 27 others); Mon, 23 Oct 2023 17:18:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231817AbjJWVRz (ORCPT ); Mon, 23 Oct 2023 17:17:55 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A09A10EA for ; Mon, 23 Oct 2023 14:17:48 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6ce37d0f1a9so2383979a34.0 for ; Mon, 23 Oct 2023 14:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698095866; x=1698700666; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uEKMOhNXhzYoW+58HZlorWdy0xM6bOeFhfp+J2ei5Pk=; b=f5v1bg2wTB/Kn6LwJpHzy/NrUL+Zta4De4mKhdOcbbckcb+8lm8bU2dzR8P6+D0mnO xfv9hqzglgRqyMOb0aOyUvdJtAJNXDLeib8zwC7uz3090sYsikxgFjXBWHeeigKVlglU q7Cp1oSC7Y7zx/1/mt5yr9r2IK7f+CbNR2g2a/dRdj8FkfxFeeVY021KbGrVO8usZEJP EqYklfSQs+Rt0VuXSUVUmMKUQiZwnFf21N+X7d57KazYF9w5WRx+AT7VEG4uq5VpJoJK 3aNXpt+L2VBzzFK9VkHqVLQupIV9MBgpLjj26o19vHFZqjFOdg6aqX63P5CRs8NM4Ukz y0Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698095866; x=1698700666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uEKMOhNXhzYoW+58HZlorWdy0xM6bOeFhfp+J2ei5Pk=; b=kZx+YPOgQMqkk9qYKCcnqz/cSbfxAE9qacDr/jPXKCv4zI9Cgd8zK/1Ye9wKHOoANF yaJWYNGWPH3G16pa8GrXCiSx6stecJhdcjGmmJYULDswSZsq5qC/zb4LwyOmlPOVqwyf r54z5ZMJf771qaKUnw0mfJxsQ9cCqS/z9H2DaiYQql0jqGHihcENNJjO/kWqIaKZNLcc sBgXcpI+76RTtseSK5NnlAlPEEel2qwMr9KEA29afsdZJj+DjT42mRIn1KLRAfuAxtx4 hYZY0Yfg2G4DTAMc/BOqPqmVTBd7PaEDqXBtjVWeOSYrDU9vS7Bx9Usrtpxrz4lpsaFI i5kA== X-Gm-Message-State: AOJu0YxnbCZBco6XN6vhtQQGM6uW0NUaasa5+NF/tOdAiha1hdYTIAqP GVheL22JTf29JSycvF9kAT8box9vQQ== X-Received: by 2002:a05:6830:2055:b0:6b9:8357:61e6 with SMTP id f21-20020a056830205500b006b9835761e6mr10532584otp.35.1698095866666; Mon, 23 Oct 2023 14:17:46 -0700 (PDT) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id o139-20020a0dcc91000000b00583e52232f1sm3485430ywd.112.2023.10.23.14.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 14:17:46 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Uros Bizjak , Brian Gerst Subject: [PATCH 9/9] kallsyms: Remove KALLSYMS_ABSOLUTE_PERCPU Date: Mon, 23 Oct 2023 17:17:30 -0400 Message-ID: <20231023211730.40566-10-brgerst@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231023211730.40566-1-brgerst@gmail.com> References: <20231023211730.40566-1-brgerst@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 14:18:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780582645611903529 X-GMAIL-MSGID: 1780582645611903529 x86-64 was the only user. Signed-off-by: Brian Gerst --- init/Kconfig | 11 +----- kernel/kallsyms.c | 12 ++----- scripts/kallsyms.c | 80 ++++++++--------------------------------- scripts/link-vmlinux.sh | 4 --- 4 files changed, 18 insertions(+), 89 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 1af31b23e376..4d91c5632aaf 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1715,11 +1715,6 @@ config KALLSYMS_ALL Say N unless you really need all symbols, or kernel live patching. -config KALLSYMS_ABSOLUTE_PERCPU - bool - depends on KALLSYMS - default n - config KALLSYMS_BASE_RELATIVE bool depends on KALLSYMS @@ -1727,11 +1722,7 @@ config KALLSYMS_BASE_RELATIVE help Instead of emitting them as absolute values in the native word size, emit the symbol references in the kallsyms table as 32-bit entries, - each containing a relative value in the range [base, base + U32_MAX] - or, when KALLSYMS_ABSOLUTE_PERCPU is in effect, each containing either - an absolute value in the range [0, S32_MAX] or a relative value in the - range [base, base + S32_MAX], where base is the lowest relative symbol - address encountered in the image. + each containing a relative value in the range [base, base + U32_MAX]. On 64-bit builds, this reduces the size of the address table by 50%, but more importantly, it results in entries whose values are build diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 18edd57b5fe8..f4e8e531052a 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -151,16 +151,8 @@ unsigned long kallsyms_sym_address(int idx) if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE)) return kallsyms_addresses[idx]; - /* values are unsigned offsets if --absolute-percpu is not in effect */ - if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU)) - return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; - - /* ...otherwise, positive offsets are absolute values */ - if (kallsyms_offsets[idx] >= 0) - return kallsyms_offsets[idx]; - - /* ...and negative offsets are relative to kallsyms_relative_base - 1 */ - return kallsyms_relative_base - 1 - kallsyms_offsets[idx]; + /* values are unsigned offsets */ + return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; } static void cleanup_symbol_name(char *s) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 653b92f6d4c8..501f978abf4b 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -5,8 +5,8 @@ * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * - * Usage: kallsyms [--all-symbols] [--absolute-percpu] - * [--base-relative] [--lto-clang] in.map > out.S + * Usage: kallsyms [--all-symbols] [--base-relative] [--lto-clang] + * in.map > out.S * * Table compression uses all the unused char codes on the symbols and * maps these to the most used substrings (tokens). For instance, it might @@ -37,7 +37,6 @@ struct sym_entry { unsigned int len; unsigned int seq; unsigned int start_pos; - unsigned int percpu_absolute; unsigned char sym[]; }; @@ -55,14 +54,9 @@ static struct addr_range text_ranges[] = { #define text_range_text (&text_ranges[0]) #define text_range_inittext (&text_ranges[1]) -static struct addr_range percpu_range = { - "__per_cpu_start", "__per_cpu_end", -1ULL, 0 -}; - static struct sym_entry **table; static unsigned int table_size, table_cnt; static int all_symbols; -static int absolute_percpu; static int base_relative; static int lto_clang; @@ -75,7 +69,7 @@ static unsigned char best_table_len[256]; static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] " + fprintf(stderr, "Usage: kallsyms [--all-symbols] " "[--base-relative] [--lto-clang] in.map > out.S\n"); exit(1); } @@ -167,7 +161,6 @@ static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len) return NULL; check_symbol_range(name, addr, text_ranges, ARRAY_SIZE(text_ranges)); - check_symbol_range(name, addr, &percpu_range, 1); /* include the type field in the symbol name, so that it gets * compressed together */ @@ -183,7 +176,6 @@ static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len) sym->len = len; sym->sym[0] = type; strcpy(sym_name(sym), name); - sym->percpu_absolute = 0; return sym; } @@ -334,11 +326,6 @@ static int expand_symbol(const unsigned char *data, int len, char *result) return total; } -static int symbol_absolute(const struct sym_entry *s) -{ - return s->percpu_absolute; -} - static void cleanup_symbol_name(char *s) { char *p; @@ -499,30 +486,17 @@ static void write_src(void) */ long long offset; - int overflow; - - if (!absolute_percpu) { - offset = table[i]->addr - relative_base; - overflow = (offset < 0 || offset > UINT_MAX); - } else if (symbol_absolute(table[i])) { - offset = table[i]->addr; - overflow = (offset < 0 || offset > INT_MAX); - } else { - offset = relative_base - table[i]->addr - 1; - overflow = (offset < INT_MIN || offset >= 0); - } - if (overflow) { + + offset = table[i]->addr - relative_base; + if (offset < 0 || offset > UINT_MAX) { fprintf(stderr, "kallsyms failure: " - "%s symbol value %#llx out of range in relative mode\n", - symbol_absolute(table[i]) ? "absolute" : "relative", + "symbol value %#llx out of range in relative mode\n", table[i]->addr); exit(EXIT_FAILURE); } printf("\t.long\t%#x /* %s */\n", (int)offset, table[i]->sym); - } else if (!symbol_absolute(table[i])) { - output_address(table[i]->addr); } else { - printf("\tPTR\t%#llx\n", table[i]->addr); + output_address(table[i]->addr); } } printf("\n"); @@ -775,36 +749,15 @@ static void sort_symbols(void) qsort(table, table_cnt, sizeof(table[0]), compare_symbols); } -static void make_percpus_absolute(void) -{ - unsigned int i; - - for (i = 0; i < table_cnt; i++) - if (symbol_in_range(table[i], &percpu_range, 1)) { - /* - * Keep the 'A' override for percpu symbols to - * ensure consistent behavior compared to older - * versions of this tool. - */ - table[i]->sym[0] = 'A'; - table[i]->percpu_absolute = 1; - } -} - -/* find the minimum non-absolute symbol address */ +/* find the minimum symbol address */ static void record_relative_base(void) { - unsigned int i; - - for (i = 0; i < table_cnt; i++) - if (!symbol_absolute(table[i])) { - /* - * The table is sorted by address. - * Take the first non-absolute symbol value. - */ - relative_base = table[i]->addr; - return; - } + /* + * The table is sorted by address. + * Take the first symbol value. + */ + if (table_cnt) + relative_base = table[0]->addr; } int main(int argc, char **argv) @@ -812,7 +765,6 @@ int main(int argc, char **argv) while (1) { static const struct option long_options[] = { {"all-symbols", no_argument, &all_symbols, 1}, - {"absolute-percpu", no_argument, &absolute_percpu, 1}, {"base-relative", no_argument, &base_relative, 1}, {"lto-clang", no_argument, <o_clang, 1}, {}, @@ -831,8 +783,6 @@ int main(int argc, char **argv) read_map(argv[optind]); shrink_table(); - if (absolute_percpu) - make_percpus_absolute(); sort_symbols(); if (base_relative) record_relative_base(); diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index a432b171be82..d25b6d5de45e 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -148,10 +148,6 @@ kallsyms() kallsymopt="${kallsymopt} --all-symbols" fi - if is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU; then - kallsymopt="${kallsymopt} --absolute-percpu" - fi - if is_enabled CONFIG_KALLSYMS_BASE_RELATIVE; then kallsymopt="${kallsymopt} --base-relative" fi