Re: [RFC PATCH 2/2] kernel/sched.c: VLA in middle of struct
From: Ingo Molnar
Date: Fri May 08 2009 - 15:11:29 EST
* Jeff Garzik <jeff@xxxxxxxxxx> wrote:
> The semantics for variable-length arrays __in the middle of structs__
> are quite muddy, and a case in sched.c presents an interesting case,
> as the preceding code comment indicates:
>
> /*
> * The cpus mask in sched_group and sched_domain hangs off
> the end. * FIXME: use cpumask_var_t or dynamic percpu alloc
> to avoid * wasting space for nr_cpu_ids < CONFIG_NR_CPUS. */
> struct static_sched_group {
> struct sched_group sg; DECLARE_BITMAP(cpus,
> CONFIG_NR_CPUS);
> };
>
> struct static_sched_domain {
> struct sched_domain sd; DECLARE_BITMAP(span,
> CONFIG_NR_CPUS);
> };
>
> Both sched_group and sched_domain have the following trailing struct
> member:
>
> unsigned long cpumask[];
>
> So this change is intended largely to spawn a discussion, because
> I'm not sure this VLA-in-middle-of-struct behavior is guaranteed to
> always behave as expected?
>
> Maybe a C expert can say whether cpumask[0] is better than cpumask[],
> or have other comments?
This bit of the code is a bit temporary, with a half-done cpumask
conversion ...
I'm not convinced at all that this code wants to be converted to
cpuvar_t. These are all either statically percpu or dynamically
allocated structures, so we wont allocate NR_CPUS of them. So i'd
lean towards embedding a full struct cpumask and that's it.
That cpumask[] should probably be cpumask[0], to document the
aliasing to ->span and ->cpus properly.
Rusty, what do you think?
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/