I am trying to declare a new variable in vvar.h
and define it near my new VDSO function. So that I could use this variable in my vdso function.
I have a question about VVar. According to the description in arch/x86/include/asm/vvar.h
, when I declare here a new variable as DECLARE_VVAR(0, int, count)
, I should use DEFINE_VVAR(type, name)
to define this variable somewhere else.
The problem is after I defined this variable somewhere else, like DEFINE_VVAR(int, count)
, when I am trying to assign an integer value to this variable count
, it is failed. This is because after kernel version 5.2 #define DEFINE_VVAR(type, name)
has been changed from #define DEFINE_VVAR(type, name) type name
to #define DEFINE_VVAR(type, name) type name[CS_BASES]
. Right now this variable count
is an integer array instead of type integer. Therefore I can't assign a integer value to it. Do you know how to fix it?
VVAR.h: https://elixir.bootlin.com/linux/v5.12/source/arch/x86/include/asm/vvar.h#L43
Typically, you cannot add a variable simply through
DECLARE_VVAR
macro.The first thing you have to be aware of is that
.vvar
is a page of memory located inside the memory (more specifically, before.vdso
) and could access by both kernel and userland. You can see this inside the linker script https://elixir.bootlin.com/linux/latest/source/arch/x86/entry/vdso/vdso-layout.lds.S. For now, kernel already has a data structure `struct video to format the data inside this page.Second, assume you want to add a variable inside the
.vvar
page and access it in your new vdso function, the easiest way is to add it inside thesturct vdso
structure of include/vdso/datapage.h: https://elixir.bootlin.com/linux/latest/source/include/vdso/datapage.h. After that, you can update them inside the kernel (for example, in schedule) in the same way as other vvar variables.Second, if you want to own your own vvar page, you have to define your own vvar data structure inside the
datapage.h
and do not forgetDEFINE_VVAR
invsyscall.h
: https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/vdso/vsyscall.h ALso, since the vvar memory layout is compact, you also need to allocate another page through linker script: https://elixir.bootlin.com/linux/latest/source/arch/x86/entry/vdso/vdso-layout.lds.S by changevvar_start = . - 4 * PAGE_SIZE;
intovvar_start = . - 5 * PAGE_SIZE;