From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.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 60EE05D47A for ; Fri, 22 Mar 2024 16:52:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126370; cv=none; b=uI6ahPFcemvRO2w/64lBfVITvlA7UUzk9feVK1s8uuCIesfbv/8kwx1Tnjvmqgw5spwoIxv7cXhHVrfuRxikc4JqM8mD+gbWYzi91VNlsAIsBDzpjMI4eCQ0wGQIS1RICpM2ELvKwJ3POaUZJXgS7EJNgZGPI8exL268KI3K9Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126370; c=relaxed/simple; bh=0ghGhHkYB5a3QE//W4UnFTfqJRNvrjDLfq9w7NmbnE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ec+MmrH7U8z5o0u95B+ovH/ZUC2dSd26fPuCcUUheozw3kKjC3PgUPPVefc3DnmjCaq40kZm7M2jsOc4fZmJR8b8q9dtcvAwOidcNQ2+bx6/tIbsVk2woDwp88JSCp+yF8hLAQg99Dp5ef3HcefmVfpPBfQr4BeS/XJRGwsdJMg= 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=DfypVfih; arc=none smtp.client-ip=209.85.222.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="DfypVfih" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-78a2093cd44so187327885a.0 for ; Fri, 22 Mar 2024 09:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126366; x=1711731166; 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=2MEvpbcjD55OPVHZv1k/P6RoxHeXbs2ZBZ6egLEjNfc=; b=DfypVfihvSjfHp0uF+n+R3ynH5q+gqbjWBIReNQegtnnKc0zH8uutBbwtUnV4wiC2K ocauUFi86+dTyiCUHnG7zBNy/j7yU5+mwsZ/idS12W55JK5Rfzf10U+pYdCF6kYPTVMC QtmGnALiah2V96fdSrsOPQbXjtu5wJHjkb1OgO0gZNDWrJ8agkO0NDBLtD26RF2Dkh44 csLjUxirk12G3eelgZApK3tzm6a9fd5ljhNkVsaQV4ZlmP0bVC3QJd50HdQuv2sR0VV7 OsUNSS2YEPj8xwr8tnolZUEgepZa5DkLQ9v01GFdEF00H2ka/p9cml47jGlxctk8v0SC rnTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126366; x=1711731166; 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=2MEvpbcjD55OPVHZv1k/P6RoxHeXbs2ZBZ6egLEjNfc=; b=BX8+P7VOpxVFLjyXzHZe1q5NhRUxMWXi4DrEkdWQ4BVKfqGeMpqTANoYlLlD5XmBi2 y38jT+eguvlz5dvCQ14IAhT6rIM4m3IT+5alPlJzqkr5WkaZeidNmn6wzu3PkKFCNdu/ xxFgfyoI2dK8iMpoGLiA1Sq06Zb7Iyzz9a8d9xCx8qKKuUi2LzwkuLTNqoEU7LXULVY2 fhMLHGcXnexvZDRtZ8044o+fw3OPov/V7CYfNH+UT+Bta9SOdTxjQZXROsviaMGbmwGE yMYnKCAytb/XUfHE2HMdK1J2JtHYVFmjeGmOVu7Hvu6nLA0kxJ7y9J3UAU/vZefqDHJt lt8w== X-Gm-Message-State: AOJu0YyTwesn/pkUDU0TfH807KZKCzwEqCCDzInY8sXh7bQ532erBnQS onCGhQs54aQoUduCGcqD4FJmLrhG1g1dW2ZeW6jdgnAtsqTfYX4q7O+Rtfc= X-Google-Smtp-Source: AGHT+IFuqifNiOavqmdcMCLtLrAdFCt9Togq8CGLXtlPw8/Jwid/sUQIGZLI3isE+doU+3lYv/yKBA== X-Received: by 2002:a05:620a:2af1:b0:78a:3225:60c4 with SMTP id bn49-20020a05620a2af100b0078a322560c4mr2512675qkb.53.1711126366579; Fri, 22 Mar 2024 09:52:46 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:45 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 01/16] x86/stackprotector/32: Remove stack protector test script Date: Fri, 22 Mar 2024 12:52:18 -0400 Message-ID: <20240322165233.71698-2-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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" Test for compiler support directly in Kconfig. Signed-off-by: Brian Gerst Reviewed-by: Uros Bizjak --- arch/x86/Kconfig | 2 +- scripts/gcc-x86_32-has-stack-protector.sh | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100755 scripts/gcc-x86_32-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 03483b23a009..f326903cbe67 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -412,7 +412,7 @@ config PGTABLE_LEVELS config CC_HAS_SANE_STACKPROTECTOR bool default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(= CC) $(CLANG_FLAGS)) if 64BIT - default $(success,$(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(= CC) $(CLANG_FLAGS)) + default $(cc-option,-mstack-protector-guard-reg=3Dfs -mstack-protector-gu= ard-symbol=3D__stack_chk_guard) help We have to make sure stack protector is unconditionally disabled if the compiler produces broken code or if it does not let us control diff --git a/scripts/gcc-x86_32-has-stack-protector.sh b/scripts/gcc-x86_32= -has-stack-protector.sh deleted file mode 100755 index 825c75c5b715..000000000000 --- a/scripts/gcc-x86_32-has-stack-protector.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -# This requires GCC 8.1 or better. Specifically, we require -# -mstack-protector-guard-reg, added by -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D81708 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m32 -O0 -= fstack-protector -mstack-protector-guard-reg=3Dfs -mstack-protector-guard-s= ymbol=3D__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs" --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.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 0E98A5F466 for ; Fri, 22 Mar 2024 16:52:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126371; cv=none; b=Tcc4bMbEJqAqDNSLJluVNbu8VgGQEYIRYmk/yeYWq68EajilrAC7Y+ADo1oGVEizKfCBXmW9CE3rvpsElHD8g6Ic81OBSnFI+eJid+9Ih+WnmaPL1N9rkngk4L16ArjUPD5naC7hUUJqovUxUT1T3bAWFPg7xu8eH7dQYe0BfwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126371; c=relaxed/simple; bh=EDpNl4LRcs64R7xLYeFg83XcegfrjomehPC/gIvBDvM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hQ04Eh13wbkDJxQVtEy+x1APncTKZEktQg26omCXzSONbS1HH5YpaaakYz3mIUzpdX1k2EiRCAGTe4/iCmEe8jKJu9+ajhVtfs4ueSjGhmU+mIzsKP9b6ggqbshRW3nwLeg2PyrPQh79y2tUrHZF1PKaliukCeSMR5fue3JlKgw= 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=VvFEJW9w; arc=none smtp.client-ip=209.85.222.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="VvFEJW9w" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-789db18e169so176877485a.1 for ; Fri, 22 Mar 2024 09:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126368; x=1711731168; 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=zKTOB+egwNuleK2drTZ0+IAwoS6KwJYp/cKDBgEAyxM=; b=VvFEJW9wtjg5IaxppjnlMCL/YM6kp1Woq6wqVQ0Uh09xcdCfRGZZ/u6yASeJo6HrCX vRjOG48poSa66xL2oLggduqIwfYqJy8c4Xi0zCJK6pOPXUl1sLvRo+gZIh7AigyyyjjH cihwuEVijjtEvoWiQJiasntFSOYR8ScCusWtd0XFqabIfdbNuOG3VQ/FUQm6IZqDkOe+ 1aDGJTwPTpWTK6wgHNOFYQwnCTNqBvwE+GY5ZqM+qpo+ALWGw5mMbSqYg2ECkJjoofIO 6ZKXUpxgsUffNQnoVRlO1zxyuLl3Q++6HfIRu+9lpBkw+a2SvWh445eorJhx/H1f9UDe Z7+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126368; x=1711731168; 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=zKTOB+egwNuleK2drTZ0+IAwoS6KwJYp/cKDBgEAyxM=; b=F0IPx4E+S1VGT/1qGGX/fHC1vJt5z4GlQsSQpOI1cg6DhMRKkyt43jtki+n+UUNN5o zjOO6dwW4c1IKNONu9TSKIcicBWv6hJw2uCJufyoqLL9N9wHg5+dPrL56ecxHI7W4meG my/JOVb35WQxqXM3SltYbuntorxyklgVdQyKCBMAtJ+J1pZ6Fg8NpWiLr+4Xwkf4uGdG ROn5GZ8UTHe2Qngw4c3YDGTy3UITHqGnHinlNqs07JxIXuDl89Jbu5h171oIdRJrBMku nP7SovNrEHg1CjokG4r2NnzjkGznZJRljmSMtd/qfpLFwRDfx9qY5+8MscMxw9Za9Wr8 cdIA== X-Gm-Message-State: AOJu0YyxTBaDgIU71oE1uzG287UpaomWXcPfpWnWnsNo8VYLZAnKggNp PZZbHCmkqnYpk171jtIap1KY5hOiSIr6MenbNoR+3aIEsoln44a8GEtayJU= X-Google-Smtp-Source: AGHT+IFf/jYKwZ7fhbLQiCg5reXblzCosOYHLI6zgNxe3fSzI5gD+r/7AwZUtmskhFxLLGIHxbAKUA== X-Received: by 2002:a05:620a:5656:b0:789:cf19:2e05 with SMTP id vw22-20020a05620a565600b00789cf192e05mr2813358qkn.38.1711126368077; Fri, 22 Mar 2024 09:52:48 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:47 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 02/16] x86/stackprotector/64: Remove stack protector test script Date: Fri, 22 Mar 2024 12:52:19 -0400 Message-ID: <20240322165233.71698-3-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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" This test for the stack protector was added in 2006 to make sure the compiler had the PR28281 patch applied. With GCC 5.1 being the minimum supported compiler now, it is no longer necessary. Signed-off-by: Brian Gerst Reviewed-by: Uros Bizjak --- arch/x86/Kconfig | 5 ++--- scripts/gcc-x86_64-has-stack-protector.sh | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100755 scripts/gcc-x86_64-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f326903cbe67..88d72227e3cb 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -411,12 +411,11 @@ config PGTABLE_LEVELS =20 config CC_HAS_SANE_STACKPROTECTOR bool - default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(= CC) $(CLANG_FLAGS)) if 64BIT + default y if 64BIT default $(cc-option,-mstack-protector-guard-reg=3Dfs -mstack-protector-gu= ard-symbol=3D__stack_chk_guard) help We have to make sure stack protector is unconditionally disabled if - the compiler produces broken code or if it does not let us control - the segment on 32-bit kernels. + the compiler does not allow control of the segment and symbol. =20 menu "Processor type and features" =20 diff --git a/scripts/gcc-x86_64-has-stack-protector.sh b/scripts/gcc-x86_64= -has-stack-protector.sh deleted file mode 100755 index 75e4e22b986a..000000000000 --- a/scripts/gcc-x86_64-has-stack-protector.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -c -m64 -O0 -= mcmodel=3Dkernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "= %gs" --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 909BC5FBAE for ; Fri, 22 Mar 2024 16:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126373; cv=none; b=aLAuA3i8lNrNPk7QNM5rwQ/72IkSYrM5gksn9LIJHnfZyFIUvRb4gNoPw5M0JbYHNKGOpZ9TRQHonQ4f4qtNH9ReULFmLT7iBL+y7k2xaEBRCjPuvIv9GNQ8k5GVGzZlHFaPM+nz8kiPKlX3+qhGyMZtQ31PQ59A9rSkfzIsHyc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126373; c=relaxed/simple; bh=nIs8JKLHWhcAMkMuFWOz93kQ/3tiAi+vtEhNf0q70ng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oZnyUHh5M/Ys8s8YSVi3prLhyxL2GsgBJD5aMOqPLXEZegkt9Vm1DYYMVclyE8pfVPZ2UJyXx14cZVMolCDJjfoeCSCBU3CqBjI7xUQhFYHMGThB4PhSJQA5q+5kT/x1zrVf6WgWntTuGQkn/oW0qeJ/NXEhrH8L/+3tFN5vwWA= 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=NKnuXbBz; arc=none smtp.client-ip=209.85.222.53 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="NKnuXbBz" Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-7e08498aa43so993549241.3 for ; Fri, 22 Mar 2024 09:52:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126369; x=1711731169; 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=HlAhaai0XmtsEWjeCcLZPOJXYygjR0gXl78SmFs1efY=; b=NKnuXbBzA99kZTV1P7Gq0TDdz7mW/+G0yHSBHl98m4KSVCiytXxCg5bYMR0tupIzqO 62oSYAhXBh4DgMCH2A2fg0DAo0oaiE8LydvUAB5pcHX69TxDsmLyr0rHB9cRksApVK4K bruMXjw9Z0+940YH8BA2yrc8bL1ZZSpfjwOm1BTCRZvZSAKkNlVDfM2SRAEU4mWWw8ft m2YnOEcH3iDfaeFFGojpI3ijgA1VSCly6PP6rpZyFuGExEYGDtb2FxR0qDNo+AMLGgL4 DrBt3ZoczTNyjgUz6QyWBoD6PUt4ygjZg/Jgx6D5dkxxhCUAfSaKyDg1pDKTSeJLOhYf ryYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126369; x=1711731169; 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=HlAhaai0XmtsEWjeCcLZPOJXYygjR0gXl78SmFs1efY=; b=H8dKXETY8J1ItEjj5Gq/dkaYxs4Hg490r93DVF45ggTtLyWdUOHy+ef+j2YapiLYWp jtxUmGSiOiGWNxHtnyZyi7JCBZsPwERAQ557KIAIlFOyoDzViCm6++wKq5ORKfI0JDCK eewX1VtkUuQD9UYp0MrdhvA2rz6ioArIitOrp4/aPq7TJgHJlDsZB5vCdJzGR3lXelnr O/wx+Z2jyJpgez7fVPpTFyQ0KQ73upqUrgdls3VKxzUMPJ+T4TSpw5DGRl9OKKyCqqOA eFjAXlm+y0PyIqDu81uxR7EKvxttqG4v5qXYVgwLVuN+l3qSHsJdy3ladppszoSptxb9 cPJA== X-Gm-Message-State: AOJu0YxigA9NSfuGoH1MO8D9ZSFYxn1NIp2sjVWOJuBkyIvd58Aqb0TJ LrugHd57EM4EIQx2ae3W33D+JmActxR9EKe18r4Mq+YrUMvL+8crMFUqd+U= X-Google-Smtp-Source: AGHT+IE5FqCK5eXVoI4hEVWqaKrMV/hBIglk7+a97G86DupCD/QFQEMSKGaby20Qb3Ze9eYeS6VkZg== X-Received: by 2002:a67:f895:0:b0:475:623d:ff36 with SMTP id h21-20020a67f895000000b00475623dff36mr163607vso.2.1711126369494; Fri, 22 Mar 2024 09:52:49 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:48 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 03/16] x86/boot: Disable stack protector for early boot code Date: Fri, 22 Mar 2024 12:52:20 -0400 Message-ID: <20240322165233.71698-4-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- arch/x86/kernel/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 5d128167e2e2..9884d2c9de15 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -40,6 +40,8 @@ KMSAN_SANITIZE_sev.o :=3D n KCOV_INSTRUMENT_head$(BITS).o :=3D n KCOV_INSTRUMENT_sev.o :=3D n =20 +CFLAGS_head32.o :=3D -fno-stack-protector +CFLAGS_head64.o :=3D -fno-stack-protector CFLAGS_irq.o :=3D -I $(srctree)/$(src)/../include/asm/trace =20 obj-y +=3D head_$(BITS).o --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 272915FDCF for ; Fri, 22 Mar 2024 16:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126374; cv=none; b=Aunc4YQ2ymbzpeUnvjpxoBIu0HiaL9NtqJFEvEohs+cpGNIaE40l+1kiiHIQ/RpKyMHeZa417Jk8yGLYoltDYmZ2VFkJoSeXKBggpg6RsHf6UFkzYZyRTLS/5a/+27kLMzAfcvZNUKjjbX+BiK8D9kGWcz64PM0x/cnj1iHj1GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126374; c=relaxed/simple; bh=RklUhCugdS79Sgvea9NKA5O8n1Z8/hDlRq99HOBTwEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DQCr+OY9haYSvsldl9Qfd7qmEKaWQL7zCLJuHwe49BEx/7GhkJCt/PGRCACts4mGzQdM/pudQD2OlPul64Clv4Wv/50QoT9ihUrsi1kPQX0jPqnqBzf2Jm9q3FSuCS/Aynsc/MvZ3a0ZUophKg4/SpvNAt8Qx2DfJb3neWdG9qo= 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=XLY1kkgI; arc=none smtp.client-ip=209.85.222.174 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="XLY1kkgI" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-789e3f17a6eso164790885a.0 for ; Fri, 22 Mar 2024 09:52:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126371; x=1711731171; 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=rbNPugqeDmoqssGoWTn8SPKVapnb1hcd5ZsudgigNFk=; b=XLY1kkgIj8iY3ILqtiv4myLjJE7RD/nEojwcOJiJlcL4KFb60jSlkm803c1g/IVRI3 m5A12yMS52J7G8NWE501OrukG8MzUD7KNSPTQeXh/B+luEAhHt3R5D0oJyj4OwmH0Pni sgnHKtqILvSbteW5gR6rwu5v5n40iK3ai8dbm3VI+y3oPsmf5UQWRkLTrXnKb9Qaf1uO W1yaWPXbFhOUu85z7AwjC8Sm0QKcJYGciUfamF5GGHvTcCuNc8ykrWbr7d5pafC6LBNX XZUjMFm89sOTsfYyMcQYhFByBpxo10HTNQbxI+NS0FZncy5BOpIemKe2avaVEnQu15Pq QQxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126371; x=1711731171; 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=rbNPugqeDmoqssGoWTn8SPKVapnb1hcd5ZsudgigNFk=; b=NteSN6/AtQK61SEU1SIePEAYRfiKW484XsYHhP4L98j2EG51pqBcJWd0dqBMrH5soH DGll8hQE6LhOSaAy7FJ0Si0OdXyaodg8rUzgv99QX2bJ+BC3rBNRTklYZlbrbO1fLBJ7 2xYdEdOaUR58ptkIEqCs155oj0DZeLzWaRmRkkcyk+Ln35ECzUvfiePovLYQiByBkxa+ /EhkRgs2FN5jwc1so+WOvTn0erJBwaeLM+j3+snJKLIBDqQVWU3+apF4YXAXDVQMLxQy h3AseP0bW7ahrSATZEogEmpuhw+ElEgt5CuK/jXfp5L4Y+QLlB4F2O0anYcgGnPUlWeY Y2ZA== X-Gm-Message-State: AOJu0Yx+4EK6/Gg541W+qaOL5Fb4d3jAVJJZAYFuhir51JV8Khnoj2Uk SwnAEqv5md610hcjJIgWBMg6HWvZLx9pNNtIYgpMKBSHhw9ntQ4h8/eUBn0= X-Google-Smtp-Source: AGHT+IFp9Qt9VzC4/JAJENgOHxRsYrn05WAatJAj6yqKGA84MaofhjDez1oAYNaaK2ot81K/pVO0tA== X-Received: by 2002:a05:620a:210c:b0:78a:2945:8658 with SMTP id l12-20020a05620a210c00b0078a29458658mr2789389qkl.33.1711126371089; Fri, 22 Mar 2024 09:52:51 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:50 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 04/16] x86/pvh: Use fixed_percpu_data for early boot GSBASE Date: Fri, 22 Mar 2024 12:52:21 -0400 Message-ID: <20240322165233.71698-5-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- arch/x86/platform/pvh/head.S | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index f7235ef87bc3..1f1c3230b27b 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -95,10 +95,15 @@ SYM_CODE_START_LOCAL(pvh_start_xen) /* 64-bit entry point. */ .code64 1: - /* Set base address in stack canary descriptor. */ + /* + * Set up GSBASE. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ mov $MSR_GS_BASE,%ecx - mov $_pa(canary), %eax - xor %edx, %edx + lea INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx + mov %edx, %eax + shr $32, %rdx wrmsr =20 call xen_prepare_pvh @@ -157,8 +162,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.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.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 8519660254 for ; Fri, 22 Mar 2024 16:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126376; cv=none; b=UGxmPGToh4/BhHoQQQX3Wf52c9fB1A8CHdd+psJKDXwqzAY0BDgKs4+ItJPNXOvMSVq91zbOVE3tU901RREiJzpBUhC9rnAm0qWLoyr3F0fNPX5jZGNkOU/IF550tXhVHmGklunxEutTcQugpFf77iGZ+aYjFNhkX/Qn9gbnp1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126376; c=relaxed/simple; bh=vHCEtQUNKboF1EBobqFitqfcjvkiF76fENvbIuSp/p4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eDoQ0Br7ZENzYHQF0sdk6cBLDuRu5EiwXhPDanAz/+JgIladYsu1hayuRx3B2xr1AI5D3fZBfGSe+l/3vBfo9/K0CgR/ArL3APSvtB2FnvzYkQNjSOTuDpjljRmUs++jJNusuABicMk1QpxOC1G8ZzZYN36/tVQ7L+gXzMHtNik= 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=g+6NjRLI; arc=none smtp.client-ip=209.85.222.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="g+6NjRLI" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-789e4a4d3a5so160939085a.1 for ; Fri, 22 Mar 2024 09:52:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126372; x=1711731172; 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=HZ0GbtudtLz2tjdpQffeTy/JKfNLrKUmMY/gqagEmlQ=; b=g+6NjRLITYdScf+tGlwFJl7BJJCuvxaeWN8LDlsu0d2xQ3bGOBqFReT5Nsa89+hN/S Tu3UXbDtfcDjPBfKP9ljoaUBC7q91xecP/y3e+ezGB/RYErWlxICqBjkpD0ZSkjDVtdY JDq+eKxHEq1I+TL+jTssJ2wmHBfzrZlx+RVJJUQHbY/mtRUu5lldWi+Af5Js/K21asWy xT1D43q7zPk42/IkmTg405knmwlvXebbYYP2sJuQwWQXPj3LyJ75o1JD0QwZ9gQMmBDG imbmWRNlDl28NPNx90oCpvGJvs+mvTf+/Dhtdk02e/pmw1skASPyxoK0bn3MIV1LpqCo Asvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126372; x=1711731172; 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=HZ0GbtudtLz2tjdpQffeTy/JKfNLrKUmMY/gqagEmlQ=; b=r8rYAspJG3ASrN3PKAlrwOxVHu5dcofPKLV+gYH0kNkgrFIPfaRWm0CxaaNlOKQrRw r8NMqxBe+I7ay9QhlO3VY8/cF6lSSYsk8qMnVeVjuHg6dq073+sHLasPyHO0C4jIr1sI bWKZjHLBED2BIEdb9BaZiHtxHztlrUVusjOJB/06KX3o6dLDCCWF4fhZLr+Kl8OwcRnz bWmwnygO4KGN7DrXFOlbq6KikeW5mSGI7uZJsuac8n/rFvfY1IMQcVUiduIkw+RQKUyw vx1PJo2E9n4HIx6CcCS103LkvgTpECQ1pnPcYbtE1fMh/zXFfoqyEQQZ5BF8J6vKV1La 0moQ== X-Gm-Message-State: AOJu0YwQrtJIeeG/7eM4lB81/uco5GX3oniOV3LAdgtIww2pP9p7cqXB dNvEyyOfk9t0s08jqPfgSFKDxP5a8HtVaGDkyvevh0K86Y0fcYuwE/vp/J8= X-Google-Smtp-Source: AGHT+IHYguapQSmH5+/TDI2EpFKsaKdcAAFmZIGnZVztKI7x9IXwVGFPaJNPesx49FQClUBMfkh38Q== X-Received: by 2002:a05:620a:16dc:b0:78a:2809:dc69 with SMTP id a28-20020a05620a16dc00b0078a2809dc69mr3143112qkn.51.1711126372661; Fri, 22 Mar 2024 09:52:52 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:52 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 05/16] x86/relocs: Handle R_X86_64_REX_GOTPCRELX relocations Date: Fri, 22 Mar 2024 12:52:22 -0400 Message-ID: <20240322165233.71698-6-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- 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 e7a44a7f617f..adf11a48ec70 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -31,6 +31,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 @@ -224,6 +229,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), @@ -865,6 +871,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.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.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 7A82C60277 for ; Fri, 22 Mar 2024 16:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126377; cv=none; b=jsbiJ/mtlVIfb0+Bv5SIfwtq7e51GDnqkxIJaUfzoU9noeovtoJUbVQVlGYlWFYcxUTaYyOPezdKlNETID88qwYab9xsmkT8aGysGPsMfruFsP/uSKBE16g/VLPx0GHSjxb9wrDzzPyvVc4krMm1GoEomAJmJsv0cWsQr58JgiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126377; c=relaxed/simple; bh=QWJIypdY0CvW+wo9ydMAZKiFXAxpjytAC8MBF5uqHC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A1h4/kAKo3am34qQQo7AEA+sDXGQGG+svS4vW5hrjQ7x+EZV+33ygAtw74q1WFRiS5kGY8Z35dzBXSyvuOiImgrNeWXMV8IM6ySm1y62MSVgbeXpaeDlpHZCxcfhzEV7SbRhdDZ6hxt+llreX3tYxHPAXZ6CdfIRVrLgM/fgpbM= 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=ZxQXec7G; arc=none smtp.client-ip=209.85.222.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="ZxQXec7G" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-789db18e24eso154494085a.1 for ; Fri, 22 Mar 2024 09:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126374; x=1711731174; 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=m5DU/vZcDbeSUX/IUEB2wszFdA5PfNHk+If8FV6cjJc=; b=ZxQXec7GtpGkuMwiVpGJeC+fSfQdC/PY4g2fJQDZ0RB3lUk/XpUN6a7bO1W0Va9UEU BfAokl9shcvro4sOj1fbWPJFNQOmyJGcSbe/ly7WLa5kqzEcbs3Tarqiw0bNvfojqksA kU2j2mTJ3HRdZEYtEBSgEd+g1J2xsli6Phuxw3pvKvXMcIIao94pFAwQonbAeLTmtqdQ crdL6kC+NiP1e2oZVhKU5/4YL/u0TYrAPOEIghJ95AkR/a9l2Mgg9tamXhZ98zp4Wivu j/1ICWw8EOBnW1R5rqf6IKQCLb94h+yd5ESNz2hb+saw5LpqqFzH7R9pU4Lo+kjB7mlL e0zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126374; x=1711731174; 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=m5DU/vZcDbeSUX/IUEB2wszFdA5PfNHk+If8FV6cjJc=; b=niTqHQcLIw5JI6Te/uacclQc2RPdnCvuE1A9Urm63XXuGqk+hXpuGDw2bXNX82HftI 7RryI+HvCU8G9zuLEc9IJmMEaOB+Rt76zN3yPnKZY3chcWSOTLsUYps8dmIuqu1q8vrU tITcyv9bQ3vqU0s7ncmWhx0FVPyGhpD58l1dt8brqsEzqhtbtpNnKOseheQCDIL83vcl 0zeWY5bRNJXK0b3QigvbEO90IJE5Wo6Ax/o69RSYiqrwIku40W5WQnUHKF1v2wBht4j2 JQE/HPcWsSuYg3fC3A/Rt2iHG5asl6/VYxF7EiFNZ9QEMpLYJ1ogcgJIJ0ttRkU9Qr4e Uw/Q== X-Gm-Message-State: AOJu0YwGi+cos81nJyUNsMnuUab43KoPnPvGyDuOQ0K4otAhW1RLqq/b jIYyjDOAe5MXZZ2XeW+QuGrvSboQWAjZirtlI3F7YHHtyfjgvXkzdj7QZrE= X-Google-Smtp-Source: AGHT+IHZpToUOEhNCP/TnbPU/wvyqff9rTijW2pwCbptSCj/CF90lSssQxXf80Mxyk1Kzq53zdb3Tw== X-Received: by 2002:a05:620a:4110:b0:789:f195:6702 with SMTP id j16-20020a05620a411000b00789f1956702mr14196qko.3.1711126374137; Fri, 22 Mar 2024 09:52:54 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:53 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 06/16] objtool: Allow adding relocations to an existing section Date: Fri, 22 Mar 2024 12:52:23 -0400 Message-ID: <20240322165233.71698-7-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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" In order to add relocations to existing sections (e.g. ".rela.text"), encapsulate the reloc array in a block header to allow chaining blocks to add more relocs without moving and relinking the existing ones. This adds minimal memory overhead, while still being able to easily access the arrays by index. Signed-off-by: Brian Gerst --- tools/objtool/check.c | 2 +- tools/objtool/elf.c | 99 +++++++++++++++++++++++------ tools/objtool/include/objtool/elf.h | 84 +++++++++++++++++++----- 3 files changed, 148 insertions(+), 37 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index eb7e12ebc1d0..0a2c161fc04d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -4421,7 +4421,7 @@ static int validate_ibt_data_reloc(struct objtool_fil= e *file, return 0; =20 WARN_FUNC("data relocation to !ENDBR: %s", - reloc->sec->base, reloc_offset(reloc), + reloc->block->sec->base, reloc_offset(reloc), offstr(dest->sec, dest->offset)); =20 return 1; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 3d27983dc908..cfb970727c8a 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -277,7 +277,7 @@ struct reloc *find_reloc_by_dest_range(const struct elf= *elf, struct section *se for_offset_range(o, offset, offset + len) { elf_hash_for_each_possible(reloc, reloc, hash, sec_offset_hash(rsec, o)) { - if (reloc->sec !=3D rsec) + if (reloc->block->sec !=3D rsec) continue; =20 if (reloc_offset(reloc) >=3D offset && @@ -333,6 +333,7 @@ static int read_sections(struct elf *elf) sec =3D &elf->section_data[i]; =20 INIT_LIST_HEAD(&sec->symbol_list); + INIT_LIST_HEAD(&sec->reloc_list); =20 s =3D elf_getscn(elf->elf, i); if (!s) { @@ -850,7 +851,7 @@ static struct reloc *elf_init_reloc(struct elf *elf, st= ruct section *rsec, unsigned long offset, struct symbol *sym, s64 addend, unsigned int type) { - struct reloc *reloc, empty =3D { 0 }; + struct reloc *reloc; =20 if (reloc_idx >=3D sec_num_entries(rsec)) { WARN("%s: bad reloc_idx %u for %s with %d relocs", @@ -858,15 +859,18 @@ static struct reloc *elf_init_reloc(struct elf *elf, = struct section *rsec, return NULL; } =20 - reloc =3D &rsec->relocs[reloc_idx]; + reloc =3D get_reloc_by_index(rsec, reloc_idx); + if (!reloc) { + WARN("%s: %s: reloc %d out of range!", + __func__, rsec->name, reloc_idx); + return NULL; + } =20 - if (memcmp(reloc, &empty, sizeof(empty))) { + if (reloc->sym) { WARN("%s: %s: reloc %d already initialized!", __func__, rsec->name, reloc_idx); return NULL; } - - reloc->sec =3D rsec; reloc->sym =3D sym; =20 set_reloc_offset(elf, reloc, offset); @@ -930,19 +934,45 @@ struct reloc *elf_init_reloc_data_sym(struct elf *elf= , struct section *sec, elf_data_rela_type(elf)); } =20 +static struct reloc_block *alloc_reloc_block(struct section *rsec, size_t = num_relocs) +{ + struct reloc_block *block; + size_t block_size =3D sizeof(struct reloc_block) + sec_num_entries(rsec) = * sizeof(struct reloc); + int i; + + block =3D malloc(block_size); + if (!block) { + perror("malloc"); + return NULL; + } + + memset(block, 0, block_size); + INIT_LIST_HEAD(&block->list); + block->sec =3D rsec; + block->start_idx =3D rsec->num_relocs; + block->len =3D num_relocs; + + for (i =3D 0; i < num_relocs; i++) + block->relocs[i].block =3D block; + + rsec->num_relocs +=3D num_relocs; + list_add_tail(&block->list, &rsec->reloc_list); + + return block; +} + static int read_relocs(struct elf *elf) { unsigned long nr_reloc, max_reloc =3D 0; struct section *rsec; - struct reloc *reloc; - unsigned int symndx; - struct symbol *sym; int i; =20 if (!elf_alloc_hash(reloc, elf->num_relocs)) return -1; =20 list_for_each_entry(rsec, &elf->sections, list) { + struct reloc_block *block; + if (!is_reloc_sec(rsec)) continue; =20 @@ -956,15 +986,15 @@ static int read_relocs(struct elf *elf) rsec->base->rsec =3D rsec; =20 nr_reloc =3D 0; - rsec->relocs =3D calloc(sec_num_entries(rsec), sizeof(*reloc)); - if (!rsec->relocs) { - perror("calloc"); + block =3D alloc_reloc_block(rsec, sec_num_entries(rsec)); + if (!block) return -1; - } + for (i =3D 0; i < sec_num_entries(rsec); i++) { - reloc =3D &rsec->relocs[i]; + struct reloc *reloc =3D &block->relocs[i]; + struct symbol *sym; + unsigned int symndx; =20 - reloc->sec =3D rsec; symndx =3D reloc_sym(reloc); reloc->sym =3D sym =3D find_symbol_by_index(elf, symndx); if (!reloc->sym) { @@ -1100,6 +1130,7 @@ struct section *elf_create_section(struct elf *elf, c= onst char *name, memset(sec, 0, sizeof(*sec)); =20 INIT_LIST_HEAD(&sec->symbol_list); + INIT_LIST_HEAD(&sec->reloc_list); =20 s =3D elf_newscn(elf->elf); if (!s) { @@ -1170,6 +1201,7 @@ static struct section *elf_create_rela_section(struct= elf *elf, unsigned int reloc_nr) { struct section *rsec; + struct reloc_block *block; char *rsec_name; =20 rsec_name =3D malloc(strlen(sec->name) + strlen(".rela") + 1); @@ -1192,11 +1224,9 @@ static struct section *elf_create_rela_section(struc= t elf *elf, rsec->sh.sh_info =3D sec->idx; rsec->sh.sh_flags =3D SHF_INFO_LINK; =20 - rsec->relocs =3D calloc(sec_num_entries(rsec), sizeof(struct reloc)); - if (!rsec->relocs) { - perror("calloc"); + block =3D alloc_reloc_block(rsec, sec_num_entries(rsec)); + if (!block) return NULL; - } =20 sec->rsec =3D rsec; rsec->base =3D sec; @@ -1204,6 +1234,37 @@ static struct section *elf_create_rela_section(struc= t elf *elf, return rsec; } =20 +int elf_extend_rela_section(struct elf *elf, + struct section *rsec, + int add_relocs) +{ + int newnr =3D sec_num_entries(rsec) + add_relocs; + size_t oldsize =3D rsec->sh.sh_size; + size_t newsize =3D newnr * rsec->sh.sh_entsize; + void *buf; + struct reloc_block *block; + + buf =3D realloc(rsec->data->d_buf, newnr * rsec->sh.sh_entsize); + if (!buf) { + perror("realloc"); + return -1; + } + + memset(buf + oldsize, 0, newsize - oldsize); + + rsec->data->d_size =3D newsize; + rsec->data->d_buf =3D buf; + rsec->sh.sh_size =3D newsize; + + mark_sec_changed(elf, rsec, true); + + block =3D alloc_reloc_block(rsec, add_relocs); + if (!block) + return -1; + + return 0; +} + struct section *elf_create_section_pair(struct elf *elf, const char *name, size_t entsize, unsigned int nr, unsigned int reloc_nr) diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 9f71e988eca4..7851467f6878 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -43,7 +43,8 @@ struct section { char *name; int idx; bool _changed, text, rodata, noinstr, init, truncate; - struct reloc *relocs; + struct list_head reloc_list; + int num_relocs; }; =20 struct symbol { @@ -71,13 +72,23 @@ struct symbol { struct reloc *relocs; }; =20 +struct reloc_block; + struct reloc { struct elf_hash_node hash; - struct section *sec; + struct reloc_block *block; struct symbol *sym; struct reloc *sym_next_reloc; }; =20 +struct reloc_block { + struct list_head list; + struct section *sec; + int start_idx; + int len; + struct reloc relocs[0]; +}; + struct elf { Elf *elf; GElf_Ehdr ehdr; @@ -108,6 +119,11 @@ struct elf *elf_open_read(const char *name, int flags); =20 struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, unsigned int nr); + +int elf_extend_rela_section(struct elf *elf, + struct section *rsec, + int add_relocs); + struct section *elf_create_section_pair(struct elf *elf, const char *name, size_t entsize, unsigned int nr, unsigned int reloc_nr); @@ -197,12 +213,12 @@ static inline unsigned int sec_num_entries(struct sec= tion *sec) =20 static inline unsigned int reloc_idx(struct reloc *reloc) { - return reloc - reloc->sec->relocs; + return reloc->block->start_idx + (reloc - &reloc->block->relocs[0]); } =20 static inline void *reloc_rel(struct reloc *reloc) { - struct section *rsec =3D reloc->sec; + struct section *rsec =3D reloc->block->sec; =20 return rsec->data->d_buf + (reloc_idx(reloc) * rsec->sh.sh_entsize); } @@ -215,7 +231,7 @@ static inline bool is_32bit_reloc(struct reloc *reloc) * Elf64_Rel: 16 bytes * Elf64_Rela: 24 bytes */ - return reloc->sec->sh.sh_entsize < 16; + return reloc->block->sec->sh.sh_entsize < 16; } =20 #define __get_reloc_field(reloc, field) \ @@ -241,7 +257,7 @@ static inline u64 reloc_offset(struct reloc *reloc) static inline void set_reloc_offset(struct elf *elf, struct reloc *reloc, = u64 offset) { __set_reloc_field(reloc, r_offset, offset); - mark_sec_changed(elf, reloc->sec, true); + mark_sec_changed(elf, reloc->block->sec, true); } =20 static inline s64 reloc_addend(struct reloc *reloc) @@ -252,7 +268,7 @@ static inline s64 reloc_addend(struct reloc *reloc) static inline void set_reloc_addend(struct elf *elf, struct reloc *reloc, = s64 addend) { __set_reloc_field(reloc, r_addend, addend); - mark_sec_changed(elf, reloc->sec, true); + mark_sec_changed(elf, reloc->block->sec, true); } =20 =20 @@ -282,7 +298,7 @@ static inline void set_reloc_sym(struct elf *elf, struc= t reloc *reloc, unsigned =20 __set_reloc_field(reloc, r_info, info); =20 - mark_sec_changed(elf, reloc->sec, true); + mark_sec_changed(elf, reloc->block->sec, true); } static inline void set_reloc_type(struct elf *elf, struct reloc *reloc, un= signed int type) { @@ -292,7 +308,46 @@ static inline void set_reloc_type(struct elf *elf, str= uct reloc *reloc, unsigned =20 __set_reloc_field(reloc, r_info, info); =20 - mark_sec_changed(elf, reloc->sec, true); + mark_sec_changed(elf, reloc->block->sec, true); +} + +static inline struct reloc *get_reloc_by_index(struct section *rsec, int i= dx) +{ + struct reloc_block *block; + + list_for_each_entry(block, &rsec->reloc_list, list) { + if (idx < block->len) + return &block->relocs[idx]; + idx -=3D block->len; + } + + return NULL; +} + +static inline struct reloc *first_reloc(struct section *sec) +{ + struct reloc_block *block; + + if (list_empty(&sec->reloc_list)) + return NULL; + + block =3D list_first_entry(&sec->reloc_list, struct reloc_block, list); + return &block->relocs[0]; +} + +static inline struct reloc *next_reloc(struct reloc *reloc) +{ + struct reloc_block *block =3D reloc->block; + + reloc++; + if (reloc < &block->relocs[block->len]) + return reloc; + + if (list_is_last(&block->list, &block->sec->reloc_list)) + return NULL; + + block =3D list_next_entry(block, list); + return &block->relocs[0]; } =20 #define for_each_sec(file, sec) \ @@ -308,15 +363,10 @@ static inline void set_reloc_type(struct elf *elf, st= ruct reloc *reloc, unsigned sec_for_each_sym(__sec, sym) =20 #define for_each_reloc(rsec, reloc) \ - for (int __i =3D 0, __fake =3D 1; __fake; __fake =3D 0) \ - for (reloc =3D rsec->relocs; \ - __i < sec_num_entries(rsec); \ - __i++, reloc++) + for (reloc =3D first_reloc(rsec); reloc; reloc =3D next_reloc(reloc)) =20 #define for_each_reloc_from(rsec, reloc) \ - for (int __i =3D reloc_idx(reloc); \ - __i < sec_num_entries(rsec); \ - __i++, reloc++) + for (; reloc; reloc =3D next_reloc(reloc)) =20 #define OFFSET_STRIDE_BITS 4 #define OFFSET_STRIDE (1UL << OFFSET_STRIDE_BITS) @@ -344,7 +394,7 @@ static inline u32 sec_offset_hash(struct section *sec, = unsigned long offset) =20 static inline u32 reloc_hash(struct reloc *reloc) { - return sec_offset_hash(reloc->sec, reloc_offset(reloc)); + return sec_offset_hash(reloc->block->sec, reloc_offset(reloc)); } =20 #endif /* _OBJTOOL_ELF_H */ --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.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 DA312604BD for ; Fri, 22 Mar 2024 16:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126378; cv=none; b=INLS4peyzxn8x3BTViWNj2XKj88PH1SbSZNYfAHZ45dp6oBVBrfw5x++qpW3BGJ77o08JsLS+wmC3dngszVYbZMgdZsclZN9OXLDvy2ihRhnkC6ZXW7oPjD5SjYcvpIvpdkmt+opJH0cN1+FjGVG/0VqrYnRWwG2M4REJLOmR44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126378; c=relaxed/simple; bh=VR1+nGqlR4FTm7oUOrp5UCygrbh+Wx8G/j58KZi1cVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDzoALDDEy84yH4xkeaxkg9JDDt5s/bkNyo6uQdYUTExYFjW/W3I/A6VDJQSsYDHuWWGSVCTagHcCXO25g2VtzV0RUgjlhijz/ztsce4qkFq92pQi/8kzEkHIrySjuWUSUUKxtsjLCiKM9JVVgjlbK7JmNQt6y5NQRtJLgLmSGY= 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=cH0SSv8w; arc=none smtp.client-ip=209.85.222.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="cH0SSv8w" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-789d0c90cadso153885085a.3 for ; Fri, 22 Mar 2024 09:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126375; x=1711731175; 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=Sroh3+iJ8M197CSoj2xHZgfa/yPhMhF/D1xZhTI7Hb4=; b=cH0SSv8w8KpxGH1GSDlKgpVyyjKUI3acZWO9cLYGWy5boWMOBxgE2ytR9Fw/i0JkSv 9wY4KOJIgW5BlAhc0lFRT4KG/R8v7CAyROvXxsBnNrnuGXEAcuWFO1u7nCyajL6Dg6R8 OQS7bIHcBuUtBlh5fBLPqXBkm1oVA4jZug14rGy2KXI53hWLst6fIAI8kYHP+QIVzdli H4kFvz/CXCbXyQLuUiNdLdcCM2N0yOOnwczUXwjj7zOVf6EYWXTf5wrBhKm0w/LvlddC qcR0cUM0gQggCZ3p9MMZmZMDQ7IMxVsDMRr+Imgu0nLJAnPCn9JglXTWm1dMax3+Hd9w bHxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126375; x=1711731175; 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=Sroh3+iJ8M197CSoj2xHZgfa/yPhMhF/D1xZhTI7Hb4=; b=ZJgH9Jigdozq/B/uxrV8VtUezSNC9CxSBgNenbafPGr8sBXZIuhqqJLAtRKUaVnkI5 fkstbi2OAJV7wCrCnhf7NHyAXmgALf+Hoik7P9RMhByD6+FOMGwG0N5VU5oHQdzRa0Vm 4xQPz18kTpWhREW1pbn25cVj01qUNQjb5BBUqyVFJldEA2Mmil4AwaU/NqrAqnZ46XKI +DrDvRE4f695H4eKjHN4RiiOiOzI+Hg94qhtPu0C7qpit9xLqgJUYvC4O6//RM2NI3mm deENcSaqsuI1P664vJYEizIGkIqEmA9IkbpZscKu91gMhJLtJhAqfR4o+RYlnxCk/59Q 0ISA== X-Gm-Message-State: AOJu0YyyLDk9TueUYN90Qp++pEHoKIEUGgoHFAuVtpUzMEexVc+jg7GM at9DvMjKEIUqHkrt+YvFqTuYlLylWtyUiU4DVOKCI5uwAVq18T9x4uph+mU= X-Google-Smtp-Source: AGHT+IEn9IgchdQoZDhoHK+WO7foFRm6sSI5hWXMZJzSFOTdr4X3oECgPHWN2HOx8u9kj0fskVbZ8Q== X-Received: by 2002:a05:620a:1714:b0:789:f8b3:d89d with SMTP id az20-20020a05620a171400b00789f8b3d89dmr3227492qkb.46.1711126375446; Fri, 22 Mar 2024 09:52:55 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:54 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 07/16] objtool: Convert fixed location stack protector accesses Date: Fri, 22 Mar 2024 12:52:24 -0400 Message-ID: <20240322165233.71698-8-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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. Use objtool to convert these accesses to normal percpu accesses to __stack_chk_guard. Signed-off-by: Brian Gerst --- arch/x86/Kconfig | 4 ++ scripts/Makefile.lib | 2 + tools/objtool/arch/x86/decode.c | 46 +++++++++++++ tools/objtool/arch/x86/special.c | 91 +++++++++++++++++++++++++ tools/objtool/builtin-check.c | 9 ++- tools/objtool/check.c | 12 ++++ tools/objtool/elf.c | 34 +++++++-- tools/objtool/include/objtool/arch.h | 3 + tools/objtool/include/objtool/builtin.h | 2 + tools/objtool/include/objtool/elf.h | 6 ++ 10 files changed, 204 insertions(+), 5 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 88d72227e3cb..121cfb9ffc0e 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -417,6 +417,10 @@ config CC_HAS_SANE_STACKPROTECTOR We have to make sure stack protector is unconditionally disabled if the compiler does not allow control of the segment and symbol. =20 +config STACKPROTECTOR_OBJTOOL + bool + default n + menu "Processor type and features" =20 config SMP diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1bd59b8db05f..6bc4c69a9e50 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -258,6 +258,8 @@ objtool :=3D $(objtree)/tools/objtool/objtool objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) +=3D --hacks=3Djump_label objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) +=3D --hacks=3Dnoinstr objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) +=3D --hacks=3Dskyla= ke +objtool-args-$(CONFIG_STACKPROTECTOR_OBJTOOL) +=3D --hacks=3Dstackprotect= or +objtool-args-$(CONFIG_SMP) +=3D --smp objtool-args-$(CONFIG_X86_KERNEL_IBT) +=3D --ibt objtool-args-$(CONFIG_FINEIBT) +=3D --cfi objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) +=3D --mcount diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index 3a1d80a7878d..583a16b8bf47 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -144,6 +144,18 @@ static bool has_notrack_prefix(struct insn *insn) return false; } =20 +static bool has_gs_prefix(struct insn *insn) +{ + int i; + + for (i =3D 0; i < insn->prefixes.nbytes; i++) { + if (insn->prefixes.bytes[i] =3D=3D 0x65) + return true; + } + + return false; +} + int arch_decode_instruction(struct objtool_file *file, const struct sectio= n *sec, unsigned long offset, unsigned int maxlen, struct instruction *insn) @@ -408,10 +420,44 @@ int arch_decode_instruction(struct objtool_file *file= , const struct section *sec =20 break; =20 + case 0x2b: + case 0x3b: + case 0x39: + if (!rex_w) + break; + + /* sub %gs:0x28, reg */ + /* cmp %gs:0x28, reg */ + /* cmp reg, %gs:0x28 */ + if (has_gs_prefix(&ins) && + modrm_mod =3D=3D 0 && + modrm_rm =3D=3D 4 && + sib_index =3D=3D 4 && + sib_base =3D=3D 5 && + ins.displacement.value =3D=3D 0x28) + { + insn->type =3D INSN_STACKPROTECTOR; + break; + } + + break; + case 0x8b: if (!rex_w) break; =20 + /* mov %gs:0x28, reg */ + if (has_gs_prefix(&ins) && + modrm_mod =3D=3D 0 && + modrm_rm =3D=3D 4 && + sib_index =3D=3D 4 && + sib_base =3D=3D 5 && + ins.displacement.value =3D=3D 0x28) + { + insn->type =3D INSN_STACKPROTECTOR; + break; + } + if (rm_is_mem(CFI_BP)) { =20 /* mov disp(%rbp), reg */ diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 4134d27c696b..020b6040c487 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -3,6 +3,9 @@ =20 #include #include +#include +#include +#include =20 #define X86_FEATURE_POPCNT (4 * 32 + 23) #define X86_FEATURE_SMAP (9 * 32 + 20) @@ -137,3 +140,91 @@ struct reloc *arch_find_switch_table(struct objtool_fi= le *file, =20 return rodata_reloc; } + +/* + * Convert op %gs:0x28, reg -> op __stack_chk_guard(%rip), reg + * op is MOV, SUB, or CMP. + * + * This can be removed when the minimum supported GCC version is raised + * to 8.1 or later. + */ +int arch_hack_stackprotector(struct objtool_file *file) +{ + struct section *sec; + struct symbol *__stack_chk_guard; + struct instruction *insn; + + int i; + + __stack_chk_guard =3D find_symbol_by_name(file->elf, "__stack_chk_guard"); + + for_each_sec(file, sec) { + int count =3D 0; + int idx; + struct section *rsec =3D sec->rsec; + + sec_for_each_insn(file, sec, insn) { + if (insn->type =3D=3D INSN_STACKPROTECTOR) + count++; + } + + if (!count) + continue; + + if (!__stack_chk_guard) + __stack_chk_guard =3D elf_create_undef_symbol(file->elf, "__stack_chk_g= uard"); + + if (!rsec) { + idx =3D 0; + rsec =3D sec->rsec =3D elf_create_rela_section(file->elf, sec, count); + } else { + idx =3D sec_num_entries(rsec); + if (elf_extend_rela_section(file->elf, rsec, count)) + return -1; + } + + sec_for_each_insn(file, sec, insn) { + unsigned char *data =3D sec->data->d_buf + insn->offset; + + if (insn->type !=3D INSN_STACKPROTECTOR) + continue; + + if (insn->len !=3D 9) + goto invalid; + + /* Convert GS prefix to DS if !SMP */ + if (data[0] !=3D 0x65) + goto invalid; + if (!opts.smp) + data[0] =3D 0x3e; + + /* Set Mod=3D00, R/M=3D101. Preserve Reg */ + data[3] =3D (data[3] & 0x38) | 5; + + /* Displacement 0 */ + data[4] =3D 0; + data[5] =3D 0; + data[6] =3D 0; + data[7] =3D 0; + + /* Pad with NOP */ + data[8] =3D 0x90; + + if (!elf_init_reloc_data_sym(file->elf, sec, insn->offset + 4, idx++, _= _stack_chk_guard, -4)) + return -1; + + continue; + +invalid: + fprintf(stderr, "Invalid stackprotector instruction at %s+0x%lx: ", sec= ->name, insn->offset); + for (i =3D 0; i < insn->len; i++) + fprintf(stderr, "%02x ", data[i]); + fprintf(stderr, "\n"); + return -1; + } + + mark_sec_changed(file->elf, sec, true); + } + + return 0; +} diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 5e21cfb7661d..0ab2efb45c0e 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c @@ -62,12 +62,17 @@ static int parse_hacks(const struct option *opt, const = char *str, int unset) found =3D true; } =20 + if (!str || strstr(str, "stackprotector")) { + opts.hack_stackprotector =3D true; + found =3D true; + } + return found ? 0 : -1; } =20 static const struct option check_options[] =3D { OPT_GROUP("Actions:"), - OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ", "patch toolchain bugs/limitations", parse_hacks), + OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake= ,stackprotector", "patch toolchain bugs/limitations", parse_hacks), OPT_BOOLEAN('i', "ibt", &opts.ibt, "validate and annotate IBT"), OPT_BOOLEAN('m', "mcount", &opts.mcount, "annotate mcount/fentry calls fo= r ftrace"), OPT_BOOLEAN('n', "noinstr", &opts.noinstr, "validate noinstr rules"), @@ -94,6 +99,7 @@ static const struct option check_options[] =3D { OPT_BOOLEAN(0, "sec-address", &opts.sec_address, "print section addresses= in warnings"), OPT_BOOLEAN(0, "stats", &opts.stats, "print statistics"), OPT_BOOLEAN('v', "verbose", &opts.verbose, "verbose warnings"), + OPT_BOOLEAN(0, "smp", &opts.smp, "building an SMP kernel"), =20 OPT_END(), }; @@ -133,6 +139,7 @@ static bool opts_valid(void) { if (opts.hack_jump_label || opts.hack_noinstr || + opts.hack_stackprotector || opts.ibt || opts.mcount || opts.noinstr || diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0a2c161fc04d..0056dd99ff7f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1315,6 +1315,11 @@ __weak bool arch_is_embedded_insn(struct symbol *sym) return false; } =20 +__weak int arch_hack_stackprotector(struct objtool_file *file) +{ + return 0; +} + static struct reloc *insn_reloc(struct objtool_file *file, struct instruct= ion *insn) { struct reloc *reloc; @@ -4824,6 +4829,13 @@ int check(struct objtool_file *file) warnings +=3D ret; } =20 + if (opts.hack_stackprotector) { + ret =3D arch_hack_stackprotector(file); + if (ret < 0) + goto out; + warnings +=3D ret; + } + free_insns(file); =20 if (opts.verbose) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index cfb970727c8a..2af99b2a054c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -846,6 +846,32 @@ elf_create_prefix_symbol(struct elf *elf, struct symbo= l *orig, long size) return sym; } =20 +struct symbol * +elf_create_undef_symbol(struct elf *elf, const char *sym_name) +{ + struct symbol *sym =3D calloc(1, sizeof(*sym)); + char *name =3D strdup(sym_name); + + if (!sym || !name) { + perror("malloc"); + return NULL; + } + + sym->name =3D name; + sym->sec =3D find_section_by_index(elf, 0); + + sym->sym.st_name =3D elf_add_string(elf, NULL, name); + sym->sym.st_info =3D GELF_ST_INFO(STB_GLOBAL, STT_NOTYPE); + sym->sym.st_value =3D 0; + sym->sym.st_size =3D 0; + + sym =3D __elf_create_symbol(elf, sym); + if (sym) + elf_add_symbol(elf, sym); + + return sym; +} + static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, unsigned int reloc_idx, unsigned long offset, struct symbol *sym, @@ -924,7 +950,7 @@ struct reloc *elf_init_reloc_data_sym(struct elf *elf, = struct section *sec, struct symbol *sym, s64 addend) { - if (sym->sec && (sec->sh.sh_flags & SHF_EXECINSTR)) { + if (sym->sec && (sym->sec->sh.sh_flags & SHF_EXECINSTR)) { WARN("bad call to %s() for text symbol %s", __func__, sym->name); return NULL; @@ -1196,9 +1222,9 @@ struct section *elf_create_section(struct elf *elf, c= onst char *name, return sec; } =20 -static struct section *elf_create_rela_section(struct elf *elf, - struct section *sec, - unsigned int reloc_nr) +struct section *elf_create_rela_section(struct elf *elf, + struct section *sec, + unsigned int reloc_nr) { struct section *rsec; struct reloc_block *block; diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/o= bjtool/arch.h index 0b303eba660e..c60fec88b3af 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -28,6 +28,7 @@ enum insn_type { INSN_CLD, INSN_TRAP, INSN_ENDBR, + INSN_STACKPROTECTOR, INSN_OTHER, }; =20 @@ -96,4 +97,6 @@ int arch_rewrite_retpolines(struct objtool_file *file); =20 bool arch_pc_relative_reloc(struct reloc *reloc); =20 +int arch_hack_stackprotector(struct objtool_file *file); + #endif /* _ARCH_H */ diff --git a/tools/objtool/include/objtool/builtin.h b/tools/objtool/includ= e/objtool/builtin.h index fcca6662c8b4..5085d3135e6b 100644 --- a/tools/objtool/include/objtool/builtin.h +++ b/tools/objtool/include/objtool/builtin.h @@ -13,6 +13,7 @@ struct opts { bool hack_jump_label; bool hack_noinstr; bool hack_skylake; + bool hack_stackprotector; bool ibt; bool mcount; bool noinstr; @@ -38,6 +39,7 @@ struct opts { bool sec_address; bool stats; bool verbose; + bool smp; }; =20 extern struct opts opts; diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 7851467f6878..b5eec9e4a65d 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -120,6 +120,10 @@ struct elf *elf_open_read(const char *name, int flags); struct section *elf_create_section(struct elf *elf, const char *name, size_t entsize, unsigned int nr); =20 +struct section *elf_create_rela_section(struct elf *elf, + struct section *sec, + unsigned int reloc_nr); + int elf_extend_rela_section(struct elf *elf, struct section *rsec, int add_relocs); @@ -130,6 +134,8 @@ struct section *elf_create_section_pair(struct elf *elf= , const char *name, =20 struct symbol *elf_create_prefix_symbol(struct elf *elf, struct symbol *or= ig, long size); =20 +struct symbol *elf_create_undef_symbol(struct elf *elf, const char *sym_na= me); + struct reloc *elf_init_reloc_text_sym(struct elf *elf, struct section *sec, unsigned long offset, unsigned int reloc_idx, --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.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 F2396604DA for ; Fri, 22 Mar 2024 16:52:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126379; cv=none; b=i67ciJISf2qtfPFdx0iMoAxlFwVIROO+s3DctpGZzCs8KsGlSUSPJf1Sj1MIp1BnZQy+w3cIFXUfLlkwt5HCIYAzVSZ8K9aaet9wXZjFitUThO0eqZkbRUXypOyXLPz1WCg55LD/Itq+c7Zm6csHmXC5kdNeLI+7RMtoIUniW90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126379; c=relaxed/simple; bh=ZQ683fxTBC0cltc7iuh7WXmR5+v1UXe5xO6cUtiL1iM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K10gMy4D5HuHeHqoatKK1T/Hha9NbKpRRW+9rqddd4TLb4oYESaxFFcCnk9ZibhdAuDlObYY8UxsJGSy0obsl0/SiNVWv7hsEqQV7pPdNsBtEFYTJtwgOrU3fZgO8veYGAbwU10AP8a3hwBx9T+LevhVhxeAGMIQY9Tr7VYxkRc= 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=gcHgopvo; arc=none smtp.client-ip=209.85.222.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="gcHgopvo" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-789e6ceaff1so317882585a.0 for ; Fri, 22 Mar 2024 09:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126376; x=1711731176; 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=MY5D337qL3lZHb49Uvgq3uHMbzigT03YWvbgK9Cha9Y=; b=gcHgopvoIKCBEk0IdWYau+gBKs866DoiSgw608FLNEPViCWbdwlYsSukK0CkHxHy8P bnHunt+ukvdgJ421e8Axzj0RmaNpa49lWO3WwDMrTciqiLmpa+6HbVaQb09bpWssNa71 DLFUenXDdbH1H2Anc2BtDJN4WeyNA52G+HnZea8JMvc2zqo4kahNw+qitDc1xr2eeGIf 0WmPwpUqyGU+kebF1m1P0G9RIOaTDV65TPbFeACFX5tbEgUEdF6bXari0vqAoiwlrKk5 7YrPWtARxn1xmij9etrp92dTT285urOsABhv6d+YmL6WWHE5mmEBEECouhfxeuY84kkQ ehMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126376; x=1711731176; 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=MY5D337qL3lZHb49Uvgq3uHMbzigT03YWvbgK9Cha9Y=; b=TOVYyhAJvBUWNSNbC2vaQBdfzbMlu72sab1MYjL+K9Fck7wXDtwvNMMk7DBGSVEM8d AqGBq3lKOyZXQKJgJ/NZdZJ4xiJk7ne+Pw0NWBcx+vHAikiw7kPUmiRu6fjL/JQCNJEY pcqhaL+nVDuscsWFVwAn9j2gS1M3eaCES58S6DykxF5AsGmoiAHoC1v34GzCzvNknA9/ AQxt5AmKqBZvmmyVrdwv26GNYqtxrgyg6DORJgPZvZR9Y0Cde00CRoEuMbGVs+CBpFCS rTomHM6dlAnWXz86lVPlLsQrDDtdPm1sgBN2j/SlT87RY6t+Qwk4bsnWHQI50E/j86sC SaEg== X-Gm-Message-State: AOJu0YxECrvBF03Yr+TZEnqjW4xlOhu0NKJDS5yqbe6nwAnX7jB6syEO cpbuYgxXZdDbhGWt9djDFFBXoaEQvRswRa+xblOuQs4VJgrVe/XhSabmxZk= X-Google-Smtp-Source: AGHT+IH0WfM67NC7jA3maIyhtYVDQwTjD+v0j92xOZqBFhEx6T+xxxJvv1GDFUqAjoP5wz43jlvS5A== X-Received: by 2002:a05:620a:4953:b0:789:f80d:4625 with SMTP id vz19-20020a05620a495300b00789f80d4625mr212092qkn.12.1711126376585; Fri, 22 Mar 2024 09:52:56 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:56 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 08/16] x86/stackprotector/64: Convert to normal percpu variable Date: Fri, 22 Mar 2024 12:52:25 -0400 Message-ID: <20240322165233.71698-9-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 virtual address 0 so that the canary could be the first data object in the percpu section. Supporting the zero-based percpu section requires additional code to handle relocations for RIP-relative references to percpu data, extra complexity to kallsyms, and workarounds for linker bugs due to the use of absolute symbols. Use compiler options to redefine the stack protector location if supported, otherwise use objtool. This will remove the contraint that the percpu section must be zero-based. Signed-off-by: Brian Gerst Reviewed-by: Uros Bizjak --- arch/x86/Kconfig | 11 ++++---- arch/x86/Makefile | 21 ++++++++++------ 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, 30 insertions(+), 73 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 121cfb9ffc0e..3dbefdb8a5d6 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -271,7 +271,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 if X86_64 || CC_HAS_SANE_STACKPROTECTOR select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL @@ -411,15 +411,14 @@ config PGTABLE_LEVELS =20 config CC_HAS_SANE_STACKPROTECTOR bool - default y if 64BIT + default $(cc-option,-mstack-protector-guard-reg=3Dgs -mstack-protector-gu= ard-symbol=3D__stack_chk_guard) if 64BIT default $(cc-option,-mstack-protector-guard-reg=3Dfs -mstack-protector-gu= ard-symbol=3D__stack_chk_guard) - help - We have to make sure stack protector is unconditionally disabled if - the compiler does not allow control of the segment and symbol. =20 config STACKPROTECTOR_OBJTOOL bool - default n + depends on X86_64 && STACKPROTECTOR + default !CC_HAS_SANE_STACKPROTECTOR + prompt "Debug objtool stack protector conversion" if CC_HAS_SANE_STACKPRO= TECTOR && DEBUG_KERNEL =20 menu "Processor type and features" =20 diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 662d9d4033e6..2a3ba1abb802 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -116,13 +116,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-g= uard-symbol=3D__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 @@ -172,6 +166,19 @@ 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) + ifneq ($(CONFIG_STACKPROTECTOR_OBJTOOL),y) + ifeq ($(CONFIG_SMP),y) + KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3D$(percpu_seg) + KBUILD_CFLAGS +=3D -mstack-protector-guard-symbol=3D__stack_chk_guard + else + KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal + endif + endif endif =20 # diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 8af2a26b24f6..9478ff768dd0 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -191,7 +191,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 89ed5237e79f..946bebce396f 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -387,16 +387,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; @@ -411,11 +403,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 9a34651d24e7..f49e8f5b858d 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2063,16 +2063,13 @@ 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); EXPORT_PER_CPU_SYMBOL(__stack_chk_guard); #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 b11526869a40..cfbf0486d424 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 758bcd47b72d..ae4672ea00bb 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -53,8 +53,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.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 8AFA2605B3 for ; Fri, 22 Mar 2024 16:52:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126381; cv=none; b=Ak/42WoqzI6+MCzZHLL4f6U/cckNwVVHSmgMEFFv7iFFAPbPIQtcvfjqLhnn6/nNznszidzPHICiWvj5qEr63tdwSJi/6mw69a47FZJ3VLdjjllnGQPDZVKNMA0bqdNWvqQkGXd51E/TRcQJO4xF/IVnX3T5nIu7p0CJUCOwY2o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126381; c=relaxed/simple; bh=w74KHiO+YST9ARW1jHTpRqiePbvHH2TmcOuZXl0KFiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wzk8dU/BF4uFUccgAe00XwSHKyGcOPOS8/9ZmWYWyzBmN8XqMUzuMZmDpLi74Of/eLzbHmcUxrCZNEIDZO4m4E/MlDod7NLFIoovYSEUqTmEt/xBlRlN2VasYicsdYE/AYNbKFzPC6A8AG8F1CYUazrUOifbiGL0kL5jh9mDS0E= 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=jcaeD4vo; arc=none smtp.client-ip=209.85.222.178 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="jcaeD4vo" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78a15537fa1so140542785a.1 for ; Fri, 22 Mar 2024 09:52:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126378; x=1711731178; 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=W92Rk8kM7/AXvQoVC7dyXuqJmhy1XSFxQGTPsQsT0t4=; b=jcaeD4voozas/8GrhH/lTqgNPu/M6j/3a9pDH/vzThW7OmOWXnOAvh2e3+zEQLu47M k+IJYC8JNcyI4X+uLqpmtXCBequgmEPjp8p4EdcWpDbPlFBtQjl3Bh/Pkoz3Rc2j6BZi eWqCivx4Z+ckgu84WaGkEhtN5FzulHA6qE1w1MthEWJegdqoZdLzzKeux1hIQL9M6T6L gqRYhfHbap9Hov/lYxZd6ozHDjtbij+Ohg8APydE/APdX6fXIZ+KHRsAJ+YaXlhlmWTF htwL9vY/XLMuTPaTJ12NAMYj2bw6WIyRMPV64hBYIX1Vc61/68D3qxY8Y0WwaUOjnPzp xJNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126378; x=1711731178; 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=W92Rk8kM7/AXvQoVC7dyXuqJmhy1XSFxQGTPsQsT0t4=; b=hMrtShVfvf7UhTz5P9cMzp4p63X3/pey7xgsGl3rDngmSLMpBc8salEb1ngt0fxTx6 i+tgfcvEHK0GSlMxJJWO0382dK2+PCOfDDTHMncCsO+7Awmev9Wgpea3XnQOD1sWoQmW 8sSo4x2PVGJGJppHtgbzdHmRPkgv6IA6x4RqYs9b+YgkCnCA4L9xcmozq5LnnsJjoYK/ SlQgVpje8xzr26qFKxA5GT0isv4xKJUOFVu0B7JqHAltjniZNcy0+mEeW4+e9RHUkI65 BsYp4QJo9Fc81DEuBmY9mkp2TlXkOO1v4BknZ0bLkTc72mDFO0O/SlMwAq4gfW/wEQNu sPDw== X-Gm-Message-State: AOJu0YzMdaY2bowcAPQClJsbx5S9s9NWyy1y+oaeGv8Ocau6HMRvJVrO EG+hE0Gk+gNa89/Wob+YcvHuokHLWfgYjAWN1vjd3zmweB9PgO2Y4PFTI8A= X-Google-Smtp-Source: AGHT+IFOfu8nOq3c30WzRZvtC4ZlrrvO2Eepx/p6GBhCRoKI3ql1SDQRkNJcDPE0t07IpcYeysSlvQ== X-Received: by 2002:a05:620a:7ed:b0:78a:3fa5:9f30 with SMTP id k13-20020a05620a07ed00b0078a3fa59f30mr8685qkk.14.1711126377705; Fri, 22 Mar 2024 09:52:57 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:57 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 09/16] x86/percpu/64: Use relative percpu offsets Date: Fri, 22 Mar 2024 12:52:26 -0400 Message-ID: <20240322165233.71698-10-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 virtual address 0, because older compilers hardcoded the stack protector canary value at a fixed offset from the start of the GS segment. Now that the canary is a normal percpu variable, the percpu section does not need to be linked at a specific virtual address. This means that x86-64 will calculate percpu offsets like most other architectures, as the delta between the initial percpu address and the dynamically allocated memory. Signed-off-by: Brian Gerst 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 946bebce396f..40d6add8ff31 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -396,7 +396,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 cfbf0486d424..5b2cc711feec 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -68,11 +68,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 3509afc6a672..0b152f96c24e 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -99,12 +99,6 @@ const_pcpu_hot =3D pcpu_hot; 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 @@ -222,21 +216,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 @@ -353,9 +333,7 @@ SECTIONS EXIT_DATA } =20 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP) PERCPU_SECTION(INTERNODE_CACHE_BYTES) -#endif =20 . =3D ALIGN(PAGE_SIZE); =20 @@ -493,16 +471,11 @@ SECTIONS * Per-cpu symbols which need to be offset from __per_cpu_load * for the boot processor. */ -#define INIT_PER_CPU(x) init_per_cpu__##x =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 1f1c3230b27b..7e3e07c6170f 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -101,9 +101,8 @@ SYM_CODE_START_LOCAL(pvh_start_xen) * the per cpu areas are set up. */ mov $MSR_GS_BASE,%ecx - lea INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx - mov %edx, %eax - shr $32, %rdx + xor %eax, %eax + xor %edx, %edx wrmsr =20 call xen_prepare_pvh diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index adf11a48ec70..016650ddaf7f 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -839,12 +839,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 @@ -1068,7 +1063,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 ae4672ea00bb..1796884b727d 100644 --- a/arch/x86/xen/xen-head.S +++ b/arch/x86/xen/xen-head.S @@ -51,15 +51,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 f3ea5dea9c85..0f928f82dc7a 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1784,7 +1784,7 @@ config KALLSYMS_ALL config KALLSYMS_ABSOLUTE_PERCPU bool depends on KALLSYMS - default X86_64 && SMP + default n =20 config KALLSYMS_BASE_RELATIVE bool --=20 2.44.0 From nobody Sat Feb 7 20:47: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 73DAF605C1 for ; Fri, 22 Mar 2024 16:53:00 +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=1711126382; cv=none; b=KpnVpTp71CHM689eGsN5By9yBFoMR6BkURHdEgpnrE8c01pKoddPGoXyMUYG+pwVGQ1Qqz9WftfJ4wGxncRGsvOBndPWlCJGn3Hdr6HFOA0uO+Yah1Tyw9KcVTqDo1fWmQ7MYJAIjnZsGFR87vAXqOZpd25pE8gypkrKC4oAN6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126382; c=relaxed/simple; bh=avYapo0EFqaCq2WtjSTlPyiOsoi1q9qa0+9WdAJqEy8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dqcwna5OBLfOi4XGWEs2Ay7swd5zB3U7WElCtu62u50ykVJjQtb4tZW8KpO3hGeWt+bIQC7WNxwkZ8bjp6X54zRXGlhWCYbJobKuJ4cKX2YUcebpnDm1yxa8bC9mvVdm2k0uyy1S8kz2GlzHrI3MmqajyFufnQEhz6BqiqB+0Ws= 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=bX44u9Et; 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="bX44u9Et" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78a2093cd44so187344485a.0 for ; Fri, 22 Mar 2024 09:53:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126379; x=1711731179; 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=Y0pfakbWaglqIoATRtXvgwUhPasnZ0G2B+uvX65Dwq4=; b=bX44u9Et+WQQ7YgLCEFOZZZx3mljnf8qoMXBkacOQwBYKDm5hr+RnN0VY/3dPrj3Qm PA7OR7bUSGvVB0YDOWOSnCAeAHXWbZ1pfEX3iXGd4YH/mC8bdUAy6kbOZLc11QdcY7Xz UqYV1pBsAhg2tMc1ZjJ4YCmTm+JuUeBY2AxdpIz9Xxfg6GtOmp+n/w3aT89kk8UZq6Rc GuwmbC5vrs2d1hVn4u+G6OmrhELZMHNQobn/p4bKv7rkZiEGuKiJJ0t9VrHjKr5E8H7D I9vtiOGgN8rvu9yI4IIye3fZ2xnQ9qHsW4mXsLC8bniI08Osg/Uug7YJPwP8ntkRFsMM Ntqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126379; x=1711731179; 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=Y0pfakbWaglqIoATRtXvgwUhPasnZ0G2B+uvX65Dwq4=; b=k192oLZILwXI6n10hjrVr1g20ERQwt6PLBTc8VtUJUvQCO1mFw0EPkEZhKV/dp8E21 LANlOw6tf4Wvo9cvqA8YWf+JQnk+fT038GlVORWOzil2VI8+1mOVTSXolaBvYTsJ9wYm bYbhNsEdRrtb1oSfBHDKEpv+jGoofbjhIO3nc5NqYZOSecYhzZVCx0A96uVwHnyrMuNc SGrspNfFjG5NwKuFbx/5ABDaRt1dQmIz2aEGALyJljAuXz7TKTywl0ZCRNbPBfkFyPFR YDeL2RXxz5PEewhME6IDtKbZ4J0FlLGL/yvYnPn31EySoNBpcOzilTO2dnoaoogbM6UY coEw== X-Gm-Message-State: AOJu0YwePNK29HuuR3M9O1AcHOYNUtKTiQFwXpjMcmyJfK+zE3AXzUnt txaxoL2Zjocnc7sPmziLeMSn2JO4qCC8UZFCmUp64H1emCJBVCxGIYeYWsU= X-Google-Smtp-Source: AGHT+IF0AAdlE4uIoVz7sxvN8rbXVr8QSHh1wK0otrEBF/dPfTo3pmBesRKuaCdH27sU11LYp/AlUQ== X-Received: by 2002:a05:620a:a1d:b0:789:d43b:3702 with SMTP id i29-20020a05620a0a1d00b00789d43b3702mr2598412qka.59.1711126379139; Fri, 22 Mar 2024 09:52:59 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:58 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 10/16] x86/percpu/64: Remove fixed_percpu_data Date: Fri, 22 Mar 2024 12:52:27 -0400 Message-ID: <20240322165233.71698-11-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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: 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 40d6add8ff31..1f15a7bee876 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -386,14 +386,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 f49e8f5b858d..395a8831d507 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1997,10 +1997,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 0b152f96c24e..667202ebd37f 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -473,7 +473,6 @@ SECTIONS */ #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 016650ddaf7f..65e6f3d6d890 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -834,7 +834,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.44.0 From nobody Sat Feb 7 20:47: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 A3CCF5FB86 for ; Fri, 22 Mar 2024 16:53:01 +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=1711126383; cv=none; b=icTBFSZzpZ1NVAIuzLk1oXRQxsE9TJSSxygTMC2PdP0CXUWVnXcdyCBG/XGTkwvpQ87akuDfgJkoJEqtSmtHwppUwwdi6r9gKba6lWCtpEliWilsudAA7P44hfU/9CikRIxEHYL3WcdI4qO8Y0TJMC9z23Uwn2VZttHHg4tMOwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126383; c=relaxed/simple; bh=OYUzYLr+7DFc0Yg8XJUmqtJvSULKfoOk7CEJH8QvPOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IighiEP//NAnYOhg1mXv4GyJfaV/iUCdkBtefNo1cuPUtUge8X9Y5WimcApYfBhm8wnhyRh8/qcEVQT1RrRBLa7jjVhv2sCkLAE7kb0dKa+UCo9hz4tQnFXayGnKLP5xSFLYS7B01J9Rb+S6DBQMwQjip7WqC3qtq5IcSXGqzho= 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=RiM1cQGD; 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="RiM1cQGD" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-789db18e24eso154501685a.1 for ; Fri, 22 Mar 2024 09:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126380; x=1711731180; 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=QVeh0+wAyXSYjyC1NzNd5L1fFSfCLsOJXPOqL3R9BXM=; b=RiM1cQGDDFvd8fy7WvcCc2E5/c3kPShmWa+NEFP7jEq9mqE4ow/jAFg+RRG8pYrVsb zKrOUoPUZP8e2lFK9S4sG9rVJKZKVQwBTrvpXK1Tpd3TPRKlOmwz+IryI97r4as6G/Jw FSehRcOtZhp+YNdaheHbK+Y4R3jV1FeCXP3oNAjuq+vCYCBS6hdEOdFfVbS8PCY4hHGC DV0WKJt9JRM4StJB3e5832Qb5tjE8Z1yPwrtUc3cMKsP70fxv5JEPkcflyQ3rpDXI5iM stkcpqJ2nWx25csTS6KHF1OOyyYV/dwpVTs/9ky4KOOuwplvjkwrb2LdW/4bwXFnKHt1 Uh6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126380; x=1711731180; 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=QVeh0+wAyXSYjyC1NzNd5L1fFSfCLsOJXPOqL3R9BXM=; b=VR4sQLiZFveVPIjMNGePcoZGrsKLp8oPRcyI4TjBdRSqMvN4ASsv6ewb324N/ncJTp 0gy2gv8g2QVvhRHWIE2rOQXVN6n5rwm9W+kpH7LHObKjtYRnAk2m5ObscgXwMLwCcA5c yD8JTipsmRfwtaLgLf62uFmj4dqazByPKCnmEJuI4ia8CR8ZONU6apx6gA6922MXNzaF FlX9/8oZ3E7AE0xkakVVvGSraIXfYQPiedHgpIa6q/2FFvJEmfcTylRLMwAM3YiTNn21 s0eBXNDTGeGYT5rfjsuPJkWgGnTYsT3HPcmGx5mLQenRIwrAOy/YSFKLyLhektuMroIP KjXA== X-Gm-Message-State: AOJu0YxUwKfU9Hmh5EIccJiNzjTzbSkTkeukMyMHEpdMu+QV75ON1361 il9ztBlRFOzWnbKKqhB+tY7uXCi4VzZLuFm6Q5G3BnO2Ij99M89aU4CMYeY= X-Google-Smtp-Source: AGHT+IHTSl3k0/ZKKffxZcJ/Pvsut4x1mP3K7EcGRwm++0TiWkLAR4DWO11FqlpIfkF1jSsbEAIFRQ== X-Received: by 2002:a37:ef01:0:b0:788:41d6:14cb with SMTP id j1-20020a37ef01000000b0078841d614cbmr3908qkk.24.1711126380355; Fri, 22 Mar 2024 09:53:00 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.52.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:52:59 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 11/16] x86/boot/64: Remove inverse relocations Date: Fri, 22 Mar 2024 12:52:28 -0400 Message-ID: <20240322165233.71698-12-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- arch/x86/boot/compressed/misc.c | 14 +--- arch/x86/tools/relocs.c | 126 +------------------------------- 2 files changed, 2 insertions(+), 138 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index b70e4a21c15f..371288202268 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 65e6f3d6d890..e490297a486b 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -28,7 +28,6 @@ struct relocs { static struct relocs relocs16; static struct relocs relocs32; #if ELF_BITS =3D=3D 64 -static struct relocs relocs32neg; static struct relocs relocs64; #define FMT PRIu64 =20 @@ -89,7 +88,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 @@ -287,33 +285,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) @@ -773,75 +744,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) { @@ -852,12 +756,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. */ @@ -867,33 +765,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", - symname); 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 @@ -1107,7 +993,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); @@ -1139,13 +1024,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 */ @@ -1196,8 +1074,6 @@ void process(FILE *fp, int use_real_mode, int as_text, read_strtabs(fp); read_symtabs(fp); read_relocs(fp); - if (ELF_BITS =3D=3D 64) - percpu_init(); if (show_absolute_syms) { print_absolute_symbols(); return; --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 2BB0A6086C for ; Fri, 22 Mar 2024 16:53:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126384; cv=none; b=DDN+7fVETX4UFylMgOP+DltciwKhKcQhMGEqHrqie+lZo+lTumXRnB42hL4a387mqss87ISmt/H1kI+Tr+9nKwe6R8z7uRKfFZPsZjV/yoQHb4kFJ3O4y4T/l4z6OtjydeMv9T49VuavUk/w8k0Blhmq+REPXyMkypK9Euo0C3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126384; c=relaxed/simple; bh=8ZtYCXtgnnwm7AtoyNUej+XZO1HFRBmoCJyDMs9VzX4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aLSWaLHx5QndpepUjpbNuGl60vdMVfMSntRLRfyg7kEGtBLePAzoJAoMtR4D3aEW6vCDEx863fTQh/8qXmBTzOTnajm6JwGIQKM8ea8ENVlqQ4NjbMoHqaWonN0Id6WsalVMTl99fl2Gt9H3S2BMC5rHepiMVLfGgrnldNvlIvs= 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=fcb9jEp5; arc=none smtp.client-ip=209.85.210.48 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="fcb9jEp5" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6e674136ba4so1363484a34.2 for ; Fri, 22 Mar 2024 09:53:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126381; x=1711731181; 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=oHxT6FSxev8VQpBaoe+RR19/PxZNROcYVuEUEA5+ZXs=; b=fcb9jEp5eoM1QtSz6uVxjy5n8nsfoZurQ1Pc70iuxX9xRD/dzbeDtQmuF1NLwH8Fja HuvYEypLL6ut5uo6RGhyvouz7VX6KWFtiyBVoDiHQj2jMsLrGhcLcM2loIBC3iAPQ1hq g7YOTZ+JxyRR/HSvNQVUIfZD43o6rO1wG3ReqmQ03Rue7fzTCAMZq09fV/BDlKzS8jaD FILvcZzj5badAva+C6qarsangeDf0KjOxkpqZh8CNvc6PLPhyu5jfriIFDlY/lb6dmeg tf5ulVuGdM/g96Zfd10Pc53/z7vZpApyklgaa9C7MbK0MWkuaXwBbMKFnvqrUS5Q9lmw fAZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126381; x=1711731181; 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=oHxT6FSxev8VQpBaoe+RR19/PxZNROcYVuEUEA5+ZXs=; b=G2IZ1gT9z8bnxnlOZIbkj24xJz7W+//aU8C5jzWupnLY79O293PuEQRBEldTYnNTi2 qEpUkcr2gAdaUlXv2o0+zEId4e3mIOUV+KlzBGG650GY12Wr0elgIsG0CeX4wJPfnq7x 9eOYfoJWS3WR8GotmHjf0VX2aDEbhqvkZrvLDdJPmqOqdr41Wt2ktu2bjtGesohnQy3j 68z6Gh/fDDNOmuWYKxkVRMsKhGFLszydwV9sT7ABVT3mr9cRcHlMckIhOLqCNEvu0jkB TYjBgASD6nDQ/iXsAEZTeFvD/4oPCUFSzSM4CESxvbxNvUplkZQWT8DsOwL3KppRim73 QAmw== X-Gm-Message-State: AOJu0Yz+Y+tcZKFQaEBQsP+yP3wujtTEjutQ7S1IyDLfrHFBnEfbNBli MUzLEmQzUJ7pnPSb+QNzz6PhyqQWZ0sw645vY7ABq++vIbyb9KLOvV9xT6s= X-Google-Smtp-Source: AGHT+IFBIHRFPbnRJdlLPiZbQQMDkOQWh+QBM3w28nze8664BF4d6w4st8UmlHwoTeYt494QQGMHOQ== X-Received: by 2002:a9d:7696:0:b0:6e6:80da:c34f with SMTP id j22-20020a9d7696000000b006e680dac34fmr199579otl.32.1711126381497; Fri, 22 Mar 2024 09:53:01 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.53.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:53:01 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 12/16] x86/percpu/64: Remove INIT_PER_CPU macros Date: Fri, 22 Mar 2024 12:52:29 -0400 Message-ID: <20240322165233.71698-13-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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: 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 f6ddbaaf80bc..59d91fdfe037 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 @@ -101,22 +95,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). */ =20 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 212e8e06aeba..5f0523610e92 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -564,7 +564,7 @@ void __head startup_64_setup_gdt_idt(void) void *handler =3D NULL; =20 struct desc_ptr startup_gdt_descr =3D { - .address =3D (unsigned long)&RIP_REL_REF(init_per_cpu_var(gdt_page.gdt)), + .address =3D (unsigned long)&RIP_REL_REF(gdt_page.gdt), .size =3D GDT_SIZE - 1, }; =20 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c index fe0c859873d1..30424f9876bc 100644 --- a/arch/x86/kernel/irq_64.c +++ b/arch/x86/kernel/irq_64.c @@ -26,7 +26,6 @@ #include =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 667202ebd37f..8d5bf4a71e39 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -467,13 +467,6 @@ SECTIONS "kernel image bigger than KERNEL_IMAGE_SIZE"); =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 e490297a486b..8db231affba2 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -88,7 +88,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 "__vvar_page|" --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (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 B06B0608FD for ; Fri, 22 Mar 2024 16:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126386; cv=none; b=i6flPHql5fRazLSm2oEL78TsELtaOtsbjg35JiZF+DXps7i7Rz5+khWPZyS1BX/F4JYnmM4sbbSscZ4zfNStvA7hvnKlShuDDgupT+uPVxJm6vAlILke+pYxALpjMyF495ou5VKxgSmsyYlr95hooCQzPgb7nQR+QLTtcF0tTBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126386; c=relaxed/simple; bh=1igDXVcGgPluBlHDLoIaqQCElcppshSoQ7wAP1/2GMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AiBAeLTHTNa53fxN2RDa3lROd2hzPQEF9nLOmL6vdJ9RvCRTi7zaG/AbFZSH6x7iKYi84e4o+QxSMbfnZYXOqaUn9PsVLUtcegSNAG79Ny2xdxIBAlBlw35iSeRZKGnF5DDIZnSBfGJ6A3ciYiwMMXKiF9JSCNvuded8lClDVK4= 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=K5JDXIjJ; arc=none smtp.client-ip=209.85.210.42 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="K5JDXIjJ" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6e50e8dcc72so888806a34.3 for ; Fri, 22 Mar 2024 09:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126383; x=1711731183; 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=bcrz+iNlkSMaXga6GjK/dXFl4dsslQPtza4Zz/b9aGg=; b=K5JDXIjJFFX0dP4n7csFbzd1pVAdoeRL9F4wIy2yH6Sd8a85ygOHRUL2VoixwWL/hd 7AKgg+1K4ayMEdzYNmeHt1ZA+XJQuvAKolmYFIf8hHyqrdvDB2TLKu47iB7EVQ6T3CCX 2CB5B4z+6YecUDmq6DZamPN4hN1bWbue0nrpia6xEKIFBQa8VVC/+Yyv+LTPjsz5mHS6 h89MFdJ0bTI+oM6Z/Wzv2/3Z6OqeYKnVxyE4XkUZXOV/cUAWDbSG25yboHbgFCxZxy0s 9glxm+jORA3N7Lz1ljPM8xeFtPv2oEjcLNSf5uPRxFpzZNVeteMzAvpz+sHQnelqKPXQ Yo6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126383; x=1711731183; 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=bcrz+iNlkSMaXga6GjK/dXFl4dsslQPtza4Zz/b9aGg=; b=kKbmNTRNoXnnUhH6hRrF6yP7CvsCwJcOe5mySTfYE0eKPfEBr/bB9EXAeZKh28wmLy 286lBYPuCvqk0jCgSg0R/NcpMEs1WMR4JuSPLFu+wehaSgASwiGszCLIzvEUF4xMEQ+j 9flCWJ/0FFJG313LaJGHT96BZwQPH7pDE+OcROnvnpYTAxFp7V8D7G4sktVFYoF6FY6T s0ngYrcN5QhZcNQONMem9Ow1BuIVAJpO2yU1xhDKvdNVNMxYCAh+gXxQSdk/nRbZbqP+ VqF7JnLfDNz5x/tusnVzhRoDNhN7/saq5Y8VDZ7hFLFpIlxEmxKOroorKmSvHh93Soco pODA== X-Gm-Message-State: AOJu0YxVlepqr11d0WxPDfWnPJKoCak+/t0z+kQADIV1H4CdYVqjRyZr 4jDorPbLoyna5F3zikLexdH6D7yj5fBCsOyd7Ekoui/atcSEIE2cZ6It0L4= X-Google-Smtp-Source: AGHT+IHnay89mvxVTEIyVPO+JjskcQi/vAYJjqahDXajbrzckh3L8YDk1E/ySeWNG2F0jixB7/q6Lg== X-Received: by 2002:a05:6830:148b:b0:6e6:97e5:7949 with SMTP id s11-20020a056830148b00b006e697e57949mr229305otq.6.1711126382941; Fri, 22 Mar 2024 09:53:02 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:53:02 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 13/16] percpu: Remove PER_CPU_FIRST_SECTION Date: Fri, 22 Mar 2024 12:52:30 -0400 Message-ID: <20240322165233.71698-14-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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: Uros Bizjak --- 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 9752eb420ffa..74f169772778 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1033,7 +1033,6 @@ */ #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 ec3573119923..b9ddee91e6c7 100644 --- a/include/linux/percpu-defs.h +++ b/include/linux/percpu-defs.h @@ -26,13 +26,11 @@ #define PER_CPU_SHARED_ALIGNED_SECTION "..shared_aligned" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" #endif -#define PER_CPU_FIRST_SECTION "..first" =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.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 6B43E60BB0 for ; Fri, 22 Mar 2024 16:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126387; cv=none; b=COHJz/ou/FuFiU9It8N/xVmRhJSicDtG6OFFvRS7BvJXMFrRceL7MoBuHkL/P92aBFRwziTLoBckcbZjpfY9IaRkBnWXwr0CfAHMqwf4s4F3FaRSVtKBAPAiRMDAf/MPoEWB1RR8jwEMA1LrlE9CNdJ2EfXRsWIO1Fvbk2RHs5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126387; c=relaxed/simple; bh=adghTFAiBRcGv1s4L/JWtTrZ77UQy5mB45gZTj8Fw1o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IA7BGFf3j1rhhbfXNy9HQ3sc4PQ2dF0bRg3yBRWMy7bxPZGv0DhgXyOpNUnnKKZqm24snodLQWfideYMw5fgQEKUTNk+xMVjt8qD5ZZapofWcecjMFFf7/3GkrQH8Ys9Z2Dsws0EE0U00BvxSJ7Np2PhSE9/S0yewSYND9gjozM= 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=bBHV3xKK; arc=none smtp.client-ip=209.85.222.178 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="bBHV3xKK" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-789f3bbe3d6so168584385a.0 for ; Fri, 22 Mar 2024 09:53:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126384; x=1711731184; 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=Att3x3WRfP739iu4vR8QvOBOGtQSu4+V6eHVKQWaBoQ=; b=bBHV3xKKPOzV6wK3qdmnyX/LdVEn8i6FSjVeKxZA4KPC2RdgeWOXjcvcKck2Na0rsT dKM1tkfnpztja5Z187VxMW5NfCMjBvj4/Maj1YePuBuDCHhV8jTJobo771jHl7HdYdiM F6haEEIYjo16RZKPwhjF/pYPADsM4qJXagL6r9BS9nlE22Rw973/zB+JD2fuh7K1Inzj 7rreKi7A7Z6UZzl3vdCHi+eEOFqVHuhYnTCP00VSr05Q4zERzUArfV7Uy37hjhi1bAZp DcJAoC81pS7B5WDMd4ieYyzhfgy1eNJ/JTnkbd6nTmF9DaJVt6CEwLQkLJLyswEW+nEw TLtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126384; x=1711731184; 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=Att3x3WRfP739iu4vR8QvOBOGtQSu4+V6eHVKQWaBoQ=; b=xRAa0GVULiiG81kepQwJgXAEZInuYAthfc/7rc9CwrxjHltXgctPSArffQ3boxSZFB igPjAJKBZM/lnnrEz5VpuZZ5T71RSO0JrtAuHC/1vYlg9RCYZxnvU0CrVNN+5xCfa3b9 0WV2Hg5dpsNwNU/8/5BKrsBXnQO7q8TYmhrqH8ZEN72E2oCts949TEXUslEx/y2mn2yf xSAz64wZ1UGX60PoB084cegPoBfwoTNJVxRVgiWfSc4DUbJoSM8TzwR6o8J2z0LJ8la+ AXN07YAF2FjSCxbrIrTc9wf9HTaZ9R0qvzn15L6IuDPjwDUV3NgvBZD45CD2rNPW/dXN UzEg== X-Gm-Message-State: AOJu0Yzq3ShoMGL/KPOTOLKkFpgtmr40brmuI7lmLpgV4xv/eG64Ckvb Kxx+H05H4EzsLdG96z9EFdCgNenDr437g531191I5w8D2iRp9pjRU+XPyKk= X-Google-Smtp-Source: AGHT+IG9Be47ZO3qLJv82ZM7piyxvucAHz94ZN85hLcNaUIR/QOR5nkQ8WYtKbY1121XuxZVwykt2Q== X-Received: by 2002:a05:620a:40d3:b0:788:3cb:5cf8 with SMTP id g19-20020a05620a40d300b0078803cb5cf8mr8161qko.6.1711126384492; Fri, 22 Mar 2024 09:53:04 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.53.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:53:03 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 14/16] percpu: Remove PERCPU_VADDR() Date: Fri, 22 Mar 2024 12:52:31 -0400 Message-ID: <20240322165233.71698-15-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- include/asm-generic/vmlinux.lds.h | 41 ++----------------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 74f169772778..430b2ed2aa58 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1044,47 +1044,10 @@ __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. + * Align to PAGE_SIZE and outputs output section for percpu area. */ #define PERCPU_SECTION(cacheline) \ . =3D ALIGN(PAGE_SIZE); \ --=20 2.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-yw1-f172.google.com (mail-yw1-f172.google.com [209.85.128.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 7A08F60889 for ; Fri, 22 Mar 2024 16:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126388; cv=none; b=Kz5pOhnZP/LU4kSBwirY+tMqharGxzxo8nEvApkdacIKWYHshXa1AHkxLBX57vdwbtsHujZAHDxJGU5wN8pFpQic5gJUEHi033RpSyK0GSNxbt8CQQJb9kYA5sDpWenrawmchnLr9QhcEoP+3V5UpzbSEVW6DAA0tYq3gDUxyPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126388; c=relaxed/simple; bh=f3K2IlHly9KsbWiXAM8d/JSq/+g0AfeJL+4wTF0gobQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K41/yWktMGKhe37QyMeovcK1GBF56zZVv9sbBXZV57KOyxA7nsKkl0ju2VcV7h/mrToEfClxbTP9pyUnh1fLJCt3NBPhrXUN+kdD5qqrOjHQ6MiZxaPfkgqTN7CrFRj1mzqdaTmXe3REukyA7dYsr9oUniF5Y1XwNOIi3K+ZdXg= 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=YQsICfS6; arc=none smtp.client-ip=209.85.128.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="YQsICfS6" Received: by mail-yw1-f172.google.com with SMTP id 00721157ae682-609fc742044so24997397b3.1 for ; Fri, 22 Mar 2024 09:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126386; x=1711731186; 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=ClIpZptlCct6LbR2ubvvxFMAK2t5s49KsuXa2pT/TK4=; b=YQsICfS6uoyoCLCHgD1KTPJn7JfcM0R1ddPc4PztS5uPjLoVUnXnnj4NSCUb1TpFrk l7hf4gP04/ENo/uByyRcGjmvhL0t3gAtnXcOgtEJp2Go6j6UMJPLhJcnZwa1BiRBChq/ lb3At7E23lcPk2/bjg4L7aizG0a4dy7lSOM0yIOjWBKqQIudq+tJy7WRCx/c9lN3uXIp NIBKGctnyaS1qr9r6zWgwZRAAPF8cvHzpnXO2RkW8L6zS6SxGhJjj8jrtosxy8hP50HN 9ji3mPskhvjpLkTb1408TQ/HP8RXMyXFrstrpwgX6C930OoaHF3cnidXpIi27WL5OP9e oqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126386; x=1711731186; 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=ClIpZptlCct6LbR2ubvvxFMAK2t5s49KsuXa2pT/TK4=; b=oDn20bviXhFm5ZKN8rQYKCYMyhfD+VWQ/ppUBiC5uWur8Z2iabm86b+uiGZbRDEsVh +6uOqxLFtP18Ur5952ZkyGHFOQLEKuuea9YmDoYNampx8jpQ0Te/kqWF79xxPLQ2C6tO uK7aW83+O5ANH+u6khplPHIHrjllZ55Kw0t3RDvbqG/SMNPsl81338mY1gn3Jty0oSjX 7mqz/YaivNGVhyALQZgnLijsdlgP5VZkb3prvOmKrJry+acOnaVjcJTja7wl1OoePcVM mXJroGVReQfUT5mJsW5VgGGiL5Xk/XNJEpXQQ+Zp+9N3HSI2DNSjVQXRquXR6tcKxLep y0Jg== X-Gm-Message-State: AOJu0YyJKW6JRC+OOPYZDxgBJbSNFjdyWosylHHnPxg3NbC93EG+MxEX yO0kPwERSjX5GLtValQRHnvgkLAZKSWbfDVqHdZu2tY6gAPsVxYok2y7xyo= X-Google-Smtp-Source: AGHT+IGCDYDmlDjwXduTWclfEmLjb0w2VmViDJPb3X5xJ3QOfOsK8VTmisl2+tEDgIwB06jFV9mv3A== X-Received: by 2002:a81:910c:0:b0:610:f602:de1d with SMTP id i12-20020a81910c000000b00610f602de1dmr200975ywg.2.1711126386001; Fri, 22 Mar 2024 09:53:06 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:53:05 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 15/16] percpu: Remove __per_cpu_load Date: Fri, 22 Mar 2024 12:52:32 -0400 Message-ID: <20240322165233.71698-16-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- 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 430b2ed2aa58..a67452ea94d3 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1052,7 +1052,6 @@ #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 4e11fc1e6def..a584b5a78f72 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -3153,7 +3153,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); } } @@ -3336,7 +3336,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.44.0 From nobody Sat Feb 7 20:47:49 2026 Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.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 DAA5A60DD7 for ; Fri, 22 Mar 2024 16:53:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126390; cv=none; b=kIlTjKYaVORzZuI35fhwxYPTX0S2e5iTGQmNrS3eR7B8GXisUgPQfiI9q2tcwJ55h5NkIet55Pu9lxl4/eLT42sHTXg4sc9ePdacGggYKpe3D0JVwYMF3j59uMuGC/z4BrQWIQJSjMIND5l9Q38gnwEYyX5/www+TmG4VCyHcXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711126390; c=relaxed/simple; bh=w5lRor2gDUTAnKWbRfo5S7pLGPoO+/siZMlAQOcuzkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FgUdURZcRdWAxWiJqAwYYXDDwJu9Bvi7yx9nG51pDlhChMVEosFATwGfxKa6+M3VUKHkc5GncwbSGwqT3RsrrOQ8Qpo1ZZAIrXsstT9bdFsaGI6rVeZYFh7LpcnbIrezx3CCFoI46vfdqdAegjovlvulfsUVvEo4AUPCQ07WVJI= 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=VMaE6ww5; arc=none smtp.client-ip=209.85.222.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="VMaE6ww5" Received: by mail-qk1-f182.google.com with SMTP id af79cd13be357-789e83637e0so148243185a.2 for ; Fri, 22 Mar 2024 09:53:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711126387; x=1711731187; 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=9enSTXYKk4Zrvj4rfHNHKtmAkQZHAnQu5tvlI07i35w=; b=VMaE6ww5qId5pi8MhC+CK5vYO+NtcWjIRoQyF2uWaKcJDLgkEDFg8BqjVkJ3avo527 ewE87W+PAz+3F+nykIEqfQNnikh2h7pyh4SZ814EvUz8dHtCkkIG16r9ppxKBcW43dlh YGmtBh6iDy/RLQWXzxy9tYaS/QWXfDS0QU3k3xEoe/zqTn0JQhkT9pHxAA4ahhOBU93e z/inmex5SbdAe8971+TGh6+TV7AlyvzTac57Qeomwic5md2ChW+KONrPD8hvSzQt+Zjp OVRp5Xx7eZsnvJYH9ESpDyo6/7uUUW7cxk46wHM9IBYeLhr6/WM9X2K8B6ymacxHy6Ui bVnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711126387; x=1711731187; 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=9enSTXYKk4Zrvj4rfHNHKtmAkQZHAnQu5tvlI07i35w=; b=uome9eq6DPn6JcAx+HNS+izYptUUr6tA9G7Pzk/sXebAHIuPnWw2Lfi5ioiMVGAPyJ +2NmIaZWJw37Xw1vN1wNlSu8+xHtACn8tqnI55LbcdpNERwDSYaBlFsphTOYxwRkWGpo ivmGVLRHhHKtIK0FaOptwdIEOYumIoA+ZutBXPgygfeHZvQTGp8NYl7BAMWuCbE8CwM4 nWS8V5fX/XjE1J/R1dbu+/2puxE3YMMk3UXdgsDyn+3gUiqpAoGJZ9xzIzSzB/+cETNH 0dOdpeZ0UO9qNKbk/bYNyOOvVzwe/8J9rebPZmvMpEUPAuFTc8HqZfSKgQ43t5uThLQb 118A== X-Gm-Message-State: AOJu0YySin5AGH/87wiHedFLChh57h74sOLaTJqpRJSZr+3yxG7B7/Gr vYc5QG6uA3oixl8knKWYyvySYxozKJ7iZ4o8AkIeC+28x5fEX0NzTHEfJdM= X-Google-Smtp-Source: AGHT+IE77AtBJ2T3L4/FCqCn71Qd678y5r9QRm/DcKAWicsPNMT6z27t7nqp07NFmrz/FP2C2Q4UzQ== X-Received: by 2002:a05:620a:8016:b0:78a:40fb:b199 with SMTP id ee22-20020a05620a801600b0078a40fbb199mr1562979qkb.38.1711126387496; Fri, 22 Mar 2024 09:53:07 -0700 (PDT) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id j1-20020a37ef01000000b00789e9bbf962sm894901qkk.133.2024.03.22.09.53.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 09:53:07 -0700 (PDT) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Uros Bizjak , David.Laight@aculab.com, Brian Gerst Subject: [PATCH v4 16/16] kallsyms: Remove KALLSYMS_ABSOLUTE_PERCPU Date: Fri, 22 Mar 2024 12:52:33 -0400 Message-ID: <20240322165233.71698-17-brgerst@gmail.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240322165233.71698-1-brgerst@gmail.com> References: <20240322165233.71698-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 --- init/Kconfig | 11 +----- kernel/kallsyms.c | 12 ++----- scripts/kallsyms.c | 80 ++++++++--------------------------------- scripts/link-vmlinux.sh | 4 --- 4 files changed, 18 insertions(+), 89 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index 0f928f82dc7a..0622599ce503 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1781,11 +1781,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 - config KALLSYMS_BASE_RELATIVE bool depends on KALLSYMS @@ -1793,11 +1788,7 @@ config KALLSYMS_BASE_RELATIVE help Instead of emitting them as absolute values in the native word size, emit the symbol references in the kallsyms table as 32-bit entries, - each containing a relative value in the range [base, base + U32_MAX] - or, when KALLSYMS_ABSOLUTE_PERCPU is in effect, each containing either - an absolute value in the range [0, S32_MAX] or a relative value in the - range [base, base + S32_MAX], where base is the lowest relative symbol - address encountered in the image. + each containing a relative value in the range [base, base + U32_MAX]. =20 On 64-bit builds, this reduces the size of the address table by 50%, but more importantly, it results in entries whose values are build diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 18edd57b5fe8..f4e8e531052a 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -151,16 +151,8 @@ unsigned long kallsyms_sym_address(int idx) if (!IS_ENABLED(CONFIG_KALLSYMS_BASE_RELATIVE)) return kallsyms_addresses[idx]; =20 - /* 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 void cleanup_symbol_name(char *s) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 653b92f6d4c8..501f978abf4b 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -5,8 +5,8 @@ * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * - * Usage: kallsyms [--all-symbols] [--absolute-percpu] - * [--base-relative] [--lto-clang] in.map > out.S + * Usage: kallsyms [--all-symbols] [--base-relative] [--lto-clang] + * in.map > out.S * * Table compression uses all the unused char codes on the symbols and * maps these to the most used substrings (tokens). For instance, it might @@ -37,7 +37,6 @@ struct sym_entry { unsigned int len; unsigned int seq; unsigned int start_pos; - unsigned int percpu_absolute; unsigned char sym[]; }; =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; static int base_relative; static int lto_clang; =20 @@ -75,7 +69,7 @@ static unsigned char best_table_len[256]; =20 static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] " + fprintf(stderr, "Usage: kallsyms [--all-symbols] " "[--base-relative] [--lto-clang] in.map > out.S\n"); exit(1); } @@ -167,7 +161,6 @@ static struct sym_entry *read_symbol(FILE *in, char **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 */ @@ -183,7 +176,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 0; =20 return sym; } @@ -334,11 +326,6 @@ static int expand_symbol(const unsigned char *data, in= t len, char *result) return total; } =20 -static int symbol_absolute(const struct sym_entry *s) -{ - return s->percpu_absolute; -} - static void cleanup_symbol_name(char *s) { char *p; @@ -499,30 +486,17 @@ static void write_src(void) */ =20 long long offset; - int 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", + "symbol value %#llx out of range in relative mode\n", table[i]->addr); exit(EXIT_FAILURE); } printf("\t.long\t%#x /* %s */\n", (int)offset, table[i]->sym); - } else if (!symbol_absolute(table[i])) { - output_address(table[i]->addr); } else { - printf("\tPTR\t%#llx\n", table[i]->addr); + output_address(table[i]->addr); } } printf("\n"); @@ -775,36 +749,15 @@ static void sort_symbols(void) qsort(table, table_cnt, sizeof(table[0]), compare_symbols); } =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 1; - } -} - -/* find the minimum non-absolute symbol address */ +/* find the minimum 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) @@ -812,7 +765,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}, {"base-relative", no_argument, &base_relative, 1}, {"lto-clang", no_argument, <o_clang, 1}, {}, @@ -831,8 +783,6 @@ int main(int argc, char **argv) =20 read_map(argv[optind]); shrink_table(); - if (absolute_percpu) - make_percpus_absolute(); sort_symbols(); if (base_relative) record_relative_base(); diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index 7862a8101747..7b0596cd5a80 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -153,10 +153,6 @@ kallsyms() kallsymopt=3D"${kallsymopt} --all-symbols" fi =20 - if is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU; then - kallsymopt=3D"${kallsymopt} --absolute-percpu" - fi - if is_enabled CONFIG_KALLSYMS_BASE_RELATIVE; then kallsymopt=3D"${kallsymopt} --base-relative" fi --=20 2.44.0