[PATCH v2 00/11] tools: Introduce a kernel configuration checker
From: Ahmed S. Darwish
Date: Thu Dec 03 2026 - 17:49:33 EST
Hi,
Last September in Prague I proposed a kernel configuration checker:
https://youtu.be/hqnOmdpGBdQ
This series adds kconfig-audit, a Python tool that checks a kernel .config
against a YAML configuration policy and reports found issues by severity.
It also adds a PREEMPT_RT configuration policy, support for policy
overlays, documentation, and a make auditconfig target.
Beside mainline policies, the tool is designed to let downstream projects,
such as Debian and systemd, check their kernel configuration requirements.
Special thanks to Julian Braha, Nathan Chancellor, Nicolas Schier, and
Emanuele Rocca for all the v1 reviews.
v1: https://msgid.link/20261106091922.7560-1-darwi@xxxxxxxxxxxxx
Changelog v2
============
(I) Standardize terminology
---------------------------
Rename the tool to 'kconfig-audit'.
Use 'policy' for kernel configuration policies, instead of 'rules'.
Use 'enabled', 'disabled', and 'neutral' for rule expectations.
Adapt all code and documentation accordingly.
(II) Introduce strict schema versioning
---------------------------------------
This allows repositories outside of the kernel tree (e.g. systemd) to
include their own kernel configuration policies while being sure that such
policies will continue to work for future kconfig-audit releases.
Implement a light schema versioning scheme that is similar in spirit to
Kubernetes object specs; i.e., with an `api_version` and `kind` fields.
Policy files are now required to have on top:
api_version: kconfig-audit.kernel.org/v1
kind: Policy
Overlay files are now required to have:
api_version: kconfig-audit.kernel.org/v1
kind: PolicyOverlay
And the tool's schemas are now structured as:
$ tree ~/linux/tools/kconfig-audit/schema/
tools/kconfig-audit/schema/
├── policy-overlay-v1.yml
├── policy-v1.yml
└── rule.yml
The Python code loads the appropriate schema according to `api_version`.
After merge, forward compatibility is intended to be strictly enforced.
Also introduce a new sub-command for listing supported APIs:
$ ./tools/kconfig-audit/audit.py list-api-versions
kconfig-audit.kernel.org/v1
(III) Introduce a pattern priority mechanism
--------------------------------------------
Introduce pattern rules priorities, so that a .config symbol matching more
than one pattern rule can be gracefully handled.
For example, for the policy file below:
rules:
- name_pattern: CONFIG_DEBUG
expected: disabled
severity: medium
- name_pattern: CONFIG_DEBUG_INFO
pattern_prio: 1
expected: enabled
severity: low
If the checked .config has CONFIG_DEBUG_INFO_DWARF4, then that symbol is
expected to be enabled. That's the case because the CONFIG_DEBUG_INFO
pattern has a higher priority of 1, while the broader CONFIG_DEBUG pattern
has a (lower) default priority of zero.
Priorities are enforced by the schema from 1 to 100.
(IV) Handle all kconfig symbol types
------------------------------------
Model kconfig symbols in a proper python objects data model. For below
policy:
rules:
- name: CONFIG_PREEMPT_RT
expected: enabled
severity: fatal
- name: CONFIG_CPU_FREQ
expected: enabled
severity: high
- name: CONFIG_DRM
expected: disabled
severity: info
The checked .config:
CONFIG_PREEMPT_RT=1
CONFIG_CPU_FREQ="string"
CONFIG_DRM=0x1234
will trigger error reports of a type mismatch for each symbol, since a
kconfig tristate was expected instead.
Due to the better kconfig symbols modelling, the tool also now complains
about any invalid syntax in config files.
(V) Add a configuration policies guide
--------------------------------------
Transform v1 documentation into a full configuration policies guide.
Document kconfig-audit report format, exit codes, policy file format,
overlay files format, rule matching semantics, rule precedence semantics,
and a reference for the policy files grammar.
(VI) Maintain stricter separation between YAML parsing and data model
---------------------------------------------------------------------
Remove all YAML dictionary access from the data model init code.
The tool was already very careful about separating the data model from the
parsed YAML dictionaries, but some minimal YAML parsing leaked into objects
initialization logic. This is now fully removed.
The tool's python code has below design:
KernelConfig # internal model, typed .config symbols repository
KernelConfigFile # parser
Policy # internal model, typed policy rules repository
PolicyFile # parser
PolicyOverlay # internal model, typed overrides repository
PolicyOverlayFile # parser
Schema # internal model, dictionary-like
SchemaFile # parser
(VII) Tighten policy checking
-----------------------------
Allow pattern rules with `expected: enabled`.
Make explicit rules poke a hole in name_pattern rules, or modify it. For
example, below policy:
rules:
- name_pattern: CONFIG_CC_HAS_COUNTED_BY
expected: enabled
severity: fatal
- name: CONFIG_CC_HAS_COUNTED_BY_PTR
expected: enabled
severity: low
If the .config has CONFIG_CC_HAS_COUNTED_BY_PTR disabled, then the conflict
will be reported with a low (instead of fatal) severity.
Moreover:
* Report conflicting expectations when a symbol matches multiple pattern
rules.
* Report an issue if an `expected: enabled` pattern matches no .config
enabled symbols.
* Reject invalid .config syntax, repeated CONFIG_* definitions, and policy
overlays containing duplicate rules.
* Let pattern rules matching non-tristate symbols report type mismatches.
* Update the PREEMPT_RT policy for CONFIG_DEBUG_FS_ALLOW_{ALL,NONE} and
CONFIG_DEBUG_INFO. Correct the CONFIG_DEBUG_KERNEL rationale. Add entry
for CONFIG_RCU_NOCB_CPU. Incorporate further review feedback.
(VIII) Move the auditconfig Makefile target to PQ end
-----------------------------------------------------
Place the `auditconfig` Makefile target after the Python tool and its
documentation, so it does not block review and merging of the tool itself.
Thanks!
8<-----
Ahmed S. Darwish (11):
kconfig-audit: Add schema for policy files
kconfig-audit: Introduce a PREEMPT_RT configuration policy
kconfig-audit: Add the configuration checker code
Documentation: Describe kconfig-audit usage and design
kconfig-audit: Split policy schema for component reuse
kconfig-audit: Introduce policy overlays schema
kconfig-audit: Add support for policy overlays
Documentation: kconfig-audit: Describe policy overlays
MAINTAINERS: Add entry for kernel configuration audit
kconfig: Introduce auditconfig target
Documentation: Describe auditconfig build target
Documentation/admin-guide/README.rst | 29 +
.../real-time/kernel-configuration.rst | 3 +
Documentation/tools/index.rst | 1 +
Documentation/tools/kconfig-audit.rst | 628 +++++++++
MAINTAINERS | 10 +
scripts/kconfig/Makefile | 25 +
tools/kconfig-audit/audit.py | 1151 +++++++++++++++++
tools/kconfig-audit/policy/preempt_rt.yml | 179 +++
.../schema/policy-overlay-v1.yml | 49 +
tools/kconfig-audit/schema/policy-v1.yml | 40 +
tools/kconfig-audit/schema/rule.yml | 117 ++
11 files changed, 2232 insertions(+)
create mode 100644 Documentation/tools/kconfig-audit.rst
create mode 100755 tools/kconfig-audit/audit.py
create mode 100644 tools/kconfig-audit/policy/preempt_rt.yml
create mode 100644 tools/kconfig-audit/schema/policy-overlay-v1.yml
create mode 100644 tools/kconfig-audit/schema/policy-v1.yml
create mode 100644 tools/kconfig-audit/schema/rule.yml
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.56.0