2
votes

Is the linux kernel stack at the same virtual address in each process context?

Before answer, please note that I've specified the KERNEL stack and not the user space one.

1
Every kernel thread has its own stack. Because whole kernel shares the same virtual address space, kernel's stacks should be different for different threads. - Tsyvarev
Assuming that I have a single thread cpu. I deduce that all the processes kernel stacks are mapped to the same virtual address. Agree? - davyjunz
Do not understand you. Lets kernel thread T1 has stack S1, and thread T2 has stack S2. If you talk about single stack for different threads, then yes, stack S1 has the same virtual address for both T1 and T2. If you talk about stack addresses for their own threads, then address of S1 differs from one of S2. - Tsyvarev
Ok, i try to re-elaborate. Live alone the threads and think about two processes (tasks) running in a single core cpu (no multithread and no SMP). They have two different physical stacks at two different physical addresses. I was wondering if the physical addresses are mapped to the same virtual address. - davyjunz
I was wondering if the physical addresses are mapped to the same virtual address. - No. As I explained in the first comment, all kernel threads live in the same virtual address space. Within that space, different physical addresses cannot be mapped into the same virtual address. It is simply impossible to create such address space. - Tsyvarev

1 Answers

-1
votes

If you have only one core then you only need one kernel stack. If you have more than one core than is possible two or more cores execute kernel code so there will be problem if two cores use the same stack. Of course kernel must map all the stacks to all virtual address spaces because the different stack is per cpu not per process and a process may run by two cpus (not the same time) and they will need to find at every process virtual address space his own stack.