Skip to contentSkip to conversation

: PowerPC: make sure the rtas stop-self token is defined.

PATCH In review Linas Vepstas 5 participants 12 messages Nov 10, 2006 – Nov 15, 2006 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : PowerPC: make sure the rtas stop-self token is defined.

Paul,

I presume this looks reasonable, please apply.

--linas

There are a variety of code paths that lead to rtas_stop_self() being called, primarily through cpu_die(). However, rtas_stop_self() has a BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE); in it, and this rtas token is only set up if CONFIG_HOTPLUG_CPU is defined.

Rather than wrapping all of the callers of rtas_stop_self() with CONFIG_HOTPLUG_CPU, it seems wiser to just unwrap the token definition.

----

 arch/powerpc/kernel/rtas.c |    2 --
 1 file changed, 2 deletions(-)
arch/powerpc/kernel/rtas.c +0 -2
Index: linux-2.6.19-rc4-git3/arch/powerpc/kernel/rtas.c
===================================================================
@@ -879,9 +879,7 @@ void __init rtas_initialize(void)
 #endif
 	rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region);
 
-#ifdef CONFIG_HOTPLUG_CPU
 	rtas_stop_self_args.token = rtas_token("stop-self");
-#endif
 #ifdef CONFIG_RTAS_ERROR_LOGGING
 	rtas_last_error_token = rtas_token("rtas-last-error");
 #endif
#1 lore raw
Quoted 9 lines · Linas Vepstas

There are a variety of code paths that lead to rtas_stop_self() being called, primarily through cpu_die(). However, rtas_stop_self() has a BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE); in it, and this rtas token is only set up if CONFIG_HOTPLUG_CPU is defined.

Rather than wrapping all of the callers of rtas_stop_self() with CONFIG_HOTPLUG_CPU, it seems wiser to just unwrap the token definition.

Is there actually a code path that calls rtas_stop_self with CONFIG_HOTPLUG_CPU=n? That would be a bug, I think.

#2 lore raw
Quoted 7 lines · Nathan Lynch
Quoted 6 lines · Linas Vepstas

There are a variety of code paths that lead to rtas_stop_self() being called, primarily through cpu_die(). However, rtas_stop_self() has a BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE); in it, and this rtas token is only set up if CONFIG_HOTPLUG_CPU is defined.

Quoted 6 lines
Quoted 3 lines

Rather than wrapping all of the callers of rtas_stop_self() with CONFIG_HOTPLUG_CPU, it seems wiser to just unwrap the token definition.

Is there actually a code path that calls rtas_stop_self with CONFIG_HOTPLUG_CPU=n? That would be a bug, I think.

Yeah, that was my first reaction too, right next to "user error". But then I started tracing the code paths, and after they multiplied a bit, it was clear that the answer wouldn't be clear.

So then I philosophized a bit: if the code cannot be called unless CONFIG_HOTPLUG_CPU=y, then I should add #ifdef CONFIG_HOTPLUG_CPU to make sure that the code doesn't even get compiled in.

Well, there used to be such ifdefs (according to Joel) but someone removed the ifdefs. I'm guessing that these got removed during the powerpc tree migration.

So... Rather than wrapping all of the callers of rtas_stop_self() ...

--linas

#3 lore raw
Quoted 23 lines · Linas Vepstas
Quoted 7 lines · Nathan Lynch
Quoted 6 lines · Linas Vepstas

There are a variety of code paths that lead to rtas_stop_self() being called, primarily through cpu_die(). However, rtas_stop_self() has a BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE); in it, and this rtas token is only set up if CONFIG_HOTPLUG_CPU is defined.

Quoted 6 lines
Quoted 3 lines

Rather than wrapping all of the callers of rtas_stop_self() with CONFIG_HOTPLUG_CPU, it seems wiser to just unwrap the token definition.

Is there actually a code path that calls rtas_stop_self with CONFIG_HOTPLUG_CPU=n? That would be a bug, I think.

Yeah, that was my first reaction too, right next to "user error". But then I started tracing the code paths, and after they multiplied a bit, it was clear that the answer wouldn't be clear.

So then I philosophized a bit: if the code cannot be called unless CONFIG_HOTPLUG_CPU=y, then I should add #ifdef CONFIG_HOTPLUG_CPU to make sure that the code doesn't even get compiled in.

Quoted 5 lines

Well, there used to be such ifdefs (according to Joel) but someone removed the ifdefs. I'm guessing that these got removed during the powerpc tree migration.

So... Rather than wrapping all of the callers of rtas_stop_self() ...

I can only find one caller? Is it called via a #define or something?

Wouldn't it be preferable to just change rtas.h like so:

#ifdef CONFIG_HOTPLUG_CPU
extern void rtas_stop_self(void);
#else
static inline void rtas_stop_self(void) { }
#endif

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#4 lore raw
Quoted 10 lines

I can only find one caller? Is it called via a #define or something?

Wouldn't it be preferable to just change rtas.h like so:

#ifdef CONFIG_HOTPLUG_CPU
extern void rtas_stop_self(void);
#else
static inline void rtas_stop_self(void) { }
#endif

There seem to be a couple problems here. First I'm guessing the file you said there was catting into was the online attribute, which shouldn't appear, or at least shouldn't do anything, if cpu hotplug isn't configured. It's a stupid thing to do, but it shouldn't crash the kernel. I guess one of us should fix that, though it probably doesn't merit 2.6.19 consideration.

