Linus Torvalds Cleans Up The Intel LAM Code In Linux 6.4

Written by Michael Larabel in Linux Kernel on 6 May 2023 at 06:30 AM EDT. 1 Comment
LINUX KERNEL
While these days Linus Torvalds is mostly dealing with herding new code into the Linux kernel and being a gate keeper rather than actively developing new kernel code himself, for the in-development Linux 6.4 he's found himself doing a bit of coding.

As noted last week he personally took to cleaning up the x86 memory copy code for Linux 6.4. This week he's merged more of his own code as he took issue with some of the code merged by Intel engineers as part of their Linear Address Masking enabling.

Back during the Linux 6.2 days at the end of last year, Linus rejected the Intel LAM code at the time for various technical issues. Intel then reworked it for Linux 6.4.


This time around Linus merged Intel LAM into Linux 6.4 as this new CPU feature for letting user-space store metadata within some bits of pointers without masking it out before use. Intel LAM - like Arm TBI - can be of use to virtual machines, profiling / sanitizers / tagging, and other applications. But this time around there were some less than ideal code that he personally took to sprucing up.

Linus wrote in a new merge on Friday:
Merge my x86 uaccess updates branch.

The LAM ("Linear Address Masking") updates in this release made me unhappy about how "access_ok()" was done, and it actually turned out to have a couple of small bugs in it too. This is my cleanup of the code:

- use the sign bit of the __user pointer rather than masking the address and checking it against the TASK_SIZE range.

We already did this part for the get/put_user() side, but 'access_ok()' did the naïve "mask and range check" thing, which not only generates nasty code, but also ended up meaning that __access_ok itself didn't do a good job, and so copy_from_user_nmi() didn't get the check right.

- move all the code that is 64-bit only into the 64-bit version of the header file, so that we don't unnecessarily pollute the shared x86 code and make it look like LAM might work in 32-bit too.

- fix a bug in the address masking (that doesn't end up mattering: in this case the fix was to just remove the buggy code entirely).

- a couple of trivial cleanups and added commentary about the access_ok() rules.

So Intel LAM remains ready to go for Linux 6.4 and Torvalds reworked around one hundred lines of code for cleaning it up.


Now for Linux user-space to prepare to make use of Intel LAM.
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week