Page MenuHomeFreeBSD

Make it possible to safely use TPIDRURW from userspace.
ClosedPublic

Authored by ed on Sep 19 2016, 10:05 AM.
Tags
None
Referenced Files
F107706811: D7951.diff
Fri, Jan 17, 5:07 PM
Unknown Object (File)
Fri, Jan 10, 4:42 PM
Unknown Object (File)
Sun, Dec 29, 4:27 AM
Unknown Object (File)
Dec 15 2024, 1:16 AM
Unknown Object (File)
Dec 7 2024, 10:45 AM
Unknown Object (File)
Nov 27 2024, 1:08 PM
Unknown Object (File)
Nov 17 2024, 12:58 AM
Unknown Object (File)
Nov 12 2024, 5:13 AM
Subscribers

Details

Summary

On amd64, arm64 and i386, we have the possibility to switch between TLS areas in userspace. The nice thing about this is that it makes it easier to do light-weight threading, if we ever feel like doing that. On armv6, let's go into the same direction by making it possible to safely use the TPIDRURW register, which is intended for this purpose.

Clean up the ARMv6 code to remove md_tp entirely. Simply add a dedicated field to the PCB to hold the value of TPIDRURW across context switches, like we do for any other register. As userspace currently uses the read-only TPIDRURO register, simply ensure that we keep both values in sync where possible. The system calls for modifying the read-only register will simply write the intended value into both registers, so that it lazily ends up in the PCB during the next context switch.

Test Plan

FreeBSD executables still work. CloudABI executables now work properly. Modulo some other small changes, the cloudlibc unit test suite now passes.

Diff Detail

Event Timeline

ed retitled this revision from to Work-in-progress support for saving/restoring TPIDRURW..
ed updated this object.
ed edited the test plan for this revision. (Show Details)
sys/arm/arm/swtch-v6.S
464–466

Have you checked if this gets executed? The ldmia above loads to pc so will return to the caller.

sys/arm/arm/swtch-v6.S
464–466

I have to confess I haven't tried this change after refactoring it to store the value in the PCB. In an earlier version I reuse md_tp for this, which did work, but was still done at line 440.

That said, thanks for noticing. I'll fix this and test this change again this evening.

As noted by Andrew, restore TLS before the other registers.

The ldmia already effectively does a return for us, so we need to
restore the TLS registers before we restore the rest.

ed retitled this revision from Work-in-progress support for saving/restoring TPIDRURW. to Make it possible to safely use TPIDRURW from userspace..Sep 19 2016, 5:05 PM
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added reviewers: andrew, imp.
ed added inline comments.
sys/arm/arm/swtch-v6.S
464–466

Yes. You were right. Looks like we're good to go now. :-)

Looks good to my eye, but take this only as a weak endorsement.

sys/arm/arm/swtch-v6.S
457

why twice?

sys/arm/include/pcpu.h
115

Au, that explains my question above. Perhaps a similar comment is in order.

ed edited edge metadata.

Extend comment regarding TPIDRURO.

ed marked 2 inline comments as done.Sep 20 2016, 4:51 PM

I've just extended the comment to clarify this.

sys/arm/include/pcpu.h
115

Can you change this to a single asm statement?

We also need to make sure the RW register is written first to ensure if we context switch between the two this will be correctly set. A comment to say so would be useful.

Put register updates in a single asm block. Extend the comments.

ed marked an inline comment as done.Sep 22 2016, 8:12 AM
andrew edited edge metadata.
This revision is now accepted and ready to land.Sep 22 2016, 8:13 AM
This revision was automatically updated to reflect the committed changes.