Page MenuHomeFreeBSD

kern/proc: expose reaper PID and subtree root in struct kinfo_proc
ClosedPublic

Authored by rikka.goering_outlook.de on Mon, Apr 20, 11:35 PM.
Tags
None
Referenced Files
F153987803: D56538.id176041.diff
Sat, Apr 25, 6:52 AM
F153975752: D56538.id176046.diff
Sat, Apr 25, 5:22 AM
F153973183: D56538.id176015.diff
Sat, Apr 25, 5:01 AM
F153972775: D56538.id175945.diff
Sat, Apr 25, 4:58 AM
F153972303: D56538.id176042.diff
Sat, Apr 25, 4:54 AM
Unknown Object (File)
Fri, Apr 24, 5:39 AM
Unknown Object (File)
Wed, Apr 22, 7:31 AM
Subscribers

Details

Summary

Expose process reaper metadata through struct kinfo_proc so userland can reconstruct reaper hierarchies from kern.proc.all without adding a new procctl(2) operation.
The patch adds two pid_t fields consuming the two remaining KI_NSPARE_INT slots (KI_NSPARE_INT 2->0), without changing sizeof(struct kinfo_proc):

  • ki_reaper: PID of the owning reaper process
  • ki_reapsubtree: PID of the direct child of the reaper that roots the subtree the process belongs to

Updated components:

  • sys/sys/user.h: add the new kinfo_proc fields
  • sys/kern/kern_proc.c: populate the fields in fill_kinfo_proc_pgrp()
  • lib/libkvm/kvm_proc.c: update crash dump consumers
  • sys/compat/freebsd32/freebsd32.h and freebsd32_kinfo_proc_out(): update 32-bit compat layout and conversion

The implementation follows the existing kern.proc.all snapshot model. The values are populated while the sysctl path holds proctree_lock shared, and NULL reaper pointers fall back to NO_PID.
Tested locally with a small userland program covering baseline state, PROC_REAP_ACQUIRE, direct-child subtree tracking, and reparenting after PROC_REAP_RELEASE.

Bugzilla PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=293871

Diff Detail

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

Event Timeline

sys/kern/kern_proc.c
1238

Is it ever possible that p_reaper == NULL?

sys/sys/user.h
190–192

KI_NSPARE_INT is zero, and the field does not make sense anymore. Also I suspect that the member array with zero length is not valid C, but accepted by both gcc and clang.

Consuming the last int spare makes me nervous. I think we should carve some space from ki_sparestrings for at least one spare int.

rikka.goering_outlook.de marked 2 inline comments as done.

kern/proc: address review feedback on kinfo_proc reaper fields

  • Remove unnecessary NULL guard around p_reaper in fill_kinfo_proc_pgrp(); grep confirms p_reaper is always non-NULL for any live process
  • Restore KI_NSPARE_INT to 2 by carving 8 bytes from ki_sparestrings (46 -> 38), avoiding a zero-length array and preserving spare room for future growth
lib/libkvm/kvm_proc.c
369

p_reaper should be not NULL even in core dumps

sys/sys/user.h
190–192

I would move ki_spareints[] up, right after ki_sparestrings[]

rikka.goering_outlook.de marked 2 inline comments as done.

kern/proc: address review feedback on kinfo_proc reaper fields

  • Removed leftover NULL guard around p_reaper in lib/libkvm/kvm_proc.c
  • Re-ordered ki_spareints position in struct kinfo_proc  and in struct kinfo_proc32
lib/libkvm/kvm_proc.c
369

Please move the rproc declaration to around line 123

sys/kern/kern_proc.c
1238

It seems that the indent is incorrect?

kern/proc: address review feedback on kinfo_proc reaper fields

  • Fixed indentation error in sys/kern/kern_proc.c
lib/libkvm/kvm_proc.c
369

Please fix this. Then mail me the output from the 'git format-patch -1' with the proper author set.

rikka.goering_outlook.de marked 3 inline comments as done.

kern/proc: expose reaper PID and subtree root in struct kinfo_proc

  • moved rproc struct declaration to similar struct definitions in kvm_proc.c
This revision was not accepted when it landed; it landed in state Needs Review.Wed, Apr 22, 12:44 AM
This revision was automatically updated to reflect the committed changes.