Tuesday, February 22, 2022

[SOLVED] Writing per-cpu variables physical address during kernel initialization

Issue

I have the following code:

static DEFINE_PER_CPU_ALIGNED(cpu_clock_t, cpu_clock);

static void func(void *info)
{
        uint64_t cpu_clock_pa = per_cpu_ptr_to_phys(get_cpu_ptr(&cpu_clock));
        __asm__ __volatile__ ... //Giving the PA to VMware kernel which is supposed to write something to there
        put_cpu_ptr(cpu_clock);
}

Problem is, when this code runs as part of the kernel initialization, I get a message in VMware workstation "The CPU is disabled on the guest operating system" which means some kernel panic occurred and when I use the same code after the kernel boots (Call it as part of a module initialization) it works fine...


Solution

My code was running before setup_per_cpu_areas as a3f pointed out.



Answered By - tomer.z
Answer Checked By - Robin (WPSolving Admin)