Page MenuHomeFreeBSD

arm64: set FPEN if we're stuck with HCR_EL2.E2H
ClosedPublic

Authored by kevans on Feb 28 2023, 7:13 AM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 10 2024, 3:01 PM
Unknown Object (File)
Oct 2 2024, 9:55 AM
Unknown Object (File)
Sep 29 2024, 8:22 PM
Unknown Object (File)
Sep 27 2024, 8:15 AM
Unknown Object (File)
Sep 24 2024, 9:25 AM
Unknown Object (File)
Sep 9 2024, 10:45 PM
Unknown Object (File)
Sep 5 2024, 1:02 AM
Unknown Object (File)
Aug 19 2024, 6:47 PM
Subscribers

Details

Summary

On Apple Silicon systems, E2H can't actually be cleared; we're stuck
with it. Check it again when we're setting up CPTR_EL2 and set FPEN
appropriately to avoid later trapping to EL2 on writes to SIMD
registers.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 50066
Build 46958: arc lint + arc unit

Event Timeline

sys/arm64/arm64/locore.S
264

I think we'll need an isb between setting hcr_el2 and reading it to ensure the change is visible to instructions after it (i.e. the mrs)

sys/arm64/include/hypervisor.h
51

We should have two sets of macros. The current ones are only valid when HCR_EL2.E2H == 0. TTA and TCPAC are the only macros that are shared between the two.

95–96

This is normally named ..._SHIFT in this file and armreg.h

Address review commentary:

  • Add an isb
  • Follow convention for shift naming

I also went back to https://developer.arm.com/documentation/ddi0601/2020-12/AArch64-Registers/CPTR-EL2--Architectural-Feature-Trap-Register--EL2-
and discovered where I misunderstood the differences (the second table depicting
HCR_EL2.E2H == 0 didn't stick out on my first read, so there was some confusion
there) -- for E2H == 1, we shouldn't be using CPTR_RES1 at all as there are no
RES1 bits.

andrew added inline comments.
sys/arm64/arm64/locore.S
282–297

I think you can write this as (but might have x3 and x4 backwards in the csel instruction):

tst     x4, #HCR_E2H
mov     x3, #CPTR_RES1
mov     x4, #CPTR_FPEN
csel    x2, x3, x4, eq
This revision is now accepted and ready to land.Feb 28 2023, 8:39 PM
kevans added inline comments.
sys/arm64/arm64/locore.S
282–297

Ah, that's much cleaner, thanks! I've confirmed that it still works as expected on both an M1 as well as a Mt. Snow; reverted the HCR_* part of the hypervisor.h changes and will commit soon.

This revision was automatically updated to reflect the committed changes.
kevans marked an inline comment as done.