Page MenuHomeFreeBSD

panic()/KERNEL_PANICKED(): Move back to using 'panicstr' as a flag
ClosedPublic

Authored by olce on Jan 24 2024, 1:25 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, May 11, 6:51 AM
Unknown Object (File)
Sat, May 11, 5:14 AM
Unknown Object (File)
Fri, May 10, 7:40 PM
Unknown Object (File)
Fri, May 10, 5:36 PM
Unknown Object (File)
Mar 13 2024, 7:28 PM
Unknown Object (File)
Feb 1 2024, 4:01 AM
Unknown Object (File)
Jan 29 2024, 1:56 PM
Unknown Object (File)
Jan 29 2024, 1:53 PM
Subscribers

Details

Summary

Currently, no performance-critical path tests for a panic. Moreover, we
today have KERNEL_PANICKED() which wraps the test into
__predict_false(), already catering to those (potential) use cases.
Also, in practice we don't support 64-bit architectures without caches,
so reading an 'int' instead of a pointer doesn't (directly) save any
memory access. Finally, 'panicked' is redundant with 'panicstr' (and
wastes a tiny amount of memory).

Consequently:

  1. Use again 'panicstr' as a flag indicating that the system is

panicking. To this end:

    • Modify panic() so that it ensures this pointer is set to some non-NULL value even if the caller didn't pass any panic string.
    • Modify KERNEL_PANICKED() to test for 'panicstr'.
    • Remove 'panicked'.
  1. Annotate 'panicstr' with '__read_mostly' (instead of using

'__read_frequently' as for 'panicked'). This may have to be changed if,
in the future, some performance-intensive path needs to test it.

  1. Convert a few more direct tests of 'panicstr' to using

KERNEL_PANICKED().

MFC after: 2 weeks

Diff Detail

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

Event Timeline

olce requested review of this revision.Jan 24 2024, 1:25 PM
sys/kern/kern_shutdown.c
901–908

This is just defensive, there are no current callers that call panic(NULL) at present, right?

olce marked an inline comment as done.Jan 24 2024, 2:24 PM
olce added inline comments.
sys/kern/kern_shutdown.c
901–908

Exactly.

This revision is now accepted and ready to land.Jan 24 2024, 10:32 PM
sys/kern/kern_shutdown.c
918

I do not understand this conversion. Is KERNEL_PANICED() check reversed?

olce marked 2 inline comments as done.
olce edited the summary of this revision. (Show Details)

Fix inverted test after panicstr => KERNEL_PANICKED() conversion.

This revision now requires review to proceed.Jan 25 2024, 1:39 PM
sys/kern/kern_shutdown.c
918

Oh yes, you're right... I tested different working scenarios but not a panic one, should have... Thanks for noticing this.

This revision is now accepted and ready to land.Jan 25 2024, 1:55 PM