public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Dangerous code in cpumask_of_cpu?
@ 2008-07-08  8:16 Rusty Russell
  2008-07-08  8:35 ` Johannes Weiner
  0 siblings, 1 reply; 10+ messages in thread
From: Rusty Russell @ 2008-07-08  8:16 UTC (permalink / raw)
  To: Mike Travis; +Cc: linux-kernel, H. Anvin, Christoph Lameter, Ingo Molnar

Hi Christoph/Mike,

  Looked at cpumask_of_cpu as introduced in 
9f0e8d0400d925c3acd5f4e01dbeb736e4011882 (x86: convert cpumask_of_cpu macro 
to allocated array), and I don't think it's safe:

  #define cpumask_of_cpu(cpu)						\
  (*({									\
	typeof(_unused_cpumask_arg_) m;					\
	if (sizeof(m) == sizeof(unsigned long)) {			\
		m.bits[0] = 1UL<<(cpu);					\
	} else {							\
		cpus_clear(m);						\
		cpu_set((cpu), m);					\
	}								\
	&m;								\
  }))

Referring to &m once out of scope is invalid, and I can't find any evidence 
that it's legal here.  In particular, the change 
b53e921ba1cff8453dc9a87a84052fa12d5b30bd (generic: reduce stack pressure in 
sched_affinity) which passes &m to other functions seems highly risky.

I'm surprised this hasn't already hit us, but perhaps gcc isn't as clever as 
it could be?

I don't know what the right answer is, but we might need to go to a pool of 
cpumask_ts, a get_cpumask_of_cpu() which can sleep and a put_cpumask_of_cpu?

Or maybe a gcc guru can refute this?
Rusty.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-07-09 14:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-08  8:16 Dangerous code in cpumask_of_cpu? Rusty Russell
2008-07-08  8:35 ` Johannes Weiner
2008-07-08  8:54   ` Johannes Weiner
2008-07-08  9:03     ` Johannes Weiner
2008-07-08  9:28       ` Johannes Weiner
2008-07-08 15:29       ` Mike Travis
2008-07-09  2:22         ` Rusty Russell
2008-07-09 14:42           ` Mike Travis
2008-07-08  9:33     ` Rusty Russell
2008-07-08 10:24   ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox