Skip to contentSkip to conversation

Question about arch/x86/xen/mmu.c

DISCUSSION Jan-Simon Moeller 2 participants 2 messages Dec 4, 2014 – Dec 5, 2014

lore
Share & tools
lore
#0 lore raw

Hi !

My name is Jan-Simon Moeller and I'm looking into compiling the kernel with LLVM/Clang (see llvm.linuxfoundation.org) .

Right now we face this issue when compiling with clang:

CC arch/x86/xen/mmu.o
arch/x86/xen/mmu.c:1343:18: error: fields must have a constant size:

     'variable length array in structure' extension will never be
     supported
               DECLARE_BITMAP(mask, num_processors);
                              ^

include/linux/types.h:10:16: note: expanded from macro 'DECLARE_BITMAP'
unsigned long name[BITS_TO_LONGS(bits)]
^
1 error generated.

Question to the experts: why can't we just use NR_CPUS and be done with it ? NR_CPUS will be setup by CONFIG_NR_CPUS and thus static.
( e.g. arch/x86/configs/x86_64_defconfig:CONFIG_NR_CPUS=64 )

The code in question is:

static void xen_flush_tlb_others(const struct cpumask *cpus,
struct mm_struct *mm, unsigned long start, unsigned long end)

{
	struct {
		struct mmuext_op op;
#ifdef CONFIG_SMP
		DECLARE_BITMAP(mask, num_processors);
#else
		DECLARE_BITMAP(mask, NR_CPUS);
#endif
	} *args;
	struct multicall_space mcs;

	trace_xen_mmu_flush_tlb_others(cpus, mm, start, end);

	if (cpumask_empty(cpus))
		return;		/* nothing to do */

	mcs = xen_mc_entry(sizeof(*args));
	args = mcs.args;
	args->op.arg2.vcpumask = to_cpumask(args->mask);

	/* Remove us, and any offline CPUS. */
	cpumask_and(to_cpumask(args->mask), cpus, cpu_online_mask);
	cpumask_clear_cpu(smp_processor_id(), to_cpumask(args->mask));

	args->op.cmd = MMUEXT_TLB_FLUSH_MULTI;
	if (end != TLB_FLUSH_ALL && (end - start) <= PAGE_SIZE) {
		args->op.cmd = MMUEXT_INVLPG_MULTI;
		args->op.arg1.linear_addr = start;
	}

	MULTI_mmuext_op(mcs.mc, &args->op, 1, NULL, DOMID_SELF);

	xen_mc_issue(PARAVIRT_LAZY_MMU);
}

Pointers:
http://www.slideshare.net/linaroorg/lcu14-209-llvm-linux-39165110 # slide 19
http://lwn.net/Articles/441018/
http://stackoverflow.com/questions/14629504/variable-length-array-in-the-middle-of-struct-why-this-c-code-is-valid-for-gcc

Thanks!

Jan-Simon

#1 lore raw
Quoted 19 lines · Jan-Simon Moeller

Hi !

My name is Jan-Simon Moeller and I'm looking into compiling the kernel with LLVM/Clang (see llvm.linuxfoundation.org) .

Right now we face this issue when compiling with clang:

CC arch/x86/xen/mmu.o
arch/x86/xen/mmu.c:1343:18: error: fields must have a constant size:

      'variable length array in structure' extension will never be
      supported
                DECLARE_BITMAP(mask, num_processors);
                               ^

include/linux/types.h:10:16: note: expanded from macro 'DECLARE_BITMAP'
unsigned long name[BITS_TO_LONGS(bits)]
^
1 error generated.

Quoted 3 lines

Question to the experts: why can't we just use NR_CPUS and be done with it ? NR_CPUS will be setup by CONFIG_NR_CPUS and thus static.
( e.g. arch/x86/configs/x86_64_defconfig:CONFIG_NR_CPUS=64 )

This would expand the structure on kernels configured for many cpus (e.g. 4096) but running on a smaller machine dramatically.

Juergen