Commit 1a51e3a0 authored by Tejun Heo's avatar Tejun Heo Committed by Ingo Molnar
Browse files

x86: fold pda into percpu area on SMP



[ Based on original patch from Christoph Lameter and Mike Travis. ]

Currently pdas and percpu areas are allocated separately.  %gs points
to local pda and percpu area can be reached using pda->data_offset.
This patch folds pda into percpu area.

Due to strange gcc requirement, pda needs to be at the beginning of
the percpu area so that pda->stack_canary is at %gs:40.  To achieve
this, a new percpu output section macro - PERCPU_VADDR_PREALLOC() - is
added and used to reserve pda sized chunk at the start of the percpu
area.

After this change, for boot cpu, %gs first points to pda in the
data.init area and later during setup_per_cpu_areas() gets updated to
point to the actual pda.  This means that setup_per_cpu_areas() need
to reload %gs for CPU0 while clearing pda area for other cpus as cpu0
already has modified it when control reaches setup_per_cpu_areas().

This patch also removes now unnecessary get_local_pda() and its call
sites.

A lot of this patch is taken from Mike Travis' "x86_64: Fold pda into
per cpu area" patch.

Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent c8f3329a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
#ifndef _ASM_X86_PERCPU_H
#define _ASM_X86_PERCPU_H

#ifndef __ASSEMBLY__
#ifdef CONFIG_X86_64
extern void load_pda_offset(int cpu);
#else
static inline void load_pda_offset(int cpu) { }
#endif
#endif

#ifdef CONFIG_X86_64
#include <linux/compiler.h>

+0 −2
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@
#include <asm/thread_info.h>
#include <asm/cpumask.h>

extern int __cpuinit get_local_pda(int cpu);

extern int smp_num_siblings;
extern unsigned int num_processors;

+1 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ int main(void)
	ENTRY(cpunumber);
	ENTRY(irqstackptr);
	ENTRY(data_offset);
	DEFINE(pda_size, sizeof(struct x8664_pda));
	BLANK();
#undef ENTRY
#ifdef CONFIG_PARAVIRT
+2 −4
Original line number Diff line number Diff line
@@ -893,10 +893,8 @@ void __cpuinit pda_init(int cpu)
	/* Setup up data that may be needed in __get_free_pages early */
	loadsegment(fs, 0);
	loadsegment(gs, 0);
	/* Memory clobbers used to order PDA accessed */
	mb();
	wrmsrl(MSR_GS_BASE, pda);
	mb();

	load_pda_offset(cpu);

	pda->cpunumber = cpu;
	pda->irqcount = -1;
+7 −1
Original line number Diff line number Diff line
@@ -26,12 +26,18 @@
#include <asm/bios_ebda.h>
#include <asm/trampoline.h>

/* boot cpu pda, referenced by head_64.S to initialize %gs for boot CPU */
#ifndef CONFIG_SMP
/* boot cpu pda, referenced by head_64.S to initialize %gs on UP */
struct x8664_pda _boot_cpu_pda;
#endif

void __init x86_64_init_pda(void)
{
#ifdef CONFIG_SMP
	cpu_pda(0) = (void *)__per_cpu_load;
#else
	cpu_pda(0) = &_boot_cpu_pda;
#endif
	cpu_pda(0)->data_offset =
		(unsigned long)(__per_cpu_load - __per_cpu_start);
	pda_init(0);
Loading