Page MenuHomeFreeBSD

arm64: extend ESR/SPSR registers to 64b
ClosedPublic

Authored by zachary.leaf_arm.com on Mar 8 2023, 2:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 28 2024, 8:55 AM
Unknown Object (File)
Mar 5 2024, 3:35 PM
Unknown Object (File)
Dec 20 2023, 3:54 AM
Unknown Object (File)
Dec 12 2023, 4:59 AM
Unknown Object (File)
Oct 15 2023, 5:17 AM
Unknown Object (File)
Oct 15 2023, 5:17 AM
Unknown Object (File)
Sep 5 2023, 11:52 PM
Unknown Object (File)
Aug 14 2023, 11:09 PM

Details

Summary

For the Exception Syndrome Register, ESR_ELx, the upper 32b were
previously unused, but now may contain additional exception info as of
Armv8.7 (FEAT_LS64).

Extend ESR from u32->u64 in exception handling code to support this. In
addition, also extend Saved Program Status Register SPSR_ELx in the same
way to allow for future extensions.

Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/arm64/include/reg.h
43

One thing I'm not sure about is if this will break the ABI of existing programs that use struct reg. As we are using padding from the end of the struct the data may be non-zero when passed back to the kernel from userspace.

jhb added inline comments.
sys/arm64/include/reg.h
43

Humm, I think spsr is a read-only register for ptrace()?

Oh, hmm, it is not.

frame->tf_spsr &= ~PSR_SETTABLE_64;
frame->tf_spsr |= regs->spsr & PSR_SETTABLE_64;

Were we always careful to clear the padding? Hmm, no, we only started clearing the regs structure up in sys_ptrace() back in 2018 (commit 352aaa51225671cce8ea44347e6f5a1e5f7daaf8 by @markj).

That said, GDB at least always does a read-modify-write sequence anytime it calls PT_SETREGS where it does a PT_GETREGS first, applies specific register modifications, then does a PT_SETREGS, so it should be ok so long as I only make it start treating the register as wider in sufficiently recent versions via a __FreeBSD_version check at compile-time. I don't know what LLDB does, but I think read-modify-write is the only really sane way to use PT_SETREGS.

My plan is to commit this stack with D35378 and a separate __FreeBSD_version bump

sys/arm64/include/reg.h
43

I think this one is ok, as long as PSR_SETTABLE_64 doesn't include the upper 32 bits of reg->spsr. The issue is if the copy is stored in struct reg the compiler is free to modify the trailing padding.

From memory, lldb will store it in a buffer large enough to hold struct reg and knows the offset of each field so should only change the field it needs to change.

This revision is now accepted and ready to land.Mar 22 2023, 11:57 AM
This revision was automatically updated to reflect the committed changes.