Skip to content

Commit

Permalink
x86: Sanitize smp_record and move it to x86_init_ops
Browse files Browse the repository at this point in the history
The x86 quirkification introduced an extra ugly hackery with a
variable pointer in the mpparse code. If the pointer is initialized
then it is dereferenced and the variable set to 0 or incremented.

Create a x86_init_ops function and let the affected numaq code
hold the function. Default init is a setup noop.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Aug 27, 2009
1 parent 6b18ae3 commit f484847
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
1 change: 0 additions & 1 deletion arch/x86/include/asm/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ struct x86_quirks {
int (*mach_get_smp_config)(unsigned int early);
int (*mach_find_smp_config)(unsigned int reserve);

int *mpc_record;
int (*mpc_apic_id)(struct mpc_cpu *m);
void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
void (*mpc_oem_pci_bus)(struct mpc_bus *m);
Expand Down
12 changes: 11 additions & 1 deletion arch/x86/include/asm/x86_init.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#ifndef _ASM_X86_PLATFORM_H
#define _ASM_X86_PLATFORM_H

/**
* struct x86_init_mpparse - platform specific mpparse ops
* @mpc_record: platform specific mpc record accounting
*/
struct x86_init_mpparse {
void (*mpc_record)(unsigned int mode);
};

/**
* struct x86_init_resources - platform specific resource related ops
* @probe_roms: probe BIOS roms
Expand All @@ -22,11 +30,13 @@ struct x86_init_resources {
*
*/
struct x86_init_ops {
struct x86_init_resources resources;
struct x86_init_resources resources;
struct x86_init_mpparse mpparse;
};

extern struct x86_init_ops x86_init;

extern void x86_init_noop(void);
extern void x86_init_uint_noop(unsigned int unused);

#endif
19 changes: 16 additions & 3 deletions arch/x86/kernel/apic/numaq_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ struct mpc_trans {
unsigned short trans_reserved;
};

/* x86_quirks member */
static int mpc_record;

static struct mpc_trans *translation_table[MAX_MPC_ENTRY];
Expand Down Expand Up @@ -177,6 +176,19 @@ static void mpc_oem_pci_bus(struct mpc_bus *m)
quad_local_to_mp_bus_id[quad][local] = m->busid;
}

/*
* Called from mpparse code.
* mode = 0: prescan
* mode = 1: one mpc entry scanned
*/
static void numaq_mpc_record(unsigned int mode)
{
if (!mode)
mpc_record = 0;
else
mpc_record++;
}

static void __init MP_translation_info(struct mpc_trans *m)
{
printk(KERN_INFO
Expand Down Expand Up @@ -264,7 +276,6 @@ static struct x86_quirks numaq_x86_quirks __initdata = {
.arch_trap_init = NULL,
.mach_get_smp_config = NULL,
.mach_find_smp_config = NULL,
.mpc_record = &mpc_record,
.mpc_apic_id = mpc_apic_id,
.mpc_oem_bus_info = mpc_oem_bus_info,
.mpc_oem_pci_bus = mpc_oem_pci_bus,
Expand All @@ -285,8 +296,10 @@ static __init void early_check_numaq(void)
if (smp_found_config)
early_get_smp_config();

if (found_numaq)
if (found_numaq) {
x86_quirks = &numaq_x86_quirks;
x86_init.mpparse.mpc_record = numaq_mpc_record;
}
}

int __init get_memcfg_numaq(void)
Expand Down
6 changes: 2 additions & 4 deletions arch/x86/kernel/mpparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
/*
* Now process the configuration blocks.
*/
if (x86_quirks->mpc_record)
*x86_quirks->mpc_record = 0;
x86_init.mpparse.mpc_record(0);

while (count < mpc->length) {
switch (*mpt) {
Expand Down Expand Up @@ -353,8 +352,7 @@ static int __init smp_read_mpc(struct mpc_table *mpc, unsigned early)
count = mpc->length;
break;
}
if (x86_quirks->mpc_record)
(*x86_quirks->mpc_record)++;
x86_init.mpparse.mpc_record(1);
}

#ifdef CONFIG_X86_BIGSMP
Expand Down
5 changes: 5 additions & 0 deletions arch/x86/kernel/x86_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <asm/e820.h>

void __cpuinit x86_init_noop(void) { }
void __init x86_init_uint_noop(unsigned int unused) { }

/*
* The platform setup functions are preset with the default functions
Expand All @@ -23,4 +24,8 @@ struct __initdata x86_init_ops x86_init = {
.reserve_ebda_region = reserve_ebda_region,
.memory_setup = default_machine_specific_memory_setup,
},

.mpparse = {
.mpc_record = x86_init_uint_noop,
},
};

0 comments on commit f484847

Please sign in to comment.