2005-09-08 16:37:59

by Tom Rini

[permalink] [raw]
Subject: [PATCH 2.6.13] 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(-)

diff -puN arch/x86_64/kernel/setup.c~x86_64-early_funcs arch/x86_64/kernel/setup.c
--- linux-2.6.13/arch/x86_64/kernel/setup.c~x86_64-early_funcs 2005-09-01 12:00:44.000000000 -0700
+++ linux-2.6.13-trini/arch/x86_64/kernel/setup.c 2005-09-01 12:00:44.000000000 -0700
@@ -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;
diff -puN arch/x86_64/kernel/setup64.c~x86_64-early_funcs arch/x86_64/kernel/setup64.c
--- linux-2.6.13/arch/x86_64/kernel/setup64.c~x86_64-early_funcs 2005-09-01 12:00:44.000000000 -0700
+++ linux-2.6.13-trini/arch/x86_64/kernel/setup64.c 2005-09-01 12:00:44.000000000 -0700
@@ -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);
diff -puN arch/x86_64/kernel/traps.c~x86_64-early_funcs arch/x86_64/kernel/traps.c
--- linux-2.6.13/arch/x86_64/kernel/traps.c~x86_64-early_funcs 2005-09-01 12:00:44.000000000 -0700
+++ linux-2.6.13-trini/arch/x86_64/kernel/traps.c 2005-09-01 12:00:44.000000000 -0700
@@ -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);
diff -puN include/asm-x86_64/proto.h~x86_64-early_funcs include/asm-x86_64/proto.h
--- linux-2.6.13/include/asm-x86_64/proto.h~x86_64-early_funcs 2005-09-01 12:00:44.000000000 -0700
+++ linux-2.6.13-trini/include/asm-x86_64/proto.h 2005-09-01 12:00:44.000000000 -0700
@@ -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);

--
Tom Rini
http://gate.crashing.org/~trini/


2005-09-09 08:06:38

by Andi Kleen

[permalink] [raw]
Subject: Re: [PATCH 2.6.13] x86_64: Make trap_init() happen earlier

On Thursday 08 September 2005 18:37, Tom Rini wrote:
> 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

2005-09-09 14:17:49

by Andi Kleen

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

On Thursday 08 September 2005 18:37, Tom Rini wrote:
> 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)

>
> +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

2005-09-09 15:25:53

by Bob Picco

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

Andi Kleen wrote: [Fri Sep 09 2005, 10:17:40AM EDT]
> On Thursday 08 September 2005 18:37, Tom Rini wrote:
> > 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)
>
> >
> > +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
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