Thread (38 messages) 38 messages, 7 authors, 2024-08-22
STALE685d

[PATCH RFC v3 12/13] mm: add SLAB_TYPESAFE_BY_RCU to files_cache

From: Andrii Nakryiko <andrii@kernel.org>
Date: 2024-08-13 04:30:19
Also in: bpf, linux-mm, lkml
Subsystem: exec & binfmt api, elf, memory management - core, scheduler, the rest · Maintainers: Kees Cook, Andrew Morton, David Hildenbrand, Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot, Linus Torvalds

Add RCU protection for file struct's backing memory by adding
SLAB_TYPESAFE_BY_RCU flag to files_cachep. This will allow to locklessly
access struct file's fields under RCU lock protection without having to
take much more expensive and contended locks.

This is going to be used for lockless uprobe look up in the next patch.

Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 kernel/fork.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 76ebafb956a6..91ecc32a491c 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -3157,8 +3157,8 @@ void __init proc_caches_init(void)
 			NULL);
 	files_cachep = kmem_cache_create("files_cache",
 			sizeof(struct files_struct), 0,
-			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
-			NULL);
+			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU|
+			SLAB_ACCOUNT, NULL);
 	fs_cachep = kmem_cache_create("fs_cache",
 			sizeof(struct fs_struct), 0,
 			SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT,
-- 
2.43.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help