0
votes

I'm trying to export a per-cpu symbol "x86_cpu_to_logical_apicid" from kernel so that my kernel module can access it. In "arch/x86/kernel/apic/x2apic_cluster.c", I did

//static DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid);
DEFINE_PER_CPU(u32, x86_cpu_to_logical_apicid); //I remove static
EXPORT_PER_CPU_SYMBOL(x86_cpu_to_logical_apicid); // I add this 

And after I recompile the kernel, the /proc/kallsyms shows

0000000000011fc0 V x86_cpu_to_logical_apicid
0000000000012288 V x86_cpu_to_node_map
ffffffff8187df50 r __ksymtab_x86_cpu_to_apicid

Then I try to access the "x86_cpu_to_logical_apicid" in my kernel module, by using

int apicid = per_cpu(x86_cpu_to_logical_apicid, 2) 

However, when I loaded it, it fails to load it due to "Unknown symbol in module". The flag "V" means weak object, however I'm not sure whether this is the reason I fails to export the symbol. Can anyone give me some suggestions? Thank you!

1

1 Answers

1
votes

I realize that the OP perhaps is not interested in the answer anymore, but today I had a similar issue, and I thought it might help others as well.

Before using an exported per_cpu variable in a module, you have to declare it first. For your case:

DECLARE_PER_CPU(u32, x86_cpu_to_logical_apicid);

Then you can use get_cpu_var and put_cpu_var to safely access the current processor's copy of the variable. You can read more here.