Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

xattr: add rcu_head and rhash_head to struct simple_xattr

In preparation for converting simple_xattrs from rbtree to rhashtable,
add rhash_head and rcu_head members to struct simple_xattr. The
rhashtable implementation will use rhash_head for hash table linkage
and RCU-based lockless reads, requiring that replaced or removed xattr
entries be freed via call_rcu() rather than immediately.

Add simple_xattr_free_rcu() which schedules RCU-deferred freeing of an
xattr entry. This will be used by callers of simple_xattr_set() once
they switch to the rhashtable-based xattr store.

No functional changes.

Link: https://patch.msgid.link/20260216-work-xattr-socket-v1-1-c2efa4f74cb7@kernel.org
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+27
+23
fs/xattr.c
··· 1197 1197 kvfree(xattr); 1198 1198 } 1199 1199 1200 + static void simple_xattr_rcu_free(struct rcu_head *head) 1201 + { 1202 + struct simple_xattr *xattr; 1203 + 1204 + xattr = container_of(head, struct simple_xattr, rcu); 1205 + simple_xattr_free(xattr); 1206 + } 1207 + 1208 + /** 1209 + * simple_xattr_free_rcu - free an xattr object after an RCU grace period 1210 + * @xattr: the xattr object 1211 + * 1212 + * Schedule RCU-deferred freeing of an xattr entry. This is used by 1213 + * rhashtable-based callers of simple_xattr_set() that replace or remove 1214 + * an existing entry while concurrent RCU readers may still be accessing 1215 + * it. 1216 + */ 1217 + void simple_xattr_free_rcu(struct simple_xattr *xattr) 1218 + { 1219 + if (xattr) 1220 + call_rcu(&xattr->rcu, simple_xattr_rcu_free); 1221 + } 1222 + 1200 1223 /** 1201 1224 * simple_xattr_alloc - allocate new xattr object 1202 1225 * @value: value of the xattr object
+4
include/linux/xattr.h
··· 16 16 #include <linux/types.h> 17 17 #include <linux/spinlock.h> 18 18 #include <linux/mm.h> 19 + #include <linux/rhashtable-types.h> 19 20 #include <linux/user_namespace.h> 20 21 #include <uapi/linux/xattr.h> 21 22 ··· 113 112 114 113 struct simple_xattr { 115 114 struct rb_node rb_node; 115 + struct rhash_head hash_node; 116 + struct rcu_head rcu; 116 117 char *name; 117 118 size_t size; 118 119 char value[] __counted_by(size); ··· 125 122 size_t simple_xattr_space(const char *name, size_t size); 126 123 struct simple_xattr *simple_xattr_alloc(const void *value, size_t size); 127 124 void simple_xattr_free(struct simple_xattr *xattr); 125 + void simple_xattr_free_rcu(struct simple_xattr *xattr); 128 126 int simple_xattr_get(struct simple_xattrs *xattrs, const char *name, 129 127 void *buffer, size_t size); 130 128 struct simple_xattr *simple_xattr_set(struct simple_xattrs *xattrs,