From nobody Fri Sep 19 09:24:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0161FC4332F for ; Fri, 25 Nov 2022 09:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229782AbiKYJmz (ORCPT ); Fri, 25 Nov 2022 04:42:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229770AbiKYJmo (ORCPT ); Fri, 25 Nov 2022 04:42:44 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08D061A830 for ; Fri, 25 Nov 2022 01:42:38 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SYtDKXEAvjEf1YJAc3x9GyPrR/5UvNDnbCTQFLZPR1w=; b=JPV14MvtFeNQp++zT40Gqm8cARU4bfG1isYMsoAiY1/WXq385FYLd5KVgD+uhAhEduV7+I 3BtKsCL85s+p2MsSjLeMIAOvX2eeX5zSYJxvQ0UPRqKVhGOVoQ9PykSJt583Z0Ng7fWAJR JAtZlCwKakltdLb8YhYyzKZnsT/sLaorNW9qJeTzwhU9Ftvwkx1yglWnCi0SrsTGvzzzCk FLOYri3OJzFJWDHT64mHZpecz/Sxm/2quSGXl0jqPjMQKmJWW3G/trbwIqSABjauBA6wZH +feookW5xemzgdB6E4xZtS1FJ06AespFxKvlVRJZ/+h4aduc06DCdMCmuhmWXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SYtDKXEAvjEf1YJAc3x9GyPrR/5UvNDnbCTQFLZPR1w=; b=ZJrOcsZXlB3YdtykG4rliywnUljEYGheHx6C02eBpywX2uS5WzsXsWv+L2J327+YyJPnYD yKGYZo+bYQc4o4BQ== To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Roland Mainz , "H. Peter Anvin" , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 1/3] x86: Provide a full setup for getcpu on x86-32. Date: Fri, 25 Nov 2022 10:42:14 +0100 Message-Id: <20221125094216.3663444-2-bigeasy@linutronix.de> In-Reply-To: <20221125094216.3663444-1-bigeasy@linutronix.de> References: <20221125094216.3663444-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" setup_getcpu() configures two things: - writes the current CPU & node information into the MSR_TSC_AUX. - writes the same information as a GDT entry. By using the "full" setup_getcpu() on i386 it is possible to read the CPU information in userland via rdtscp. Provide an GDT_ENTRY_CPUNODE for x86-32. Move the CONFIG_X86_64 so the x86-64 implementation becomes also available for x86-32. Reviewed-By: Roland Mainz Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/include/asm/segment.h | 8 ++++---- arch/x86/kernel/cpu/common.c | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h index 2e7890dd58a47..662281c2a907c 100644 --- a/arch/x86/include/asm/segment.h +++ b/arch/x86/include/asm/segment.h @@ -96,7 +96,7 @@ * * 26 - ESPFIX small SS * 27 - per-cpu [ offset to per-cpu data area ] - * 28 - unused + * 28 - VDSO getcpu * 29 - unused * 30 - unused * 31 - TSS for double fault handler @@ -119,6 +119,7 @@ =20 #define GDT_ENTRY_ESPFIX_SS 26 #define GDT_ENTRY_PERCPU 27 +#define GDT_ENTRY_CPUNODE 28 =20 #define GDT_ENTRY_DOUBLEFAULT_TSS 31 =20 @@ -158,6 +159,8 @@ # define __KERNEL_PERCPU 0 #endif =20 +#define __CPUNODE_SEG (GDT_ENTRY_CPUNODE*8 + 3) + #else /* 64-bit: */ =20 #include @@ -226,8 +229,6 @@ #define GDT_ENTRY_TLS_ENTRIES 3 #define TLS_SIZE (GDT_ENTRY_TLS_ENTRIES* 8) =20 -#ifdef CONFIG_X86_64 - /* Bit size and mask of CPU number stored in the per CPU data (and TSC_AUX= ) */ #define VDSO_CPUNODE_BITS 12 #define VDSO_CPUNODE_MASK 0xfff @@ -265,7 +266,6 @@ static inline void vdso_read_cpunode(unsigned *cpu, uns= igned *node) } =20 #endif /* !__ASSEMBLY__ */ -#endif /* CONFIG_X86_64 */ =20 #ifdef __KERNEL__ =20 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 3e508f2390983..520a0a2e765d3 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2128,7 +2128,6 @@ static void wait_for_master_cpu(int cpu) #endif } =20 -#ifdef CONFIG_X86_64 static inline void setup_getcpu(int cpu) { unsigned long cpudata =3D vdso_encode_cpunode(cpu, early_cpu_to_node(cpu)= ); @@ -2150,6 +2149,7 @@ static inline void setup_getcpu(int cpu) write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_CPUNODE, &d, DESCTYPE_S); } =20 +#ifdef CONFIG_X86_64 static inline void ucode_cpu_init(int cpu) { if (cpu) @@ -2169,8 +2169,6 @@ static inline void tss_setup_ist(struct tss_struct *t= ss) =20 #else /* CONFIG_X86_64 */ =20 -static inline void setup_getcpu(int cpu) { } - static inline void ucode_cpu_init(int cpu) { show_ucode_info_early(); --=20 2.38.1 From nobody Fri Sep 19 09:24:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2E63C4332F for ; Fri, 25 Nov 2022 09:43:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229866AbiKYJnA (ORCPT ); Fri, 25 Nov 2022 04:43:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiKYJmo (ORCPT ); Fri, 25 Nov 2022 04:42:44 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDBB23BF9 for ; Fri, 25 Nov 2022 01:42:39 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ksDDcmQCY+1As7J2HctVpfMXUOEO/R8OEqcyPN1HAtc=; b=sV3Ks6WnkZ68pgk95VzupBIV3V6E8bwuylnssY4zHQwhs0VzeWVz3mq+F3DpVZmvr6RXC0 FyEifY8N1A2E3UQzxkJaS9OuijDNpIz/Bzn1b0H8eeoucEpBSGVRcYvgt3LQTR2ooxBI+f iogtYQ9zLp4PR3xG0tUVeAwIcjrQLIPh8m4fd6Zhm9qIHcGaqgSmK6MZc7bYWrbH7nqJaj gApVZUYjEg5JdGWG8H12V2q832ho0b5NSbcszudy5JxvW7qAXXrkIDHrbif3PEwye+P7lc DnvG27Dj6+vrh+qMLKwEmTGzthj5ulN43WArk0AheUHGMXKN2DatzcH0KTOxUg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ksDDcmQCY+1As7J2HctVpfMXUOEO/R8OEqcyPN1HAtc=; b=dGP36mBtjGK+hzexrC2h0GV58AMU2lCv//tdl3WWVpcD5QvjxW3lrHK6uuc3d8caDFXHjD 1XY/wPu77bAOe1Bw== To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Roland Mainz , "H. Peter Anvin" , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Sebastian Andrzej Siewior Subject: [PATCH 2/3] x86/vdso: Provide getcpu for x86-32. Date: Fri, 25 Nov 2022 10:42:15 +0100 Message-Id: <20221125094216.3663444-3-bigeasy@linutronix.de> In-Reply-To: <20221125094216.3663444-1-bigeasy@linutronix.de> References: <20221125094216.3663444-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Wire up __vdso_getcpu() for x86-32. The version for 64bit can be reused. The defines must no be faked (like it is done for vclock_gettime.c) because we need the 64bit defines for the 32bit VDSO because the segment number of the host kernel is required. Reuse the vgetcpu.c for vdso32. Remove the time* header files which lead to compile errors on 32bit. Add segment.h which provides vdso_read_cpunode() and its requirements. Signed-off-by: Sebastian Andrzej Siewior --- arch/x86/entry/vdso/Makefile | 3 ++- arch/x86/entry/vdso/vdso32/vdso32.lds.S | 1 + arch/x86/entry/vdso/vdso32/vgetcpu.c | 2 ++ arch/x86/entry/vdso/vgetcpu.c | 3 +-- 4 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 arch/x86/entry/vdso/vdso32/vgetcpu.c diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 3e88b9df8c8f1..fcbcfc2b4e1a7 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -29,7 +29,7 @@ VDSO32-$(CONFIG_IA32_EMULATION) :=3D y # files to link into the vdso vobjs-y :=3D vdso-note.o vclock_gettime.o vgetcpu.o vobjs32-y :=3D vdso32/note.o vdso32/system_call.o vdso32/sigreturn.o -vobjs32-y +=3D vdso32/vclock_gettime.o +vobjs32-y +=3D vdso32/vclock_gettime.o vdso32/vgetcpu.o vobjs-$(CONFIG_X86_SGX) +=3D vsgx.o =20 # files to link into kernel @@ -103,6 +103,7 @@ $(vobjs): KBUILD_AFLAGS +=3D -DBUILD_VDSO CFLAGS_REMOVE_vclock_gettime.o =3D -pg CFLAGS_REMOVE_vdso32/vclock_gettime.o =3D -pg CFLAGS_REMOVE_vgetcpu.o =3D -pg +CFLAGS_REMOVE_vdso32/vgetcpu.o =3D -pg CFLAGS_REMOVE_vsgx.o =3D -pg =20 # diff --git a/arch/x86/entry/vdso/vdso32/vdso32.lds.S b/arch/x86/entry/vdso/= vdso32/vdso32.lds.S index c7720995ab1af..8a3be07006bb6 100644 --- a/arch/x86/entry/vdso/vdso32/vdso32.lds.S +++ b/arch/x86/entry/vdso/vdso32/vdso32.lds.S @@ -28,6 +28,7 @@ VERSION __vdso_time; __vdso_clock_getres; __vdso_clock_gettime64; + __vdso_getcpu; }; =20 LINUX_2.5 { diff --git a/arch/x86/entry/vdso/vdso32/vgetcpu.c b/arch/x86/entry/vdso/vds= o32/vgetcpu.c new file mode 100644 index 0000000000000..b777f84ffae9b --- /dev/null +++ b/arch/x86/entry/vdso/vdso32/vgetcpu.c @@ -0,0 +1,2 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "../vgetcpu.c" diff --git a/arch/x86/entry/vdso/vgetcpu.c b/arch/x86/entry/vdso/vgetcpu.c index b88a82bbc3593..0a9007c240568 100644 --- a/arch/x86/entry/vdso/vgetcpu.c +++ b/arch/x86/entry/vdso/vgetcpu.c @@ -7,8 +7,7 @@ =20 #include #include -#include -#include +#include =20 notrace long __vdso_getcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *unused) --=20 2.38.1 From nobody Fri Sep 19 09:24:33 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43D8DC4332F for ; Fri, 25 Nov 2022 09:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229481AbiKYJnF (ORCPT ); Fri, 25 Nov 2022 04:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbiKYJmo (ORCPT ); Fri, 25 Nov 2022 04:42:44 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FE2E23BFE; Fri, 25 Nov 2022 01:42:39 -0800 (PST) From: Sebastian Andrzej Siewior DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tkHfIWZ+AXddA17Vln4Zv2kJvTG9y3spaF3cG2QDrJU=; b=U9GnlAVlA00LESkky61O56pvX9stU5T9eAGYoI06mvV7ObkG7eQmZw6BDKMJpjzb2Kbcgk P1ikq9bsh06PjSX/DyKKNpGxfl2CQ8m/Mk+dh0w7bYfH/1x2spaJjayHM+MaDoca7aa9JI nIvyEv2d4dlgkxMZulNU0mjKoHHCbOEMizE2XD1EKKWQPPsJ8nIU14EdvsBJHugSEDslJL YlcepZNvqBFqYfWMdS5dzjpPFtSExSayFWDbMDYYKWPtVEnkjoiKfO6nVsg6Y9v93CtD/0 Jd2JSPaq08cS/ZivTWkdb6I18BxKL7z1HPbWK4ZtOVdoDrGqUDEqj9x4uh8tXA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669369357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tkHfIWZ+AXddA17Vln4Zv2kJvTG9y3spaF3cG2QDrJU=; b=/nPSkX2ux5m+/P5mpV/FRizufVbb7UsOHs/O4CpzXs35wg3eH1hgnEmBsJAVPHcsxjOrHX AxcsAWw9yHd7pzDg== To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Roland Mainz , "H. Peter Anvin" , Borislav Petkov , Dave Hansen , Ingo Molnar , Thomas Gleixner , Sebastian Andrzej Siewior , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH 3/3] selftests: Make a warning if getcpu is missing on 32bit. Date: Fri, 25 Nov 2022 10:42:16 +0100 Message-Id: <20221125094216.3663444-4-bigeasy@linutronix.de> In-Reply-To: <20221125094216.3663444-1-bigeasy@linutronix.de> References: <20221125094216.3663444-1-bigeasy@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The vsyscall for getcpu has been wired up on 32bit so it can be warned now if missing. Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior Acked-by: Shuah Khan --- tools/testing/selftests/x86/test_vsyscall.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/se= lftests/x86/test_vsyscall.c index 5b45e6986aeab..47cab972807c4 100644 --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c @@ -92,11 +92,8 @@ static void init_vdso(void) printf("[WARN]\tfailed to find time in vDSO\n"); =20 vdso_getcpu =3D (getcpu_t)dlsym(vdso, "__vdso_getcpu"); - if (!vdso_getcpu) { - /* getcpu() was never wired up in the 32-bit vDSO. */ - printf("[%s]\tfailed to find getcpu in vDSO\n", - sizeof(long) =3D=3D 8 ? "WARN" : "NOTE"); - } + if (!vdso_getcpu) + printf("[WARN]\tfailed to find getcpu in vDSO\n"); } =20 static int init_vsys(void) --=20 2.38.1