Re: [RFC 11/14] x86: add support for Dynamic Kernel Stacks

From: Thomas Gleixner
Date: Thu Mar 14 2024 - 14:26:24 EST


On Thu, Mar 14 2024 at 10:03, Pasha Tatashin wrote:
> On Wed, Mar 13, 2024 at 12:12 PM Thomas Gleixner <tglx@linutronixde> wrote:
>> That needs to validate whether anything uses current between the stack
>> switch and the place where current is updated today. I think nothing
>> should do so, but I would not be surprised either if it would be the
>> case. Such code would already today just work by chance I think,
>>
>> That should not be hard to analyze and fixup if necessary.
>>
>> So that's fixable, but I'm not really convinced that all of this is safe
>> and correct under all circumstances. That needs a lot more analysis than
>> just the trivial one I did for switch_to().
>
> Agreed, if the current task pointer can be switched later, after loads
> and stores to the stack, that would be a better solution. I will
> incorporate this approach into my next version.

No. You need to ensure that there is neither a load or store on the
stack between:

movq %rsp, TASK_threadsp(%rdi)
movq TASK_threadsp(%rsi), %rsp

and update_current(). IOW, you need to move the update of
pcpu_hot.current to ASM right after the RSP switch.

> I also concur that this proposal necessitates more rigorous analysis.

Glad we agree here :)

Thanks,

tglx