Linus Torvalds Hands-On Improving Linux User-Mode Stack Extensions
Linus Torvalds Hands-On Improving Linux User-Mode Stack Extensions
Linus Torvalds Hands-On Improving Linux User-Mode Stack Extensions.
On July 1, Linus Torvalds actually rarely writes kernel code himself; more is busy monitoring the upstream kernel development community, reviewing code, managing releases, and discussing on mailing lists.
Recently, however, he has reworked nearly 500 lines of code for Linux 6.5 to improve the user-mode stack extension code .
He explained in the consolidated report:
This modifies our user-mode stack extension code to always acquire mmap_lock for writing before modifying the VM layout.
It’s actually something we’re technically supposed to do, but since we don’t strictly need it, we’re kind of lazy (“opportunistic” sounds much better, doesn’t it?). And setting up this hack where we need it, will expand the stack vma in-place without proper locking.
And it works great. We just need to change vm_start (or, in the case of grow-up stacks, vm_end), plus some special temporary locks using anon_vma locks and mm>page_table_lock, it’s all pretty straightforward.
That said, it was all fine until Ruihan Li pointed out that now that the vma layout uses maple tree code, we really don’t just change vm_start and vm_end, and the locking is really broken.
Fixing this once and for all and doing proper locking is actually not terrible, but a bit of a pain. We basically have three different stack extension situations, all of which work slightly differently.
Currently, this issue should have been resolved in Linux 6.5. More details can be found here .
