If my understanding is not wrong, every process has a Kernel Address space associated with it (which is typically 1GB). As far as local variables are concerned, they are assigned on the kernel stack and so their virtual address is according to the address of the kernel stack.
However, if there are global variables in the kernel code, what will be the virtual address of these variables? When and who will assign this address? If it is the compiler, how does the compiler know that some part of code is kernel code?
Sorry for asking such a naive question, but I'm really confused here.