]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
kernfs: adapt to rhashtable-based simple_xattrs with lazy allocation
authorChristian Brauner <brauner@kernel.org>
Mon, 16 Feb 2026 13:32:00 +0000 (14:32 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 2 Mar 2026 10:05:50 +0000 (11:05 +0100)
commit5bd97f5c5f241a5610c4412d1b93995a26241f81
treeac1c543b7e6aaa79ac1227579ccbe73d981d1337
parent52b364fed6e1578e551fee20c76fecb3fc0e10ed
kernfs: adapt to rhashtable-based simple_xattrs with lazy allocation

Adapt kernfs to use the rhashtable-based xattr path and switch from an
embedded struct to pointer-based lazy allocation.

Change kernfs_iattrs.xattrs from embedded 'struct simple_xattrs' to a
pointer 'struct simple_xattrs *', initialized to NULL (zeroed by
kmem_cache_zalloc). Since kernfs_iattrs is already lazily allocated
itself, this adds a second level of lazy allocation specifically for
the xattr store.

The xattr store is allocated on first setxattr. Read paths
check for NULL and return -ENODATA or empty list.

Replaced xattr entries are freed via simple_xattr_free_rcu() to allow
concurrent RCU readers to finish.

The cleanup paths in kernfs_free_rcu() and __kernfs_new_node() error
handling conditionally free the xattr store only when allocated.

As Jan noted in [1]:

> This is a slight change in the lifetime rules because previously kernfs
> xattrs could be safely accessed only under RCU but after this change you
> have to hold inode reference *and* RCU to safely access them. I don't think
> anybody would be accessing xattrs without holding inode reference so this
> should be safe [...].

Link: https://patch.msgid.link/20260216-work-xattr-socket-v1-4-c2efa4f74cb7@kernel.org
Link:
https://lore.kernel.org/3cnmtqmakpbb2uwhenrj7kdqu3uefykiykjllgfbtpkiwhaa4s@sghkevv7jned [1]
Acked-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/kernfs/dir.c
fs/kernfs/inode.c
fs/kernfs/kernfs-internal.h