voltron_cgroup_lp)Live-inject voltron.policy into the cgroup filesystem.
A loadable module that live-injects Voltron's per-cgroup policy into the running kernel's cgroup-v2 hierarchy — no reboot, no kernel rebuild — so policy appears in its natural place:
/sys/fs/cgroup/<some.slice>/voltron.policy
This module provides only the cgroup-fs view. The data lives in the main module (voltron.ko), which exports voltron_policy_show() and voltron_policy_set_kv(); this module calls them, so both surfaces are the same store:
| Surface | Backed by |
|---|---|
/sys/fs/cgroup/<cg>/voltron.policy (this module) | voltron.ko policy store |
/sys/kernel/voltron/policy/cgroups/<id>/… (voltron.ko) | voltron.ko policy store |
Writing a field through either surface updates the one record; the resolver voltron_policy_resolve() and the (future) migration engine see it immediately. Consequently voltron_cgroup_lp **depends on voltron** (load order enforced by module deps).
/sys/fs/cgroup the ordinary way. (That is why the main module exposes policy under /sys/kernel/voltron/ instead.)cgroup_add_dfl_cftypes(), is not exported to modules.CONFIG_LIVEPATCH (klp) framework is the wrong vehicle**: klp_check_patch() rejects a patch with no replaced function, and klp cannot create new interface files. So we perform the equivalent live kernel modification directly.kallsyms_lookup_name via a short-lived kprobe (it is no longer exported since 5.7).cgroup_add_dfl_cftypes / cgroup_rm_cftypes and the target controller subsystem symbol (default memory_cgrp_subsys).cftype (voltron.policy) to that subsystem with cgroup_add_dfl_cftypes(). The files appear in every cgroup where that controller is enabled, and automatically in future cgroups.voltron.ko's voltron_policy_show() / voltron_policy_set_kv() — the shared store.cgroup_rm_cftypes() removes them.Link-time symbols are the exported ones (of_css, register_kprobe, seq_printf, and voltron.ko's voltron_policy_*); the sensitive cgroup internals are resolved at runtime via kallsyms.
Build voltron.ko first (it provides src/Module.symvers with the exported policy symbols), then this module with KBUILD_EXTRA_SYMBOLS pointing at it — the Makefile/make remote targets do this automatically.
(cd ../src && make) && make KBUILD_EXTRA_SYMBOLS=$(abspath ../src/Module.symvers)
voltron.policy is one line-oriented file per cgroup:
cat /sys/fs/cgroup/batch.slice/voltron.policy # cgroup_id 1234 # mode deny # target 0 # psi_metric cpu # psi_threshold 0 # min_residency_ms 0 # inherit 1 # write "<key> <value>": echo "mode auto" > /sys/fs/cgroup/batch.slice/voltron.policy echo "psi_metric cpu" > /sys/fs/cgroup/batch.slice/voltron.policy echo "psi_threshold 400">/sys/fs/cgroup/batch.slice/voltron.policy echo "target 2" > /sys/fs/cgroup/batch.slice/voltron.policy # manual mode echo "inherit 1" > /sys/fs/cgroup/batch.slice/voltron.policy
Keys: mode (deny|auto|manual), target, psi_metric (cpu|memory|io|full), psi_threshold (0..1000 permille), min_residency_ms, inherit (0|1).
cd livepatch make # against ../kernel-src make KDIR=/lib/modules/$(uname -r)/build # against the running kernel make remote # build on the kernel-build box sudo insmod voltron_cgroup_lp.ko # default: attach to memory controller sudo insmod voltron_cgroup_lp.ko subsys=cpu_cgrp_subsys # or another controller dmesg | tail ls /sys/fs/cgroup/*/voltron.policy sudo rmmod voltron_cgroup_lp
CONFIG_KPROBES=y and CONFIG_KALLSYMS_ALL=y (our config has both). Must be loaded on a matching kernel vermagic.subsys=).voltron.ko must be loaded first (module dependency). Policy records live in it; this module adds/removes only the cgroup-fs files.voltron unload). A future revision will hook css-offline.