From nobody Mon Feb 9 23:19:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699984687874898.8682865601911; Tue, 14 Nov 2023 09:58:07 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.633094.987669 (Exim 4.92) (envelope-from ) id 1r2xfQ-0001na-Rk; Tue, 14 Nov 2023 17:57:40 +0000 Received: by outflank-mailman (output) from mailman id 633094.987669; Tue, 14 Nov 2023 17:57:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2xfQ-0001h0-AC; Tue, 14 Nov 2023 17:57:40 +0000 Received: by outflank-mailman (input) for mailman id 633094; Tue, 14 Nov 2023 17:50:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2xYi-0004wk-1V for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 17:50:44 +0000 Received: from 16.mo583.mail-out.ovh.net (16.mo583.mail-out.ovh.net [87.98.174.144]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 543a844c-8316-11ee-9b0e-b553b5be7939; Tue, 14 Nov 2023 18:50:42 +0100 (CET) Received: from director8.ghost.mail-out.ovh.net (unknown [10.108.4.72]) by mo583.mail-out.ovh.net (Postfix) with ESMTP id EF364293F1 for ; Tue, 14 Nov 2023 17:50:41 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-x5j2z (unknown [10.110.115.90]) by director8.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 5A2C81FDE8; Tue, 14 Nov 2023 17:50:41 +0000 (UTC) Received: from 3mdeb.com ([37.59.142.103]) by ghost-submission-6684bf9d7b-x5j2z with ESMTPSA id ECwfE3GzU2V/lwcATVRwWg (envelope-from ); Tue, 14 Nov 2023 17:50:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 543a844c-8316-11ee-9b0e-b553b5be7939 Authentication-Results: garm.ovh; auth=pass (GARM-103G005e72757b5-b2ca-46ec-9247-acf9452f6a5b, 1C6EC45AC3E1968723EBE40916FD99D0F8B07574) smtp.auth=krystian.hebel@3mdeb.com X-OVh-ClientIp: 213.192.77.249 From: Krystian Hebel To: xen-devel@lists.xenproject.org Cc: Krystian Hebel , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Julien Grall , Stefano Stabellini Subject: [XEN PATCH 4/9] x86/smp: move stack_base to cpu_data Date: Tue, 14 Nov 2023 18:50:04 +0100 Message-ID: <70e3b7c84a69a7ec52b3ed6314395165c281734c.1699982111.git.krystian.hebel@3mdeb.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Ovh-Tracer-Id: 12930116006320056778 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrudeffedgudefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepmfhrhihsthhirghnucfjvggsvghluceokhhrhihsthhirghnrdhhvggsvghlseefmhguvggsrdgtohhmqeenucggtffrrghtthgvrhhnpeehleekveevvdfhgeetlefhjedtjefgjedtkeekffeitdffkeffueetkedtgfeiueenucffohhmrghinhepgiekiegpieegrdhssgenucfkphepuddvjedrtddrtddruddpvddufedrudelvddrjeejrddvgeelpdefjedrheelrddugedvrddutdefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeokhhrhihsthhirghnrdhhvggsvghlseefmhguvggsrdgtohhmqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeigvghnqdguvghvvghlsehlihhsthhsrdigvghnphhrohhjvggtthdrohhrghdpoffvtefjohhsthepmhhoheekfedpmhhouggvpehsmhhtphhouhht X-ZM-MESSAGEID: 1699984689018100001 Content-Type: text/plain; charset="utf-8" This location is easier to access from assembly. Having it close to other data required during initialization has also positive (although rather small) impact on prefetching data from RAM. Signed-off-by: Krystian Hebel --- xen/arch/x86/boot/x86_64.S | 5 ++--- xen/arch/x86/include/asm/cpufeature.h | 1 + xen/arch/x86/include/asm/smp.h | 2 +- xen/arch/x86/setup.c | 6 +++--- xen/arch/x86/smpboot.c | 25 +++++++++++++------------ xen/arch/x86/traps.c | 4 ++-- xen/arch/x86/x86_64/asm-offsets.c | 1 + xen/include/xen/smp.h | 2 -- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S index 195550b5c0ea..8d61f270761f 100644 --- a/xen/arch/x86/boot/x86_64.S +++ b/xen/arch/x86/boot/x86_64.S @@ -33,9 +33,8 @@ ENTRY(__high_start) cmp %esp, CPUINFO_X86_apicid(%rcx) jne 1b =20 - /* %eax is now Xen CPU index. */ - lea stack_base(%rip), %rcx - mov (%rcx, %rax, 8), %rsp + /* %rcx is now cpu_data[cpu], read stack base from it. */ + mov CPUINFO_X86_stack_base(%rcx), %rsp =20 test %rsp,%rsp jnz 1f diff --git a/xen/arch/x86/include/asm/cpufeature.h b/xen/arch/x86/include/a= sm/cpufeature.h index 06e1dd7f3332..ff0e18864cc7 100644 --- a/xen/arch/x86/include/asm/cpufeature.h +++ b/xen/arch/x86/include/asm/cpufeature.h @@ -37,6 +37,7 @@ struct cpuinfo_x86 { unsigned int phys_proc_id; /* package ID of each logical CPU */ unsigned int cpu_core_id; /* core ID of each logical CPU */ unsigned int compute_unit_id; /* AMD compute unit ID of each logi= cal CPU */ + void *stack_base; unsigned short x86_clflush_size; } __cacheline_aligned; =20 diff --git a/xen/arch/x86/include/asm/smp.h b/xen/arch/x86/include/asm/smp.h index 94c557491860..98739028a6ed 100644 --- a/xen/arch/x86/include/asm/smp.h +++ b/xen/arch/x86/include/asm/smp.h @@ -69,7 +69,7 @@ extern cpumask_t **socket_cpumask; * by certain scheduling code only. */ #define get_cpu_current(cpu) \ - (get_cpu_info_from_stack((unsigned long)stack_base[cpu])->current_vcpu) + (get_cpu_info_from_stack((unsigned long)cpu_data[cpu].stack_base)->cur= rent_vcpu) =20 extern unsigned int disabled_cpus; extern bool unaccounted_cpus; diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index a19fe219bbf6..b2c0679725ea 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -798,7 +798,7 @@ static void __init noreturn reinit_bsp_stack(void) /* Update SYSCALL trampolines */ percpu_traps_init(); =20 - stack_base[0] =3D stack; + cpu_data[0].stack_base =3D stack; =20 rc =3D setup_cpu_root_pgt(0); if ( rc ) @@ -1959,8 +1959,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) /* Set up node_to_cpumask based on cpu_to_node[]. */ numa_add_cpu(i); =20 - if ( stack_base[i] =3D=3D NULL ) - stack_base[i] =3D cpu_alloc_stack(i); + if ( cpu_data[i].stack_base =3D=3D NULL ) + cpu_data[i].stack_base =3D cpu_alloc_stack(i); } =20 for_each_present_cpu ( i ) diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c index f061486e56eb..8ae65ab1769f 100644 --- a/xen/arch/x86/smpboot.c +++ b/xen/arch/x86/smpboot.c @@ -75,13 +75,15 @@ static enum cpu_state { } cpu_state; #define set_cpu_state(state) do { smp_mb(); cpu_state =3D (state); } while= (0) =20 -void *stack_base[NR_CPUS]; - void initialize_cpu_data(unsigned int cpu) { uint32_t apicid =3D cpu_physical_id(cpu); + void *stack =3D cpu_data[cpu].stack_base; + cpu_data[cpu] =3D boot_cpu_data; + cpu_physical_id(cpu) =3D apicid; + cpu_data[cpu].stack_base =3D stack; } =20 static bool smp_store_cpu_info(unsigned int id) @@ -579,8 +581,6 @@ static int do_boot_cpu(int apicid, int cpu) printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip); =20 - stack_start =3D stack_base[cpu] + STACK_SIZE - sizeof(struct cpu_info); - /* This grunge runs the startup process for the targeted processor. */ =20 set_cpu_state(CPU_STATE_INIT); @@ -856,7 +856,7 @@ int setup_cpu_root_pgt(unsigned int cpu) =20 /* Install direct map page table entries for stack, IDT, and TSS. */ for ( off =3D rc =3D 0; !rc && off < STACK_SIZE; off +=3D PAGE_SIZE ) - rc =3D clone_mapping(__va(__pa(stack_base[cpu])) + off, rpt); + rc =3D clone_mapping(__va(__pa(cpu_data[cpu].stack_base)) + off, r= pt); =20 if ( !rc ) rc =3D clone_mapping(idt_tables[cpu], rpt); @@ -1007,10 +1007,10 @@ static void cpu_smpboot_free(unsigned int cpu, bool= remove) FREE_XENHEAP_PAGE(per_cpu(gdt, cpu)); FREE_XENHEAP_PAGE(idt_tables[cpu]); =20 - if ( stack_base[cpu] ) + if ( cpu_data[cpu].stack_base ) { - memguard_unguard_stack(stack_base[cpu]); - FREE_XENHEAP_PAGES(stack_base[cpu], STACK_ORDER); + memguard_unguard_stack(cpu_data[cpu].stack_base); + FREE_XENHEAP_PAGES(cpu_data[cpu].stack_base, STACK_ORDER); } } } @@ -1044,11 +1044,11 @@ static int cpu_smpboot_alloc(unsigned int cpu) if ( node !=3D NUMA_NO_NODE ) memflags =3D MEMF_node(node); =20 - if ( stack_base[cpu] =3D=3D NULL && - (stack_base[cpu] =3D cpu_alloc_stack(cpu)) =3D=3D NULL ) + if ( cpu_data[cpu].stack_base =3D=3D NULL && + (cpu_data[cpu].stack_base =3D cpu_alloc_stack(cpu)) =3D=3D NULL ) goto out; =20 - info =3D get_cpu_info_from_stack((unsigned long)stack_base[cpu]); + info =3D get_cpu_info_from_stack((unsigned long)cpu_data[cpu].stack_ba= se); info->processor_id =3D cpu; info->per_cpu_offset =3D __per_cpu_offset[cpu]; =20 @@ -1156,7 +1156,8 @@ void __init smp_prepare_cpus(void) boot_cpu_physical_apicid =3D get_apic_id(); cpu_physical_id(0) =3D boot_cpu_physical_apicid; =20 - stack_base[0] =3D (void *)((unsigned long)stack_start & ~(STACK_SIZE -= 1)); + cpu_data[0].stack_base =3D (void *) + ((unsigned long)stack_start & ~(STACK_SIZE - 1)); =20 set_nr_sockets(); =20 diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index e1356f696aba..90d9201d1c52 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -611,9 +611,9 @@ void show_stack_overflow(unsigned int cpu, const struct= cpu_user_regs *regs) unsigned long curr_stack_base =3D esp & ~(STACK_SIZE - 1); unsigned long esp_top, esp_bottom; =20 - if ( _p(curr_stack_base) !=3D stack_base[cpu] ) + if ( _p(curr_stack_base) !=3D cpu_data[cpu].stack_base ) printk("Current stack base %p differs from expected %p\n", - _p(curr_stack_base), stack_base[cpu]); + _p(curr_stack_base), cpu_data[cpu].stack_base); =20 esp_bottom =3D (esp | (STACK_SIZE - 1)) + 1; esp_top =3D esp_bottom - PRIMARY_STACK_SIZE; diff --git a/xen/arch/x86/x86_64/asm-offsets.c b/xen/arch/x86/x86_64/asm-of= fsets.c index e881cd5de0a0..d81a30344677 100644 --- a/xen/arch/x86/x86_64/asm-offsets.c +++ b/xen/arch/x86/x86_64/asm-offsets.c @@ -161,6 +161,7 @@ void __dummy__(void) =20 OFFSET(CPUINFO_X86_features, struct cpuinfo_x86, x86_capability); OFFSET(CPUINFO_X86_apicid, struct cpuinfo_x86, apicid); + OFFSET(CPUINFO_X86_stack_base, struct cpuinfo_x86, stack_base); DEFINE(CPUINFO_X86_sizeof, sizeof(struct cpuinfo_x86)); BLANK(); =20 diff --git a/xen/include/xen/smp.h b/xen/include/xen/smp.h index 0a9219173f0f..994fdc474200 100644 --- a/xen/include/xen/smp.h +++ b/xen/include/xen/smp.h @@ -67,8 +67,6 @@ void smp_send_call_function_mask(const cpumask_t *mask); =20 int alloc_cpu_id(void); =20 -extern void *stack_base[NR_CPUS]; - void initialize_cpu_data(unsigned int cpu); int setup_cpu_root_pgt(unsigned int cpu); =20 --=20 2.41.0