Skip to contentSkip to conversation

x86_64: Make trap_init() happen earlier

PATCH Applied Tom Rini 3 participants 4 messages Sep 8, 2005 – Sep 9, 2005

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 x86_64: Make trap_init() happen earlier

It can be handy in some situations to have run trap_init() sooner than the generic code does. In order to do this on x86_64 we need to add a custom early_setup_per_cpu_areas() call as well.

---

 linux-2.6.13-trini/arch/x86_64/kernel/setup.c   |    3 +++
 linux-2.6.13-trini/arch/x86_64/kernel/setup64.c |   16 +++++++++++++++-
 linux-2.6.13-trini/arch/x86_64/kernel/traps.c   |    4 ++++
 linux-2.6.13-trini/include/asm-x86_64/proto.h   |    2 ++
 4 files changed, 24 insertions(+), 1 deletion(-)
arch/x86_64/kernel/setup.c renamed from arch/x86_64/kernel/setup.c~x86_64-early_funcs +3 -0
diff -puN arch/x86_64/kernel/setup.c~x86_64-early_funcs arch/x86_64/kernel/setup.c
@@ -525,6 +525,9 @@ void __init setup_arch(char **cmdline_p)
 {
 	unsigned long kernel_end;
 
+	early_setup_per_cpu_areas();
+	early_trap_init();
+
  	ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  	drive_info = DRIVE_INFO;
  	screen_info = SCREEN_INFO;
arch/x86_64/kernel/setup64.c renamed from arch/x86_64/kernel/setup64.c~x86_64-early_funcs +15 -1
diff -puN arch/x86_64/kernel/setup64.c~x86_64-early_funcs arch/x86_64/kernel/setup64.c
@@ -77,7 +77,19 @@ static int __init nonx32_setup(char *str
 }
 __setup("noexec32=", nonx32_setup);
 
+void __init early_setup_per_cpu_areas(void)
+{
+	static char cpu0[PERCPU_ENOUGH_ROOM] __cacheline_aligned
+		__attribute__ ((aligned (SMP_CACHE_BYTES)));
+	char *ptr = cpu0;
+
+	cpu_pda[0].data_offset = ptr - __per_cpu_start;
+	memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
+}
+
 /*
+ * We run this a bit sooner than the normal code, so provide a dummy
+ * function as well.
  * Great future plan:
  * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
  * Always point %gs to its beginning
@@ -97,7 +109,9 @@ void __init setup_per_cpu_areas(void)
 	for (i = 0; i < NR_CPUS; i++) { 
 		char *ptr;
 
-		if (!NODE_DATA(cpu_to_node(i))) {
+		if (cpu_pda[i].data_offset)
+			continue;
+		else if (!NODE_DATA(cpu_to_node(i))) {
 			printk("cpu with no node %d, num_online_nodes %d\n",
 			       i, num_online_nodes());
 			ptr = alloc_bootmem(size);
arch/x86_64/kernel/traps.c renamed from arch/x86_64/kernel/traps.c~x86_64-early_funcs +4 -0
diff -puN arch/x86_64/kernel/traps.c~x86_64-early_funcs arch/x86_64/kernel/traps.c
@@ -904,6 +904,10 @@ void do_call_debug(struct pt_regs *regs)
 
 void __init trap_init(void)
 {
+}
+
+void __init early_trap_init(void)
+{
 	set_intr_gate(0,&divide_error);
 	set_intr_gate_ist(1,&debug,DEBUG_STACK);
 	set_intr_gate_ist(2,&nmi,NMI_STACK);
include/asm-x86_64/proto.h renamed from include/asm-x86_64/proto.h~x86_64-early_funcs +2 -0
diff -puN include/asm-x86_64/proto.h~x86_64-early_funcs include/asm-x86_64/proto.h
@@ -10,6 +10,8 @@ struct pt_regs;
 
 extern void get_cpu_vendor(struct cpuinfo_x86*);
 extern void start_kernel(void);
+extern void early_trap_init(void);
+extern void early_setup_per_cpu_areas(void);
 extern void pda_init(int); 
 
 extern void early_idt_handler(void);
Signature · 2 lines
Tom Rini
http://gate.crashing.org/~trini/
Applied
#1 lore raw
Quoted 3 lines · Tom Rini

It can be handy in some situations to have run trap_init() sooner than the generic code does. In order to do this on x86_64 we need to add a custom early_setup_per_cpu_areas() call as well.

Queued, thanks.
-Andi

#2 lore raw

Re: [PATCH 2.6.13] x86_64: Make trap_init() happen earlier - dropped

In reply to Tom Rini
Quoted 3 lines · Tom Rini

It can be handy in some situations to have run trap_init() sooner than the generic code does. In order to do this on x86_64 we need to add a custom early_setup_per_cpu_areas() call as well.

The patch is totally broken and causes crash even under light load (just found it after a lengthy binary search)

arch/x86_64/kernel/setup64.c static int __init nonx32_setup(char *str · line 83

Quoted 5 lines
arch/x86_64/kernel/setup64.c renamed from arch/x86_64/kernel/setup64.c~x86_64-early_funcs +4 -0
+void __init early_setup_per_cpu_areas(void)
+{
+	static char cpu0[PERCPU_ENOUGH_ROOM] __cacheline_aligned
+		__attribute__ ((aligned (SMP_CACHE_BYTES)));

The original code does

    /* Copy section for each CPU (we discard the original) */
        size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);

#ifdef CONFIG_MODULES
if (size < PERCPU_ENOUGH_ROOM)
size = PERCPU_ENOUGH_ROOM;
#endif

perhaps end-start is larger than PERCPU_ENOUGH_ROOM ? (using defconfig)

Dropped from my tree for now.

-Andi

#3 lore raw

Re: [PATCH 2.6.13] x86_64: Make trap_init() happen earlier - dropped

Andi Kleen wrote: [Fri Sep 09 2005, 10:17:40AM EDT]

Quoted 24 lines · Tom Rini
Quoted 3 lines

It can be handy in some situations to have run trap_init() sooner than the generic code does. In order to do this on x86_64 we need to add a custom early_setup_per_cpu_areas() call as well.

The patch is totally broken and causes crash even under light load (just found it after a lengthy binary search)

arch/x86_64/kernel/setup64.c static int __init nonx32_setup(char *str · line 83

Quoted 5 lines
arch/x86_64/kernel/setup64.c renamed from arch/x86_64/kernel/setup64.c~x86_64-early_funcs +4 -0
+void __init early_setup_per_cpu_areas(void)
+{
+	static char cpu0[PERCPU_ENOUGH_ROOM] __cacheline_aligned
+		__attribute__ ((aligned (SMP_CACHE_BYTES)));

The original code does

    /* Copy section for each CPU (we discard the original) */
        size = ALIGN(__per_cpu_end - __per_cpu_start, SMP_CACHE_BYTES);

#ifdef CONFIG_MODULES
if (size < PERCPU_ENOUGH_ROOM)
size = PERCPU_ENOUGH_ROOM;
#endif

Quoted 5 lines

perhaps end-start is larger than PERCPU_ENOUGH_ROOM ? (using defconfig)

Dropped from my tree for now.

-Andi

Andi:

Sorry about that. I originally intended this for KGDB only. The hardcoded PERCPU_ENOUGH_ROOM value is dangerous and could be the issue. Let me take a look at this.

bob