Skip to content

kerf: preserve PCI host bridge metadata - #11

Draft
nickolaev wants to merge 3 commits into
multikernel:mainfrom
nickolaev:sriov-vf-assignment
Draft

kerf: preserve PCI host bridge metadata#11
nickolaev wants to merge 3 commits into
multikernel:mainfrom
nickolaev:sriov-vf-assignment

Conversation

@nickolaev

@nickolaev nickolaev commented Jul 22, 2026

Copy link
Copy Markdown

Kerf must preserve PCI host-bridge information when parsing and generating Multikernel device trees. A spawned kernel
needs the PCI segment, bus range, and ECAM base to discover and access its assigned SR-IOV VF.

This change:

  • adds PCI host bridges to Kerf’s hardware model;
  • parses and emits the metadata in DTB and DTS formats;
  • validates segments, bus ranges, ECAM alignment, and overlaps;
  • supports explicit 64-bit physical CPU IDs in DTS input; and
  • remains compatible with device trees without PCI host-bridge metadata.

This complements the Linux SR-IOV assignment work in multikernel/linux#4.

@nickolaev
nickolaev force-pushed the sriov-vf-assignment branch 2 times, most recently from 2a44f01 to d98d1e8 Compare July 30, 2026 16:41
congwang-mk and others added 3 commits July 30, 2026 12:11
The topology models, allocation policies and validators already existed
but were dead code in practice: the baseline DTB generator never emitted
the topology section, so every create/update reading state back from the
kernel saw no topology, and nothing ever discovered it from the host.

Make the support real:

- Emit the topology section (NUMA nodes, per-node memory range, CPUs as
  64-bit physical ID cells, distance matrix as <target distance> pairs,
  memory type) and device numa-node into the baseline DTB, and parse
  them back, so topology survives the kernel round trip.

- Add kerf/topology.py to discover the host topology at kerf init time:
  NUMA nodes and distances from /sys/devices/system/node, per-node
  memory ranges from /proc/zoneinfo, and PCI device locality from sysfs.
  Sysfs is keyed by logical CPU while kerf speaks physical APIC IDs, so
  discovery translates through the processor/apicid pairs in
  /proc/cpuinfo.

- Fix DTS parsing bugs that broke hand-written topology sections: the
  topology/numa-nodes/cores regexes could not handle nested braces (only
  the first node parsed), comments inside multi-line property values
  broke value parsing, and the pool memory-base regex could match a NUMA
  node's memory-base instead.

- Keep manual allocation authoritative: explicit --cpus no longer gets
  a compact affinity policy attached implicitly, so deliberate
  topology-crossing layouts do not accumulate spurious warnings.
  Auto-allocation (--cpu-count) still defaults to compact. Topology
  violations remain warnings; only impossible requests are errors.

- Fold the topology documentation into README.md, replacing the stale
  docs/CPU_NUMA_TOPOLOGY.md, and update the NUMA examples to the
  supported format.

Instance memory is still allocated first-fit from a single pool;
NUMA-aware per-node pools via /dev/lazy_cma's node parameter are the
next step.
Kerf rebuilds an instance device tree from the parsed baseline.
Dropping pci-host-bridges during that round trip leaves the spawned
kernel without the immutable ECAM descriptors required to construct
its synthetic PCI roots.

Add a PCI host-bridge model, parse it from binary and source device
trees, validate segment and bus ranges, ECAM alignment, and overlap,
and emit the metadata into generated instance trees. Cover valid round
trips and malformed descriptors in the baseline tests.

Signed-off-by: Nikolay Nikolaev <nicknickolaev@gmail.com>
The device-tree compiler can render CPU lists with an explicit /bits/ width and hexadecimal cells. Treating that syntax as plain decimal values makes Kerf reject valid extracted instance trees.\n\nAccept the 32-bit and 64-bit forms, parse each cell with base detection, and limit the lookup to direct /resources properties so nested NUMA CPU lists cannot shadow the global inventory. Cover the legacy and explicit-width forms in the parser tests.\n\nSigned-off-by: Nikolay Nikolaev <nicknickolaev@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants