Page MenuHomeFreeBSD

exterror(9): dynamic kernel categories
ClosedPublic

Authored by brooks on Jul 14 2026, 8:08 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Aug 13, 1:26 AM
Unknown Object (File)
Mon, Aug 10, 12:51 PM
Unknown Object (File)
Mon, Aug 10, 10:14 AM
Unknown Object (File)
Sun, Aug 9, 10:58 PM
Unknown Object (File)
Sun, Aug 9, 9:57 PM
Unknown Object (File)
Sat, Aug 8, 11:05 PM
Unknown Object (File)
Sat, Aug 8, 8:05 PM
Unknown Object (File)
Sat, Aug 8, 5:16 PM
Subscribers

Details

Summary

Make it possible to define categories without compiling their
paths into libc (important for third-party modules). A
EXTERR_CATEGORY_DYNAMIC macro can be defined to a string describing the
compilation unit (generally the path relative to src/sys) which takes
the place of EXTERR_CATEGORY.

These strings are assembled in linker sets with category numbers
assigned at system startup or module load time. The strings can be
retrieved from the kern.exterr.categories.<category> sysctl.

Sponsored by: Innovate UK

Diff Detail

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

Event Timeline

This addresses an issue I realized during Kirk's talk at BSDCan. In the existing model, it's quite hard to support third-party modules and even in-tree modules for downstreams would require reserving a portion of the identifier space. This approach adds cost to the EXTERROR_VERBOSE reporting path, but significantly decouples the kernel and libc. I'm not sure I'd want to go as far moving entirely to dynamic, but it's probably not a problem in practice.

If I wanted to make this more efficient I'd add an AT_EXTERR_CATS and AT_EXTERR_CAT_MAX or the like and use shared pages to push out an array of pointers (or maybe with a third variable indexes) into processes addresses spaces. You might still want a fallback for categories larger than AT_EXTERR_CAT_MAX to use the sysctl interface if modules were loaded so I think this is the right direction regardless.

sys/kern/subr_exterr.c
35

This might want to be an RB tree if there are lots of modules, but this is simple

sys/kern/subr_exterr.c
41

I think this lock can usefully be rwlock.

104

free under the mutex establishes the order between uma locks (and transitively VM locks) and the cat_mtx. Then it would be impossible to use that somewhere deep in VM.

This might be not a serious issues because a loadable module probably does not provide low-level VM functionality, but there it is trivial to avoid introducing the order.

brooks marked 2 inline comments as done.

Switch to rwlock, hoist free outside the locked region.

This comment was removed by brooks.
This revision is now accepted and ready to land.Fri, Jul 24, 7:51 PM
This revision was automatically updated to reflect the committed changes.