Page MenuHomeFreeBSD

arm64: Add BTI support to pmap
ClosedPublic

Authored by andrew on Oct 23 2023, 2:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 4 2024, 9:33 AM
Unknown Object (File)
Oct 4 2024, 7:59 AM
Unknown Object (File)
Oct 1 2024, 8:59 PM
Unknown Object (File)
Sep 30 2024, 12:45 AM
Unknown Object (File)
Sep 28 2024, 12:26 AM
Unknown Object (File)
Sep 27 2024, 12:17 AM
Unknown Object (File)
Sep 25 2024, 6:31 PM
Unknown Object (File)
Sep 24 2024, 7:48 PM
Subscribers

Details

Summary

Add a rangeset to the arm64 pmap to describe which address space needs
the Branch Target Identification (BTI) Guard Page flag set in the page
table.

On hardware that supports BTI the Guard Page flag tells the hardware
to raise an exception if the target of a BR* and BLR* instruction is
not an appropriate landing pad instruction.

To support this in userspace we need to know which address space
should be guarded. For this add a rangeset to the arm64 pmap when the
hardware supports BTI. The kernel can then use pmap_bti_set and
pmap_bti_clear mark and unmark which address space is guarded.

Sponsored by: Arm Ltd
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 54386
Build 51276: arc lint + arc unit

Event Timeline

sys/arm64/arm64/pmap.c
437

Please add a comment explaining what this flag does.

2353

I think it would be better to embed pm_bti into the pmap, like we do with the rangeset for PKRU. Or perhaps just use malloc(). A dedicated zone for one allocation per pmap is overkill IMO.

3662

Hmm, do we want to call pmap_bti_on_remove() even when pm_stats.resident_count == 0? If so, I think PKRU has the same problem.

5531

The case where pm_stage is not equal seems like it should be an error.

7520

We should really just reuse the zone created in rs_rangeset_init(). That could be a followup change though.

8037

I think we want to add a rangeset_lookup_ge(), i.e., find the next range at or above the specified place, instead of looking up each page. That should be easy to implement, the underlying pctrie implementation provides it.

8050

Why "on_remove" instead of "remove"?

8054

Isn't it sufficient to just check pm_bti != NULL?

8084

Why not perform these checks in pmap_bti_check_args()?

sys/arm64/arm64/pmap.c
2353

I did it this way to break the KBI so it could be MFCd to 14, I could change to malloc.

3662

It should be called if the address space could be reused. If there is a guarantee that the address space will not be reused when pm_stats.resident_count == 0 then we can add a check.

8050

That's how it's named on amd64

sys/arm64/arm64/pmap.c
2353

Why is it a problem to add fields to the end of struct pmap? vm_pmap is the last field of struct vmspace, so growing it shouldn't break any important KBI.

3662

I don't believe there is any particular guarantee that resident_count == 0 implies that the address space won't be reused. A process may be completely swapped out. In practice, I suspect the VDSO page would keep the resident count positive, but that's not a guarantee.

  • Add a comment above pmap_bti_support
  • Remove pmap_bti_ranges_root_zone and switch to malloc for pm_bti
  • Remove pmap_bti_clear and pmap_bti_deassign, they are unused
  • Move the pmap_bti_check_uargs checks to pmap_bti_set
  • Remove unneeded PM_STAGE1 checks
sys/arm64/arm64/pmap.c
2353

I still don't see why the rangeset can't be embedded.

sys/arm64/arm64/pmap.c
2353

I can see a use for a rangeset for 2 or 3 other features. As these are unimplemented on most current CPUs I'd prefer to not add too much bloat to struct pmap if it's not used on most currently shipping devices.

3662

In that case we need to call pmap_bti_on_remove even when resident_count == 0. We need to remove the bti flag as the address space may be reused by code that doesn't understand BTI.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 22 2024, 4:28 PM
This revision was automatically updated to reflect the committed changes.