The second problem is rtas_stop_self shouldn't be defined or called either. Michael's solution above seems best for that to me. Care to give us a patch Michael?

#5 lore raw
Quoted 1 line · jschopp
Quoted 1 line

I can only find one caller? Is it called via a #define or something?

Right. I was looking at pSeries_mach_cpu_die(), which is called as md.cpu_die from many places.

Quoted 7 lines
Quoted 7 lines

Wouldn't it be preferable to just change rtas.h like so:

#ifdef CONFIG_HOTPLUG_CPU
extern void rtas_stop_self(void);
#else
static inline void rtas_stop_self(void) { }
#endif

Well, the problem is that this would just pass the BUG() to the next level, in pSeries_mach_cpu_die():

static void pSeries_mach_cpu_die(void)
{
local_irq_disable();
idle_task_exit();
xics_teardown_cpu(0);
rtas_stop_self();
/* Should never get here... */
BUG();
for(;;);
}

so does that mean that CONFIG_HOTPLUG_CPU should also be used to stop the complation of pSeries_mach_cpu_die() ?

--linas

#6 lore raw
Quoted 28 lines · Linas Vepstas
Quoted 1 line · jschopp
Quoted 1 line

I can only find one caller? Is it called via a #define or something?

Right. I was looking at pSeries_mach_cpu_die(), which is called as md.cpu_die from many places.

Quoted 7 lines
Quoted 7 lines

Wouldn't it be preferable to just change rtas.h like so:

#ifdef CONFIG_HOTPLUG_CPU
extern void rtas_stop_self(void);
#else
static inline void rtas_stop_self(void) { }
#endif

Well, the problem is that this would just pass the BUG() to the next level, in pSeries_mach_cpu_die():

static void pSeries_mach_cpu_die(void)

{
   local_irq_disable();
   idle_task_exit();
   xics_teardown_cpu(0);
   rtas_stop_self();
   /* Should never get here... */
   BUG();
   for(;;);
}
Quoted 2 lines

so does that mean that CONFIG_HOTPLUG_CPU should also be used to stop the complation of pSeries_mach_cpu_die() ?

Yes. And its connection to ppc_md.cpu_die.

cheers

Signature · 8 lines
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
#7 lore raw
Quoted 16 lines · Michael Ellerman
Quoted 15 lines · Linas Vepstas

Well, the problem is that this would just pass the BUG() to the next level, in pSeries_mach_cpu_die():

static void pSeries_mach_cpu_die(void)

{
   local_irq_disable();
   idle_task_exit();
   xics_teardown_cpu(0);
   rtas_stop_self();
   /* Should never get here... */
   BUG();
   for(;;);
}
Quoted 4 lines
Quoted 2 lines

so does that mean that CONFIG_HOTPLUG_CPU should also be used to stop the complation of pSeries_mach_cpu_die() ?

Yes. And its connection to ppc_md.cpu_die.

OK, will send patch for this shortly. I reviewed the other cases, and see now that this would e the consistent thing to do.

--linas

#8 lore raw
In reply to Linas Vepstas
Quoted 1 line · Linas Vepstas

I presume this looks reasonable, please apply.

OK, is this a fix for a bug that needs to be fixed before 2.6.19 is release?

Thanks,
Paul.

#9 lore raw
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Linas Vepstas

I presume this looks reasonable, please apply.

OK, is this a fix for a bug that needs to be fixed before 2.6.19 is release?

Probably not. This was uncovered during "unusual" testing, with user catting values int sysfs files. Since you need to be root to do this, I don't think its a security flaw.

--linas

#10 lore raw
Quoted 11 lines · Linas Vepstas
Quoted 6 lines · Paul Mackerras
Quoted 1 line · Linas Vepstas

I presume this looks reasonable, please apply.

OK, is this a fix for a bug that needs to be fixed before 2.6.19 is release?

Probably not. This was uncovered during "unusual" testing, with user catting values int sysfs files. Since you need to be root to do this, I don't think its a security flaw.

I'm still not clear on what problem this patch is intended to address.

If the 'online' cpu attribute in sysfs can be used to attempt an offline operation on a kernel with CONFIG_HOTPLUG_CPU=n, that's what needs to be fixed.

#11 lore raw
Quoted 2 lines · Nathan Lynch

I'm still not clear on what problem this patch is intended to address.

There's a code path that is compiled unconditonally, that expects this token to be defined.

Quoted 3 lines

If the 'online' cpu attribute in sysfs can be used to attempt an offline operation on a kernel with CONFIG_HOTPLUG_CPU=n, that's what needs to be fixed.

There are many places where cpu_die() might be called, and I am sufficiently lazy to not want to audit them to make sure that none of these code paths are taken if CONFIG_HOTPLUG_CPU=n.

Besides, if I audit all of these code paths today, and find that none of them are ever called when CONFIG_HOTPLUG_CPU=n, I still have no assurance that someone might not unwittingly change one of the code paths in the future.

Code that might fail because someone makes an unwitting change in the future is "brittle". The goal of my patch was to remove the brittleness.

Besides, I notice that platforms/powermac/smp.c defines cpu_die() as well, which tells me that there are code paths that lead to its being called, even if CONFIG_HOTPLUG_CPU=n. That would seem to conclude the audit, right?

--linas