Implement Layer 1: slab cache allow/deny list filtering#3
Merged
Conversation
Add per-cache slab filtering so operators can specify an allowlist or denylist of kmem_cache names instead of the all-or-nothing filter_slab=1. New module parameters: slab_action=allow|deny — list interpretation (default: allow) slab_cache_list=X,Y,Z — comma-separated cache names (load-time only) Priority hierarchy: 1. filter_slab=1 overrides everything (runtime kill switch) 2. slab_cache_list + slab_action when list is non-empty 3. Default: allow all slab pages Implementation accesses the slab_cache pointer via a minimal two-word struct overlay on struct page (stable since Linux 5.17), then uses the exported kmem_cache_name() to compare against the parsed list. NULL checks on both the cache pointer and name handle races conservatively. Performance: zero overhead when list is inactive. ~100ns/slab-page when active (pointer deref + linear strcmp over typically 10-30 entries), roughly 1-3% of per-page read cost. https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
kmem_cache_name() is EXPORT_SYMBOL_GPL in mm/slab_common.c but its declaration lives in mm/slab.h (kernel-internal header). Modules cannot include that header, so provide our own forward declaration. https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
kmem_cache_name() is declared in the internal mm/slab.h header, so modpost cannot resolve it for out-of-tree modules even though the symbol is exported. Replace with a self-discovering probe: at init time, create a temporary kmem_cache with a known name, scan the struct for a pointer to that name string, record the byte offset, and destroy the probe. At runtime, read the name at the discovered offset. This is config-independent, version-independent, and gracefully disables the slab list feature if the probe fails. Also fix non-ASCII em-dashes and a declaration-after-statement that checkpatch flags. https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add per-cache slab filtering so operators can specify an allowlist or
denylist of kmem_cache names instead of the all-or-nothing filter_slab=1.
New module parameters:
slab_action=allow|deny — list interpretation (default: allow)
slab_cache_list=X,Y,Z — comma-separated cache names (load-time only)
Priority hierarchy:
Implementation accesses the slab_cache pointer via a minimal two-word
struct overlay on struct page (stable since Linux 5.17), then uses the
exported kmem_cache_name() to compare against the parsed list. NULL
checks on both the cache pointer and name handle races conservatively.
Performance: zero overhead when list is inactive. ~100ns/slab-page when
active (pointer deref + linear strcmp over typically 10-30 entries),
roughly 1-3% of per-page read cost.
https://claude.ai/code/session_01PLNNAGRvUAS84y8JhoUJof