From nobody Sun Nov 24 11:58:12 2024 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 51AD61384B3; Tue, 5 Nov 2024 15:58:17 +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=1730822298; cv=none; b=Yne7bSzBbpD88N46pppSMdWFhUM8cgr2WS0YJWV/5rCU6dT6evID6VLSFDH5eO41KQKAMF17ICbwwUCRYSIRHh+yONb4zamuSsi5iiJn6zb+79Fg7DLfLumDfTRxBmav6uBbBWZnt+Z3loosOg8bxANhoU6PSFL5OGg6PP0yIDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822298; c=relaxed/simple; bh=NX7H3MvTsW9DRuBwQkrInDdn6GS/Et44Ott+QFyFoiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ui5geVrytqfh+h8MXtuqiG66lBcA8WQrDD2oVIeRcncNBJxSWXUC1ZHKXeSx/2DO3Qi7nWTZ5TC1dLc5q4ip0HKK2P38lS4YrDjsT95EG6qqlZRC32beMJKFpimU0gI1mrYqSTosM0vGHV2xsuEyfGhJqJL4GXyW3xzaoDTf98s= 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=J/AdAzqC; 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="J/AdAzqC" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7b15467f383so395769485a.3; Tue, 05 Nov 2024 07:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822296; x=1731427096; 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=qSGF9RIONMCy+lm6lwN/0OP9d1KIw8FJWDz+4Vvo1qE=; b=J/AdAzqCnJ9qVn4IyYKBuJ2T4Dwx/RQzrWNuRjCi5uJ1l4D3nYrUqOYA2KBBm8zxVF KZJsgud7N5bX0CVwHZ8+AsHCHECa4QAgpSgNecWCq2obK+t4gHGF/14/bowyWy9PgbSQ LR5NkqT9UCNul0Pn2gs2h0M1DVATvYqQIabjioQz1oYdfZPtRVbhFKVHbqpJVHfRhKX9 Kao3lCrh82HO3VEeRanjIk0Gz7kzLZk/Z7VmRyg7L7tKIsBLzad3KtUJnTx1EJq9H4yB 9xuvViseKSTb5zxVegbx6jdErxvRAzfzxWsiqaoonGw4XTkFZohBy3S0OiGTB6jGhtf5 rqnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822296; x=1731427096; 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=qSGF9RIONMCy+lm6lwN/0OP9d1KIw8FJWDz+4Vvo1qE=; b=Bg293YVBCncqblGq7fNkft9zxH4iW7RPHXg7ZArlRiRs7GLiIyVSqD6TtflniKS7vW AMrnGdZE4FAnkH6yqwps6F4U2ZpBov1tOpzOMlKLbQSyQWjRghLHNp2gxeBM+zBT5ald SnRJFK07bWhSMxF+1OKGFa0Etlql4FBno4eODsOnI3+N7BJlelqOLiq5IqhiJUyb3Wxy 4dOwsgyw41MgYaJg93uhdiShZQIiIHvU5Lt86doq+CFlo44guWlpOcjzTmiUndXAp0QU Apy2+Lm2qXQ8hnO6r/Z8mAIA04e62xoz6pBLfraia1iFDVS8qNlvEuEeyB5Yo8SJZTCE x24w== X-Forwarded-Encrypted: i=1; AJvYcCU0lz5n4CFmSbXZB9aKBn67l2btMc+2ANqzqKOLLl1inQyZGToDSHRmFwDuO6LwJRd/cIwbgxY=@vger.kernel.org X-Gm-Message-State: AOJu0YwEeunP4KFuVDw/Xn4eqn/ZtjdbPqvPhsLEdLayxwTbvNNOXDVd OR0R/neoO2K48yYodrN9NOepjtzqRPz3wwk12AIm7Kx718v4dE54P9kI X-Google-Smtp-Source: AGHT+IF72m9JE3C6mYCC457d4K6hcqs2XKMqtnJi7ytPhEDIUKBZ/dL5xKmqM82I1eo3ZS58f4hvyw== X-Received: by 2002:a05:6214:2c10:b0:6d3:452d:e1a1 with SMTP id 6a1803df08f44-6d351ad3f37mr263141716d6.31.1730822295721; Tue, 05 Nov 2024 07:58:15 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:15 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , stable@vger.kernel.org, Fangrui Song , Nathan Chancellor , Andy Lutomirski , Brian Gerst Subject: [PATCH v5 01/16] x86/stackprotector: Work around strict Clang TLS symbol requirements Date: Tue, 5 Nov 2024 10:57:46 -0500 Message-ID: <20241105155801.1779119-2-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel GCC and Clang both implement stack protector support based on Thread Local Storage (TLS) variables, and this is used in the kernel to implement per-task stack cookies, by copying a task's stack cookie into a per-CPU variable every time it is scheduled in. Both now also implement -mstack-protector-guard-symbol=3D, which permits the TLS variable to be specified directly. This is useful because it will allow us to move away from using a fixed offset of 40 bytes into the per-CPU area on x86_64, which requires a lot of special handling in the per-CPU code and the runtime relocation code. However, while GCC is rather lax in its implementation of this command line option, Clang actually requires that the provided symbol name refers to a TLS variable (i.e., one declared with __thread), although it also permits the variable to be undeclared entirely, in which case it will use an implicit declaration of the right type. The upshot of this is that Clang will emit the correct references to the stack cookie variable in most cases, e.g., 10d: 64 a1 00 00 00 00 mov %fs:0x0,%eax 10f: R_386_32 __stack_chk_guard However, if a non-TLS definition of the symbol in question is visible in the same compilation unit (which amounts to the whole of vmlinux if LTO is enabled), it will drop the per-CPU prefix and emit a load from a bogus address. Work around this by using a symbol name that never occurs in C code, and emit it as an alias in the linker script. Fixes: 3fb0fdb3bbe7 ("x86/stackprotector/32: Make the canary into a regular= percpu variable") Cc: Cc: Fangrui Song Cc: Uros Bizjak Cc: Nathan Chancellor Cc: Andy Lutomirski Link: https://github.com/ClangBuiltLinux/linux/issues/1854 Signed-off-by: Ard Biesheuvel Signed-off-by: Brian Gerst Reviewed-by: Nathan Chancellor Tested-by: Nathan Chancellor --- arch/x86/Makefile | 5 +++-- arch/x86/entry/entry.S | 16 ++++++++++++++++ arch/x86/include/asm/asm-prototypes.h | 3 +++ arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/vmlinux.lds.S | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index cd75e78a06c1..5b773b34768d 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -142,9 +142,10 @@ ifeq ($(CONFIG_X86_32),y) =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 + KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3Dfs \ + -mstack-protector-guard-symbol=3D__ref_stack_= chk_guard else - KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal + KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal endif endif else diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S index 324686bca368..b7ea3e8e9ecc 100644 --- a/arch/x86/entry/entry.S +++ b/arch/x86/entry/entry.S @@ -51,3 +51,19 @@ EXPORT_SYMBOL_GPL(mds_verw_sel); .popsection =20 THUNK warn_thunk_thunk, __warn_thunk + +#ifndef CONFIG_X86_64 +/* + * Clang's implementation of TLS stack cookies requires the variable in + * question to be a TLS variable. If the variable happens to be defined as= an + * ordinary variable with external linkage in the same compilation unit (w= hich + * amounts to the whole of vmlinux with LTO enabled), Clang will drop the + * segment register prefix from the references, resulting in broken code. = Work + * around this by avoiding the symbol used in -mstack-protector-guard-symb= ol=3D + * entirely in the C code, and use an alias emitted by the linker script + * instead. + */ +#ifdef CONFIG_STACKPROTECTOR +EXPORT_SYMBOL(__ref_stack_chk_guard); +#endif +#endif diff --git a/arch/x86/include/asm/asm-prototypes.h b/arch/x86/include/asm/a= sm-prototypes.h index 25466c4d2134..3674006e3974 100644 --- a/arch/x86/include/asm/asm-prototypes.h +++ b/arch/x86/include/asm/asm-prototypes.h @@ -20,3 +20,6 @@ extern void cmpxchg8b_emu(void); #endif =20 +#if defined(__GENKSYMS__) && defined(CONFIG_STACKPROTECTOR) +extern unsigned long __ref_stack_chk_guard; +#endif diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 8f41ab219cf1..9d42bd15e06c 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2091,8 +2091,10 @@ void syscall_init(void) =20 #ifdef CONFIG_STACKPROTECTOR DEFINE_PER_CPU(unsigned long, __stack_chk_guard); +#ifndef CONFIG_SMP EXPORT_PER_CPU_SYMBOL(__stack_chk_guard); #endif +#endif =20 #endif /* CONFIG_X86_64 */ =20 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 410546bacc0f..d61c3584f3e6 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -468,6 +468,9 @@ SECTIONS . =3D ASSERT((_end - LOAD_OFFSET <=3D KERNEL_IMAGE_SIZE), "kernel image bigger than KERNEL_IMAGE_SIZE"); =20 +/* needed for Clang - see arch/x86/entry/entry.S */ +PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); + #ifdef CONFIG_X86_64 /* * Per-cpu symbols which need to be offset from __per_cpu_load --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4601814F119 for ; Tue, 5 Nov 2024 15:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822299; cv=none; b=S1RpPD611acnncV4qZASouj0aQz5Rv+aFEeRYxLCeyXEq2hZgDUW3+zWTpJFob2IMki6XfCu1uApclF5cG8Bxk3DQXQ1Khbushd4dTSmMhlqGVDotcFMo207VPRsKFwaUUIIRY83MvH76ZYI+AyY+Lbl5tFD2nyONc1SUZiKRuA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822299; c=relaxed/simple; bh=nP9SVYW0NtDtu5qNRV/8v5xBanCZdOryFj5rjlAsb9Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WcTl7MXUeU55+sqaE8wBdOLDwDOBxve88WDYH6XJwMx2ghKGCWH0UzZI7dIfImnzauGfuhFUaA8ch42YF6PqHyWkDNUR0/DXpEJ9rgBz+pGeAi3wzi+juh/lGc/WMAVosSZROnbf0UmwvQ2kzY9HB4uteE70P5lrI7arJ42d67M= 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=FfskLUUI; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FfskLUUI" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-4609e784352so37314821cf.0 for ; Tue, 05 Nov 2024 07:58:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822297; x=1731427097; 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=i/hvGge5OPILp7dIoYZGxsO1XwDNo9kO5R1IfIXXoTU=; b=FfskLUUItcaT40DHNquEirn9+p8rSL0CguDRLzlCz41h9aLVqHBWMjeaJHZ5HTljod lQOWzl1YDsnB/2CsqWUsN3Q1+HLkKsyCynUtbUz6mJZm3eAwy5AVWF6h7TQmS2TC7sr/ fdQZ7BHPpESRgz1SpbMq4Us9APk9V3e3JNC6OaEOxj9Xq+N+ZitmHUV+1WBRo4UIBwDe ZQzrpOodj2y8eGGw253WHG2VhMr5oXrhpR2mCnVfPMmdOaqVWjHftvO2vUOxivY5QtrC QcRDp9oLdLt72tRIn1SOxlcbH+RIlAQXQX0crtOh7BnF6+EELGEi3eSwBFhN1z0t5EkH 9JpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822297; x=1731427097; 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=i/hvGge5OPILp7dIoYZGxsO1XwDNo9kO5R1IfIXXoTU=; b=kNqZDVfxUB9Zlf6qJfcsdgUDzxpZyEkZ0F3pc/V4wIuRrCt9FY/kcsHAgSjnwTIYGo LgRoiLIAhKXjL6SB2UBLbb1SwAJBvDFGJgABhGNck6nIPSA8r3MfoyInth32YaGkfQYF QLNMC5u/VwIveDC8bymMh9oFGHXhXRt8zqrPBXrxYf+dugql4vxB/dpsHmDFyRgEN+mm L7PXZPXUlNPbKSJYk11o0Lt48nBHMrp9M10uwHyzbBjegJ2oARzpTVgtxBrGtdbMSAcy U7c1EZaVtEcP9ikrzjiWhDoZM8ntXrJXNIqhX5DYjWyfHf8AomtwamGi8AR4xl3Fbst5 mM5g== X-Gm-Message-State: AOJu0Yym9tIaWZbKSHvZyIKQ2jntqKaNmsOywNnKmUmlhnsoXFJ+LndE G1sBEVfyFpbkgm4D60ieJdLXVlWZ32sq5l3QYpQSu78tQNOZ586H/M6I X-Google-Smtp-Source: AGHT+IHAPdNsJ8C7rDc1dYEzNisX4utZGpvZ7jBDP6hK3rp1fAs7G78ZOROC4o+3PHcwAZeCmvbpUg== X-Received: by 2002:a05:6214:3bc9:b0:6cd:eeb4:4f73 with SMTP id 6a1803df08f44-6d345fc8799mr338538626d6.14.1730822296890; Tue, 05 Nov 2024 07:58:16 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:16 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 02/16] x86: Raise minimum GCC version to 8.1 Date: Tue, 5 Nov 2024 10:57:47 -0500 Message-ID: <20241105155801.1779119-3-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Stack protector support on 64-bit currently requires that the percpu section is linked at absolute address 0 because older compilers fixed the location of the canary value relative to the GS segment base. GCC 8.1 introduced options to change where the canary value is located, allowing it to be configured as a standard percpu variable. This has already been done for 32-bit. Doing the same for 64-bit will enable removing the code needed to suport zero-based percpu. Signed-off-by: Brian Gerst --- scripts/min-tool-version.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/min-tool-version.sh b/scripts/min-tool-version.sh index 91c91201212c..06c4e410ecab 100755 --- a/scripts/min-tool-version.sh +++ b/scripts/min-tool-version.sh @@ -19,6 +19,8 @@ binutils) gcc) if [ "$ARCH" =3D parisc64 ]; then echo 12.0.0 + elif [ "$SRCARCH" =3D x86 ]; then + echo 8.1.0 else echo 5.1.0 fi --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 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 9277F155758 for ; Tue, 5 Nov 2024 15:58:19 +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=1730822301; cv=none; b=T0dU21jKOwacg7mFG1oXpt9J83B0PeW8Dh1OqKTQ8H+8HGk8lQc6ARjJg3r4Q9S2xyfynsH5oaEeE9qkgg/OlEprBVZJpUPyTeJkD/Aj5L49jugp/5ShVTA1PimLKqStBM8koj2avDekx9Kn01rDmEebUaX/vy4mDQxEsn5tNM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822301; c=relaxed/simple; bh=/0jvy4opjUK7nNzQpIuudVIb5O/dI4mApBK85ttWjrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Py7tF8KVCsQB/lGA9zLDjWkxufxNQeDAgSSBWxigj9bzKc8erod/80o0lwh1nQA5+VnAaHijvwM5/woZa8XqCMqxMWY4c0+5TlJEEz9DFjA7pFrzbzPnz4HTZ6Z9pPh4raI4OUcIz8WrnghsKMG1V7xNGmCJdSDuiuiaWCI+zu4= 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=P1D7eo1r; 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="P1D7eo1r" Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7b150dc7bc0so402515885a.1 for ; Tue, 05 Nov 2024 07:58:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822298; x=1731427098; 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=I+sNbSfN1SChlVpebOlxZ+5Kd3VmPuC24W4HBOzRBNg=; b=P1D7eo1rYsI8G6cRoEpHZUnOiok0hz3Gfqc6qEb7Wioh04BhjY6bo5tJZrD5UKQfGj tJl386jsQUS2kXRHDLJzcOKvhJ7aw4G1rJu/2tQkE4Wn3BxNUthE0tlcn3e7ekkEGSvA EXRfRFPXoqqHv/KegtY29Cvq2kUZtYgVv5EmVWM9tcCrS2ri2rRjF0guX/y6eRESXLJQ R9Kt9mNuEB8oSN0/rKmf80oXKEB/qmzxCG0CbWYLEaLi5kt/41ZyMC5CJ7CczkaC/Asu /G9qtcRFrMf3Pi/iGEeFXNnne5xjZlhTVaDBrnDTCbfNxwKdBQxVXiajwsKjDsT4X9Y3 Q12Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822298; x=1731427098; 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=I+sNbSfN1SChlVpebOlxZ+5Kd3VmPuC24W4HBOzRBNg=; b=jQ+Kx9DdBDFPI6a4dpjg9rZ1uMAvTe/Gpbv7ae0Y9Qt3xtSy9P6pdv9rtW0/oQKX+R c9s5fHIPVqo/VGDDzNpW/yr6nGDpVyoQi6v0hKKzsGuQl14kdLW8JpeBvIGJy375p/nJ sHYYT269GLgENHMMqZSVpuKpGdefKHHNpak06JOptCyOYixcOFWIpJN7uKiDiZ3ZZwEY faZNFV2y3WvCeTjNanyBkNATO1Y49lfoP8XN1PSJB6aHhm+fpwPq47PexdeuwR0ONPgR 6a1q/0DoVEBe+nzA2wViqCREXEZY0M7IG9aSUI5fPuetJCe7Z7Yds36c7iV1Tfs22LU+ LZsQ== X-Gm-Message-State: AOJu0Yzw/Kgzsy4/uukRDncRp+ifRIg1H4a50yd6nW6zVDGF0Y24bnNf 4K87/NoLINPtIU5uvOUhit8hH5G4oZjZ0r24G1gggomRO2BhriSopQAz X-Google-Smtp-Source: AGHT+IF4SSNvaMqlS2cpgt71oC2HT/Sf8GceujAINQ8cBf6ufvg4L3ntBiyTMEsc1uSvfaDFCtVkMw== X-Received: by 2002:a05:6214:338a:b0:6cc:2d3c:6472 with SMTP id 6a1803df08f44-6d35c0e9a48mr221799966d6.14.1730822298007; Tue, 05 Nov 2024 07:58:18 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:17 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 03/16] x86/stackprotector: Remove stack protector test scripts Date: Tue, 5 Nov 2024 10:57:48 -0500 Message-ID: <20241105155801.1779119-4-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With GCC 8.1 now the minimum supported compiler for x86, these scripts are no longer needed. Signed-off-by: Brian Gerst Reviewed-by: Uros Bizjak --- arch/x86/Kconfig | 11 +---------- scripts/gcc-x86_32-has-stack-protector.sh | 8 -------- scripts/gcc-x86_64-has-stack-protector.sh | 4 ---- 3 files changed, 1 insertion(+), 22 deletions(-) delete mode 100755 scripts/gcc-x86_32-has-stack-protector.sh delete mode 100755 scripts/gcc-x86_64-has-stack-protector.sh diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index aa7fac6817c5..45021d57fd9f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -278,7 +278,7 @@ config X86 select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_SETUP_PER_CPU_AREA select HAVE_SOFTIRQ_ON_OWN_STACK - select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR + select HAVE_STACKPROTECTOR select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STATIC_CALL select HAVE_STATIC_CALL_INLINE if HAVE_OBJTOOL @@ -418,15 +418,6 @@ config PGTABLE_LEVELS default 3 if X86_PAE default 2 =20 -config CC_HAS_SANE_STACKPROTECTOR - bool - default $(success,$(srctree)/scripts/gcc-x86_64-has-stack-protector.sh $(= CC) $(CLANG_FLAGS)) if 64BIT - default $(success,$(srctree)/scripts/gcc-x86_32-has-stack-protector.sh $(= CC) $(CLANG_FLAGS)) - help - We have to make sure stack protector is unconditionally disabled if - the compiler produces broken code or if it does not let us control - the segment on 32-bit kernels. - menu "Processor type and features" =20 config SMP diff --git a/scripts/gcc-x86_32-has-stack-protector.sh b/scripts/gcc-x86_32= -has-stack-protector.sh deleted file mode 100755 index 9459ca4f0f11..000000000000 --- a/scripts/gcc-x86_32-has-stack-protector.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -# This requires GCC 8.1 or better. Specifically, we require -# -mstack-protector-guard-reg, added by -# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D81708 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m32 -O0 -fst= ack-protector -mstack-protector-guard-reg=3Dfs -mstack-protector-guard-symb= ol=3D__stack_chk_guard - -o - 2> /dev/null | grep -q "%fs" diff --git a/scripts/gcc-x86_64-has-stack-protector.sh b/scripts/gcc-x86_64= -has-stack-protector.sh deleted file mode 100755 index f680bb01aeeb..000000000000 --- a/scripts/gcc-x86_64-has-stack-protector.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# SPDX-License-Identifier: GPL-2.0 - -echo "int foo(void) { char X[200]; return 3; }" | $* -S -x c -m64 -O0 -mcm= odel=3Dkernel -fno-PIE -fstack-protector - -o - 2> /dev/null | grep -q "%gs" --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 97AD81684AC for ; Tue, 5 Nov 2024 15:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822302; cv=none; b=n63PSjRe9ZQCrJsbl9invGZQMj6i3QKJHFvPjFjvLDbidOtf++K7McpHKIQDcShd5XejKmLAaFO20t5aJDFqTHPodjdQlW4OtMbhtcrAwVWh+5x+rf/bpsyP5DmbyRa3iCiSijkpEhJbB9DGdTohqp0SeWzFFidj0S5KF8h3hIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822302; c=relaxed/simple; bh=C5MS93fImdZxHD4p7/Pkreols+ipmbOgNAHJMcHx2yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=okbyKNU/E2XQCsOCFDTrGN5tub20CqZDh7tBm/XVHiWsDg+crKMT0WOABxera0rBu3q52izk2AkFb8QKtbWV1que0N6ZRG83yNu8BarVlL4pnnWUTEHrJYLqEkgPyR4O6rW47Z6+rsBVJ2bxBDYeqmI+6cn38XLh4xU3FeHThoc= 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=SnpqSMij; arc=none smtp.client-ip=209.85.219.47 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="SnpqSMij" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6cbcc2bd800so48317826d6.0 for ; Tue, 05 Nov 2024 07:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822299; x=1731427099; 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=cnt8p1LQSCyPDZC/m5+ANJzjUqJreA4g+wlCc2Z5tNc=; b=SnpqSMijUfBP5j70zYAFLETHp74G0zUZUx4DIKtpcOS4f0zP2J3r95iapzf6g0cOIM V5hIDbpLbhZgd1q3Ixrb3Fck5EMK6gXPQvhBbJlD4j+BJ+6IS74cLlkI3Pipep9lSOSc qsM5Dmux3URdEPm2sJWePPwK2ocF1lkDVPNrtkYqlX/zJ6Ew5gd7DWKEuMGX/XyYEklh wlUA0MuRa1Q/alraEmAY3lW18HJc4VEu8KHjdtxJmpGmzvRNmsVS7KDObmktamqkztYE nrxRyUWdbg4LmHNYYfXdWx3MI/xBwY8EJga2MPt4V2AaorkuBYumv+TF5PTYJdkKJQiM L6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822299; x=1731427099; 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=cnt8p1LQSCyPDZC/m5+ANJzjUqJreA4g+wlCc2Z5tNc=; b=FVIaNCYVxsnigIaOnattNQ0MkE5TAMldmS2uIP1Qk7BXwOSFtoXP+LNwuhTuNJy41a ddAp7Y8vm6Z2PrkV9GsW0ecYb6so+Ki3Z70wE80tGPLKSy0Mticml2KFarg7PHipQQ0S 7mOZpxiihBqT5S0+eZ+xjoVjsBaO/Fzz8XAFsc1t0Y62JLre1gOoMT4nudICMOzmJwJa YpaF4+1d/2U/GMMR9bwSeZu9sYqoR+7ecLIWmG9Fn3eNnsSuqKt4Cg2QiMEXIV0wkTU8 f52NiTPcJ3CXCHBfUsxFS2FtZwiwivTHqJLencXQx9yubCyY8ZGoBE4r44ZoBiGc3O4+ kxGQ== X-Gm-Message-State: AOJu0YzJbLU4s+3onnCRxg8S+71tH8IxsMcyCXw5BXX1fkPBhfBj6hqy zCEPwnRmAXOuBvg9heM+g5g/1rpxIJtAo0OPwHTuOeD+uBEV481KNK7X X-Google-Smtp-Source: AGHT+IFoChsQosbw9PPkr0fRJBCDyQEHPO+vqMCXdORDQ80dF+Em/aubdAPmSAWl8ig3vUtGoAudWw== X-Received: by 2002:a05:6214:bc7:b0:6cb:f904:4633 with SMTP id 6a1803df08f44-6d35429b1b7mr248681566d6.9.1730822299151; Tue, 05 Nov 2024 07:58:19 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:18 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 04/16] x86/boot: Disable stack protector for early boot code Date: Tue, 5 Nov 2024 10:57:49 -0500 Message-ID: <20241105155801.1779119-5-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 f7918980667a..f42c0903ef86 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -44,6 +44,8 @@ KCOV_INSTRUMENT_unwind_orc.o :=3D n KCOV_INSTRUMENT_unwind_frame.o :=3D n KCOV_INSTRUMENT_unwind_guess.o :=3D n =20 +CFLAGS_head32.o :=3D -fno-stack-protector +CFLAGS_head64.o :=3D -fno-stack-protector CFLAGS_irq.o :=3D -I $(src)/../include/asm/trace =20 obj-y +=3D head_$(BITS).o --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.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 B7BD6171E43 for ; Tue, 5 Nov 2024 15:58:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822303; cv=none; b=hTtbHzxzxPka0nUWC12qHmd2P/O5KpD18zyN2Z0Vb3x09uCuGetuVboqV/WpDNxH0YDNN9XPBX/9IRT1OAK/S+E/L8tfrdU3tZhSvI30L0U2uVjI89mWgTwBmI78NBxlXax+9+5tIyamkTBIz2jWNJud5ZKZ9ejL+SgdrqDatvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822303; c=relaxed/simple; bh=aSfoz8f01sAcycyReVoobqmniWwJv2hf1ixTs7gUL4o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bGgSvjta+fATl1w7P4IIpJgZJkoC6KLMOMPsNfWcoVmuznz0YTksucDq9Y034TDdTKwU743SMpJoYdd4dcYCaaN5fpmY5WEP3CPJi8BdAMdNAFIIQZ++904hZQO5c3RSBq2gvcnngq78noS43/Wo/JKBEKIPqyq8L1GIgfj9m04= 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=b06IHHIA; arc=none smtp.client-ip=209.85.219.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="b06IHHIA" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6cbe3ea8e3fso38800466d6.0 for ; Tue, 05 Nov 2024 07:58:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822300; x=1731427100; 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=hZR9fCyHPy22vSYH6NWComy/2hJfZVn6mMOShQy32Qw=; b=b06IHHIAY6pvX6bI5VhSmY7PfTZ4WB+5uQ9YZfpsrbIi1LSV4bnDGThoz7Wc5lUuW2 xt7Tx7fu8qZV7WnfBIof5lc90ug/jaEz78dbIDrr5MUCQ5uGoV8UW49bUBAW0zKav1hu pAbwmeeROxhX9quWJY4w/M5LlzaeG50KMRyM6ZFgOwatkZGM8fedbzrnzF+Xzz8duGsR WQLxEplGJTEfMuMEXl06frRjgFaHmDR8BoBBAqGS88hnsECWcm8qP/b+8dMRPO6OvNiJ +YogyNSlvcnSly9CoEUINlaT+kqyiTTWwwuFC7C3Puffp5hA7oXeTa8Mm2qGh0ZXx2OY irTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822300; x=1731427100; 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=hZR9fCyHPy22vSYH6NWComy/2hJfZVn6mMOShQy32Qw=; b=vvBXlVpPJXkq3EuQPBkY7VmVedYXBVMy2WJYWhtJjpSDNEbkCM2v3a3lUjd1sh04vD 6uilvkLUE+Bl+24TRKfr+3DqgsFeImXj3AF5GpVq/UXnjIo04+G7Vtk6NWTGd8GW1ULe hkYjaFGYfVDQRG0jQTHUNzKNQcKue6P3UMFazn3Fv49vpqFrXE+Uy787shUnk0K9EDfF 2g8OhDgIk+KzkTfmnfOZg50g31Y+fj8ByxihpP+vNdILLL9T7MaoLt38hzpioNe1pRPt /adLQLOe3R0W4ZEP+acyk4L6knElKmjdn+zSuE8BTk0+vwkUGrZn3SPAlcNRB3ZgN9ue HpsA== X-Gm-Message-State: AOJu0YwM8oC+nJjWDsMuPsx1u044subtMNC1mNElKXM9Eqdl3ntOnPIB 08ujHk9K+/w/627Y7flEOsZhuZIa33IkMayXVfXfnwaElC4j1rzG+9a4 X-Google-Smtp-Source: AGHT+IEVsEQEBvJC9E3lWcRb9NmeXlQziTdxrVMNHUPvzXAvTMOXCNBef3tF/J+2F/Lif4NgP8C+YQ== X-Received: by 2002:a05:6214:440c:b0:6d1:9e72:596a with SMTP id 6a1803df08f44-6d351b20831mr300129496d6.37.1730822300240; Tue, 05 Nov 2024 07:58:20 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:19 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 05/16] x86/pvh: Use fixed_percpu_data for early boot GSBASE Date: Tue, 5 Nov 2024 10:57:50 -0500 Message-ID: <20241105155801.1779119-6-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index 64fca49cd88f..b0a9a58952aa 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -159,10 +159,15 @@ SYM_CODE_START_LOCAL(pvh_start_xen) 1: UNWIND_HINT_END_OF_STACK =20 - /* Set base address in stack canary descriptor. */ - mov $MSR_GS_BASE,%ecx - leal canary(%rip), %eax - xor %edx, %edx + /* + * Set up GSBASE. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ + movl $MSR_GS_BASE,%ecx + leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx + movq %edx, %eax + shrq $32, %rdx wrmsr =20 /* @@ -232,8 +237,6 @@ SYM_DATA_START_LOCAL(gdt_start) SYM_DATA_END_LABEL(gdt_start, SYM_L_LOCAL, gdt_end) =20 .balign 16 -SYM_DATA_LOCAL(canary, .fill 48, 1, 0) - SYM_DATA_START_LOCAL(early_stack) .fill BOOT_STACK_SIZE, 1, 0 SYM_DATA_END_LABEL(early_stack, SYM_L_LOCAL, early_stack_end) --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-oo1-f51.google.com (mail-oo1-f51.google.com [209.85.161.51]) (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 9A21B178CDE for ; Tue, 5 Nov 2024 15:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822304; cv=none; b=Ck+lLslIH4y9py/vC5z34sMh6u/OODMKVx3bwUUk0roPMFhhVVL3tZdZQzh5BYcl4IBgppN0Q6jjTXi8OwPD80f+p1RMOQjzoQzzzbIekNNpH0fRhDiiT3HY4FNz2BRQ9XBegrFY2kFFC4iCwtzKZ+i2vlZOmV5+lTuWK4o4aaw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822304; c=relaxed/simple; bh=e6CadN4Wjeq8ZoBSwOhz57prsTrnBh9zM8CvE9CiT5c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jAnTTOefXTuWjVjr0t3klNF/2oB9WTSbxG7A/4mG4IObXkulRRykGwPcB9CYDEYYW7qhJLuNkSCw6rrlxC5wfrTV8GQ977TK4lFh0OAP6xaafVYcXOCgl72Wrz+e5MCJLsACWDke9PXsIZRHHtfTRXeGdg8jeelTqUIGWg8JM9c= 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=BeGU4imK; arc=none smtp.client-ip=209.85.161.51 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="BeGU4imK" Received: by mail-oo1-f51.google.com with SMTP id 006d021491bc7-5ebbed44918so3266487eaf.0 for ; Tue, 05 Nov 2024 07:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822301; x=1731427101; 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=tSPWXTKyL1XQ/YdGJ/1gqxsONhCLEGuN7u7SD8r/qZw=; b=BeGU4imK2b8zbOntMcIexXrQWstRRJB/1DKlVaLDHKc9Q4cxgbuS+wNb67ynCu7Hzb FRop0UOCVlKhK8Y7U/VThX13yfWBn/oCwvlVDXG6+4LdJMDy/U7oLvaBEY2dJDxCTQEW Aj3/GG9iiM5Fu5xPzJ5hJocCrFMb1MszPHB08TfiZeLGRJYCK+Vjnn+C0gNQo20YEZRN RKtA+HgiYqg0/O5H0O4U3tugWecGubW7wxyzMHOA1hNt7om5Doe9LQuky0Tp2W346reg ZMfJXdtxLuNzAJ9CUd8K81CxPVN6TyVLDqfKcq3KPBZqTUxs5nmr2Tzt2P5mr0YzOOMz CDgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822301; x=1731427101; 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=tSPWXTKyL1XQ/YdGJ/1gqxsONhCLEGuN7u7SD8r/qZw=; b=UmVkgoGklgchGpqizLC5IfqBxQG+8X0qUlYiiZUbAJliEgTX5VsF71yzItp/rwZNyg yVaU/TB5jFudBWWUGeP2nto8fSMjLi0RSpTU6W8t8ZAguhblQBaptz6KpJgicjLkff4n 2Ykb3ZCyxXltGoY6YGkCm3O/bDLRNEyv6rSgI2hweqs7S0DwoX4cqqHT8VbAjnOH3AZa pOepSEp+XoRPaiZKc+PKWxIg3Zx52L8xvOFpPZaAvPR9orsS1I5k9pW374kiG/Vn75aj lE3L371uzSsLdMKd3G/fQOeM/9WJxO1n/+X3q64wKC7ZBlKRJH75bj8XtF8X4M8WsNWP WzYA== X-Gm-Message-State: AOJu0YyA4V8c+pyUvhqBs+N2yhPpDTmSvaK+/+WZwGmttelO8wgQeaSw TChWtUi+pCo0U4tkH9UdUFnMqwOB2tmaql/vMp5Zngt71Yr6Gg5algQt X-Google-Smtp-Source: AGHT+IHQ0gFI8DtbzdZNykJIwHj4DuvLDCq9g4+ab8Olkj6CcDH5KwrLO3AncT0VkvDMcc8SNEIuUA== X-Received: by 2002:a05:6358:98a8:b0:1bc:59a1:5bb8 with SMTP id e5c5f4694b2df-1c5e32a7767mr1305791455d.6.1730822301316; Tue, 05 Nov 2024 07:58:21 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:20 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 06/16] x86/relocs: Handle R_X86_64_REX_GOTPCRELX relocations Date: Tue, 5 Nov 2024 10:57:51 -0500 Message-ID: <20241105155801.1779119-7-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 6afe2e5e9102..7d7fc7f0a250 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -32,6 +32,11 @@ static struct relocs relocs32; static struct relocs relocs32neg; static struct relocs relocs64; # define FMT PRIu64 + +#ifndef R_X86_64_REX_GOTPCRELX +#define R_X86_64_REX_GOTPCRELX 42 +#endif + #else # define FMT PRIu32 #endif @@ -226,6 +231,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), @@ -860,6 +866,7 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel= , ElfW(Sym) *sym, =20 case R_X86_64_PC32: case R_X86_64_PLT32: + case R_X86_64_REX_GOTPCRELX: /* * PC relative relocations don't need to be adjusted unless * referencing a percpu symbol. --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.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 1BF3817BEBF for ; Tue, 5 Nov 2024 15:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822305; cv=none; b=LVUjQj0MRsGlf+I7skQx2KQh2nvWay25S3DdZUtyYPL4xKhO0Lz2V6I1L2x/iA1C5z1n0LFzcutk3lF7KNwRpy/43zFmo135XwIiuYAZ/v25mVgKISS7SBntjT1HoHEoWNehwMhHWLNh6qj7SiknylVnVzN8jltIJMdumIKaKG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822305; c=relaxed/simple; bh=uM7fZITeS4kzRvKYIAo9m9PY8ycUoTWCRTIzN1uC3eY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jb0Phlt2FNhzPFE5V5sDDLyzHlxvMckCX6w9SLXVtPpJSeiOMYTjzTaJM7Xn6xe0uNOxucqxXEa4KsyBfLBsH8dqjMMl2Xpmg19VEjGuyORqsvpWiuzQodHxaqR2fb+onW0PF8o74f4ucAvw/bkF1EBn1i68K/y20NgHFkwz7hg= 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=Wgt5mGlE; arc=none smtp.client-ip=209.85.219.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="Wgt5mGlE" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6d18dff41cdso34562646d6.0 for ; Tue, 05 Nov 2024 07:58:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822302; x=1731427102; 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=Mn3qXuCprKkV0lHxekStETofBm7VBuDAWcIvFmwwo7o=; b=Wgt5mGlEDnb1v4ES4coVxgMJOqno5PWuQPvHVeo93Q6yFUnwXp5fQ3bPaGJAnW3rOk PXDqoRnR7dNqdG8rycQ/D986ULvsTeRtbSpzj4IlOt68J5BPOSpccx+5+vPKTtUD9QgV wyPsox1i5qPgs+7mn0dTDsmq0ffjo9JBeL+YF02VPUN0yISfrMjDTGiH5vmlRJKKIcen eVk3qLAfrYEaNUWnb5Ok/oFhxDTRIYA9QerRVEZSIAz5PUr1TyVoN0EO1gT2o1Xywoxr d+zxVsi2sJoFmROidOAPo+NpsCE/yF49gvwUQ+05uNk5Q21EQtS6umjd8OTxt/99iB/A P/8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822302; x=1731427102; 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=Mn3qXuCprKkV0lHxekStETofBm7VBuDAWcIvFmwwo7o=; b=AkQeydAz+4faltMBRVcEi0aB6WOLbgeAZFQcQFsLArPEuuC/22n3tRr3GfBNnE9VKH 9p7rAlVc7bEFGThPHBUJ4exSQNiYhnKxaJbicsoKxpEx04UAhPAJeFivwEoX8zV7sPF3 1onoEDIsVilDPY81AH3qik4wjzfvR0hS6/BregR/VusrSlsETtt+H7hYf3H2owMW3psp 2SgnUArKrnKemznPqPp7xIUMmyQB8AF8wbZd5yHOTrme9JI/9a7x040gleI/aOD8qAHq v6KqK/4XHLvlU73rKSaQvxrZp2WzkLCqhcM81UpUgOT4MQt3fqbPDYo6rB4XGcgjbpGg Llxw== X-Gm-Message-State: AOJu0Yz/JxANKyBUKf/BEiG74uLR/JqnVGfPj46tNQOEs44jbpLwCjS3 J8tn2e9DAT9d26yewG/IGIWe7D101KZDVS7E5yi1+C7w3zcbEYYUVuVY X-Google-Smtp-Source: AGHT+IH8VROdhfa/CG+F5KGBYGr5o73Mev4N5h/q/3VZ7frzZivyO1+3kC+hCYIYV0hMoBqTnS46IQ== X-Received: by 2002:a05:6214:5901:b0:6cb:2456:537 with SMTP id 6a1803df08f44-6d1856fa07amr485554546d6.29.1730822302429; Tue, 05 Nov 2024 07:58:22 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:22 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 07/16] x86/module: Deal with GOT based stack cookie load on Clang < 17 Date: Tue, 5 Nov 2024 10:57:52 -0500 Message-ID: <20241105155801.1779119-8-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Clang versions before 17 will not honour -fdirect-access-external-data for the load of the stack cookie emitted into each function's prologue and epilogue. This is not an issue for the core kernel, as the linker will relax these loads into LEA instructions that take the address of __stack_chk_guard directly. For modules, however, we need to work around this, by dealing with R_X86_64_REX_GOTPCRELX relocations that refer to __stack_chk_guard. In this case, given that this is a GOT load, the reference should not refer to __stack_chk_guard directly, but to a memory location that holds its address. So take the address of __stack_chk_guard into a static variable, and fix up the relocations to refer to that. Signed-off-by: Ard Biesheuvel Signed-off-by: Brian Gerst --- arch/x86/include/asm/elf.h | 3 ++- arch/x86/kernel/module.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h index 1fb83d47711f..0d6ca771549d 100644 --- a/arch/x86/include/asm/elf.h +++ b/arch/x86/include/asm/elf.h @@ -55,7 +55,8 @@ typedef struct user_i387_struct elf_fpregset_t; #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define R_X86_64_RELATIVE 8 /* Adjust by program base */ #define R_X86_64_GOTPCREL 9 /* 32 bit signed pc relative - offset to GOT */ +#define R_X86_64_GOTPCRELX 41 offset to GOT */ +#define R_X86_64_REX_GOTPCRELX 42 #define R_X86_64_32 10 /* Direct 32 bit zero extended */ #define R_X86_64_32S 11 /* Direct 32 bit sign extended */ #define R_X86_64_16 12 /* Direct 16 bit zero extended */ diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 837450b6e882..9929be7a76e7 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -19,6 +19,7 @@ #include #include #include +#include =20 #include #include @@ -130,6 +131,20 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs, goto overflow; size =3D 4; break; +#if defined(CONFIG_STACKPROTECTOR) && \ + defined(CONFIG_CC_IS_CLANG) && CONFIG_CLANG_VERSION < 170000 + case R_X86_64_REX_GOTPCRELX: { + static unsigned long __percpu *const addr =3D &__stack_chk_guard; + + if (sym->st_value !=3D (u64)addr) { + pr_err("%s: Unsupported GOTPCREL relocation\n", me->name); + return -ENOEXEC; + } + + val =3D (u64)&addr + rel[i].r_addend; + fallthrough; + } +#endif case R_X86_64_PC32: case R_X86_64_PLT32: val -=3D (u64)loc; --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 358EE17E012 for ; Tue, 5 Nov 2024 15:58:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822307; cv=none; b=mHoR2yIZeFxHtDsHbU9SU1vMG7D4/fH7irEDg4GQFfovvHPHpmoS/JkMAqHVb5FR/YCmwfyo1juuGVhC6v5nMqaSps00HTbGK/yAmYsB8LFOXa5Zp3KbuKERoa5j46SIywkc6JhuFpn3/WqmKinYe39OYWuuIokiupMDl454sTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822307; c=relaxed/simple; bh=Vu4Aru3t+nTD/9DhTWuOwqYb5bFFth9MASE/1e7AN8M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9vvx8f1FL/SMb6IZe1h+Q5Rh4oJYuR7oZlZyCzc38+k8g2y/k9srB1oafojEt3C7XdmeTfCKRpzjrZDbFpgn48Mj3mpazM8T/sHFrIbiswg7lWUhh6FVvIo3ellZGbb0Xj8g8kpNl7hZAdfCoYuNV5Vdi9olTaWmJhpMlJvlfg= 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=JGxS1Owy; arc=none smtp.client-ip=209.85.219.44 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="JGxS1Owy" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-6cc2ea27a50so55908106d6.0 for ; Tue, 05 Nov 2024 07:58:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822304; x=1731427104; 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=kxOt6HJKiLxKCbdBkzP9Xb/0alDeNpfIlya14qEzTTk=; b=JGxS1OwyFvteJUaRxdET8kWjU80UfTHCO5oaG1apuv2fFfKC8KjhHe6vrOlXu7X2rO mZycE7Q6pCa5+FK3vv0XqKk/oHF0Hln/VZ7dcOEkxfvfjBMSZiADHKELDH7Ayx/nfRBk L/+KDnXuOb2DaL7XB/HdZndSYhpi9j5/aXLzBeILFW1r5Pr29fRF/h+xMc9gJtceNk1Y xwvwmNo2/GWYiXktSP0wVBUk8wHPrdaSFE2DDChT4Ymkz+3TqtiEVc7kVE3f78KXoLde RzyJpGNeGmHvwZAiNY6RfuidYRMltdU60T7R9Hi4K/X8/lRbWD1YGjJ6LOXVykXfH4ux bu8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822304; x=1731427104; 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=kxOt6HJKiLxKCbdBkzP9Xb/0alDeNpfIlya14qEzTTk=; b=nRPJhkIqtFLxx2XK2CJLdNic+2JdO5Tx9sFgRV4x3UVCrfC/XkeWC5TBM/HFZ8TQeH vrccnSTGtdmOv/iYHz/JLc8NLs2PnA9ih0X+tKvtnfj/sXUL1/iSFxYKf6rKOe70Z047 dYrZSzj2kK5C7Xm0JAFtZKvT0HB2+a014n4hf1wSyJSorcwt4LfOD6dUSudQdPaliwR1 pCU9Cf4pKbk6b0t44HeYoRJauSdHJAcZMa5eMcQhMDsZmyoabg0QYgCeUvGMKJhWU54r +JBjtqRibV0nG4J4GYGaQ1kPj3ko1++yDkVPXx3ca+lqcIQ2RQ1mW33fZxakLzY2o0U4 u9lw== X-Gm-Message-State: AOJu0YxTthkeplrJCWGwX/GDEi22OjGiFJjP3pZ34TXB1DGLu+kr8dV9 p8QvKvULiWR5JcKYQBuTfpAcRKi3sRw8cCDHWjtCAy9972FRQNXDgyx8 X-Google-Smtp-Source: AGHT+IG/lzUnhk7On5qjLnzU09eKlneqCzP/cSnIIFoXsH09tVs6kVXFDfbYtoMnnmFrPC3pghg4OQ== X-Received: by 2002:a05:6214:2241:b0:6cb:c892:8c17 with SMTP id 6a1803df08f44-6d35b964b39mr319750636d6.22.1730822303581; Tue, 05 Nov 2024 07:58:23 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:23 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 08/16] x86/stackprotector/64: Convert to normal percpu variable Date: Tue, 5 Nov 2024 10:57:53 -0500 Message-ID: <20241105155801.1779119-9-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Older versions of GCC fixed the location of the stack protector canary at %gs:40. This constraint forced the percpu section to be linked at absolute address 0 so that the canary could be the first data object in the percpu section. Supporting the zero-based percpu section requires additional code to handle relocations for RIP-relative references to percpu data, extra complexity to kallsyms, and workarounds for linker bugs due to the use of absolute symbols. GCC 8.1 supports redefining where the canary is located, allowng it to become a normal percpu variable instead of at a fixed location. This removes the contraint that the percpu section must be zero-based. Signed-off-by: Brian Gerst Reviewed-by: Uros Bizjak --- arch/x86/Makefile | 20 +++++++++------ arch/x86/entry/entry.S | 2 -- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/processor.h | 16 ++---------- arch/x86/include/asm/stackprotector.h | 36 ++++----------------------- arch/x86/kernel/asm-offsets_64.c | 6 ----- arch/x86/kernel/cpu/common.c | 5 +--- arch/x86/kernel/head_64.S | 3 +-- arch/x86/xen/xen-head.S | 3 +-- 9 files changed, 23 insertions(+), 70 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5b773b34768d..88a1705366f9 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -140,14 +140,7 @@ ifeq ($(CONFIG_X86_32),y) # temporary until string.h is fixed KBUILD_CFLAGS +=3D -ffreestanding =20 - ifeq ($(CONFIG_STACKPROTECTOR),y) - ifeq ($(CONFIG_SMP),y) - KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3Dfs \ - -mstack-protector-guard-symbol=3D__ref_stack_= chk_guard - else - KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal - endif - endif + percpu_seg :=3D fs else BITS :=3D 64 UTS_MACHINE :=3D x86_64 @@ -197,6 +190,17 @@ else KBUILD_CFLAGS +=3D -mcmodel=3Dkernel KBUILD_RUSTFLAGS +=3D -Cno-redzone=3Dy KBUILD_RUSTFLAGS +=3D -Ccode-model=3Dkernel + + percpu_seg :=3D gs +endif + +ifeq ($(CONFIG_STACKPROTECTOR),y) + ifeq ($(CONFIG_SMP),y) + KBUILD_CFLAGS +=3D -mstack-protector-guard-reg=3D$(percpu_seg) + KBUILD_CFLAGS +=3D -mstack-protector-guard-symbol=3D__ref_stack_chk_guard + else + KBUILD_CFLAGS +=3D -mstack-protector-guard=3Dglobal + endif endif =20 # diff --git a/arch/x86/entry/entry.S b/arch/x86/entry/entry.S index b7ea3e8e9ecc..fe5344a249a1 100644 --- a/arch/x86/entry/entry.S +++ b/arch/x86/entry/entry.S @@ -52,7 +52,6 @@ EXPORT_SYMBOL_GPL(mds_verw_sel); =20 THUNK warn_thunk_thunk, __warn_thunk =20 -#ifndef CONFIG_X86_64 /* * Clang's implementation of TLS stack cookies requires the variable in * question to be a TLS variable. If the variable happens to be defined as= an @@ -66,4 +65,3 @@ THUNK warn_thunk_thunk, __warn_thunk #ifdef CONFIG_STACKPROTECTOR EXPORT_SYMBOL(__ref_stack_chk_guard); #endif -#endif diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S index 1b5be07f8669..f78ef9667c39 100644 --- a/arch/x86/entry/entry_64.S +++ b/arch/x86/entry/entry_64.S @@ -192,7 +192,7 @@ SYM_FUNC_START(__switch_to_asm) =20 #ifdef CONFIG_STACKPROTECTOR movq TASK_stack_canary(%rsi), %rbx - movq %rbx, PER_CPU_VAR(fixed_percpu_data + FIXED_stack_canary) + movq %rbx, PER_CPU_VAR(__stack_chk_guard) #endif =20 /* diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/proces= sor.h index c0975815980c..a113c3f4f558 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -419,16 +419,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; @@ -443,11 +435,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 9d42bd15e06c..1f33d5feb050 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2086,8 +2086,7 @@ void syscall_init(void) if (!cpu_feature_enabled(X86_FEATURE_FRED)) idt_syscall_init(); } - -#else /* CONFIG_X86_64 */ +#endif /* CONFIG_X86_64 */ =20 #ifdef CONFIG_STACKPROTECTOR DEFINE_PER_CPU(unsigned long, __stack_chk_guard); @@ -2096,8 +2095,6 @@ EXPORT_PER_CPU_SYMBOL(__stack_chk_guard); #endif #endif =20 -#endif /* CONFIG_X86_64 */ - /* * Clear all 6 debug registers: */ diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 56163e2124cf..c3028b4df85f 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -355,8 +355,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.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 58598185B69 for ; Tue, 5 Nov 2024 15:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822308; cv=none; b=O4a6xkgKylNUcgcQ8TgsJbXug32jMIttpRresEMnGZt6xef4F6+B5dr3tZiGfPTXVo4uo1WZmKUYB0v4+Jm5B1tcBuQvBzXz+8E4UloNNlf95OFsfuLyPGcISMSZ62irYZ997rA5TdHkNISE0qyvK3z44YcPQUZkAhi63WxJ2uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822308; c=relaxed/simple; bh=wOAN3PdAyvx5lN8DA7Jr9l+PSsU2gFDnV0QIPvGQy/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Si9YjAvnGA9jcTCNy3u1jwnf99gyRgXFBYjgYQkteiWW2ILIfZOSdgvtTXOt21sqJCDnwlx87rrsrSbpf+X0g0uHJo5dq5NAYo/4HOD/HsHcT/Jfn7U8J8hi11hrYXesTyRerw5RW/kQEx4uLW8desOPg0eLAmd8X6i0VNQ/Yvc= 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=egwzwXQb; arc=none smtp.client-ip=209.85.219.46 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="egwzwXQb" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6cbf0769512so36330506d6.3 for ; Tue, 05 Nov 2024 07:58:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822305; x=1731427105; 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=Pk5EeZ2tUI9SbgFH2i6WD82PzVaWkSaCnBLgM6sYjJg=; b=egwzwXQbDJkZv8Xp2ui08hpVsdADolNn2uiYdguAgm30DllyNcxLFcMkP5sp63pj6Z ZoGkwXbNsArzqd/toeCVNr48HynlTBu/tvvl5hFobNs2UCIeGFULHJPVADpaU6ToTDI6 I1Z4OyVlQLJFNV6HzAa3q4v1/40p9v3Q0uP4Zi1GRl6Nb+YrGq5Loktg462jNkgTF+zG Bgm1DIAI3HYZQ9XQvUdjDXLadSI0FpL7ut1XyASKaNDGOxAltCYL/Y8BYXqvsC7uaiFK ohmAHLG6hXlpCqYL8lA9h+Pr+3TnWDL0rOv/HyW+R1f2ncTTvbM3XMpXeZcVyie5ESC4 T3Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822305; x=1731427105; 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=Pk5EeZ2tUI9SbgFH2i6WD82PzVaWkSaCnBLgM6sYjJg=; b=j6OuIkqCpoLfcoemOmiQjqpzWmM1TOaxetIiXHcw0TS0CSNxQzPMvpI0VXZz7C5Ke6 DFmGqMTmOPONAoCC0FK8H8VGfreqilZzG/gkqqRBpk1vBdPDSwzjRHdRBPNtrFYtvOgI /w0kkQIuRVaED/drHnvgtdvnuI//ldp8Zr2l3cSNchs7t+f58a96YkspxbcAfEm86gOB oEuPkdEi/jHX0BSrok1v/hjcn9EXH9WgSKaG/DbG4K1ByN2/+GwO+EbExGeGrgaoa0RV FqQgh4Zj9qyETx6MEniSU7zv+vLMX+tn17AXqEx3+96rreNWKbCoOMFqhhxXehdigsps ztNg== X-Gm-Message-State: AOJu0YzJDjApUbx7imu3nY+nHURn+gMUH4wCnws71M+33BloG6HZNLh3 tPZefvdGdwTJJ9l84HyShbWWSrQ3VdM38brV7pNSPkbW9Lh3jYD/Dqak X-Google-Smtp-Source: AGHT+IHIjQBB17G0K2htaT5VK8YQAH65Fg43pxrKi708tGNDua0ae1fTrV8uoFQ9p0Zb8EH0bTLwXg== X-Received: by 2002:a05:6214:5c89:b0:6d3:55ee:35d with SMTP id 6a1803df08f44-6d355ee0410mr327056846d6.7.1730822304772; Tue, 05 Nov 2024 07:58:24 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:24 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 09/16] x86/percpu/64: Use relative percpu offsets Date: Tue, 5 Nov 2024 10:57:54 -0500 Message-ID: <20241105155801.1779119-10-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-1-brgerst@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The percpu section is currently linked at absolute address 0, because older compilers hardcoded the stack protector canary value at a fixed offset from the start of the GS segment. Now that the canary is a normal percpu variable, the percpu section does not need to be linked at a specific address. x86-64 will now calculate the percpu offsets as the delta between the initial percpu address and the dynamically allocated memory, like other architectures. Note that GSBASE is limited to the canonical address width (48 or 57 bits, sign-extended). As long as the kernel text, modules, and the dynamically allocated percpu memmory are all in the negative address space, the delta will not overflow this limit. Signed-off-by: Brian Gerst Reviewed-by: 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 a113c3f4f558..ae50d5d4fa26 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -428,7 +428,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 c3028b4df85f..ffbcb0aea450 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -61,11 +61,14 @@ SYM_CODE_START_NOALIGN(startup_64) /* Set up the stack for verify_cpu() */ leaq __top_init_kernel_stack(%rip), %rsp =20 - /* Setup GSBASE to allow stack canary access for C code */ + /* + * Set up GSBASE. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ movl $MSR_GS_BASE, %ecx - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx - movl %edx, %eax - shrq $32, %rdx + xorl %eax, %eax + xorl %edx, %edx wrmsr =20 call startup_64_setup_gdt_idt @@ -353,16 +356,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 d61c3584f3e6..42d1c05b0207 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 @@ -199,21 +193,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 @@ -330,9 +310,7 @@ SECTIONS EXIT_DATA } =20 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP) PERCPU_SECTION(INTERNODE_CACHE_BYTES) -#endif =20 RUNTIME_CONST_VARIABLES RUNTIME_CONST(ptr, USER_PTR_MAX) @@ -476,16 +454,11 @@ PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); * Per-cpu symbols which need to be offset from __per_cpu_load * for the boot processor. */ -#define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) + __per_cpu_load +#define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) INIT_PER_CPU(gdt_page); INIT_PER_CPU(fixed_percpu_data); INIT_PER_CPU(irq_stack_backing_store); =20 -#ifdef CONFIG_SMP -. =3D ASSERT((fixed_percpu_data =3D=3D 0), - "fixed_percpu_data is not at start of per-cpu area"); -#endif - #ifdef CONFIG_MITIGATION_UNRET_ENTRY . =3D ASSERT((retbleed_return_thunk & 0x3f) =3D=3D 0, "retbleed_return_thu= nk not cacheline-aligned"); #endif diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index b0a9a58952aa..c931e680ef15 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -165,9 +165,8 @@ SYM_CODE_START_LOCAL(pvh_start_xen) * the per cpu areas are set up. */ movl $MSR_GS_BASE,%ecx - leaq INIT_PER_CPU_VAR(fixed_percpu_data)(%rip), %rdx - movq %edx, %eax - shrq $32, %rdx + xorl %eax, %eax + xorl %edx, %edx wrmsr =20 /* diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 7d7fc7f0a250..8b5e2bc3d241 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -834,12 +834,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 @@ -1055,7 +1050,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 c521e1421ad4..b374c0de5cfd 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1849,7 +1849,7 @@ config KALLSYMS_ALL config KALLSYMS_ABSOLUTE_PERCPU bool depends on KALLSYMS - default X86_64 && SMP + default n =20 # end of the "standard kernel features (expert users)" menu =20 --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 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 5F3BE153803 for ; Tue, 5 Nov 2024 15:58:27 +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=1730822309; cv=none; b=Hid/m/ZJhKEEHHZHO0hMpc0lmL6G6R0l+CfYgQTWQPlPkiERmCdl7IwkgAICPB4vjz6MRdYT/FM/OSlMwFlGnPmJZ3RmAZxTxOlYFHTm40Uxr3l4RQ+Ul3Pzi/XxccRBMatTbVQLCh1uQJEQk8uWZy9JvCosolc+SGr6nO9mlQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822309; c=relaxed/simple; bh=VKZxyxQuCeCAp7E1ZD/xgpVA5NwZJY41JC3Fi32MySo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nrlCjPwzRpxBXrhnF8YK9+nVJPnqjl31dGqo3FDAjkWNhaJK/13rOUBazZhyN/yBlQ2hSdfzQF1La/YDMsmEfGdUUK6ZzopV0hSPTYikCF2kvqzZUKQVQm37Xruvm4lzT5z/3knBWJr0KH+5QAZdbMCfTeuZeQ8mzQpj4BkoLVQ= 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=kFQlFI8w; 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="kFQlFI8w" Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7b1507c42faso488391085a.0 for ; Tue, 05 Nov 2024 07:58:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822306; x=1731427106; 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=rYtUu/3spTzBfsHpJwDAQi6vkZMUuhHEudbP0S8CJAI=; b=kFQlFI8wMajP2qN8EZWYnUrrDaVeuF3eS0NWGOyZx8NEQw+k0Unfcw/9adeOrywTVn G6NVrNSAjONM+luc+n+IFzAbZzSXRVkiSINtC0kdp4AiN5yJBsLpL2rajlHPO0JM6oI+ NyNNDs6CVzdkrkW2nsAi26InLH/e+oWtoX+YRjuqNhJTM296O1AreNjE+oF8udoEfCXw WIko07guox8dp8uw9nGbcs7xUNzm4TKuHMiyN0fNVpMvwenwVrG7izS3DZ8O7QHTVXgm VFAucQ5VBSk+QEbEO+1BAWHNzWG1l/LjXNBYL129O71Vi/V/M2EC/mBWULQHLo8E26bM hlRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822306; x=1731427106; 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=rYtUu/3spTzBfsHpJwDAQi6vkZMUuhHEudbP0S8CJAI=; b=X/IcK0nIvZtu+2wp902Xm/IvD1GqXJgN4XOyFzVpw6z+oyHuEQX+AKK3wOnrthPluU phMXBcO76OZ5S6AGgf6sORfiCAX7CBvue1Du7hYIjdu2plLGCjvKrqKNhOqPchi6timc 406hJkmWcVon2pd3s6heU6SMflpQTqQorgyjklBjMXa3UsZc3aRr8yWGOPJMgyBnAEtX 8y/x1e3uQKdKrdwWUfzoCQ46+RDv1WlBmYBMKCBWPVTqOZfGWZhXpj9bxVZLu2t23e52 +AvQ5ukAfdwMlTJt1C0bemEAJtMRhRu82AeIP5VIbQB/xd05PE5djAB/NPY7CyjRN2Tn VJUA== X-Gm-Message-State: AOJu0YzbNtwyLAPvS73jWdJjDlB+xx746mZr9s5gFZCXZLf0kFCZbgCg bqUWTij9CUSwoxuRUgSsUwls9Rxuox7mxqS3H6qksR7vLT6mAZkZK97h X-Google-Smtp-Source: AGHT+IHJ0vJs6Nk1zwPgH5KUP/ZZRTfwjSoxm05Oh/3CWA4aU8hlkdRE/ebP8IGoApHWXFwDOT1uWA== X-Received: by 2002:a05:6214:483:b0:6cb:644e:c9a8 with SMTP id 6a1803df08f44-6d35b8e6aefmr286579416d6.4.1730822305870; Tue, 05 Nov 2024 07:58:25 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:25 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 10/16] x86/percpu/64: Remove fixed_percpu_data Date: Tue, 5 Nov 2024 10:57:55 -0500 Message-ID: <20241105155801.1779119-11-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 ae50d5d4fa26..e1b856e2f944 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -418,14 +418,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 1f33d5feb050..d6102e772c7e 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2020,10 +2020,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 42d1c05b0207..859ff7c0dc02 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -456,7 +456,6 @@ PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); */ #define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) INIT_PER_CPU(gdt_page); -INIT_PER_CPU(fixed_percpu_data); INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_MITIGATION_UNRET_ENTRY diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 8b5e2bc3d241..a661a6bab4cf 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -829,7 +829,6 @@ static void percpu_init(void) * __per_cpu_load * * The "gold" linker incorrectly associates: - * init_per_cpu__fixed_percpu_data * init_per_cpu__gdt_page */ static int is_percpu_sym(ElfW(Sym) *sym, const char *symname) --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 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 A121D1D414B for ; Tue, 5 Nov 2024 15:58:28 +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=1730822310; cv=none; b=JD85Y4I5f/OtNQbIz/px+/A2dLPAj8IFEp4IL+7L0/KUDnjbV+U0sehWhfxrPg3iZxSQ0ynjzSTR9nYfYMQGKPIGvR4cDcA0iaCaNhNJ9kwljsdti9eW8t+YTDk1DU3s7U51a0sIP9A2/BIkQ62at7OItqe8cRnVqCRd/jz95c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822310; c=relaxed/simple; bh=TmUCx4UpY+BQFLsOPmL14Hg7eWM+uT42BafZdQbiR4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WVn36whMQYROhNihT8CVSPXPEBg8GUogkR2CbdWrW0u6TKqGIzw3nPfr2ocK3kDb/xfliPrTaP0cVw4sc/kfVlXq4s28gBAv9ZVogawVr8CRzYUEKdi0KmNiESZEzlouicEu2OrXGlRZqp4QNEhXG1afWv6GiQ0vRl7V6S4mmPw= 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=lFwEFWLY; 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="lFwEFWLY" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-7b14f3927ddso431239285a.3 for ; Tue, 05 Nov 2024 07:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822307; x=1731427107; 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=m9WD19gdt8CNaGFyWP/88P7iTTjUvAoc05Lsqx3RBdA=; b=lFwEFWLYXvWTEem7BdaXVuN2n/Q9W6OamrTz1TT6U9uOLNjA30m6Dbk0vvsVfGIhC6 VWCvFw6DdhNSEejGbwNJcdMn1zsCfkKTMeQQb6pBmuIxuW3hBawKGjUmLo5WopctwM4k qKuwFjaup1TC5gQbjZBZ2MjogzdII1tAGCfjawaBodAx5lEbFDUbKmN1bR7qDSRvxwVB bD6ej9ARQNERFL7WdDRxllmcJ0c4+5EVzBPEkSU3izV223P0qweiD/0Zpu4yvyp6kbFA QoFvCm6ARqX8NZhYJUXPzHzolliIBKyu9w5Z/KngrGqGPWcTAWQzCusSixxfUSXH/H0L fMEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822307; x=1731427107; 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=m9WD19gdt8CNaGFyWP/88P7iTTjUvAoc05Lsqx3RBdA=; b=DKJFi7y6jArL5VMgsOjMOEN96uIbIo4CfwofJ9PYqOgDTPTjKPPiJHi1CbS8WnL1O7 ObzFl9EDhSYYfMqL/+hTmTi4xRXyHfkgG2+lmk1n6nk3JljoFxsWt4kAamGC4UQLLH55 kUTByi1ROAv9OWBAMN9hPz1Efw3AKPiJdpuXRpau42RuUOMSLbfxwWI80T/jrIfej1cj gM2yzRbwwpkMwbQi2RCxGwhEBcgNXbC/4yyZGLNbTIdjthiVk73kdkf5G3fXEFUuI7as OTymn0ekspS0KSatkCyEQ3O9Kt9S0YKKtIqoZcBtOsiD/LdEUgrlmicT9jeJJfE8VS/p nqOQ== X-Gm-Message-State: AOJu0Yx16Oer28W3OrB/UilZnW7J0Im41QpYmlmCeK4E8giFy/ca5Uh3 2fSDP5UHGcaW33jMexZYxVix5mNb0oCqIJVIo4SbLRBsysd/qsaY3Ji/ X-Google-Smtp-Source: AGHT+IFBJUBm5do6sgjewQawqaxPEnRX6M4L/ZUZIiKr4vCweI0y7slZ6Q4FQihmyy14BQsPKfVOOw== X-Received: by 2002:a05:6214:469a:b0:6d3:45ad:d850 with SMTP id 6a1803df08f44-6d345addb51mr358711426d6.26.1730822307045; Tue, 05 Nov 2024 07:58:27 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:26 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 11/16] x86/boot/64: Remove inverse relocations Date: Tue, 5 Nov 2024 10:57:56 -0500 Message-ID: <20241105155801.1779119-12-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 | 130 +------------------------------- 2 files changed, 2 insertions(+), 142 deletions(-) diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/mis= c.c index 0d37420cad02..1cdcd4aaf395 100644 --- a/arch/x86/boot/compressed/misc.c +++ b/arch/x86/boot/compressed/misc.c @@ -235,7 +235,7 @@ static void handle_relocations(void *output, unsigned l= ong output_len, =20 /* * Process relocations: 32 bit relocations first then 64 bit after. - * Three sets of binary relocations are added to the end of the kernel + * Two sets of binary relocations are added to the end of the kernel * before compression. Each relocation table entry is the kernel * address of the location which needs to be updated stored as a * 32-bit value which is sign extended to 64 bits. @@ -245,8 +245,6 @@ static void handle_relocations(void *output, unsigned l= ong output_len, * kernel bits... * 0 - zero terminator for 64 bit relocations * 64 bit relocation repeated - * 0 - zero terminator for inverse 32 bit relocations - * 32 bit inverse relocation repeated * 0 - zero terminator for 32 bit relocations * 32 bit relocation repeated * @@ -263,16 +261,6 @@ static void handle_relocations(void *output, unsigned = long output_len, *(uint32_t *)ptr +=3D delta; } #ifdef CONFIG_X86_64 - while (*--reloc) { - long extended =3D *reloc; - extended +=3D map; - - ptr =3D (unsigned long)extended; - if (ptr < min_addr || ptr > max_addr) - error("inverse 32-bit relocation outside of kernel!\n"); - - *(int32_t *)ptr -=3D delta; - } for (reloc--; *reloc; reloc--) { long extended =3D *reloc; extended +=3D map; diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index a661a6bab4cf..8d9e82748615 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -29,7 +29,6 @@ static struct relocs relocs16; static struct relocs relocs32; =20 #if ELF_BITS =3D=3D 64 -static struct relocs relocs32neg; static struct relocs relocs64; # define FMT PRIu64 =20 @@ -90,7 +89,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 @@ -289,34 +287,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) @@ -765,78 +735,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) { @@ -847,12 +747,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. */ @@ -862,32 +756,21 @@ static int do_reloc64(struct section *sec, Elf_Rel *r= el, ElfW(Sym) *sym, case R_X86_64_PLT32: case R_X86_64_REX_GOTPCRELX: /* - * PC relative relocations don't need to be adjusted unless - * referencing a percpu symbol. + * PC relative relocations don't need to be adjusted. * * NB: R_X86_64_PLT32 can be treated as R_X86_64_PC32. */ - if (is_percpu_sym(sym, symname)) - add_reloc(&relocs32neg, offset); break; =20 case R_X86_64_PC64: /* * Only used by jump labels */ - if (is_percpu_sym(sym, symname)) - die("Invalid R_X86_64_PC64 relocation against per-CPU symbol %s\n", sym= name); break; =20 case R_X86_64_32: case R_X86_64_32S: case R_X86_64_64: - /* - * References to the percpu area don't need to be adjusted. - */ - if (is_percpu_sym(sym, symname)) - break; - if (shn_abs) { /* * Whitelisted absolute symbols do not require @@ -1094,7 +977,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); @@ -1126,13 +1008,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 */ @@ -1185,9 +1060,6 @@ void process(FILE *fp, int use_real_mode, int as_text, read_symtabs(fp); read_relocs(fp); =20 - if (ELF_BITS =3D=3D 64) - percpu_init(); - if (show_absolute_syms) { print_absolute_symbols(); return; --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.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 C0D0C1D89E2 for ; Tue, 5 Nov 2024 15:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822311; cv=none; b=JCK5Y1iiKbgFw3hi29VAZrDIqybdM9W7xPla1sYpY/kRxcJOyZ97u5OS9DgErOrsOwpvOZdvRzt/s9wSKAENXnV58Uomhl3qXapZsKX4mIcp1CbOzqO8iAb9Kpy/gHMF64nQLhWAceipgWKsPGo0JrOnJj3k0cRJRl60aV6XPD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822311; c=relaxed/simple; bh=B8Gh4qRqNjfVPy5RrfT5smuqJzTShAUNOS01qUV3gCs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VZnAfAEyBSm1jihjeqcsCwKlP+k9a6Rz5118k6Hg6WARAh11geOrFyjL6hx8kGiIpxCIO4Nb2rqt7pmMDu++sG9uU1CvVEKigLWS9BWBSvvLQO/EjEf/NorjNdnzfvpORlFJyZPordeup1qYFuKcR1zXwTCA5IMXzOWy6bCIgLM= 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=KupeMHV+; arc=none smtp.client-ip=209.85.219.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="KupeMHV+" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6cbcc2bd800so48319366d6.0 for ; Tue, 05 Nov 2024 07:58:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822308; x=1731427108; 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=WiqzMq5ogq19Mry3xz2UGi6HbqnwquvC9QM8GIeB9g8=; b=KupeMHV+EtrJwErtoiqd5ZQS+T4Bl5HhdVUyaZ/NjY5kEqlE0Syt8WDiZszElzUc/2 Id9v/gtKj46RH3HBUnzTdATW7psKVdX0gAZ5snJBNiGGSO55bYGaME1vT58DvXLa24zI OpFY0VVKJ4PHETtEGbfJ2B/7UsPysIUJDOm6eaekq4nBltnAFuUxfRJpbRkw+6sCeQTW tHXh8K2zVIe2fTXaHl0YS5H5xvKQZSTmPhgZF2X8gpj1ZMYQyUlX9Aya3Ai1NCfjHkao mDSL0PTlrev+xd9M9QCvXDb7I+8usnlrJbnRi9xjkJaGa8gj4iP/j6oLYld79xUwXNvj PlUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822308; x=1731427108; 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=WiqzMq5ogq19Mry3xz2UGi6HbqnwquvC9QM8GIeB9g8=; b=nETIcbHTeN4tk9/kYyF5Dv/whB2kIErNvoXZBRLzkr3D7+4JdX2IlexnMn//m7R9Ea oBe8lOhYHLj5YQHIZiyAtqo4NwXRYBxfo6DYtiTK/g7aU9LdcOD2ALv8FQ9PVE0HD9AO 6zuCQiiqW4ZqWrPpQ7ASF4mcKA0jMP20HMKQLO4B7i8m/e9ehgueZ/N//PadK7bHKSXG 7brOBYAN56k7Cs6DXjqd47MxcEdJ6c/d4mpTzluj8Zc+KjJO6dwGerz8/ZGktw6HE+Yx NVD/GathpmPK47KAWzgfFaubfV4H7gpk1VcrwyecCOHLzbYQatl5qJBp1clHKDiva8ho rQbQ== X-Gm-Message-State: AOJu0YzvY5kzN3ojoS500NFf9JqY5krLKx2EUTJBcnj9+D6oKDkSTmOt duXK4+z//dvcLuW/M+c5ogoq3g7rRmnnnb2uTRYZ8MBCWuiXXZBdXpNb X-Google-Smtp-Source: AGHT+IFfdaOQHcuxYV9nMbUNrGTH6r6QvGpqPsMBZrQkSqY6KHUGnvdobomssGtbVK5q31tus/UKSg== X-Received: by 2002:a0c:f90f:0:b0:6d3:6827:a7f6 with SMTP id 6a1803df08f44-6d36827ae92mr141878786d6.12.1730822308143; Tue, 05 Nov 2024 07:58:28 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:27 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 12/16] x86/percpu/64: Remove INIT_PER_CPU macros Date: Tue, 5 Nov 2024 10:57:57 -0500 Message-ID: <20241105155801.1779119-13-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 c55a79d5feae..1ded1207528d 100644 --- a/arch/x86/include/asm/percpu.h +++ b/arch/x86/include/asm/percpu.h @@ -20,12 +20,6 @@ =20 #define PER_CPU_VAR(var) __percpu(var)__percpu_rel =20 -#ifdef CONFIG_X86_64_SMP -# define INIT_PER_CPU_VAR(var) init_per_cpu__##var -#else -# define INIT_PER_CPU_VAR(var) var -#endif - #else /* !__ASSEMBLY__: */ =20 #include @@ -97,22 +91,6 @@ #define __percpu_arg(x) __percpu_prefix "%" #x #define __force_percpu_arg(x) __force_percpu_prefix "%" #x =20 -/* - * Initialized pointers to per-CPU variables needed for the boot - * processor need to use these macros to get the proper address - * offset from __per_cpu_load on SMP. - * - * There also must be an entry in vmlinux_64.lds.S - */ -#define DECLARE_INIT_PER_CPU(var) \ - extern typeof(var) init_per_cpu_var(var) - -#ifdef CONFIG_X86_64_SMP -# define init_per_cpu_var(var) init_per_cpu__##var -#else -# define init_per_cpu_var(var) var -#endif - /* * For arch-specific code, we can use direct single-insn ops (they * don't give an lvalue though). diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 4b9d4557fc94..d4398261ad81 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -559,7 +559,7 @@ void early_setup_idt(void) */ void __head startup_64_setup_gdt_idt(void) { - struct desc_struct *gdt =3D (void *)(__force unsigned long)init_per_cpu_v= ar(gdt_page.gdt); + struct desc_struct *gdt =3D (void *)(__force unsigned long)gdt_page.gdt; void *handler =3D NULL; =20 struct desc_ptr startup_gdt_descr =3D { diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c index ade0043ce56e..56bdeecd8ee0 100644 --- a/arch/x86/kernel/irq_64.c +++ b/arch/x86/kernel/irq_64.c @@ -27,7 +27,6 @@ #include =20 DEFINE_PER_CPU_PAGE_ALIGNED(struct irq_stack, irq_stack_backing_store) __v= isible; -DECLARE_INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_VMAP_STACK /* diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 859ff7c0dc02..fd1ecb1dbc1d 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S @@ -450,13 +450,6 @@ SECTIONS PROVIDE(__ref_stack_chk_guard =3D __stack_chk_guard); =20 #ifdef CONFIG_X86_64 -/* - * Per-cpu symbols which need to be offset from __per_cpu_load - * for the boot processor. - */ -#define INIT_PER_CPU(x) init_per_cpu__##x =3D ABSOLUTE(x) -INIT_PER_CPU(gdt_page); -INIT_PER_CPU(irq_stack_backing_store); =20 #ifdef CONFIG_MITIGATION_UNRET_ENTRY . =3D ASSERT((retbleed_return_thunk & 0x3f) =3D=3D 0, "retbleed_return_thu= nk not cacheline-aligned"); diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 8d9e82748615..c3124aac7ab3 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -89,7 +89,6 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = =3D { "__initramfs_start|" "(jiffies|jiffies_64)|" #if ELF_BITS =3D=3D 64 - "init_per_cpu__.*|" "__end_rodata_hpage_align|" #endif "_end)$" --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 B5117154430 for ; Tue, 5 Nov 2024 15:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822312; cv=none; b=gmuMRwNDwSVc+5IWeb0wlin3QUIN+vmAIm7WBVepLewZNxV/CH3rb9sTTXWqTXvl69/y1ERfyaz3XJ16oTqRzEASA4od1SxC3OfyIpzPwbSj9/tm8bpXBEzCPpO5Iffwq5v2gutjFq4mk1S4f4h4VbbD6jm2x/fw6IZqPNXmNns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822312; c=relaxed/simple; bh=S2HoaBKy6z1j9aGSaozTsLk4YS03z3lZSxVfuzo9TYY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AiCZybeZDHlYN8nHdKNd+MR1e20mIf/xWyj2uU8f/KZwzIdS3/Is4NHi96qzu+fVHvhVQBvYTD2BnEWEvTll5x7GMuHxIsKZRATXYsVVYejPLPkd4fF44FPcE/iZLWbyyVTM+n0511gGbK4G08t31Yd7ZFYKLtv7Mat7x7ndmKo= 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=G0I8VELd; arc=none smtp.client-ip=209.85.210.52 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="G0I8VELd" Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-7181eb9ad46so3160806a34.1 for ; Tue, 05 Nov 2024 07:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822309; x=1731427109; 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=CbRa1PSZPGrOnXl26Nh7aIvi1PhhuN4vNBAsvslx+q4=; b=G0I8VELdBoBSm9dmEmEQxsxj2raSQG5t6Uz7MyL1MtQd4ohnIUWpFFa3qruOcQ6Ynd POW1Lg70XbQCOt4G1ixcMtcZEP3ONqof2jvrPnANz+f/k3MhaCb+sQLL7RXAldCC16Fo 9+TrzpsGZsYe3fI3TNLHmiBxOGRJ+vynEbZddDc/0KdF6zKtsiGHHtUi1K6KPiIjvI6o XdaIO9gG7zPezMZ80a6ME0/4Hpq/zQDGV7Y2lDGHKIkcr1H0rkWDNuWYJ1QjaqzuwZKn +lNol6YNs73Vg0Aer+vzMlbDR+YoHVpiS32E+z7cOXQxQtsceqtPqq4wpYVbCed0wZco JfgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822309; x=1731427109; 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=CbRa1PSZPGrOnXl26Nh7aIvi1PhhuN4vNBAsvslx+q4=; b=CbqmjMimPiXN1zpc25DbwU3mjDHRrItKht+66G/MPmV/yLksi5y1tee5/pkN752Gcq ryEnwsvqKuivssuQ9QITcE3ZbPpV2lJ8V5FfcJgH2SGgHcQl6jmWi2GQ80wlhdy0fXyd CRpiIvqLGJPeLTI06gaE4LI3zn950SVFvP3IraaD5OOdnSGs5f0bXs6EUJU4UsK8c+tr xi2N8N4xulsh/Qi58YTx/KRNr9ld5V7Pv/Wwgh/qircqDkP926z6xF0u5ZK1iGcGjSkB FvMz/7yNK/jCpKsFapEQWWadmg3yla6y5nj14+JKKzvsdXSKHp39fZ+mmi9uKSQ36vvK l5/Q== X-Gm-Message-State: AOJu0Yx6uV7TZmmy/Z7Cq6PpDxAKL/c+B0r/SbZ8om+cvOU3WllIwUtZ nwaOZpiY4Mrqhwv7YmoReoRspPEwtm9W01muKooa0JR71RUOwVp+uaKW X-Google-Smtp-Source: AGHT+IGLgFAC7TVHdk51PE00KsD/F3XL1LCaUmbiEhqWt127v4d0Ih/B1vk/JY1kfTxagODV6Iq0EA== X-Received: by 2002:a05:6359:4c91:b0:1c3:724e:f4dd with SMTP id e5c5f4694b2df-1c3f9f615f2mr1797455655d.21.1730822309300; Tue, 05 Nov 2024 07:58:29 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:28 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 13/16] percpu: Remove PER_CPU_FIRST_SECTION Date: Tue, 5 Nov 2024 10:57:58 -0500 Message-ID: <20241105155801.1779119-14-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 | 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 eeadbaeccf88..70830a742095 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1034,7 +1034,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 8efce7414fad..a28fa362d685 100644 --- a/include/linux/percpu-defs.h +++ b/include/linux/percpu-defs.h @@ -26,13 +26,11 @@ #define PER_CPU_SHARED_ALIGNED_SECTION "..shared_aligned" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" #endif -#define PER_CPU_FIRST_SECTION "..first" =20 #else =20 #define PER_CPU_SHARED_ALIGNED_SECTION "" #define PER_CPU_ALIGNED_SECTION "..shared_aligned" -#define PER_CPU_FIRST_SECTION "" =20 #endif =20 @@ -114,16 +112,6 @@ #define DEFINE_PER_CPU(type, name) \ DEFINE_PER_CPU_SECTION(type, name, "") =20 -/* - * Declaration/definition used for per-CPU variables that must come first = in - * the set of variables. - */ -#define DECLARE_PER_CPU_FIRST(type, name) \ - DECLARE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) - -#define DEFINE_PER_CPU_FIRST(type, name) \ - DEFINE_PER_CPU_SECTION(type, name, PER_CPU_FIRST_SECTION) - /* * Declaration/definition used for per-CPU variables that must be cacheline * aligned under SMP conditions so that, whilst a particular instance of t= he --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E6B9F1DAC95 for ; Tue, 5 Nov 2024 15:58:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822313; cv=none; b=f208UCDLGkSY7nEqcNF6niBF77b4L4ZT2qjnb0V4k2VzftrxesHgURgx444QUYkwf1/D4qX1xXLFcKb2r6cmUm22c9rzPTz9JcfDheq05ZirUSBKEARIuMGbvKVaECrNNcl7fI26vLo3jdFkDLQNs8X12OZxA8MFmZqqiWt4niU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822313; c=relaxed/simple; bh=EuV0NACqHVtg4LSrLDeaIKpnaPwdJx4OlSUYYC2lvOk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L93Urr/5pWxZjHayCyQWlTZRt7Zl0QAx+AdwnTaTfBAK5UvzRN675UCRiyjbOkkeohQr9Gt42qUDimpLBq3J7aReI8NgY/77jen6sYOE9cYXFk7lJ23In0B9w/h71UjaXADOL9B2QMM4ZGbnhQAyVC+hfwESwNhtEeyvQtYKU4E= 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=nTQnSg+f; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nTQnSg+f" Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4608e389407so76469271cf.2 for ; Tue, 05 Nov 2024 07:58:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822310; x=1731427110; 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=9d1wa+5S0n96mgyOsVJzjpdZOT+Q+6QsVFwpuBhfxY0=; b=nTQnSg+fh7x4zFEEMPiWS4vJIBRFzQsQhVgN1n8ObOZdRRNEs4IQyEqB/+WZ4GTKLG Od3P6MiX8c0mstH6FEW59gIVR7VEDR1GAFDG9NBKIGTO5LK//gTCayazUi9+RdM6QBQE 1ULA9jO6TzK5znldOVNS+Z0iA+hiklxe9T0osgY7b9SV+5LREjPwTUQd9VKnCetXBWEa B4cQpWSXWehuBXWpj1vQn1I935QKD0lIUKx6gWR4+J/1BYikQrToBrHIsaFH/Cm/+QM7 n4wfHJUJEBXrdUuCCwvpwosEkhuaZgGIZid16M5MpiGLEY3YPyeT/KzrYKcjfsjgmVyT G8AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822310; x=1731427110; 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=9d1wa+5S0n96mgyOsVJzjpdZOT+Q+6QsVFwpuBhfxY0=; b=s7mmBELMyBBIkrKpnzuGk7uz31qUKzCpwbcyBX/ATdSG4pYailzDmsEIVLCTM9fOrr +BX5mr+4VJpc5HXgern6/8vRMl/LU9c/tQbOboGiCL5JSCqolt5l9FOLPlEMBR1KUN8K koe8kLRUawxA3b02jOowXwzTM2Z7dX8sz3ixkm4XyIgUU75dE1kajJWJOCYyGNOUTXSf KHIIIwzN3shBA12y+joE/BlPPqINZVdev8kNtJVC5FGCR6mAixcqXj6Dn9d+duXlupH+ Tq7nKgbYDSFJgR6SgEC+AQyu6q+w//aCSjhJd0VuFQn52GvYHGp3gQWlM4rCil7PQVXT eokw== X-Gm-Message-State: AOJu0YwwN38xABVgCDcSESreqKdv4f/TbpnB3vGFA6KGZergWyhygCFZ rTZGSR4tzP6Ell6lCskUNRf/jBZi348LkdUTldZZbAsSmHGfuCM1mMPN X-Google-Smtp-Source: AGHT+IFSTZxE/XYzyBJqcGhW9IfkFznpokEEMj8p9qUoTKv1t5jkstj7NRdVXps/On4QRDfv4wNjwQ== X-Received: by 2002:ad4:4d91:0:b0:6d1:8c91:99f0 with SMTP id 6a1803df08f44-6d18c919becmr440231736d6.40.1730822310376; Tue, 05 Nov 2024 07:58:30 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:29 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 14/16] percpu: Remove PERCPU_VADDR() Date: Tue, 5 Nov 2024 10:57:59 -0500 Message-ID: <20241105155801.1779119-15-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 | 36 +------------------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 70830a742095..f53915f4e777 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1045,47 +1045,13 @@ __per_cpu_end =3D .; =20 /** - * PERCPU_VADDR - define output section for percpu area + * PERCPU_SECTION - define output section for percpu area * @cacheline: cacheline size - * @vaddr: explicit base address (optional) - * @phdr: destination PHDR (optional) * * Macro which expands to output section for percpu area. * * @cacheline is used to align subsections to avoid false cacheline * sharing between subsections for different purposes. - * - * If @vaddr is not blank, it specifies explicit base address and all - * percpu symbols will be offset from the given address. If blank, - * @vaddr always equals @laddr + LOAD_OFFSET. - * - * @phdr defines the output PHDR to use if not blank. Be warned that - * output PHDR is sticky. If @phdr is specified, the next output - * section in the linker script will go there too. @phdr should have - * a leading colon. - * - * Note that this macros defines __per_cpu_load as an absolute symbol. - * If there is no need to put the percpu section at a predetermined - * address, use PERCPU_SECTION. - */ -#define PERCPU_VADDR(cacheline, vaddr, phdr) \ - __per_cpu_load =3D .; \ - .data..percpu vaddr : AT(__per_cpu_load - LOAD_OFFSET) { \ - PERCPU_INPUT(cacheline) \ - } phdr \ - . =3D __per_cpu_load + SIZEOF(.data..percpu); - -/** - * PERCPU_SECTION - define output section for percpu area, simple version - * @cacheline: cacheline size - * - * Align to PAGE_SIZE and outputs output section for percpu area. This - * macro doesn't manipulate @vaddr or @phdr and __per_cpu_load and - * __per_cpu_start will be identical. - * - * This macro is equivalent to ALIGN(PAGE_SIZE); PERCPU_VADDR(@cacheline,,) - * except that __per_cpu_load is defined as a relative symbol against - * .data..percpu which is required for relocatable x86_32 configuration. */ #define PERCPU_SECTION(cacheline) \ . =3D ALIGN(PAGE_SIZE); \ --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.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 164221DD0D7 for ; Tue, 5 Nov 2024 15:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822315; cv=none; b=J7mIxZawzTpoBGjyA+udUJfDOxrpLeNtL4lf09vjn5HXw8FKfMPZCZnHW9hfOCJPVIVS9fS2yxycgDr1cS56ANX87oKAeTO6aRAdNNlz6KAnfxJKfHGT9G3zZSZ/4mK5diNb2lCQwkvLQpwJOQeg7nQgzXXTb6pxDV0/ql2QjHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822315; c=relaxed/simple; bh=ddD8kOgUySWXU+t1Fz3l0vCDJIILQOK7HJ5sY7qrQm4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AYfTPKwfy1W9nen33M0NLXvTQd37n0lPGDiIz/4HhaWb11Y2zSY7yZHykKRuOtj4AVYo8W+eT/H/Rp0PG3YSiKZcUva94jgxFseRgMqewewUnTDVz7EWYQz3dxpHWAI6W1qIIo6ky2yCoZ3qL9U6GZCFnoxyslN4Mlb06D+CH0U= 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=WWmA1e8n; arc=none smtp.client-ip=209.85.219.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="WWmA1e8n" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-6cbd092f7f0so42075336d6.0 for ; Tue, 05 Nov 2024 07:58:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822311; x=1731427111; 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=goZZ5I0gFUaUWAFAFqOvJ466XiJgft1xakHpTSDyHJk=; b=WWmA1e8nYmmoj294mjYTmsN4QMUhNi7tXd49FyH/Tl6Z1u9o133RX0QQ4qMf6hcCuH DuOQV7nZBDk2tpRgHOWntUkZczQmIEHmumDr28qRbg8X/ZGoyz8n3TnCx4JuNBu4RLfA XnuLOdCfNYxGosP7oYYHwp0i0cWRCEqfHmJWs8Za2g0VYT5z5z3ctsT1uP2hR9qMs/Fn AXBYbJNi4ZDHPKogGCM3coNGd3E9G0UKT9EbgfTCPZR5gXfbBhBXbB8zTX9j3kOHoWTg qK56/MZVxXIU+60h8hiLFP2GY2xoPGHgbwHNYBxeoDVgydgzoGNG+ZmVfhj0P4yqoVI4 32ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822311; x=1731427111; 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=goZZ5I0gFUaUWAFAFqOvJ466XiJgft1xakHpTSDyHJk=; b=lcu1UJTALp8YXh2VGBk3wysQegrUDRPfdQfxVKdvpuSE/1xBbwuExevacj/g+7pYYE lPWR11rmS+uwrUK/29Yg6ZHAfHkCLuQvsqlhEk+t5+4ss7eqf/rc7v7jUZGvEKU1Euot zCAU3I+MuMb25UnnGp8A8BSyYum4J0IbZTu2WfEbSmjElbdGqQqfj29VHPwWf9yBd4O+ txbbZeIV5ZLcOTZmXEo2tk4QDRVhUe3tu2DNSpbotAQEeJ5DvA29m8dQuQeRwUzvnfaQ 2LjdAH01pOqjquS68xYWCbtGSlrFdqCGkhw6Eok5n+fIty2AzLLNFpOreNjKuKWHEjb9 GrvA== X-Gm-Message-State: AOJu0YzsGQ53Tc9p8G9Gll0GJr7/u1SVqhjmMyVP1WpRNFLrcR71LdJY AqmrcNwfhubNdIk8LNDzwxEE+8u6GFT/Fn6J3G1q4xoG91H9XjQ+5v1q X-Google-Smtp-Source: AGHT+IFjy/esWih/0PGZx+J4+QC6QO6d5iSL4yfzftri975vhwe9rTrUjJM8TRltshPZH+YPRKN/Rg== X-Received: by 2002:a05:6214:33c6:b0:6cc:578:7aa1 with SMTP id 6a1803df08f44-6d3460bee4amr309789816d6.49.1730822311515; Tue, 05 Nov 2024 07:58:31 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:31 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 15/16] percpu: Remove __per_cpu_load Date: Tue, 5 Nov 2024 10:58:00 -0500 Message-ID: <20241105155801.1779119-16-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 f53915f4e777..889f5885e346 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -1056,7 +1056,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 da21680ff294..6ed8ba67d1d9 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -3098,7 +3098,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); } } @@ -3281,7 +3281,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size= , pcpu_fc_cpu_to_node_fn_t flush_cache_vmap_early(unit_addr, unit_addr + ai->unit_size); =20 /* copy static data */ - memcpy((void *)unit_addr, __per_cpu_load, ai->static_size); + memcpy((void *)unit_addr, __per_cpu_start, ai->static_size); } =20 /* we're ready, commit */ --=20 2.47.0 From nobody Sun Nov 24 11:58:12 2024 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5ED191DE2A9 for ; Tue, 5 Nov 2024 15:58:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822316; cv=none; b=DaH5AHuLiWpUcSJDmjVvS+mJ494qV+A7F/ewmaF5SJoxIgfCYBsqc4sLWhw/ppK65QCpdcE2qHJVJ24Wc/qO/puHxbDUTB1MRWFSuLg1S40nAyjXAMNCUZm5e90TqPRtHSyM7I+zwAlBqomd1HKuheEPQsPu4zlIDU0OtYtTvSw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730822316; c=relaxed/simple; bh=uS7QM2OlO2Fy0ecWbAAO2d+aA/HsKz+/e9K4Qda2RF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qWYCYkCF0e44LNtyXvHOfgbwyppdMPAghLaOoFfj/YF1AL1wDLlkSZoBT5H1VeFtX+Ma6bthmFK9CSVdzdfoZVKRG3XECfg79Y48fBzWaKqhnvlPJ3IzvJooG0hHJCB3M885a8sbYImYx/dExrvXADpZt/MG5ddBLzwIqtm4VxI= 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=etRW7Ceo; arc=none smtp.client-ip=209.85.160.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="etRW7Ceo" Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-460c316fc37so41072721cf.0 for ; Tue, 05 Nov 2024 07:58:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730822313; x=1731427113; 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=7ixh7vcAwRrq/kjGmH6l0IZgJtKtt8jYOoa3BHfLv64=; b=etRW7Ceo7ceouH4XgCtd43L72QNNX6QCwyTk4Wq90I6VQ32sP9iWjFsnrnPASjUcRO PRkV3doNPHZwIWLOl9XoXJqf/6Ah3M4Qe0GOA07Zrh7rinsVclVw5DBv6LQRSZpPZOVZ uN2PJ7ERFl3Oum/acqu/ekFDYxLYJ0JTOewc22G1RNMw8AxxRd4xPvTeE3Zlymq6VQe2 E9//hIFvUrvzGavTcTaIQqx8huHkrz4XaqaDRxWp7J+v1SuXacpXY7ECX0SHSxL0Ji7K czgwQHOGN3DdiS8GX1dn+t8p6a6xxkAcaNppXiksAKt6dZcbdf6JSdwQimXvdTUjvSBR keKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730822313; x=1731427113; 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=7ixh7vcAwRrq/kjGmH6l0IZgJtKtt8jYOoa3BHfLv64=; b=FfThJ9hYKp3YIRrejDQDhOMwbS8H8dV9SwJcaCSboLpMYEiQ5MBOqCsoSspY/+7+py VqWcWTcutXCkIGzV18OCYPSW3EICyWD8dyWNTdYvv/7l/rLCIGxVieipMjvfS7YV/7je QdkKJy6GQEDgBQIFKLP1hG/E7ZTZAYhp7+Bhr9kxpOqTFgYzZ6oYK2gWFyzeUEcOq5Nd ZrOUODd43nvWXqtVf+RfB218BKzZCMoUE2BKikhMpqIMO83n68iGg/HfpNbGK3Oy/1fO Lrhc6iCfPFOBDxVQ1ZraTn6LZhDqLeLlrWrYu9Sx/QBOpUi70RRhquo9+5FcufeTAhUY zmEA== X-Gm-Message-State: AOJu0YzwRemjfD3z6/5GwivigCUDr/DWiAieBykTT6bKU8kJlZmEbNPJ /vpaOItdR7FmKW0e6xytA2qEutfX+4L3RP1vnik8Yk4bUNzF4trdoDWX X-Google-Smtp-Source: AGHT+IHqWlznjinIIbx/AjHipDuqCQmNCVECj1E8S8blpnNnVSIOBbeSXQTUl0++vBtANNxPdVOR7A== X-Received: by 2002:a05:6214:4406:b0:6d3:77b8:cb3 with SMTP id 6a1803df08f44-6d377b80d00mr98421416d6.12.1730822312663; Tue, 05 Nov 2024 07:58:32 -0800 (PST) Received: from citadel.lan ([2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d353fc6d07sm61710586d6.44.2024.11.05.07.58.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Nov 2024 07:58:32 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , "H . Peter Anvin" , Thomas Gleixner , Borislav Petkov , Ard Biesheuvel , Uros Bizjak , Brian Gerst Subject: [PATCH v5 16/16] kallsyms: Remove KALLSYMS_ABSOLUTE_PERCPU Date: Tue, 5 Nov 2024 10:58:01 -0500 Message-ID: <20241105155801.1779119-17-brgerst@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241105155801.1779119-1-brgerst@gmail.com> References: <20241105155801.1779119-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 | 5 --- kernel/kallsyms.c | 12 ++----- scripts/kallsyms.c | 72 +++++++---------------------------------- scripts/link-vmlinux.sh | 4 --- 4 files changed, 14 insertions(+), 79 deletions(-) diff --git a/init/Kconfig b/init/Kconfig index b374c0de5cfd..32db844d00d1 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1846,11 +1846,6 @@ config KALLSYMS_ALL =20 Say N unless you really need all symbols, or kernel live patching. =20 -config KALLSYMS_ABSOLUTE_PERCPU - bool - depends on KALLSYMS - default n - # end of the "standard kernel features (expert users)" menu =20 config ARCH_HAS_MEMBARRIER_CALLBACKS diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index a9a0ca605d4a..4198f30aac3c 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -148,16 +148,8 @@ static unsigned int get_symbol_offset(unsigned long po= s) =20 unsigned long kallsyms_sym_address(int idx) { - /* values are unsigned offsets if --absolute-percpu is not in effect */ - if (!IS_ENABLED(CONFIG_KALLSYMS_ABSOLUTE_PERCPU)) - return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; - - /* ...otherwise, positive offsets are absolute values */ - if (kallsyms_offsets[idx] >=3D 0) - return kallsyms_offsets[idx]; - - /* ...and negative offsets are relative to kallsyms_relative_base - 1 */ - return kallsyms_relative_base - 1 - kallsyms_offsets[idx]; + /* values are unsigned offsets */ + return kallsyms_relative_base + (u32)kallsyms_offsets[idx]; } =20 static unsigned int get_symbol_seq(int index) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 03852da3d249..4b0234e4b12f 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -5,7 +5,7 @@ * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * - * Usage: kallsyms [--all-symbols] [--absolute-percpu] in.map > out.S + * Usage: kallsyms [--all-symbols] in.map > out.S * * Table compression uses all the unused char codes on the symbols and * maps these to the most used substrings (tokens). For instance, it might @@ -37,7 +37,6 @@ struct sym_entry { unsigned long long addr; unsigned int len; unsigned int seq; - bool percpu_absolute; unsigned char sym[]; }; =20 @@ -55,14 +54,9 @@ static struct addr_range text_ranges[] =3D { #define text_range_text (&text_ranges[0]) #define text_range_inittext (&text_ranges[1]) =20 -static struct addr_range percpu_range =3D { - "__per_cpu_start", "__per_cpu_end", -1ULL, 0 -}; - static struct sym_entry **table; static unsigned int table_size, table_cnt; static int all_symbols; -static int absolute_percpu; =20 static int token_profit[0x10000]; =20 @@ -73,7 +67,7 @@ static unsigned char best_table_len[256]; =20 static void usage(void) { - fprintf(stderr, "Usage: kallsyms [--all-symbols] [--absolute-percpu] in.m= ap > out.S\n"); + fprintf(stderr, "Usage: kallsyms [--all-symbols] in.map > out.S\n"); exit(1); } =20 @@ -164,7 +158,6 @@ static struct sym_entry *read_symbol(FILE *in, char **b= uf, size_t *buf_len) return NULL; =20 check_symbol_range(name, addr, text_ranges, ARRAY_SIZE(text_ranges)); - check_symbol_range(name, addr, &percpu_range, 1); =20 /* include the type field in the symbol name, so that it gets * compressed together */ @@ -175,7 +168,6 @@ static struct sym_entry *read_symbol(FILE *in, char **b= uf, size_t *buf_len) sym->len =3D len; sym->sym[0] =3D type; strcpy(sym_name(sym), name); - sym->percpu_absolute =3D false; =20 return sym; } @@ -319,11 +311,6 @@ static int expand_symbol(const unsigned char *data, in= t len, char *result) return total; } =20 -static bool symbol_absolute(const struct sym_entry *s) -{ - return s->percpu_absolute; -} - static int compare_names(const void *a, const void *b) { int ret; @@ -455,22 +442,11 @@ static void write_src(void) */ =20 long long offset; - bool overflow; - - if (!absolute_percpu) { - offset =3D table[i]->addr - relative_base; - overflow =3D offset < 0 || offset > UINT_MAX; - } else if (symbol_absolute(table[i])) { - offset =3D table[i]->addr; - overflow =3D offset < 0 || offset > INT_MAX; - } else { - offset =3D relative_base - table[i]->addr - 1; - overflow =3D offset < INT_MIN || offset >=3D 0; - } - if (overflow) { + + offset =3D table[i]->addr - relative_base; + if (offset < 0 || offset > UINT_MAX) { fprintf(stderr, "kallsyms failure: " - "%s symbol value %#llx out of range in relative mode\n", - symbol_absolute(table[i]) ? "absolute" : "relative", + "relative symbol value %#llx out of range\n", table[i]->addr); exit(EXIT_FAILURE); } @@ -725,36 +701,15 @@ static void sort_symbols(void) qsort(table, table_cnt, sizeof(table[0]), compare_symbols); } =20 -static void make_percpus_absolute(void) -{ - unsigned int i; - - for (i =3D 0; i < table_cnt; i++) - if (symbol_in_range(table[i], &percpu_range, 1)) { - /* - * Keep the 'A' override for percpu symbols to - * ensure consistent behavior compared to older - * versions of this tool. - */ - table[i]->sym[0] =3D 'A'; - table[i]->percpu_absolute =3D true; - } -} - /* find the minimum non-absolute symbol address */ static void record_relative_base(void) { - unsigned int i; - - for (i =3D 0; i < table_cnt; i++) - if (!symbol_absolute(table[i])) { - /* - * The table is sorted by address. - * Take the first non-absolute symbol value. - */ - relative_base =3D table[i]->addr; - return; - } + /* + * The table is sorted by address. + * Take the first symbol value. + */ + if (table_cnt) + relative_base =3D table[0]->addr; } =20 int main(int argc, char **argv) @@ -762,7 +717,6 @@ int main(int argc, char **argv) while (1) { static const struct option long_options[] =3D { {"all-symbols", no_argument, &all_symbols, 1}, - {"absolute-percpu", no_argument, &absolute_percpu, 1}, {}, }; =20 @@ -779,8 +733,6 @@ int main(int argc, char **argv) =20 read_map(argv[optind]); shrink_table(); - if (absolute_percpu) - make_percpus_absolute(); sort_symbols(); record_relative_base(); optimize_token_table(); diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh index a9b3f34a78d2..df5f3fbb46f3 100755 --- a/scripts/link-vmlinux.sh +++ b/scripts/link-vmlinux.sh @@ -140,10 +140,6 @@ kallsyms() kallsymopt=3D"${kallsymopt} --all-symbols" fi =20 - if is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU; then - kallsymopt=3D"${kallsymopt} --absolute-percpu" - fi - info KSYMS "${2}.S" scripts/kallsyms ${kallsymopt} "${1}" > "${2}.S" =20 --=20 2.47.0