From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C19F01684B0 for ; Thu, 23 Jan 2025 19:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659279; cv=none; b=YsHM8JayaQ4xSyQBuTLYrh9V1lczW0LPkzcFmRJiHiGOtln2MiOoRtojfrvDbYmBQXbdzfCIwRd0fZC/9jnE2+lW/zGX69ueiai4+4xqBHd0W5jhV1CW6xBf1prxiF3SedWrIdAr3FhxNo5ZH0iKangmSQCmPt/u2uMENSA6Fmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659279; c=relaxed/simple; bh=F03TDyzppMXyi9exmVD7P3WpZ99niDCsGj7iVgR0590=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CVo57FLaS+JS10VMaiKNRX1O3o0BmMosyiXjp7QCu0Y/fqLNNsX8qudxX0iATqaJkbBBIqfldPLEvZ5B9FbPmbu8c5FTSmTKD0GvpJ5Koy7DfqaDctWJfCMo86SHsO+UwL4aw8wCjCj7eyNZKbK9cLahr6VBd4bXM6ntJwd+rZo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c3X95OC5; arc=none smtp.client-ip=209.85.160.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c3X95OC5" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-467a6781bc8so10764471cf.2 for ; Thu, 23 Jan 2025 11:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659276; x=1738264076; 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=nMzMKzFBtG4AdIKjzJU1cvZe5I82auc3f92U/sZ1KFg=; b=c3X95OC5JPrmb9UnAQcdAk5MsGGNfaSJdtwa8z/dKH4UkflLC3hDxj7Di3d8N0Rn2A EgbzlO4DsH8rWVQMI0iQm/g0gC/HuP42VXWSP4kQAEbmmESD7EkLkXyCWO1rento+VTx IO+MR8rk1ddPA2ghsrAfAgXVKckHymQ+RhW23UvEMr6yy/EbfSEboOEMTPGWotvJix3d gXgjtpYtiXbU3ojKrBklEOtmjNc9fSLTxxgN/5CRVJ93drN5X5gdT+PWGyu8Btq5W9t+ YCSkgfBacX0h27N2cvbpyN3oa+qfbSOzEx4vM8lMl/SHxKxycXnkhESsdP0c6RTgKzqG GE6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659276; x=1738264076; 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=nMzMKzFBtG4AdIKjzJU1cvZe5I82auc3f92U/sZ1KFg=; b=sJogddjhyG5wyuxfyitBz/U9itOjiveXfE2tLB1OQwhxtauCD8tgMFhVzeogylF4or Qbb6qxbpczJMzi4lXlj8HeDybR/dWw1ILQoj1tzzXraEoij8Io7G5eJwt/WwsqauSKxV lRMKVSEA6jP+aLhv1Middwz9d62pMxlN0winR/Eaq/cvBewSa8GthsvCQpFLroXjSGfx YvHC/daoQKqFzxMYb1OiLHNL22WMvU4101VsAxOCFc6AMgteIjy1RhpiXv1Iqf/tdlBm FDOQ+vpjFJvPjm/AXJaSaG8StjzSC68l7L1Cg6FGWPMsjld1EZXbFSRwO/jOntTM7XWB AD/g== X-Gm-Message-State: AOJu0YxuM/GK02DFkSbRXq0pmSKLHKo/vnrnU42dOIVZpKoUU8U4nlV2 aZtQAoa5v7lxYvnUa4zmviN/tIxZYR/lBVXaDUha8pRDfvEXja/vvZku X-Gm-Gg: ASbGncvqdNQ+qachLh1onXteCVuNjQuoBwcsceWULsCvd10FmJ4CSNP9q8mmldA2Sda Vapgh+vZaO47UZH+jKpz5RX8mCwnbtIEVV0XHkQmoliffzmgg/hq1ZXjy2BQQqPe/8+XKu+aStS 8eEKrQsOjGg1xjmvg53YJ1j5P6T2kpUscg2iffMMxadZ2u1AFUhiYQM8xsQd8xetmv6YGlOKRFV Z6+7yg04tr2q2sOu87yDK46SkW4i979/B16qToXVKmZuy/XGqu2foz6AoxlcQ== X-Google-Smtp-Source: AGHT+IFwcIne6DEOURRN0gD5dIQxBtkksOqljpkZH2x3mPsfvhGDSOOQZZUz1vsjuP0x6FEx8ncZdQ== X-Received: by 2002:a05:622a:11c1:b0:466:ac03:a714 with SMTP id d75a77b69052e-46e12c394d5mr385453371cf.36.1737659276302; Thu, 23 Jan 2025 11:07:56 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:07:55 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 01/15] x86: Raise minimum GCC version to 8.1 Date: Thu, 23 Jan 2025 14:07:33 -0500 Message-ID: <20250123190747.745588-2-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Stack protector support on 64-bit currently requires that the percpu section is linked at absolute address 0 because older compilers fixed the location of the canary value relative to the GS segment base. GCC 8.1 introduced options to change where the canary value is located, allowing it to be configured as a standard percpu variable. This has already been done for 32-bit. Doing the same for 64-bit will enable removing the code needed to support zero-based percpu. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- scripts/min-tool-version.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index 91c91201212c..06c4e410ecab 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -19,6 +19,8 @@ binutils) gcc) if [ "$ARCH" =3D parisc64 ]; then echo 12.0.0 + elif [ "$SRCARCH" =3D x86 ]; then + echo 8.1.0 else echo 5.1.0 fi --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4E4819F411 for ; Thu, 23 Jan 2025 19:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659281; cv=none; b=NHgxQwTpACRBhOwJ20lgWwBt4f9ka+UZKwPtwQBvQjNNzBJeP2wG9SOQKeGgyTfQp5qgk5nqQOrSgtOluUZFORhuJ1YqVIcarN0tl3Jq7b0+f4Du1x4SOMqOEL0ic8fkC0vzA7LrNoJP3jJSWex0m/xTuin9dYmWfMOIU6FfSkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659281; c=relaxed/simple; bh=6FrefWtnhT+pcoYN2zTzQW1S4RGvBE46M3lRKrE1ZGM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kLQqAbTcTzwtSIcszn00t32gEMbv/cvLM1wb1A3JDJzsK49eV7KOv5z5pH1dNM2hqtyzXJvFhgja2stft6r2vr3KqV+T6uo7lsetyoucnKUbCjFR2+OIMu4QiYxBoZnLCCpqII8y+ZZZjC1UFxeY0CX0/yhq88TcStxDtRNCLA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Jkp2YgFy; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Jkp2YgFy" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b702c3c021so120886485a.3 for ; Thu, 23 Jan 2025 11:07:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659277; x=1738264077; 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=ZkczgK/MjIL0RoIyDooXI2VvDc+efThUvAqWRsXi4Pk=; b=Jkp2YgFyfXX10dQX2L/nAx1FoMA+S5bhb0R0hQvUDqZwgcv4e9/j4k03C1AGX9Bdl4 qa8Mhyj8c0BrCidLYZ6Wn9kOR4FFqLEhaBGBij9wD47/N1A2f+dzC3zM37kXH8P9DP1h tp3RQi5awet/O3Zjs7IuTqRGlCRbSS4yF38DhR5EUBHXpfq62lA7UymTU7qf931c98Zk v+3AYGiEtdEhZQk/7ttNhVFY5idWaPeFb6Mcldgv5Hg5wGIYqgTZwUanAeCNg4S3E3gH XPWQkiKTzOeuxH0kHeLpjzggO/1epGp52pORXEy6gPM4Voe25RMOJiZyosiqWg0IzJEr aXug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659277; x=1738264077; 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=ZkczgK/MjIL0RoIyDooXI2VvDc+efThUvAqWRsXi4Pk=; b=l6r9f1mslKonlhbozPyyhZVWzgP+75cXgzqlC+KHYY07vWh2y2tFoe5qvoIQIlT4gg b/RsjsStuKFt45dkEQt6iF+3ltI5xraX8ZSe+c9SYG5rcLlRZIRDYnIbsv0bgDYQWGc8 pxza6zC7xhXtJz6VP8h8Kh1M2KM8fTdQ664//L61ZUnnlAbAZVuHBfgQPNUkYRtd3zJ4 nb0CQ6y3h6TI8S2oTKuaArmxrlGynXuO/m30PP6d4+/K9D0I7AdTOeN23RJLiIhPNjgq lR0FwAk6wQwAI9/W/hnnBpWpb4xXFznLuaOEIj+/L4x2FegDaeru152YvlWCzkXtXMI1 7ERw== X-Gm-Message-State: AOJu0YxnTLLJWp0Py5PojzcAsNIuKgEsjCLUq5uMqjHPu9pY78eaeS2H ubMfT+57kG/nQrA7joomC7BNtfK0gSTiN5wDZb/mzT0VS8qEN88877nR X-Gm-Gg: ASbGnctAdY2Hat2+tJNe8sd5EmEZjAT+JcyMTM4osn5kWkjfoR1We0YvLN+UJM0egyi YInXY2ph932pUjRqu/g7hhBtrKwOHs4xPMaNwye7xGHCcGkNj1+SLdppCyHTxzKkktxOzJgvF+I 54RUwFGKEQig5Hmh4UYtY1JquFR479s1TvC79aayB4gtFet66A3nRA76NXL3iALKlabs0ZPahgo F73FVjA3B1gLhkEr4l/2LHLyiySPc+pyO+Q8yGb7I0e4oy+iWMI5VOpJ+HKsw== X-Google-Smtp-Source: AGHT+IGnYNdFd2ZtvPRBAWWcT/qhjpzQeQkYh315R/ne5r/y2f7KFtXtfzS2hbo5ffS3F+2h/xlOTA== X-Received: by 2002:a05:620a:1902:b0:7b1:51df:117f with SMTP id af79cd13be357-7be6325c411mr4721141885a.56.1737659277514; Thu, 23 Jan 2025 11:07:57 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:07:57 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 02/15] x86/stackprotector: Remove stack protector test scripts Date: Thu, 23 Jan 2025 14:07:34 -0500 Message-ID: <20250123190747.745588-3-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With GCC 8.1 now the minimum supported compiler for x86, these scripts are no longer needed. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel Reviewed-by: Uros Bizjak --- arch/x86/Kconfig | 11 +---------- scripts/gcc-x86_32-has-stack-protector.sh | 8 -------- scripts/gcc-x86_64-has-stack-protector.sh | 4 ---- 3 files changed, 1 insertion(+), 22 deletions(-) delete mode 100755 scripts/gcc-x86_32-has-stack-protector.sh delete mode 100755 scripts/gcc-x86_64-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 27c21c9b6a70..bdfc6b078a1e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -283,7 +283,7 @@ config X86 select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK - select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR + select HAVE_STACKPROTECTOR select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL @@ -423,15 +423,6 @@ config PGTABLE_LEVELS default 3 if X86_PAE default 2 =20 -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)) - 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. - menu "Processor type and features" =20 config SMP 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 9459ca4f0f11..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=3D81708 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m32 -O0 -fst= ack-protector -mstack-protector-guard-reg=3Dfs -mstack-protector-guard-symb= ol=3D__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs" 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 f680bb01aeeb..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 -m64 -O0 -mcm= odel=3Dkernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD4691ADC6B for ; Thu, 23 Jan 2025 19:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659282; cv=none; b=jKP+DdQICdpLp4df60B6hVNYJTrAI6idNog+oMfDGON20cW+c8ETLWAtotcQe+7CqPlyb180zkiytwhoBhB/nguKsM3YB4cVIYwTENEzL62n+m3FCEsJpBiWIZTJrDoRqeUbDhAz/Z1PXrVTHCjf7wAPqeKsY6WURamNvPUsmXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659282; c=relaxed/simple; bh=HXT857HI/GT1wv6dwR3xqCnhlhq2CXOVCsqoYL5wf4Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jCTdRrK5OXb07kQf9tMj5m4Tn5xUfLY4hTMfJpXS+rbciEKJU94ghVZWcjKeMsG7LHGgQCZub480pUeo/xWxue+wZ41SyhM+iRZ+HzBRkH4btPO5DAwum/PzXx+lyaeVCaSUn5LOWzBOq9YFrTNXHKiXanCO5GBBz+U5r27ieCw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bdTeKguk; arc=none smtp.client-ip=209.85.160.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bdTeKguk" Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4679ea3b13bso10456891cf.1 for ; Thu, 23 Jan 2025 11:08:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659279; x=1738264079; 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=m1RtC1B+/gGlGEEDGqPPqPWp8BQI75UwQ1lUG58RUBc=; b=bdTeKgukjJER80QPjTk9BDohKPZ8ARii+AlWaTp0eAlfJUGgU9tjf8lk/1KPglWkyz odxzFolwHpoHkfSnNdW7kgZD/lp1H7SUzSdl2MKQQXVWRrqn89hvoyEzhBynqmd0YLre BpG9feQrhH5rKP+nMvGHLIOjr52qzxINl+v7vQF3V5sJ4P5iaaLDdrMz0F6LgSJb5M3j 307Ve8vzkAh3MeJILCITJg8qJarw4fexAcCYTpz7DowT2TfUWjnKQ6yClPZu0hSzAPR1 fhqDtt7nKJSSQ0VY7jpuDzdnDqIxipS77wAlq7bBMVMJc8rgcuAftZSBHv1l3dJz3LeM qzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659279; x=1738264079; 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=m1RtC1B+/gGlGEEDGqPPqPWp8BQI75UwQ1lUG58RUBc=; b=Ti5CP8hYaqtxxPLLgenSU4WVfboRAMo+ew8N84VkMH0wKbiUVN38mYa6HVEUzx5b0s fByLw0VFkkwEcP+VLnGcjcv5UpDkQCDAiAGCFrbsMnJh4b9zltQXZs58VWuSgQ2Xgn1u UUJmGHuF67+uDyiO1smxrRDlHlUZN4jZF9EF+VUbxRqD+F0cSouCOsDKxm3b+kUwRAzt XT9JwaBH+Leelq0ZS09YIOFBLUKu1nqONjGU3FJQKZ7bhsvQHqDfsZkpj7Xv3QyrPRYd XmGOi8JUm7lWXo3LjWagkyYmFBDZCJeeyhY0TJdSL2VtzxhpFbXCOGrbhv9TUZvG/S0z ijow== X-Gm-Message-State: AOJu0YycGm+kSFjQ2Hd5WTO9QdFjaVSq1re+Kct5Qt2JklTndnlL/3BD YvDlvhoJJX582igAHYBzwztJfOWVZDZ0YwEZrCa4f7ApSrBm0ZnhvXMa X-Gm-Gg: ASbGnct4+in4V4IAbhqLBxkcxoO7d+Fm79rw6VpMfnef9WDL3LVBuQYcXajPpOrOZel NS//sLGFY3OCcAFED2YCX8Ghi1rR20klgRadN4VVKhRBYCbCl8SFMBYFv4SFF48hXnqw9l03lx8 ewrH5gHQ2JWkWWAUL2SI3CMb8m7aSHliJw8gkzfnBWhkABoUrTHwFBxLVPUgm+7QspbYC2+uVtA /hrfv5CyjKLWBeMp9fUz/Dmd79hTcg6dXiKak7Wl0aqkrSh6At5NPQb2wey3g== X-Google-Smtp-Source: AGHT+IFhvpRepeLUULUqlybv+mzq0xtoslCVvae9sKgN+0cpRWTMbgR38FboDvZ+v7q0DUPygDFCcg== X-Received: by 2002:a05:622a:1820:b0:466:a824:751c with SMTP id d75a77b69052e-46e12a9cabcmr362676511cf.29.1737659279210; Thu, 23 Jan 2025 11:07:59 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:07:58 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 03/15] x86/boot: Disable stack protector for early boot code Date: Thu, 23 Jan 2025 14:07:35 -0500 Message-ID: <20250123190747.745588-4-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ard Biesheuvel --- arch/x86/kernel/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index b43eb7e384eb..84cfa179802c 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -44,6 +44,8 @@ KCOV_INSTRUMENT_unwind_orc.o :=3D n KCOV_INSTRUMENT_unwind_frame.o :=3D n KCOV_INSTRUMENT_unwind_guess.o :=3D n =20 +CFLAGS_head32.o :=3D -fno-stack-protector +CFLAGS_head64.o :=3D -fno-stack-protector CFLAGS_irq.o :=3D -I $(src)/../include/asm/trace =20 obj-y +=3D head_$(BITS).o --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 151311ADC91 for ; Thu, 23 Jan 2025 19:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659283; cv=none; b=S8phUjJ97K6sqzhjX009hP2Xp8ujFDRFniD742M2ATd9UBPk3muKbo8Fizq3xv7g05J1f2QBbvpsrrcgFx5p9cPhsw0OkfVTBIOC/iwoKAefE//PnrRl4i1/L4YmRTQexq/VYR40MI8WxsIkupVy3v92MgfIXuyowdemBqyJfyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659283; c=relaxed/simple; bh=cQBv+DubnK8rhYrmruSNwyJCE/YWkw6+R6eeO/00Jkk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elyXovijWfedp5Yhg1o6csYoDOah4cD3xcoAAwfbUXlzP/7bHLP1sYLnUIjLoMnUBpxIFrfsQ30MQItB3qegtgMCc8hLBOMc/aRF6KZbRFO3AHN5Ndt5IWV1qX7SJP4ZJqFar6i92FwiCxrJJQBJTvo7RhqTCD8IkTI0maH4SYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=P4p7IUhi; arc=none smtp.client-ip=209.85.160.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="P4p7IUhi" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4679eacf2c5so12647871cf.0 for ; Thu, 23 Jan 2025 11:08:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659280; x=1738264080; 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=J9MELk7wsy87Jt301R7Mtd0voYB2f1eT7xf1zpAQLyw=; b=P4p7IUhixgkDTFaC3l8v9KWc1aHFajRhxEdDxcUhllP+sfea1VEQQ9wa4BLqpo4w+3 UEcwj443nJz1MSZYZDNjz9R1yEiuk47TnkPOse/6prwm3ymXQge8KHBJIcyXSYYamIGj OkST5iuCCA04rYBtjzpstxgs5K+Zh5HZ57cbyIwTYjXqTVqkE+KKh7da9hJwH8+6m5Ep ZSoxRJwzEe4UDT9SoFcshsh6/LLJ4SdnYReUz2eHvzKllxjs9EXnachbhy0ZratPdyZi B1zIY4qpUh3UHVMlTH1nvRLFEDEgHL9df6yDyKWe5/7RFrIfVeITmcao1p1PT/pdcy1t R57A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659280; x=1738264080; 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=J9MELk7wsy87Jt301R7Mtd0voYB2f1eT7xf1zpAQLyw=; b=CodiT+ciY6rhOPfbpevoebrRlTFVYOmjQJGtWvepwjhEu0w4/gF9jbES9m1ivinyfu EVCiCLAKuiJZRY+N0cuLNrIgXaBuymHmaDnrGkWRE/aKJYkzsQMrIswo4qNRh6OiJw0y 0KLBrBfC1vV8Oh7M2ZMJQkLCS65uoTvVd/2jVtwKNWvoEeSBspqq3mg1gXyezNZV+2u1 KxreiEXPnfjypaMBYmmxo3hmZ08hbfqHvUPXwR6aeFFyR6q93ARo2QUcZsu4Y1Q+OlQU cbQhfJObyevjgjUmxh7h3zclrCJJGvlrE9PyzGSnUcVGu2/QTzeH9mSt7+48D0Tsq3ip eOtg== X-Gm-Message-State: AOJu0YxdIbVXl3SLDHc5ysoQdF6SzWS78o1/gFcaSDdfSkQQW9Ndv4Kw Qixt0192r5Y0u/aEVCGCHHN2eqr/lY/Wxovo/hiTeHOo8UvMgpQvgERU X-Gm-Gg: ASbGncsHpYWk1pwFBHiv8UzpJtFf4sYB2EYqN/vg0iBaK9rQZ+3ckYsBLwyaTCNC2xE WrPIkqiVoQhp7evq4K2qYqMiafiJcCt/WsDn3+4XI/Q4kG940wSoTKqaPR6f23SI01wwolyPfCw 9s6tEHkA8Pc6zLKK/RbXOlh8vA8eUmk9w7f2OrntHFoFp2ysC/0IalTIGTzBePjAqu15RTaHESZ rhEfp1a01s5Hj7VTyTUZ4fNXu25jl69QPBcfI3oHreKnaxhioRGUnZEMeMLGw== X-Google-Smtp-Source: AGHT+IHM05YvXVJZ/7AAVqFjmgwahP4I+0fHat8eEkBUgDvsqsWJfobQ6M9QWTFhRlSz6NeSFNlavg== X-Received: by 2002:a05:622a:2d5:b0:467:87df:851a with SMTP id d75a77b69052e-46e12a56380mr398220331cf.12.1737659280532; Thu, 23 Jan 2025 11:08:00 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:07:59 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 04/15] x86/pvh: Use fixed_percpu_data for early boot GSBASE Date: Thu, 23 Jan 2025 14:07:36 -0500 Message-ID: <20250123190747.745588-5-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of having a private area for the stack canary, use fixed_percpu_data for GSBASE like the native kernel. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- arch/x86/platform/pvh/head.S | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 4733a5f467b8..fa0072e0ca43 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -173,10 +173,15 @@ SYM_CODE_START(pvh_start_xen) 1: UNWIND_HINT_END_OF_STACK =20 - /* Set base address in stack canary descriptor. */ - mov $MSR_GS_BASE,%ecx - leal canary(%rip), %eax - xor %edx, %edx + /* + * Set up GSBASE. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ + movl $MSR_GS_BASE,%ecx + leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx + movq %edx, %eax + shrq $32, %rdx wrmsr =20 /* Call xen_prepare_pvh() via the kernel virtual mapping */ @@ -238,8 +243,6 @@ SYM_DATA_START_LOCAL(gdt_start) SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end) =20 .balign 16 -SYM_DATA_LOCAL(canary, .fill 48, 1, 0) - SYM_DATA_START_LOCAL(early_stack) .fill BOOT_STACK_SIZE, 1, 0 SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end) --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 766E215A85E for ; Thu, 23 Jan 2025 19:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659285; cv=none; b=pNJG8n9pPX5Tp4MeAJX8J/DjD2tajO8VvJfna7k0t4iK6GsRwHIzEPOeG2Y1cS7k5XNRQY1GqiJuMAQQrDirO9lrrasriF1wNl1EzXH5gR4LRo/o8ofS/3UbKe4vCSGomgxiylyS87zAO0FEuuN7QgIVq9iUrYR8962+ICW0duM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659285; c=relaxed/simple; bh=5BWj/e9ytZtlPdOQ5xQiGztWQDHjPEWEmXyRghVBn14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e29AFIeRyivQCPZWE8sal9SmmTK2y89kNrW2MfyeyP5U7PSNKx4Y2o2FNDbyK0j4wgE1tgdTtMSq0GuWm15VUwG0M1z8kT1mS6nF5SIvcsEBhf37qT99Sz7CKauNmtXUEFC1zSlz+UbGm4VVrTvd6adrU5gtGqOlOOYMvFnGxro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=N8K3vTnG; arc=none smtp.client-ip=209.85.160.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N8K3vTnG" Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-4678cce3d60so12971611cf.2 for ; Thu, 23 Jan 2025 11:08:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659282; x=1738264082; 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=GSLVKrkq8Z5PhnWZVyHBClujXDE7cZMJq1Yuy9oRGz8=; b=N8K3vTnGECavHdp4qf6iOp8fnTXlR9VcEdUPzfWbCtxat35IuG1CdoDG2NGaPZxg8L 7e8TLi67j7/+ad1mCAgx83WMJ4aZJJRWLd5QelTgTjJHR5Uz+WshoxqMFarfYIPDMq6h oSrDY5fcywsjL+4biyjx2GTJXTiFE5oc0Bs7/qhNtFN8sPqg5OgPc9Y53Ftvpb0hmCM4 XkoyF8HxBlKSzcnH0MRczAn5qZDGH0miqFEcGy9mbI2+PCUxO4YfStESpM9nj76ZSgWj I7lGdUxek5h57HMz44SxRd2vVGucBHThLFaxT/PiR7lt/XT6r6EQ4Z9xOovjOV+mkv0s bmdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659282; x=1738264082; 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=GSLVKrkq8Z5PhnWZVyHBClujXDE7cZMJq1Yuy9oRGz8=; b=nKf8KLidYSasT+fAcK3NtIDLSoj370xZ04FhTwxCtROqOUnI7NdgEN6WX1CL3cGheJ PUUqKjv2CoQ0yoc+eD4yIM2hKGMvYg36PMR42jvs5xvjCV7k5M0OTGSw4auzLsYWHx92 Te0kDz2znS/a95SvQLEDeJgE3ddSsVCY5xp+lvg+TV/t3em6a5x1ZheDwtC8t4bEjjlj ohXXkAb3Lwum0Lt/NnSQrohag4QxWnxlSrykNAYrqXzVnTieJvzIrfC9GkeYEgVstfF7 ScdyIaHa7n2HoHW78y+rKRq7riZ8M7KzpymM/5fcMmEnO/On2+WQVbnVcAPD0uj0NU8q 3ATA== X-Gm-Message-State: AOJu0Yyu5oXCAogpSM5GCc8oDKqOaPmzQgc/faE5yGFhE33zkaHENgla lzpbB9G+HMRipm4YvhJFIzkhSZP1pVnpG7iuFxNk4rLmmJVaM/9VK3Kp X-Gm-Gg: ASbGncuAKLGfG++tJJC1uaHUArVl0JovlyjrjZUGiqYeNOE6qCLmX27f+e6M708ZL5l EK4kLwCeoH5PsNMdSMpEM8O7iFzdPQ/kOiEosxoKphOruW51Aegr/DkYK81j29k6epLptMF3SXn I1LasN/kAmD8eV+RZ5BKvzG+XftXolwmJwKu0dRGEL7/VTv/7rSBmhAJ3uCcPTLpAsK8UroaegN mLRBcN3n6pOETlbWqN3a4VNhYjNsdixakIxTOSTkEXpo7XKZV2uFxpZteOFlg== X-Google-Smtp-Source: AGHT+IFFhkoIMRRgUsKoMOouWKjZ4y4A5hwSuWg/lqLqjE2C9HQFfz0vQ2HJfR4f8T9rFB8YfpyEYw== X-Received: by 2002:a05:622a:1922:b0:46c:7150:be3c with SMTP id d75a77b69052e-46e12a1fa2cmr437799021cf.2.1737659282087; Thu, 23 Jan 2025 11:08:02 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:01 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 05/15] x86/relocs: Handle R_X86_64_REX_GOTPCRELX relocations Date: Thu, 23 Jan 2025 14:07:37 -0500 Message-ID: <20250123190747.745588-6-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clang may produce R_X86_64_REX_GOTPCRELX relocations when redefining the stack protector location. Treat them as another type of PC-relative relocation. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- arch/x86/tools/relocs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index e937be979ec8..33dffc5c30b5 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -32,6 +32,11 @@ static struct relocs relocs32; static struct relocs relocs32neg; static struct relocs relocs64; # define FMT PRIu64 + +#ifndef R_X86_64_REX_GOTPCRELX +#define R_X86_64_REX_GOTPCRELX 42 +#endif + #else # define FMT PRIu32 #endif @@ -227,6 +232,7 @@ static const char *rel_type(unsigned type) REL_TYPE(R_X86_64_PC16), REL_TYPE(R_X86_64_8), REL_TYPE(R_X86_64_PC8), + REL_TYPE(R_X86_64_REX_GOTPCRELX), #else REL_TYPE(R_386_NONE), REL_TYPE(R_386_32), @@ -861,6 +867,7 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel= , ElfW(Sym) *sym, =20 case R_X86_64_PC32: case R_X86_64_PLT32: + case R_X86_64_REX_GOTPCRELX: /* * PC relative relocations don't need to be adjusted unless * referencing a percpu symbol. --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED3F3186E20 for ; Thu, 23 Jan 2025 19:08:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659286; cv=none; b=aDhTok5lL0R5MsNXGbvfqjrCvmUV+fsqjszN/DvikK55r1H83GRgCQ3iAkHIKFExjgstVYaqnKAgpsoBtewEadASfCw3InuNEjDtYg0hnwZH8A+AskogznW5piYfX2dUCib/zxEEYQ6XDZN7xCeEHR08Dv2B0G+LpuE6cxU2OOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659286; c=relaxed/simple; bh=cQTQCq7MFpFfimJvMJ3YRR3Q9T50HKqHoKlOrQqBDns=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=azIbgLFoXmHwBoXrjVFRSTdAga8GLA2fsBJR6MKOz5eB3CNiF/id9YknTsjhrQMEJ7p1srXhpPKff6lg6KeRKdzMUCXDAu5d9xisU7Y1jU9UdhzLh2YtCMHvsrtpn8v/+SHgxZnzSIkSwIZno4rOADZbQXUTLKSwkJ9HbKQ0YyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EU1Lwxl0; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EU1Lwxl0" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-467b74a1754so16367491cf.1 for ; Thu, 23 Jan 2025 11:08:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659283; x=1738264083; 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=SKMeShTr5yIEEuySQxpHmJWUqDYpyI8ElDfHkF9VXP0=; b=EU1Lwxl0emL2R20MV0EXbJOsFaJYMW9s0ofqf1gnseQVKNC4VWo7196Iyu4jZ0RCMx GgdwksBSgDhRq7pnicswOGUGX+2ULQK4vSpDk6mtzh9kg9Jq9ha0Z/rco5v7s9wxOHtT 1KorNET8zjn9KYei0hcDS+F5eyy7rrGnXGYDUYV/Mx0lgRp9eerwpT8K8oZZfA+Mtt0s wo6UqB8vBkdGJQcppk0TnI/64MjdefP434nXc5yWFeVVxGun3nqacM0H/2gM1+oDYj1F gI6dWsRon4DJILeOX3zafJyshD4uOF6e7BPmJKqvLG/DQBJb6JqVd8YSsRJj46n0AqeI SUTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659283; x=1738264083; 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=SKMeShTr5yIEEuySQxpHmJWUqDYpyI8ElDfHkF9VXP0=; b=bXTN8ny0m0XsLqbDd9dbVDVD1oIJBSB7wswT4a0V4jKthZesmOl5zOwg5bHJc+KE0u 0OY6bUwl0fwz5SBW4dZ4P15ZuygF3WYWJ59YF3SB6Lv4gVodN6y5SHBYURhfTOI/sJck 7goj3iKYhI65myG2kvQ9piAjJ+u8VVFVTxnbCyY+RgIM9MkPaMwNYpen17z6o3ClP3IH fBfl1dtAQmKfgPTkLSMgNcIPK6/kilqjZcd4CKsi9/sVzqjDEgoT8sAd0y3Jm+70wJLt aSNAaUoGyTxqtmc8UpHskoHSIefqzYZpZ3Cob2uxZpMXxYFRp/m73mtixbmCPnh89b0T Fj3w== X-Gm-Message-State: AOJu0YyqIrpML7gV3BN/mc+ie2QvS4eFUDHri8vi50X1Vjlu8uiedqT6 g5Zeb2uPQPdQo9whEMdZycbRtuVPu6kE5PUIR59olt/Urpr6uQzcw8a7 X-Gm-Gg: ASbGnctQGSRrNbDHZyFptzGwQlxtdyPOpI0OGtK8lY5v4yqqTqLpal2+NwwoLssmiuC NLpk4JrsZoThvGea0frlIB1YSXziT0BRZLWhPMgNNXzO+p0bQAHxkh3ZoYCso1ZciCm2a1Y5VMR iRtSUeqKBmpts73lW6ilkjaQM0K8/kGJgRX3Dicnx//+dLMbpKbHJWtMCv+HigOl7InUSln3hiG P2ll0OzYJGjNIzLv04ue5YI2s2IQbZnCpFOVD7AT+gpRu05hoJtIvWMHw4k7+e9ScEEN64o X-Google-Smtp-Source: AGHT+IFLCrefgg9t4xDY8CHyjjdoACC5ycJAWAmgLmeRxdIBQ4JyG0jnrRwnW8YerNVxGCFZT+GtmA== X-Received: by 2002:a05:622a:38b:b0:46c:7646:4a1e with SMTP id d75a77b69052e-46e12a62966mr445586521cf.13.1737659283425; Thu, 23 Jan 2025 11:08:03 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:02 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 06/15] x86/module: Deal with GOT based stack cookie load on Clang < 17 Date: Thu, 23 Jan 2025 14:07:38 -0500 Message-ID: <20250123190747.745588-7-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Clang versions before 17 will not honour -fdirect-access-external-data for the load of the stack cookie emitted into each function's prologue and epilogue. This is not an issue for the core kernel, as the linker will relax these loads into LEA instructions that take the address of __stack_chk_guard directly. For modules, however, we need to work around this, by dealing with R_X86_64_REX_GOTPCRELX relocations that refer to __stack_chk_guard. In this case, given that this is a GOT load, the reference should not refer to __stack_chk_guard directly, but to a memory location that holds its address. So take the address of __stack_chk_guard into a static variable, and fix up the relocations to refer to that. Signed-off-by: Ard Biesheuvel Signed-off-by: Brian Gerst --- arch/x86/include/asm/elf.h | 3 ++- arch/x86/kernel/module.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 1fb83d47711f..0d6ca771549d 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -55,7 +55,8 @@ typedef struct user_i387_struct elf_fpregset_t; #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define R_X86_64_RELATIVE 8 /* Adjust by program base */ #define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative - offset to GOT */ +#define R_X86_64_GOTPCRELX 41 offset to GOT */ +#define R_X86_64_REX_GOTPCRELX 42 #define R_X86_64_32 10 /* Direct 32 bit zero extended */ #define R_X86_64_32S 11 /* Direct 32 bit sign extended */ #define R_X86_64_16 12 /* Direct 16 bit zero extended */ diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 8984abd91c00..a286f32c5503 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -130,6 +131,20 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, goto overflow; size =3D 4; break; +#if defined(CONFIG_STACKPROTECTOR) && \ + defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000 + case R_X86_64_REX_GOTPCRELX: { + static unsigned long __percpu *const addr =3D &__stack_chk_guard; + + if (sym->st_value !=3D (u64)addr) { + pr_err("%s: Unsupported GOTPCREL relocation\n", me->name); + return -ENOEXEC; + } + + val =3D (u64)&addr + rel[i].r_addend; + fallthrough; + } +#endif case R_X86_64_PC32: case R_X86_64_PLT32: val -=3D (u64)loc; --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3696C20CCCF for ; Thu, 23 Jan 2025 19:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659289; cv=none; b=Iugh4kSWA8eJGQNmh4d5SS0b+x0Li0hF4LsitvnQj/X291FVsAIFlYHw+L+CKmWShA9qJ4H8wJa5FskEp89xRHsnHGzwb110gi0GvDna1gNHCeCnKWuB2rXMgxM1fRJa4j2UwcNOo+pItnxxxGEfrDG2VEg8bUVGPQORAgxHp4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659289; c=relaxed/simple; bh=1iuccXO6FFsp5UwzDf43h54JAyW3RNqTAAUFOfKKvcw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fTAQ/NW0WxQx+/BJO/xV2O00+8MYFe08fw2pLhNpw31mGlzdsDJF8mstj3RLZRduCWVmIqBdW+NJ5/hVaYFjSdC9mbXXFegaMxH6sPa0ZENxdxUDQycecIjIjsBcSSyKE28S6LBEDQJ5WXfVaL8tq9bbMH/vin2iRb8l5E37Hao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=B7QmJd5M; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="B7QmJd5M" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-4678afeb133so21730611cf.0 for ; Thu, 23 Jan 2025 11:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659286; x=1738264086; 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=wBNgO0CHxquZoEGCsy2nYv6ostqVYQH8nnC57bRQXgY=; b=B7QmJd5MBVhGjbkGjKKHtBbTJjLOSpCqAh1+aj8qGL+cBG6XL7lfzWY11wSdnoXwe1 tONwnte74vjceMgONDTZs80kkFTYEglSN1EqbgJmHihspbgWguf1RvlBah6kwqDo0VNR cKfO8xwKKl6SONYaiQkBdDNuV9hTCnJkJblmQSAkRR7krF++J6F861/tW6tB92NMTVsW /PWtLkeueoFH/erzIVRPzS28PoNJuG4o6oQBtzTUC++2WpRWGrQDAchUfRXVwTTWAw0p iThmDuUFeUXqVGRs0KiBuL6ls6jKJ8yHxTZpX+6x42fxIK43xhLtNABa26fc5+hecY1u nqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659286; x=1738264086; 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=wBNgO0CHxquZoEGCsy2nYv6ostqVYQH8nnC57bRQXgY=; b=cUWxhGGUYd/NvDsx69HcWxKJ3+WevsfbBAcJwaTnEJdktq7AalPoVI1C8Ii66Ej1Rv XCFmqDFTRJJNtzW7eZSjKe3e2CLeFuVr94f7vTTnYu/W3ZRMBu7kfyVp9hLzV3cNMxx/ VtscgfjtR6XZvDVMqHHAj6ghV2YQ89F4PdjU7um3Wxd8jQxigTI8zHHu059lH6txbiEF VjinIdAuPeD/eAJk7yyqa64bH7RDhlEPf+jwSrNY0H3M6J8BNP24OMAA0825Ahue6D0T UjOxxW1oi6/rAeJV8gemPSfc6RdaTDQ40/QrVXqGJmkI8nJt/JCezCaw6xDk05UUPkoq BNWw== X-Gm-Message-State: AOJu0YyO9IbUhePVsSBiETzURXiGBaxuoYEzzyh2GjueFRSFeky/D63b V+/67/kBk1s90ATFE/5zHy+iAwqwR8XWg+VS1WCgGeE+r+VR2V36ZUda X-Gm-Gg: ASbGncsE8M6F18A8Nm2bxLwwhJuvr69TyMWzO//Q4BO2LRVelj0C2f8kSahpIo/TvxU QvE5YNlcoTEPHWAjIgVnUng5isIsz7uIU7ie36oAPC2FqnlFk5vJFAnapRq28u45mslLhV65hdJ oK8f5EChjpmGfVxO/4Q9PHra0WpBj147M82/Xjy85q/KRGpCb5A6diFfyA6KPZSiAEneHeCJuYD RJ7IBOYb7aPatCB3MJ6LrvxN8Vb1+gDiHaIz95NjWJAJXO42HMXCDwG6WOgqg== X-Google-Smtp-Source: AGHT+IE8y+PV+Eu7SO4RBrM4Vl2/zvHyiry1OucZ40KcGU33ofoFIhLkhCfWwX/yVbIqrl8deY0/2w== X-Received: by 2002:a05:622a:91:b0:46c:7737:c509 with SMTP id d75a77b69052e-46e5b760c32mr57490331cf.4.1737659285622; Thu, 23 Jan 2025 11:08:05 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:04 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 07/15] x86/stackprotector/64: Convert to normal percpu variable Date: Thu, 23 Jan 2025 14:07:39 -0500 Message-ID: <20250123190747.745588-8-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 absolute 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. GCC 8.1 supports redefining where the canary is located, allowng it to become a normal percpu variable instead of at a fixed location. This removes the contraint that the percpu section must be zero-based. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel Reviewed-by: Uros Bizjak --- arch/x86/Makefile | 20 +++++++++------ arch/x86/entry/entry.S | 2 -- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/processor.h | 16 ++---------- arch/x86/include/asm/stackprotector.h | 36 ++++----------------------- arch/x86/kernel/asm-offsets_64.c | 6 ----- arch/x86/kernel/cpu/common.c | 5 +--- arch/x86/kernel/head_64.S | 3 +-- arch/x86/xen/xen-head.S | 3 +-- 9 files changed, 23 insertions(+), 70 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5b773b34768d..88a1705366f9 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -140,14 +140,7 @@ ifeq ($(CONFIG_X86_32),y) # temporary until string.h is fixed KBUILD_CFLAGS +=3D -ffreestanding =20 - ifeq ($(CONFIG_STACKPROTECTOR),y) - ifeq ($(CONFIG_SMP),y) - KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3Dfs \ - -mstack-protector-guard-symbol=3D__ref_stack_= chk_guard - else - KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal - endif - endif + percpu_seg :=3D fs else BITS :=3D 64 UTS_MACHINE :=3D x86_64 @@ -197,6 +190,17 @@ else KBUILD_CFLAGS +=3D -mcmodel=3Dkernel KBUILD_RUSTFLAGS +=3D -Cno-redzone=3Dy KBUILD_RUSTFLAGS +=3D -Ccode-model=3Dkernel + + percpu_seg :=3D gs +endif + +ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3D$(percpu_seg) + KBUILD_CFLAGS +=3D -mstack-protector-guard-symbol=3D__ref_stack_chk_guard + else + KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal + endif endif =20 # diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S index b7ea3e8e9ecc..fe5344a249a1 100644 --- a/arch/x86/entry/entry.S +++ b/arch/x86/entry/entry.S @@ -52,7 +52,6 @@ EXPORT_SYMBOL_GPL(mds_verw_sel); =20 THUNK warn_thunk_thunk, __warn_thunk =20 -#ifndef CONFIG_X86_64 /* * Clang's implementation of TLS stack cookies requires the variable in * question to be a TLS variable. If the variable happens to be defined as= an @@ -66,4 +65,3 @@ THUNK warn_thunk_thunk, __warn_thunk #ifdef CONFIG_STACKPROTECTOR EXPORT_SYMBOL(__ref_stack_chk_guard); #endif -#endif diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index f52dbe0ad93c..33a955aa01d8 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -192,7 +192,7 @@ SYM_FUNC_START(__switch_to_asm) =20 #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 =20 /* diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index c0cd10182e90..a4687122951f 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -422,16 +422,8 @@ struct irq_stack { =20 #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=3D - * support for x86_64 stackprotector, we can get rid of this. - */ char gs_base[40]; - unsigned long stack_canary; + unsigned long reserved; }; =20 DECLARE_PER_CPU_FIRST(struct fixed_percpu_data, fixed_percpu_data) __visib= le; @@ -446,11 +438,7 @@ extern asmlinkage void entry_SYSCALL32_ignore(void); =20 /* 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 */ =20 struct perf_event; =20 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/s= tackprotector.h index 00473a650f51..d43fb589fcf6 100644 --- a/arch/x86/include/asm/stackprotector.h +++ b/arch/x86/include/asm/stackprotector.h @@ -2,26 +2,10 @@ /* * 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. - * - * 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 =3D=3D 0, we are li= kely - * 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 stackprotec= tor - * support, we can remove some of this complexity. + * returning from the function. The pattern is called the stack canary + * and is a unique value for each task. */ =20 #ifndef _ASM_STACKPROTECTOR_H @@ -36,6 +20,8 @@ =20 #include =20 +DECLARE_PER_CPU(unsigned long, __stack_chk_guard); + /* * Initialize the stackprotector canary value. * @@ -51,25 +37,13 @@ static __always_inline void boot_init_stack_canary(void) { unsigned long canary =3D get_random_canary(); =20 -#ifdef CONFIG_X86_64 - BUILD_BUG_ON(offsetof(struct fixed_percpu_data, stack_canary) !=3D 40); -#endif - current->stack_canary =3D canary; -#ifdef CONFIG_X86_64 - this_cpu_write(fixed_percpu_data.stack_canary, canary); -#else this_cpu_write(__stack_chk_guard, canary); -#endif } =20 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) =3D idle->stack_canary; -#else per_cpu(__stack_chk_guard, cpu) =3D idle->stack_canary; -#endif } =20 #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 =20 - 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 7cce91b19fb2..b71178f0ed6c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2089,8 +2089,7 @@ void syscall_init(void) if (!cpu_feature_enabled(X86_FEATURE_FRED)) idt_syscall_init(); } - -#else /* CONFIG_X86_64 */ +#endif /* CONFIG_X86_64 */ =20 #ifdef CONFIG_STACKPROTECTOR DEFINE_PER_CPU(unsigned long, __stack_chk_guard); @@ -2099,8 +2098,6 @@ EXPORT_PER_CPU_SYMBOL(__stack_chk_guard); #endif #endif =20 -#endif /* CONFIG_X86_64 */ - /* * Clear all 6 debug registers: */ diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 31345e0ba006..c3d73c04603f 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -361,8 +361,7 @@ SYM_INNER_LABEL(common_startup_64, SYM_L_LOCAL) =20 /* 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. + * The base of %gs always points to fixed_percpu_data. * Note that, on SMP, the boot cpu uses init data section until * the per cpu areas are set up. */ diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S index 9252652afe59..5d3866ec3100 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -33,8 +33,7 @@ SYM_CODE_START(startup_xen) =20 /* 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. + * The base of %gs always points to fixed_percpu_data. * Note that, on SMP, the boot cpu uses init data section until * the per cpu areas are set up. */ --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 354AA211A19 for ; Thu, 23 Jan 2025 19:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659291; cv=none; b=U0pWhCpuuRiok/nUF5RJQ6oZIp9jnxxNsum7oeo1LJYxQdmdu9vf8WbWeCNZmf/vmNn8Z1ANCh0lN+LqFmTpiIeFPQt6A1KcH23YGhyUrvUx/BC+7qCiULuGW/THRTqU2BwTA1WYpd92gOwW1t16PuxmAbkEzlPMPUHdxfjowA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659291; c=relaxed/simple; bh=9NSrYHdVuTU1FKGbLZpdrRs3Dpy4QKqxLyKMal29PNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jY+hV1XNCYv8SVerM5W9HGaJtJKVJ0JVCi7xdJrS7GbOmbowQmcb3FBPmIs9ZH21YY6oKnT1FsT3ejkHt0dVvni9ZwA3ycKKFG2ER7MoxUtJJzfbkBKAV5EdpXC6Nn52HA84mz0ELNzD997IDHV+kak58nQ2AKdhSe3kwlfRL64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jGJGkXMD; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jGJGkXMD" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-467a63f5d1cso11850381cf.0 for ; Thu, 23 Jan 2025 11:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659287; x=1738264087; 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=ZxY+mat0ucNinf9zmPQDA/BTk1kUqVZNmJUpITMUkVI=; b=jGJGkXMD4QUMujSpIYB77mhvfTmIm0MctUvtzebYirEhnZpKiZw4gR8CvnJfRbTAVW M0DD+pnDD+wS/FkA2c3jf3jKBVsS+FC6dJtELVWTefZu5rP4gfH7asFt75cEoPc3rxOj PVTxoWKdRJVHEu6tKZZXcLud596rqc0tXcC6F82NS/mE+FZY72uz1GAa/nF7k8x9n29H gxnlLlbDfSplegEpldhhSENgUdLqaZC50jaeojjAqyhbqv13RfwyavDt0rgnbNrALdl4 dhm8B7By4WG24e8v0INxuSLdHMKTlnuSqmdDUqhdluZlParr8TxdVD2eMBdB1LDsd+QR xWQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659287; x=1738264087; 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=ZxY+mat0ucNinf9zmPQDA/BTk1kUqVZNmJUpITMUkVI=; b=LYZDnzLsl+0gIiWFDdrgnesm00nTvx8XCNmEaHDLo5kkWh/Ge7GsJSBzWqduCSR5sI nnPy9jvolpCCpMRE5qyRZIVvNKAp0lsd4vq7qvk6ZXP2AccaQsjm0rReL2PbyfVwJZSo y6FN0SA1wABbuey3EQfyO6NcHt7bcU8pLNf2jfC/+53wLfMrfAWGXmGZ2xFe0iYSgCPr cm0lV+c4jLVD4PrKcQR3Nw5cC4BK6pO9Wm4i2S01dsv0Poc6PbfS10H/GWsvP/kU+jBA ku//oRDEz2N4WIkDVBzc5TbxB8TKAA8sZIgil8mV5Rsaw4iE1x6CuXUGrW16Nf3Ogl2c CEbg== X-Gm-Message-State: AOJu0Yydkfy8wnjq3JwupYh/26oX428ThN811189yeVReFe8y0oFDUsK N1AyKrIhXsn9TkGi3KT/Npsfnj1msS7nF33rWJBWNEacOI4OVr8V+bSE X-Gm-Gg: ASbGncui2gCPjK+rdhh9xozrj3aLBtTdxSyObJIh8ZUVYEdQW4tDJ5HsHMgeWDYTzsf d6gQYrCZzqklzRQJ423s4X24BKYtHUzmyIgJ3ITOTRNKEd07i50wFZcTOHaU2sm1Xtj6FpRLaDa IXIDcPLGcGtxs3JZZdPZSRGw3r1bsRzJ2ijqI8CwdbTlDu2Uwe0BniWOAbUMWD6okNIqpkmMtZq 1yl7R92piom48jOjYPQC1bZbzM63CPI2TY3DPkuURK8HYnzT2gAzfdbuAUvqA== X-Google-Smtp-Source: AGHT+IHnkKshIjuDt/k3CVvBIf1/nTyGghd8Muti3LX4dEZWe78PQIme0BT1ggfO3ryivbHKzfOavQ== X-Received: by 2002:a05:622a:5cc:b0:466:93e2:8ba5 with SMTP id d75a77b69052e-46e12ad5ed7mr354668271cf.5.1737659287106; Thu, 23 Jan 2025 11:08:07 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:06 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 08/15] x86/percpu/64: Use relative percpu offsets Date: Thu, 23 Jan 2025 14:07:40 -0500 Message-ID: <20250123190747.745588-9-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The percpu section is currently linked at absolute 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 does not need to be linked at a specific address. x86-64 will now calculate the percpu offsets as the delta between the initial percpu address and the dynamically allocated memory, like other architectures. Note that GSBASE is limited to the canonical address width (48 or 57 bits, sign-extended). As long as the kernel text, modules, and the dynamically allocated percpu memmory are all in the negative address space, the delta will not overflow this limit. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel Reviewed-by: Uros Bizjak --- arch/x86/include/asm/processor.h | 6 +++++- arch/x86/kernel/head_64.S | 19 +++++++++---------- arch/x86/kernel/setup_percpu.c | 12 ++---------- arch/x86/kernel/vmlinux.lds.S | 29 +---------------------------- arch/x86/platform/pvh/head.S | 5 ++--- arch/x86/tools/relocs.c | 10 +++------- arch/x86/xen/xen-head.S | 9 ++++----- init/Kconfig | 2 +- 8 files changed, 27 insertions(+), 65 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index a4687122951f..b8fee88dac3d 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -431,7 +431,11 @@ DECLARE_INIT_PER_CPU(fixed_percpu_data); =20 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 } =20 extern asmlinkage void entry_SYSCALL32_ignore(void); diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index c3d73c04603f..905d8be93220 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -61,11 +61,14 @@ SYM_CODE_START_NOALIGN(startup_64) /* Set up the stack for verify_cpu() */ leaq __top_init_kernel_stack(%rip), %rsp =20 - /* Setup GSBASE to allow stack canary access for C code */ + /* + * Set up GSBASE. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ movl $MSR_GS_BASE, %ecx - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx - movl %edx, %eax - shrq $32, %rdx + xorl %eax, %eax + xorl %edx, %edx wrmsr =20 call startup_64_setup_gdt_idt @@ -359,16 +362,12 @@ SYM_INNER_LABEL(common_startup_64, SYM_L_LOCAL) movl %eax,%fs movl %eax,%gs =20 - /* Set up %gs. - * - * The base of %gs always points to fixed_percpu_data. + /* + * Set up GSBASE. * 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/setup_percpu.c b/arch/x86/kernel/setup_percpu.c index b30d6e180df7..1e7be9409aa2 100644 --- a/arch/x86/kernel/setup_percpu.c +++ b/arch/x86/kernel/setup_percpu.c @@ -23,18 +23,10 @@ #include #include =20 -#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) =3D BOOT_PERCPU_OF= FSET; +DEFINE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off); EXPORT_PER_CPU_SYMBOL(this_cpu_off); =20 -unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init =3D { - [0 ... NR_CPUS-1] =3D BOOT_PERCPU_OFFSET, -}; +unsigned long __per_cpu_offset[NR_CPUS] __ro_after_init; EXPORT_SYMBOL(__per_cpu_offset); =20 /* diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 0deb4887d6e9..8a598515239a 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -112,12 +112,6 @@ ASSERT(__relocate_kernel_end - __relocate_kernel_start= <=3D KEXEC_CONTROL_CODE_MAX 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); /* ___ */ } =20 @@ -216,21 +210,7 @@ SECTIONS __init_begin =3D .; /* paired with __init_end */ } =20 -#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 =20 /* * Section for code used exclusively before alternatives are run. All @@ -347,9 +327,7 @@ SECTIONS EXIT_DATA } =20 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP) PERCPU_SECTION(INTERNODE_CACHE_BYTES) -#endif =20 RUNTIME_CONST_VARIABLES RUNTIME_CONST(ptr, USER_PTR_MAX) @@ -497,16 +475,11 @@ PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); * 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 =3D ABSOLUTE(x) + __per_cpu_load +#define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) INIT_PER_CPU(gdt_page); INIT_PER_CPU(fixed_percpu_data); INIT_PER_CPU(irq_stack_backing_store); =20 -#ifdef CONFIG_SMP -. =3D ASSERT((fixed_percpu_data =3D=3D 0), - "fixed_percpu_data is not at start of per-cpu area"); -#endif - #ifdef CONFIG_MITIGATION_UNRET_ENTRY . =3D ASSERT((retbleed_return_thunk & 0x3f) =3D=3D 0, "retbleed_return_thu= nk not cacheline-aligned"); #endif diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index fa0072e0ca43..84bb46f86421 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -179,9 +179,8 @@ SYM_CODE_START(pvh_start_xen) * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx - movq %edx, %eax - shrq $32, %rdx + xorl %eax, %eax + xorl %edx, %edx wrmsr =20 /* Call xen_prepare_pvh() via the kernel virtual mapping */ diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 33dffc5c30b5..9aebc3b18d73 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -835,12 +835,7 @@ static void percpu_init(void) */ static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) { - int shndx =3D sym_index(sym); - - return (shndx =3D=3D per_cpu_shndx) && - strcmp(symname, "__init_begin") && - strcmp(symname, "__per_cpu_load") && - strncmp(symname, "init_per_cpu_", 13); + return 0; } =20 =20 @@ -1062,7 +1057,8 @@ static int cmp_relocs(const void *va, const void *vb) =20 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); } =20 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 5d3866ec3100..0aed24540212 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -31,15 +31,14 @@ SYM_CODE_START(startup_xen) =20 leaq __top_init_kernel_stack(%rip), %rsp =20 - /* Set up %gs. - * - * The base of %gs always points to fixed_percpu_data. + /* + * Set up GSBASE. * 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 + xorl %eax, %eax + xorl %edx, %edx wrmsr =20 mov %rsi, %rdi diff --git a/init/Kconfig b/init/Kconfig index 7fe82a46e88c..01d36a84cf66 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1873,7 +1873,7 @@ config KALLSYMS_ALL config KALLSYMS_ABSOLUTE_PERCPU bool depends on KALLSYMS - default X86_64 && SMP + default n =20 # end of the "standard kernel features (expert users)" menu =20 --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 111DB19C56C for ; Thu, 23 Jan 2025 19:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659292; cv=none; b=RSWgZ/HcB1q/6gqIFQkXqi8jqI1I6wFbE/A+mTCY7gRazmTSYk0SOvZOXNDKO4mq3U07rpmFZyKgaXQ/e904FL/dTL8GMlQsrJAv3YjIgVe3qWV7QuBDgJvBzlznw1qxCpRK8nqoXBhHDTadMzyxtWOssDqHV5GauthW3lnPk/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659292; c=relaxed/simple; bh=SPCrGEGzRxozPI8il6Nmrrtf0zQjmbOAljNZ+rmcz/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZEyfAyJoXA/nR58hRj30Dg9y9/GwVdPzK6xVwVd0+Q1VGqgyejbsZ4yxdb3YmNlLOQYhA/Cskguymi4yVmWRVNXMCcvLDgW8+QObtA2KGRRd3NwKMu70DZZC6CbYbXR1clDauRPlYNpqT86hk0iKvkX4zpHQgPA5VmjVWkqaffg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IejgW5Nk; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IejgW5Nk" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-4679fc9b5f1so10972631cf.1 for ; Thu, 23 Jan 2025 11:08:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659289; x=1738264089; 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=NSZsdEiUForqBevZb9/vDiQuDr1gktMsWnWsyuKttGk=; b=IejgW5NkUisQJYJRupqCZm96kEBxL43sA7umpAf8R45IuytnAIHGG8rllP8pGAs/+/ 00+4buDYVW7ONhClR+aUCpcRY9YPHNJiY4T0AVWc1KveFg9SjMUxhK/9cMWvj3aYwYPb hxxwUN629hs89CU4GdXGvVBkjISS3P7cJmm23x/gQoFUDclN1yBMnJrGEUDXhSlO+aUd 4z7xHyIiaNjBspN5qhgtYI4fIGBkdsJb3Xb51BrXWuADGrD0ahiyvWZ2Dh3QsFRvlVAY qzHClRtEqP+snjPFyfse0dvY557f77aE/V6EGENxIbLd8u9wS3R2DPBZyl8HRrP+h845 T7JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659289; x=1738264089; 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=NSZsdEiUForqBevZb9/vDiQuDr1gktMsWnWsyuKttGk=; b=NB1wqBCK7LoYoU4fhDOTRObwMF6gVf56as7DOahpVwT1NLNW41vgw4wBd+uZNM9kUm tqzxEam8Z1Zs1E7lrWoduIYuNX9Y5K89c0+kffyf7t5QNIAG7Ae1ou0hFrsplKhvuNu6 E2MqGP1zOhs3O8iIgn82gGYCJ7CZM57KZGZtzGi3YYWM+Ajdubb5NenYEBV1VpkT05y7 DQx91YTzX4idlaMfOeGEXdbdRwBrEXH/hk5K6YlFQUywBIMcDLadZwLdgO1QGbyk5Cdr K+Qc96m7RMRLBjaYapoRCYszcTZMeTGt4okXB5uAAoqL21ngSRsNCWCkCF2SPmTVeJd7 Pbzg== X-Gm-Message-State: AOJu0YzOKA0749AKEcWGxDTNif+YZkKcwRcEBiUR0jD7PPwNe1Gq09t4 RGRPa5tIzmKaLaUeLZWwl8iJONZ0Yev9Bjz5ptvuPCgoxzpt69ga5BVr X-Gm-Gg: ASbGncsqEHmpNkPz+mKLxiiS9c7qZw+PAz+3SKKueI63oXgFitHO0GKKEyj37vEBM5M pG+2Wm0fcBucaj7ar9rmaxdtltkvZTpgzzCHEIQck3qcKjdQT0pGmecms1WY0rFqqNBbqGG9y3I UCAXx7JBTBg3T7S+UIkLheEfCP/6Z006MgkjHbXQeZ1d5Lf0LJKZcHSYNbX7LgNSllwkaSHHFns /0uiXdmnE000KOL9orfKQ6seYwwZIaXqtj75pZJN6CmNaTOpkCuXev61FTMNg== X-Google-Smtp-Source: AGHT+IHPcwD5FZNHF+g9QuRD5LRWxT27kxHYKmlOpZePxcVoDids2ycunCzuQ/iLiGb8OxH6noaTRQ== X-Received: by 2002:ac8:7c47:0:b0:467:45b7:c495 with SMTP id d75a77b69052e-46e12a56246mr347921731cf.15.1737659288924; Thu, 23 Jan 2025 11:08:08 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:07 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 09/15] x86/percpu/64: Remove fixed_percpu_data Date: Thu, 23 Jan 2025 14:07:41 -0500 Message-ID: <20250123190747.745588-10-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ard Biesheuvel Reviewed-by: Uros Bizjak --- arch/x86/include/asm/processor.h | 8 -------- arch/x86/kernel/cpu/common.c | 4 ---- arch/x86/kernel/vmlinux.lds.S | 1 - arch/x86/tools/relocs.c | 1 - 4 files changed, 14 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index b8fee88dac3d..b3d153730f63 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -421,14 +421,6 @@ struct irq_stack { } __aligned(IRQ_STACK_SIZE); =20 #ifdef CONFIG_X86_64 -struct fixed_percpu_data { - char gs_base[40]; - unsigned long reserved; -}; - -DECLARE_PER_CPU_FIRST(struct fixed_percpu_data, fixed_percpu_data) __visib= le; -DECLARE_INIT_PER_CPU(fixed_percpu_data); - static inline unsigned long cpu_kernelmode_gs_base(int cpu) { #ifdef CONFIG_SMP diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b71178f0ed6c..8b49b1338f76 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2023,10 +2023,6 @@ EXPORT_PER_CPU_SYMBOL(pcpu_hot); EXPORT_PER_CPU_SYMBOL(const_pcpu_hot); =20 #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/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 8a598515239a..93c2fa8a7522 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -477,7 +477,6 @@ PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); */ #define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) INIT_PER_CPU(gdt_page); -INIT_PER_CPU(fixed_percpu_data); INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_MITIGATION_UNRET_ENTRY diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 9aebc3b18d73..a9f8bc6aaafc 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -830,7 +830,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) --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14CEA213256 for ; Thu, 23 Jan 2025 19:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659293; cv=none; b=nU/RcRF9Bb1OY/9I94nQoOK2mWgo/Lfbk6n6VwM8BJdPNtbmp7U+rtJhxwTtr19IbDwgheh7c9lLW7/0oqApupKXHNQoSe3HGT0v84x7UpZxhSNxrZOrwH/cVArlcuUrmY+mJwTN8n7JK09e81HT1m8r+TxqEWTw5/u3WYhmYiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659293; c=relaxed/simple; bh=Gq+OxU5lHEJXPCNbbew2RslSYSBer2OYXHWpAiA9Noc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+/aHjPUByIV98tZxj2Og3cYrIwZH2qKue/NVarbNJuGpiKxWd10k1ygTrELYynKE2RkPzTLPv4JaCxBRP/91dKzDYxDv9YXuqvc03aeSZn/TFxo4wNUXYQLzL0kiqApRnJbj6DcQB7NL3w2CAVZ1GRbL+zrAdIUSb21KW1T/Lw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hTFSvvw2; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hTFSvvw2" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-46783d44db0so12130221cf.1 for ; Thu, 23 Jan 2025 11:08:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659291; x=1738264091; 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=hw751hoVX6XVip8VLdBmgMpa4BCHH6Q4+N76uDL0CYE=; b=hTFSvvw2VEiaAg0xNmEYXHcwRev1F4LqF4x0TN69wbZTvGOw1iAJfdapswnrlOEqXs dKeepODuw+8eSV1Bz/xTlT6HL+hyDotFI1lRqy+itno9uiQChFBqwvqE1elY49TVN4wR 1QriW7AKwdGZBmPxzzW4dC0VOLXcy9nYDuzbbnWEkHPry0ULZnV6urBPeDSBY/wc7uup uJN5ASFvTq3l//Lpoplel9GD5pQcnpSPlU9crXXO2sctfJ+2kLMpiuCMK9wfJRvneF6U RWY5uYbteiR/EEXuoZWVGc5lj8V22Jivf3o1bnt/l565IfYZ/v3bliyCfMuUCbhBOKbU Ey0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659291; x=1738264091; 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=hw751hoVX6XVip8VLdBmgMpa4BCHH6Q4+N76uDL0CYE=; b=w1X4IpzNfXzxyQYpVvZI6rEL7mr40pbdpPn8FSrZiulILqAIx1VNZh1J6KXcfGapF/ wmBfUZZN/TdHaDqy0OAIKBFY4IuO2JOyQGLNdLaImCrLe0gNRVvo4x57gcUOFDWQbB3U CHEl8Chc7feABosE+EBBEYc9NPzhA15SE17yrX5c/GvYTDj1mqC1LF5/o2rrQtw00kAJ AjxwWUPhA8qDxbotERzl4CaxpDnwa5XNJkzLwatneaBJ3iS4B+Vq+fEjlyNMDqKRp4nJ 0rWC1/ktJ4WCZjuVNxJNAaTlt1MyITF2dx9Ef7eEb1uIjpRc4cY+FppDBxJa9evPn34/ o24g== X-Gm-Message-State: AOJu0YxoI6py7Tm6f9tt1WvYqVrGnguEHzStUqUPnOoKOvz2Lc0upsa+ ewYEQKU3bpwG8ywGzbDYcDhqVrxprnNGlOjoAEyc6dPH8Y+a0A1/Wx8e X-Gm-Gg: ASbGncs7X7MPX7CT1MoPNA51D8QEu459ezpz8b1zWzeMmzDRQM4Dgh6j3KPlP1ihqPN RkY2B2aEThhnLvNk3yNI0c5fUe2UYA5RTR3JXHZJ9B2pSnOv75WvfRADyMxr9EA4HNLk69Caxgp uLnAUUoqMob/7TFog1amg7JkqO0xJTtQL+1n9U2UqlMLQj5pChM/BzrmcPGwrNATZdyy4v4TpdJ KWjmisRF+zUe8WssIrUF4w5q3zqC1JNT6cB/N/bKUE5LRdfHvNscYWBt5ISRw== X-Google-Smtp-Source: AGHT+IH9m3B25afOR7J4tZTyV3NKmFBPWx1sIp5+PoZGflGWJQt2ucCYStyYV9WAGNCYazHOX9WtjA== X-Received: by 2002:ac8:7d50:0:b0:46c:7276:eda6 with SMTP id d75a77b69052e-46e12a252cemr348287021cf.7.1737659290770; Thu, 23 Jan 2025 11:08:10 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:09 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 10/15] x86/boot/64: Remove inverse relocations Date: Thu, 23 Jan 2025 14:07:42 -0500 Message-ID: <20250123190747.745588-11-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Inverse relocations were needed to offset the effects of relocation for RIP-relative accesses to zero-based percpu data. Now that the percpu section is linked normally as part of the kernel image, they are no longer needed. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- arch/x86/boot/compressed/misc.c | 14 +--- arch/x86/tools/relocs.c | 130 +------------------------------- 2 files changed, 2 insertions(+), 142 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 0d37420cad02..1cdcd4aaf395 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -235,7 +235,7 @@ static void handle_relocations(void *output, unsigned l= ong output_len, =20 /* * 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. @@ -245,8 +245,6 @@ static void handle_relocations(void *output, unsigned l= ong 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 * @@ -263,16 +261,6 @@ static void handle_relocations(void *output, unsigned = long output_len, *(uint32_t *)ptr +=3D delta; } #ifdef CONFIG_X86_64 - while (*--reloc) { - long extended =3D *reloc; - extended +=3D map; - - ptr =3D (unsigned long)extended; - if (ptr < min_addr || ptr > max_addr) - error("inverse 32-bit relocation outside of kernel!\n"); - - *(int32_t *)ptr -=3D delta; - } for (reloc--; *reloc; reloc--) { long extended =3D *reloc; extended +=3D map; diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index a9f8bc6aaafc..9e8d5a62ff50 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -29,7 +29,6 @@ static struct relocs relocs16; static struct relocs relocs32; =20 #if ELF_BITS =3D=3D 64 -static struct relocs relocs32neg; static struct relocs relocs64; # define FMT PRIu64 =20 @@ -91,7 +90,6 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = =3D { "__initramfs_start|" "(jiffies|jiffies_64)|" #if ELF_BITS =3D=3D 64 - "__per_cpu_load|" "init_per_cpu__.*|" "__end_rodata_hpage_align|" #endif @@ -290,34 +288,6 @@ static const char *sym_name(const char *sym_strtab, El= f_Sym *sym) return name; } =20 -static Elf_Sym *sym_lookup(const char *symname) -{ - int i; - - for (i =3D 0; i < shnum; i++) { - struct section *sec =3D &secs[i]; - long nsyms; - char *strtab; - Elf_Sym *symtab; - Elf_Sym *sym; - - if (sec->shdr.sh_type !=3D SHT_SYMTAB) - continue; - - nsyms =3D sec->shdr.sh_size/sizeof(Elf_Sym); - symtab =3D sec->symtab; - strtab =3D sec->link->strtab; - - for (sym =3D symtab; --nsyms >=3D 0; sym++) { - if (!sym->st_name) - continue; - if (strcmp(symname, strtab + sym->st_name) =3D=3D 0) - return sym; - } - } - return 0; -} - #if BYTE_ORDER =3D=3D LITTLE_ENDIAN # define le16_to_cpu(val) (val) # define le32_to_cpu(val) (val) @@ -766,78 +736,8 @@ static void walk_relocs(int (*process)(struct section = *sec, Elf_Rel *rel, } } =20 -/* - * 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 =3D -1; -static Elf_Addr per_cpu_load_addr; - -static void percpu_init(void) -{ - int i; - - for (i =3D 0; i < shnum; i++) { - ElfW(Sym) *sym; - - if (strcmp(sec_name(i), ".data..percpu")) - continue; - - if (secs[i].shdr.sh_addr !=3D 0) /* non SMP kernel */ - return; - - sym =3D sym_lookup("__per_cpu_load"); - if (!sym) - die("can't find __per_cpu_load\n"); - - per_cpu_shndx =3D i; - per_cpu_load_addr =3D sym->st_value; - - return; - } -} - #if ELF_BITS =3D=3D 64 =20 -/* - * 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) { @@ -848,12 +748,6 @@ static int do_reloc64(struct section *sec, Elf_Rel *re= l, ElfW(Sym) *sym, if (sym->st_shndx =3D=3D SHN_UNDEF) return 0; =20 - /* - * Adjust the offset if this reloc applies to the percpu section. - */ - if (sec->shdr.sh_info =3D=3D per_cpu_shndx) - offset +=3D per_cpu_load_addr; - switch (r_type) { case R_X86_64_NONE: /* NONE can be ignored. */ @@ -863,32 +757,21 @@ static int do_reloc64(struct section *sec, Elf_Rel *r= el, ElfW(Sym) *sym, case R_X86_64_PLT32: case R_X86_64_REX_GOTPCRELX: /* - * 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; =20 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", sym= name); break; =20 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 @@ -1101,7 +984,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 =3D=3D 64 - sort_relocs(&relocs32neg); sort_relocs(&relocs64); #else sort_relocs(&relocs16); @@ -1133,13 +1015,6 @@ static void emit_relocs(int as_text, int use_real_mo= de) /* Now print each relocation */ for (i =3D 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 =3D 0; i < relocs32neg.count; i++) - write_reloc(relocs32neg.offset[i], stdout); #endif =20 /* Print a stop */ @@ -1192,9 +1067,6 @@ void process(FILE *fp, int use_real_mode, int as_text, read_symtabs(fp); read_relocs(fp); =20 - if (ELF_BITS =3D=3D 64) - percpu_init(); - if (show_absolute_syms) { print_absolute_symbols(); return; --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09FFA2139B6 for ; Thu, 23 Jan 2025 19:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659295; cv=none; b=MIUiTEN3CREbihAEcdN5Fcvag62g8x2JpZaz80PbvUgPzPaiNLeox7lDA9P0oqHCjB459CgXRy8DcS6V+SmoySNj1+estkut26/q97fv8TyVtunIY5lMZgaBT7yaP5nPc77O23/apkAoivUl4Gjy9cPOnBDrvPDLZcG+RLgt3bY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659295; c=relaxed/simple; bh=GqqiKN9ry7OW7W1QQdszws3Y0i49SwJdC1nA3tZdveE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NsdfuRgtwdy4TTNYZ1pYQJ3S0YxjKS6arTc1lv+HlcKBCnmFDWilIVgblA4Wz1OSOkG184WXpuXR1silVXc9qx98VA1KX0jzkh3ZyEqud8WcXSa2hMmN3OY0+nJov1wAL7Xuxg3Bc54Ed6Rlusjq7oM5V0UUjf+RTNG+s94zRJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SEVFF8PX; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SEVFF8PX" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-46b1d40abbdso13191151cf.2 for ; Thu, 23 Jan 2025 11:08:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659292; x=1738264092; 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=fzRFJC57j6C4PHDj6UKs7NhJ6sOmiSf/M/lgYJifJ1E=; b=SEVFF8PX1HbE4TT8IZF2ulTZbwS8AuFDXBcTgq/+1lvtEk9l/nugHeqt4sy2jIai9Y zYq6ySyr9xcWyEfcmdwv+Mi4Nv1NArxLTD4UQFwvC7PjMTwTdw19MtTFn7cLeqnKrRZS tHy55U160Dwk1V233IRS2Mw7EsBTG9cEYsSq6g7sOi3koZIyVkFaVmytSyxMC/ym5HTj PkXygSQQFkmHcUmiyqJBen1aauk5n0I1UFgY5M91QEWUUer61yeLHczZX1rcovJcMONK UgQx9K78Et+/kReBO99WGf88Q0ciNwCYFkJP8j8IEUETw7KuU8oJgTfoujBo8keXrRtz 5Dwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659292; x=1738264092; 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=fzRFJC57j6C4PHDj6UKs7NhJ6sOmiSf/M/lgYJifJ1E=; b=lw40BShW7BpvTzHlrxz0P+9Ch0S6ZVW1YfSbPDJ5vrBOt38OCdRuTZxQ0n11GIkg/3 Y748v8aQuSLSwROfWN5O68o6p8ReFEG+0jtstG1FrBv7bIyYB1LvwytINLBegWbuGw/y I8bw6FdKMbjp5LfTD3dP/+yTcG/RjboVwmeMEGY5Jg0cpA4nLU514oFUnpOVCeQezbvN VMS/qVLES1s2RWhjzhaANspNVnNX0fUnoC/2s/ONMaxzXkCmR7IXegslxmZTMr14Dqav pLfKrCzjLuEVyX33PJpsCFTGT4dRvHaXnXhs8PbYhembvMrrNhN/HQ6EWeF3wCAUBcRd G/iw== X-Gm-Message-State: AOJu0YytxliflQkXWISoaiapUBAdh9I6wpSlr20uXv0n9C981rMq1Sr7 ZWGuThrRmaO0tSdEvEUirW1pEvOGJI97cVJuFGuXFNr+yeJadAirBI6O X-Gm-Gg: ASbGncsAzHi8UEUv9r0Ui/GmSlDJpicsOaajC+6GJNKzQa/on5919UlD8tcvHl53pHl VL7qZ/kugtPhkeCTmAhE8Ln462Rj5LKe1HoOF/9LC359KLbtN7yXkBcZxCBgeyQk7MrU3bwScTc EhHTQFKVQraa9XGR2Cep4JcqPHLcEsm+cP3WxYheFQ8Rb2bw/NdmKg0M4upFfGeKRbu9epVa1uH I6EsmmzwFzXuCM60owRl/6MSGGNcPBCMhvDD4tKdpGaVYEigGZ1XlWnTtyLFA== X-Google-Smtp-Source: AGHT+IHhQIeKs2EeJIpa+LqUvlfpn07hdpic1Xxjp8WnpLLIPPJbx2OVYjD1pFws8I6E10itT5nm+w== X-Received: by 2002:a05:622a:1a83:b0:460:aa51:8411 with SMTP id d75a77b69052e-46e12a9a0dbmr349290911cf.24.1737659292058; Thu, 23 Jan 2025 11:08:12 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:11 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 11/15] x86/percpu/64: Remove INIT_PER_CPU macros Date: Thu, 23 Jan 2025 14:07:43 -0500 Message-ID: <20250123190747.745588-12-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the load and link addresses of percpu variables are the same, these macros are no longer necessary. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel Reviewed-by: Uros Bizjak --- arch/x86/include/asm/desc.h | 1 - arch/x86/include/asm/percpu.h | 22 ---------------------- arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/irq_64.c | 1 - arch/x86/kernel/vmlinux.lds.S | 7 ------- arch/x86/tools/relocs.c | 1 - 6 files changed, 1 insertion(+), 33 deletions(-) diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index 62dc9f59ea76..ec95fe44fa3a 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -46,7 +46,6 @@ struct gdt_page { } __attribute__((aligned(PAGE_SIZE))); =20 DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page); -DECLARE_INIT_PER_CPU(gdt_page); =20 /* Provide the original GDT */ static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu) diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h index e525cd85f999..1a76eb87c5d8 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -20,12 +20,6 @@ =20 #define PER_CPU_VAR(var) __percpu(var)__percpu_rel =20 -#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__: */ =20 #include @@ -97,22 +91,6 @@ #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x =20 -/* - * 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/head64.c b/arch/x86/kernel/head64.c index 22c9ba305ac1..05f8b8acf784 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -567,7 +567,7 @@ void early_setup_idt(void) */ void __head startup_64_setup_gdt_idt(void) { - struct desc_struct *gdt =3D (void *)(__force unsigned long)init_per_cpu_v= ar(gdt_page.gdt); + struct desc_struct *gdt =3D (void *)(__force unsigned long)gdt_page.gdt; void *handler =3D NULL; =20 struct desc_ptr startup_gdt_descr =3D { diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c index ade0043ce56e..56bdeecd8ee0 100644 --- a/arch/x86/kernel/irq_64.c +++ b/arch/x86/kernel/irq_64.c @@ -27,7 +27,6 @@ #include =20 DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __v= isible; -DECLARE_INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_VMAP_STACK /* diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 93c2fa8a7522..1769a7126224 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -471,13 +471,6 @@ SECTIONS PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); =20 #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 =3D ABSOLUTE(x) -INIT_PER_CPU(gdt_page); -INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_MITIGATION_UNRET_ENTRY . =3D ASSERT((retbleed_return_thunk & 0x3f) =3D=3D 0, "retbleed_return_thu= nk not cacheline-aligned"); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 9e8d5a62ff50..199ab867da7f 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -90,7 +90,6 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = =3D { "__initramfs_start|" "(jiffies|jiffies_64)|" #if ELF_BITS =3D=3D 64 - "init_per_cpu__.*|" "__end_rodata_hpage_align|" #endif "_end)$" --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f169.google.com (mail-qt1-f169.google.com [209.85.160.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 370F0213E97 for ; Thu, 23 Jan 2025 19:08:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659296; cv=none; b=VL052exg5PgNbnssR6O3QP+jzP18jt5AT12KAd67M6FIKv/Bs65sBfySMD2HFI6zqVELANP/BEIFLWPJ4W/SGh6E5jVFLK0V8lDhUyLgqmH/Eu91v34pWDqQnkWuNKQqlDV2zrWNaJU3MX/Pw9m9A7ZVPXNy+XvGKu3LhpHH/pA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659296; c=relaxed/simple; bh=BEPFEYfZhVnrc2haWzepIzQUSH71N7kszwYEBMJYM8Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KoOPD3zZGR1mun0MwYnehfGHxibE2N0unthWpehh3k1RHGZills0bgYeLsPyTmpmi35BnAGXgCeMzuE4IkFcXcD7S2rgq9Rhy/v25wb8HGB8Tmu4piX5GXgowKk/ZazJUc0WGYreok64VblhM2/YjbxD1Wuha4idWeiDyvIjlZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SfzUp0h3; arc=none smtp.client-ip=209.85.160.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SfzUp0h3" Received: by mail-qt1-f169.google.com with SMTP id d75a77b69052e-467725245a2so13489661cf.3 for ; Thu, 23 Jan 2025 11:08:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659294; x=1738264094; 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=5sGGkTFKJLssIh+3P+6euS+EEOl7z8lG+7Njs3tNXqY=; b=SfzUp0h3hmA3GSk+kh7R7ANK6+17scnD5W/vcnOlhhN+nmkyOdUOqFy09QxUZkcKWv eIkLI10BuZDW+KCw56Hyr8ORrVdUKgyxQrotaf7yfN3ljsG8CDzSpFZvNxtwiufs9x0O hEWKi76V0xoU4iA2HGQLqbMQG/XWy4QuhE7NEksEvXOIeUdzNnRaULXFjya8TY8w7pOP 8NkPSV/3KrKp0zeGiartdqT/o2zIzJBg52HxK5AD4fLDosJnV4iXf1yl+24E7eSwQNOH 24X06FhDlayUainS9TRUcZDYczgmLCal6tLcs/w7G8MDORdQG9PR9eL3J5zRlWGVog5u m+2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659294; x=1738264094; 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=5sGGkTFKJLssIh+3P+6euS+EEOl7z8lG+7Njs3tNXqY=; b=oDbCtKBQzvV0p3sARjFQbP+BTkShxBdIRrlFe0Z1uAPzAk37KhvyCh3l7ozR5/jGeF SgIPZv8WQK0Td7seqyykruYIekxVQg/D+IQBwUSeGSDHTruQTWhGhQJFmQgrGGlh+R1d SJFNKuWf6V4A17992/lexY9i9N60MCsxblG9/m4vbmlkdWScEC+/C771212MVIwvF4+M +zC6fxQhT4CQXyXqrEwdMFHDrGOc0VcyynRhx3oWO4AIOh73bLwSTwENCX68lrBgEzxT uPfDhF50q6l3BFmmYpXoNAUeWMrpLCkTXmKRHrJnNKsQVczU1VxsPdeRD1Wu+RUHs2qB D3fA== X-Gm-Message-State: AOJu0YzsGsKHfXxyWyaPGRZPEpOl09UT6HZb6UD+Ur3k5yNqkJtl4bXM pp4VQS8lZfN0ES+/sKOJtGXtHcpPLfNYreKx7MD60FDKLkcGIBLBnVYi X-Gm-Gg: ASbGncuxMPDuG37a0r97aJAvGQ2rqNmdg7K6GlskSicMF6fzDxNhTfQ2SmYW+3k0GLc QYO20SDt0xsXU+bJJtOZRo15oYWRrMv/xhKu8Ny5Ri/PkExekf4zFP6UPBSCHal9WR7686M5YYp GtpQVQwY3rJj11kmT9qAXQ9FX6vsKOa9OrNycrWoaEwk1ojtUGNPlMefox/0u909X1mTPTHl9QT sMS3Tu8FJ2+y6Pk6fl208Kv8BF03QiSv4tfnxYJ+cRj1x/Joy3GgjJ/gQWVgw== X-Google-Smtp-Source: AGHT+IFz7JaTy7x6Z82B+hqGNgtHsIHNadVI/9ViLaI6EIAxXhK9pHeEJ+h/GwAspFXVmKdGcVzEUw== X-Received: by 2002:a05:622a:20d:b0:467:70ce:75ea with SMTP id d75a77b69052e-46e12a9a0d0mr436747401cf.23.1737659293664; Thu, 23 Jan 2025 11:08:13 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:12 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 12/15] percpu: Remove PER_CPU_FIRST_SECTION Date: Thu, 23 Jan 2025 14:07:44 -0500 Message-ID: <20250123190747.745588-13-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x86-64 was the last user. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- 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/vmlinu= x.lds.h index 54504013c749..4a69658739de 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1061,7 +1061,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPE= LLER_CLANG) */ #define PERCPU_INPUT(cacheline) \ __per_cpu_start =3D .; \ - *(.data..percpu..first) \ . =3D ALIGN(PAGE_SIZE); \ *(.data..percpu..page_aligned) \ . =3D ALIGN(cacheline); \ diff --git a/include/linux/percpu-defs.h b/include/linux/percpu-defs.h index 5b520fe86b60..40d34e032d5b 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" =20 #else =20 #define PER_CPU_SHARED_ALIGNED_SECTION "" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" -#define PER_CPU_FIRST_SECTION "" =20 #endif =20 @@ -114,16 +112,6 @@ #define DEFINE_PER_CPU(type, name) \ DEFINE_PER_CPU_SECTION(type, name, "") =20 -/* - * 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 t= he --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B7FB2144D7 for ; Thu, 23 Jan 2025 19:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659299; cv=none; b=qwvdtfO4A/P9uJ3smKuEzU+4T2oCz8d1pdJk56nxkyS+gCdT7UtMq0TId1JebaYxvZFt9omDtDvpdkn24hn14L2EC4LbUbDLhOlIXsAyA5et5eT7WtgZUdUv30u/XUEym+6Km8MjeArwKzM+X61DFObldXLHNhiy8dbE87IHIF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659299; c=relaxed/simple; bh=f0DEyMh64/yaIhaMzdXmL9CCZQryy4eTt5TpeUZJXI8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eOBFhSAkKCSTSu8jtxRwhRUWrosXj9WiCFeN7Njk44TwcmepehJvR+UHOqQJ1EJMyU0c5dRsek3W32L0DLyu0/YvNgjmu71hYzYEn6os5ZVMHMOllj8P0NcIjGEI6swsFCgYp/Xwa4kPKZPqM/ZqTwWv1A5srIA/HgWYim4APtU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GBOo+vgX; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GBOo+vgX" Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-467a37a2a53so13736141cf.2 for ; Thu, 23 Jan 2025 11:08:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659295; x=1738264095; 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=jMQTLT58nLO17Tx2k995Oj0sTehDvSRdhS3JQcXU9B8=; b=GBOo+vgXXphBvMxqtfgGXY8b06I3zpl2qIJ0XuFUG4ECC2FCRLilKiQdQXHtD55Lgu 4Tk0tXnIe/55+0KDkGx4uSgJWlTinvAlw9dNw19tz3ZL+VCGlp2xPN5EJPTguXLBmCn/ EO2ranzbNujvgyFDnIMyqmlEJc6yc/iTIUxVj0B0UsA9IpoUq0rZgoH7H/ohT0q9keTj gnBIlE0wP2lwCkkcRRl6Nr408ZT3Iee0MSKt/hIBbIAvX3Qfj0RfgAngVJH+sIpj516s bWU7m4Cc5jSW/uB7eX16OV1Q6sgaPCWohe34uYG3Qb9/2rqI2h9TgdMhnGDtlBe/RG7C HQkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659295; x=1738264095; 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=jMQTLT58nLO17Tx2k995Oj0sTehDvSRdhS3JQcXU9B8=; b=N3tYAj/Q7fZWQj8HRACZ89oRNJgz1TFATzyWScpj4UhkllTl8Jy/Y6SbWa4dWi8qT1 iPLVahFmcExBWKmL8cirx/kfB14BMnAee2Bypj31POgCHuWqft18WI6oQjIbKn/OYYME vi86Ewr6Pi1GKFIKIu7KnQYUpAQgvpMJpVRm1OgawYqYUb6dfBRweTnmoGMGtEtqtcDT PjgarmN5Qew8ejD9hs5Q68Z2iArwUAm7iLEspwHvY3v43Bfn0HRWFHbfjJoRSiT9BqKu wq6crfiutvcuymI3WnNyUAC+e0dgnT/xLUmR42FUgouoD0Qkj3QCf5pFuZmyQ8dasTWC /FlQ== X-Gm-Message-State: AOJu0YwxgEC1Ml9R/Kgr35WIbJN357JICTgjL6vmBHY6O9WjHU63CCfl pa2aoxNxj0qLSZAkYyhjZg+lQXL+3KfhY/2u/pHYKkH5vt/h4V5NBlhi X-Gm-Gg: ASbGncvgmAX1uH0MzEE+4xDHDCZpV9duUcmurC2NrN+p5/v7TzBmkcvqmYDiKio+Omy Puw9ZtrXyKE5W6Ckl0FaVlZM94hwl1p4MYn1++wcdSUib7oKd2GkSdMvPFm3OJQfHL6D2RiFFdF xmZCIufN6X6F6TJIxwzRq4Dulq6mSyIgzp4HNbL+kuIlDV1egzSwWRIZeAKHVeCmxSdP5FR/Muo JClp8g2NRg8s7uxdX3rWi1XKm2aOAz09Ci5BNTGqtAq+4H74RZIiaLCRnPwVg== X-Google-Smtp-Source: AGHT+IF4DjZY6kWAXZqwSs1QL3SAUtgmNIIjbWEy51bvNOzXRl0/728mAl85beUXkjG7/N3y0mf40g== X-Received: by 2002:a05:622a:1902:b0:467:8703:a740 with SMTP id d75a77b69052e-46e12a3f76amr470492971cf.18.1737659295000; Thu, 23 Jan 2025 11:08:15 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:14 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 13/15] percpu: Remove PERCPU_VADDR() Date: Thu, 23 Jan 2025 14:07:45 -0500 Message-ID: <20250123190747.745588-14-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x86-64 was the last user. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- include/asm-generic/vmlinux.lds.h | 36 +------------------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 4a69658739de..b2cbc1628118 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1072,47 +1072,13 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PRO= PELLER_CLANG) __per_cpu_end =3D .; =20 /** - * PERCPU_VADDR - define output section for percpu area + * PERCPU_SECTION - define output section for percpu area * @cacheline: cacheline size - * @vaddr: explicit base address (optional) - * @phdr: destination PHDR (optional) * * Macro which expands to output section for percpu area. * * @cacheline is used to align subsections to avoid false cacheline * sharing between subsections for different purposes. - * - * If @vaddr is not blank, it specifies explicit base address and all - * percpu symbols will be offset from the given address. If blank, - * @vaddr always equals @laddr + LOAD_OFFSET. - * - * @phdr defines the output PHDR to use if not blank. Be warned that - * output PHDR is sticky. If @phdr is specified, the next output - * section in the linker script will go there too. @phdr should have - * a leading colon. - * - * Note that this macros defines __per_cpu_load as an absolute symbol. - * If there is no need to put the percpu section at a predetermined - * address, use PERCPU_SECTION. - */ -#define PERCPU_VADDR(cacheline, vaddr, phdr) \ - __per_cpu_load =3D .; \ - .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \ - PERCPU_INPUT(cacheline) \ - } phdr \ - . =3D __per_cpu_load + SIZEOF(.data..percpu); - -/** - * PERCPU_SECTION - define output section for percpu area, simple version - * @cacheline: cacheline size - * - * Align to PAGE_SIZE and outputs output section for percpu area. This - * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and - * __per_cpu_start will be identical. - * - * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) - * except that __per_cpu_load is defined as a relative symbol against - * .data..percpu which is required for relocatable x86_32 configuration. */ #define PERCPU_SECTION(cacheline) \ . =3D ALIGN(PAGE_SIZE); \ --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E03D321504D for ; Thu, 23 Jan 2025 19:08:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659301; cv=none; b=Ob5gkqWml3o7skZKiqOCgQMsHopmyhvgE+kjCcXFq9db3ILY9EVk9kSzaecK7VaD6RePAxLNekUUZY47xQUQzPUNHr2pkoeBDeVjU47qA2P3NM73b4ScsFRI19I/jDEwCfL8Wl4Z5JN4/9SCHUzm+BN7WGr3S/3lwNxOhuK7nVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659301; c=relaxed/simple; bh=TLLboa2onWAvydbiY/60N73N8Tj4Oda2dgjE0GX3TmU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AU6rt8Td9OukCG1vytWA8/EtymQAH19jknWA079fvBPHzVQlRwfbv9Tqv1K31vnhpdSp0KqIxHssRtI3tPyJvFtscizlczX01xCcykqbetq1q8heNPhIW9lW5xjwCDypHTBh8Tz3gbIkBn9uha3ZTW5ZZiz57ljjsFrWiCJgWP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=YD6sr0Rq; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YD6sr0Rq" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7b702c3c021so120909485a.3 for ; Thu, 23 Jan 2025 11:08:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659297; x=1738264097; 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=Zt49qJ5WRNR5SppLzjPbVJiksJr5LusnDD+5sHwzSGo=; b=YD6sr0Rq3Vehozt2Wg1Gg56mltC6IMX9T3MfQI3Xe1Ene4/UgjQFfxa6lKn3dkI8p1 dsXFoyY+KgWx73+A2l6a/nH3HXK2/EtmiKhNbNcg48ftfnAfDPllDxNWGD5YhivEfzp6 rTkbAPzSLkjkH2lZv+pgNRyvJHeybyIzARm5fjsrx+F+t2drnDpA5uPMCTwe7UI6KlLA o4Uu3vu6/o+635WcV+wzULCUfioiKpUA1zPZToyNSaDF4jMpDc8UNK0GbUA6QbkM0dFq 8g0WubhgOL7jkU6erCp0uEEO4S3cj+Y6nMDqXt/PywQjRnQx7QcYmtcoZPgXywO3rPwP pSoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659297; x=1738264097; 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=Zt49qJ5WRNR5SppLzjPbVJiksJr5LusnDD+5sHwzSGo=; b=e3IDVrWH30eHItlP3okX6aV3WETv49/65r7EoRXM3bb1j7DB62sljtk8KD8dj5XwX7 ZKTxwT/leXE9KgjWALY6Oyto4bOGNJ632tEg7pPFAW9U44/1XHXmiNPbfdyWooHBQz4m 14UdelJc3356HHsDvn9lXqOmulqVZ77QH2wwSIiF80WLqrMLDYsnwHJq4Pb3TeoOgG8O S1B6tDK8I/qofJRu0eBJaiGwDe8/cAy+ddz/G7KneKqytGj6Hd8tmvQnXrQIbHfyKejw pV//Gt/PerC24Kop7wXYdmuO+9dWnwr2io8M34DQ+BsWjEFlc4c8mL4/YvticrrfjCYW Uv6g== X-Gm-Message-State: AOJu0Yzhw1Osg1w8vJzMgNsvkXKZaIGl+xX9sGzDB4a8xSr8EaCPsD9c 56+4e1SzMYPWUkUYk+j0YyzN4elRZ3SyB6LfQetQmfm4a6CzwdlYTSO9 X-Gm-Gg: ASbGncsMXVjf6tpjfk6HdgvPyk10hI8zOCzAwS62StLoNbOqPK4DjMa7w6qbzkF8Rbl vnX/DkTUBYohuqdhQNRK5+drlQNvFPkRnpbo5CA9h7jaSoeLNH8QIhtN6IyOW3KRzADbYOELPCN /kZtg7qS9xQGxomZLFkpSn6CYfuv8IjOHWhSo6cgCYq3VVDVM90Pe+iRwrC7JbNToOrDPvg0iYQ 1hhjHeAiyuFvTYaLLClo5QqAWHWPr2DWTRqwND8hpPoXnowFwWLHASc8ivz+zGiT+lT/zo+ X-Google-Smtp-Source: AGHT+IHMeGX/MOhGipGR+kDP+MbuGAd886iBj7kejr8e33c8YzLoF95ejd9nFSFm3v3eX5cy9tQ7Vw== X-Received: by 2002:a05:622a:15cd:b0:467:7745:f0a9 with SMTP id d75a77b69052e-46e12a0d2bamr442281271cf.4.1737659297162; Thu, 23 Jan 2025 11:08:17 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:16 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 14/15] percpu: Remove __per_cpu_load Date: Thu, 23 Jan 2025 14:07:46 -0500 Message-ID: <20250123190747.745588-15-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" __per_cpu_load is now always equal to __per_cpu_start. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- include/asm-generic/sections.h | 2 +- include/asm-generic/vmlinux.lds.h | 1 - mm/percpu.c | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index c768de6f19a9..0755bc39b0d8 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -39,7 +39,7 @@ extern char __init_begin[], __init_end[]; extern char _sinittext[], _einittext[]; extern char __start_ro_after_init[], __end_ro_after_init[]; extern char _end[]; -extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[]; +extern char __per_cpu_start[], __per_cpu_end[]; extern char __kprobes_text_start[], __kprobes_text_end[]; extern char __entry_text_start[], __entry_text_end[]; extern char __start_rodata[], __end_rodata[]; diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index b2cbc1628118..c616749ebcf7 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1083,7 +1083,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPE= LLER_CLANG) #define PERCPU_SECTION(cacheline) \ . =3D ALIGN(PAGE_SIZE); \ .data..percpu : AT(ADDR(.data..percpu) - LOAD_OFFSET) { \ - __per_cpu_load =3D .; \ PERCPU_INPUT(cacheline) \ } =20 diff --git a/mm/percpu.c b/mm/percpu.c index d8dd31a2e407..8c9f2164cea9 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -3099,7 +3099,7 @@ int __init pcpu_embed_first_chunk(size_t reserved_siz= e, size_t dyn_size, continue; } /* copy and return the unused part */ - memcpy(ptr, __per_cpu_load, ai->static_size); + memcpy(ptr, __per_cpu_start, ai->static_size); pcpu_fc_free(ptr + size_sum, ai->unit_size - size_sum); } } @@ -3282,7 +3282,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size= , pcpu_fc_cpu_to_node_fn_t flush_cache_vmap_early(unit_addr, unit_addr + ai->unit_size); =20 /* copy static data */ - memcpy((void *)unit_addr, __per_cpu_load, ai->static_size); + memcpy((void *)unit_addr, __per_cpu_start, ai->static_size); } =20 /* we're ready, commit */ --=20 2.47.1 From nobody Sat Feb 7 13:52:49 2026 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0695621506B for ; Thu, 23 Jan 2025 19:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659302; cv=none; b=XEIpTAD3TosOaqaj1ewQKZxCNky1K2Vfhzkv1A+g800g/Hz+NWGUMxZknvEvaGRuWnxq96bRscj6bcLel5pKYriHQzWpV6eVq3JUXRoBy0nc6hsGgvxdWAUsP33/UczHyMkmspcGsERsn6OpfVxT9dW/Lorp+SqScSgTJx4Tj18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737659302; c=relaxed/simple; bh=/Sw8DrbgjlFEUghzlY2lPSlywc9lhhOKf3sO84GGfh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W74GQvNFYitJsDOoVvqoFK37UA+R4byr3JTwhD/3s+0nNCH1wft3ITLiXi1m+9T7626CBxKna1P2T+xqiAFHgfg10udtn4xgwjnrZVxXhRCrJMqo5yft0NKpu2FreifFV4Y278Nuu+Y7o8mx+In/tYnKeVrRu+5ELCci07FTtBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c2uJgnUs; arc=none smtp.client-ip=209.85.160.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c2uJgnUs" Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-46e28597955so12352171cf.0 for ; Thu, 23 Jan 2025 11:08:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737659298; x=1738264098; 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=d9VcziS1sMJYbohbMWXO0F+nEULOK+VJfuPxDY0yNJg=; b=c2uJgnUsjWBh4y9da4gMPXzOMH4wGdn9afBuoPtO1KA54tDsP4RrXgrli/gIm8hz7T B3RZ6fOWR0RpokMIvcrwinHPA/MAyCMcdMhnryf3hNDXv7+Kw/0zzLb/RK8qAzp1AnxY g4OoVemhZGidgubvo06l/nWgQcy3p3zXrHlLjXxup6NHqojmXrOX41SjjN/WMzpYWb+a mKSnKG+qX6/xTAT3zdfcZJGhGT7LN+WyjZbS9bYv6S6BD79Bhaowuby767xCCXviZh9B 5Y/NNUTZMlQaeOuLavB9KwJ6mQ4+tmWDUIzJcGyWbTMsNYR24tEy929b26E9mAj/vim4 1erg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737659298; x=1738264098; 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=d9VcziS1sMJYbohbMWXO0F+nEULOK+VJfuPxDY0yNJg=; b=Nj7h/m/X/yeLLgjfBFlbtSHxVhhl/Fn8SU5EACTzvvC0guIdLFrcZm5IK5ZvmFLGuD CZdNyzusbqL+EoIfYuqwsKAjODf0LtwThQ9opqlvAu5UilLEY2ELSU56kq5pqsWI3J+3 Zd2n9ZMG5r4D4IvFjMZoxgxDyQtg4adNGSai0d88jWqo89eLNbDymTVfUOStiDJ3UkjV mmGi586tx5lRdt0FhfTc/k8oxIBDK6Pce5PoW3r8vg3QqccZI3en7uDgIOJeSXOVeD7x tOXyGiDZ3FiNAVkuSzSZjpWCL/t1i30A6bx9F0s8QmHJRQm4dzp3PrN7v5uHbv3ZSZUG oRoQ== X-Gm-Message-State: AOJu0Yyr0xuBpRcq9mdnlovSpSTCAdGuruRhnf+1pNPQ2fzmNfy03j+v bdlPSqSxkipQE9oBcB1lObOmUv/AQdtFShJKLaZVw3Af6Ar1EvmAiouD X-Gm-Gg: ASbGncubzXVdXJHtIs9FD8+buNQx7yBV8KKVyo+sZ/hbDdwdRxFV4JaUlOkW/CGOH/5 vu6zGvyTYKIS7ES6hkxrzs1BLqOG1D/rGQ9nNOLhVhH9vtAdHLgaldEk1qovxfq+PC5S1/6SF9j KumivuZEuv5FnWG+hVZi0YtnEQVIkALA+AgrO0vhalSUuck2OqliIokXkpJ5OIABdk+cCUEPrnh xWbmfLzwHOZcWudFerdULXnpgpp0bcMEUefb28WfIOgVRbxCtLSfTS2svx1Mg== X-Google-Smtp-Source: AGHT+IF0manR3fdlhkXC/73MhFbOLaorQ8PYGMREXZ6DarhuF11829bkM6XFiiW+KFdAxuViEsclXQ== X-Received: by 2002:a05:622a:311:b0:467:672a:abb8 with SMTP id d75a77b69052e-46e12a1e603mr428298331cf.5.1737659298375; Thu, 23 Jan 2025 11:08:18 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46e66b880b6sm1768021cf.69.2025.01.23.11.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 11:08:17 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v6 15/15] kallsyms: Remove KALLSYMS_ABSOLUTE_PERCPU Date: Thu, 23 Jan 2025 14:07:47 -0500 Message-ID: <20250123190747.745588-16-brgerst@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250123190747.745588-1-brgerst@gmail.com> References: <20250123190747.745588-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x86-64 was the only user. Signed-off-by: Brian Gerst Reviewed-by: Ard Biesheuvel --- init/Kconfig | 5 --- kernel/kallsyms.c | 12 ++----- scripts/kallsyms.c | 72 +++++++---------------------------------- scripts/link-vmlinux.sh | 4 --- 4 files changed, 14 insertions(+), 79 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 01d36a84cf66..c2a92fb00a98 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1870,11 +1870,6 @@ config KALLSYMS_ALL =20 Say N unless you really need all symbols, or kernel live patching. =20 -config KALLSYMS_ABSOLUTE_PERCPU - bool - depends on KALLSYMS - default n - # end of the "standard kernel features (expert users)" menu =20 config ARCH_HAS_MEMBARRIER_CALLBACKS diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index a9a0ca605d4a..4198f30aac3c 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -148,16 +148,8 @@ static unsigned int get_symbol_offset(unsigned long po= s) =20 unsigned long kallsyms_sym_address(int 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] >=3D 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]; } =20 static unsigned int get_symbol_seq(int index) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 03852da3d249..4b0234e4b12f 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -5,7 +5,7 @@ * 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] in.map > out.S + * Usage: kallsyms [--all-symbols] 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 long long addr; unsigned int len; unsigned int seq; - bool percpu_absolute; unsigned char sym[]; }; =20 @@ -55,14 +54,9 @@ static struct addr_range text_ranges[] =3D { #define text_range_text (&text_ranges[0]) #define text_range_inittext (&text_ranges[1]) =20 -static struct addr_range percpu_range =3D { - "__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; =20 static int token_profit[0x10000]; =20 @@ -73,7 +67,7 @@ static unsigned char best_table_len[256]; =20 static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] in.m= ap > out.S\n"); + fprintf(stderr, "Usage: kallsyms [--all-symbols] in.map > out.S\n"); exit(1); } =20 @@ -164,7 +158,6 @@ static struct sym_entry *read_symbol(FILE *in, char **b= uf, size_t *buf_len) return NULL; =20 check_symbol_range(name, addr, text_ranges, ARRAY_SIZE(text_ranges)); - check_symbol_range(name, addr, &percpu_range, 1); =20 /* include the type field in the symbol name, so that it gets * compressed together */ @@ -175,7 +168,6 @@ static struct sym_entry *read_symbol(FILE *in, char **b= uf, size_t *buf_len) sym->len =3D len; sym->sym[0] =3D type; strcpy(sym_name(sym), name); - sym->percpu_absolute =3D false; =20 return sym; } @@ -319,11 +311,6 @@ static int expand_symbol(const unsigned char *data, in= t len, char *result) return total; } =20 -static bool symbol_absolute(const struct sym_entry *s) -{ - return s->percpu_absolute; -} - static int compare_names(const void *a, const void *b) { int ret; @@ -455,22 +442,11 @@ static void write_src(void) */ =20 long long offset; - bool overflow; - - if (!absolute_percpu) { - offset =3D table[i]->addr - relative_base; - overflow =3D offset < 0 || offset > UINT_MAX; - } else if (symbol_absolute(table[i])) { - offset =3D table[i]->addr; - overflow =3D offset < 0 || offset > INT_MAX; - } else { - offset =3D relative_base - table[i]->addr - 1; - overflow =3D offset < INT_MIN || offset >=3D 0; - } - if (overflow) { + + offset =3D 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", + "relative symbol value %#llx out of range\n", table[i]->addr); exit(EXIT_FAILURE); } @@ -725,36 +701,15 @@ static void sort_symbols(void) qsort(table, table_cnt, sizeof(table[0]), compare_symbols); } =20 -static void make_percpus_absolute(void) -{ - unsigned int i; - - for (i =3D 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] =3D 'A'; - table[i]->percpu_absolute =3D true; - } -} - /* find the minimum non-absolute symbol address */ static void record_relative_base(void) { - unsigned int i; - - for (i =3D 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 =3D table[i]->addr; - return; - } + /* + * The table is sorted by address. + * Take the first symbol value. + */ + if (table_cnt) + relative_base =3D table[0]->addr; } =20 int main(int argc, char **argv) @@ -762,7 +717,6 @@ int main(int argc, char **argv) while (1) { static const struct option long_options[] =3D { {"all-symbols", no_argument, &all_symbols, 1}, - {"absolute-percpu", no_argument, &absolute_percpu, 1}, {}, }; =20 @@ -779,8 +733,6 @@ int main(int argc, char **argv) =20 read_map(argv[optind]); shrink_table(); - if (absolute_percpu) - make_percpus_absolute(); sort_symbols(); record_relative_base(); optimize_token_table(); diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index d853ddb3b28c..8e23066323eb 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -144,10 +144,6 @@ kallsyms() kallsymopt=3D"${kallsymopt} --all-symbols" fi =20 - if is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU; then - kallsymopt=3D"${kallsymopt} --absolute-percpu" - fi - info KSYMS "${2}.S" scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S" =20 --=20 2.47.1