Re: [PATCH 04/14] kernfs: adapt to rhashtable-based simple_xattrs with lazy allocation
From: Christian Brauner <brauner@kernel.org>
Date: 2026-03-02 10:06:59
Also in:
linux-fsdevel, linux-mm, lkml
On Fri, Feb 27, 2026 at 04:00:37PM +0100, Jan Kara wrote:
On Mon 16-02-26 14:32:00, Christian Brauner wrote:quoted
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. Signed-off-by: Christian Brauner <brauner@kernel.org>...quoted
@@ -584,6 +582,12 @@ void kernfs_put(struct kernfs_node *kn) if (kernfs_type(kn) == KERNFS_LINK) kernfs_put(kn->symlink.target_kn); + if (kn->iattr && kn->iattr->xattrs) { + simple_xattrs_free(kn->iattr->xattrs, NULL); + kfree(kn->iattr->xattrs); + kn->iattr->xattrs = NULL; + } + spin_lock(&root->kernfs_idr_lock); idr_remove(&root->ino_idr, (u32)kernfs_ino(kn)); spin_unlock(&root->kernfs_idr_lock);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 but it would be good to mention this in the changelog.
Done.