Page MenuHomeFreeBSD

Don't panic for PT_GETFPREGS.
ClosedPublic

Authored by jhb on Aug 11 2017, 12:37 AM.
Tags
None
Referenced Files
Unknown Object (File)
Feb 23 2024, 5:01 AM
Unknown Object (File)
Jan 16 2024, 4:42 AM
Unknown Object (File)
Dec 29 2023, 6:00 PM
Unknown Object (File)
Dec 20 2023, 6:34 AM
Unknown Object (File)
Nov 25 2023, 2:22 PM
Unknown Object (File)
Nov 15 2023, 7:12 AM
Unknown Object (File)
Sep 11 2023, 6:55 PM
Unknown Object (File)
Sep 3 2023, 10:53 PM
Subscribers

Details

Reviewers
andrew
Summary

Only fetch the VFP state from the CPU if the thread whose registers are being requested is
the current thread. If a stopped thread's registers are being fetched by a debugger, the
saved state in the PCB is already valid.

Test Plan
  • info registers in gdb panics a debug kernel when PT_GETFPGREGS is invoked on a non-running thread.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 11045
Build 11430: arc lint + arc unit

Event Timeline

Where is this being called from? I think the bug is calling vfp_save_state on a non-current thread.

fill_fpregs(). Once a thread uses the FPU once the "started" flag is set but never cleared. The approach in the patch matches the behavior of sys/amd64/amd64/fpu.c:fpugetregs().

One thing I'm not quite certain amd64 does is if the thread is suspended in ptracestop(), is the FPU state "flushed" out or could it be sitting in some other CPU that the debugger isn't running on when it calls ptrace(). In that case amd64 would return stale info. In some ways I think amd64 would be better off not doing lazy save/restore of the FPU state during context switches as that would solve that.

On arm64 if a thread has used the vfp unit we will store the state on context switch. This means we should only need to call vfp_save_state when we need access to the fpu registers from the current thread. I don't think fill_fpregs has been tested as lldb didn't have vfp support when we did the initial port.

sys/arm64/arm64/vfp.c
208 ↗(On Diff #31909)

Feel free to commit the comment fix.

Ok. So would you rather me change fill_regs() to only call vfp_save_state() if td == curthread? Also, it seems we could at that point make vfp_save_state() assume curthread the way vfp_restore_state() assumes curthread.

Yes. I'm not sure why I made the save KPI look like it does. I think curthread is correct at the point it's called in cpu_switch(), however it would pay to check that.

Make the vfp_save_state() call conditional instead.

jhb retitled this revision from Don't panic in fill_fpregs if the current thread isn't the fpcurthread. to Don't panic for PT_GETFPREGS..Aug 12 2017, 3:31 AM
jhb edited the summary of this revision. (Show Details)

I didn't change the vfp_save_state() API yet. curthread is correct in the cpu_switch case at least, and savectx() is what passes NULL as the thread pointer. I think it would be safe to have it work like vfp_restore_state() and assume curpcb / curthread.

This revision is now accepted and ready to land.Aug 12 2017, 7:21 AM