Re: [PATCH 09/14] xattr: move user limits for xattrs to generic infra
From: Darrick J. Wong
Date: Fri Feb 20 2026 - 19:03:44 EST
On Mon, Feb 16, 2026 at 02:32:05PM +0100, Christian Brauner wrote:
> Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
> ---
> fs/kernfs/inode.c | 75 ++-------------------------------------------
> fs/kernfs/kernfs-internal.h | 3 +-
> fs/xattr.c | 65 +++++++++++++++++++++++++++++++++++++++
> include/linux/kernfs.h | 2 --
> include/linux/xattr.h | 18 +++++++++++
> 5 files changed, 87 insertions(+), 76 deletions(-)
>
I know you're just moving code around and that looks ok, but:
> diff --git a/include/linux/kernfs.h b/include/linux/kernfs.h
> index b5a5f32fdfd1..d8f57f0af5e4 100644
> --- a/include/linux/kernfs.h
> +++ b/include/linux/kernfs.h
> @@ -99,8 +99,6 @@ enum kernfs_node_type {
>
> #define KERNFS_TYPE_MASK 0x000f
> #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK
> -#define KERNFS_MAX_USER_XATTRS 128
> -#define KERNFS_USER_XATTR_SIZE_LIMIT (128 << 10)
I guess this means you can't have more than 128 xattrs total, and
sum(values) must be less than 128k? The fixed limit is a little odd,
but it's all pinned kernel memory, right?
(IOWs, you haven't done anything wild ala xfile.c to make it possible to
swap that out to disk?)
--D
>
> enum kernfs_node_flag {
> KERNFS_ACTIVATED = 0x0010,
> diff --git a/include/linux/xattr.h b/include/linux/xattr.h
> index f60357d9f938..90a43a117127 100644
> --- a/include/linux/xattr.h
> +++ b/include/linux/xattr.h
> @@ -118,6 +118,20 @@ struct simple_xattr {
> char value[];
> };
>
> +#define SIMPLE_XATTR_MAX_NR 128
> +#define SIMPLE_XATTR_MAX_SIZE (128 << 10)
> +
> +struct simple_xattr_limits {
> + atomic_t nr_xattrs; /* current user.* xattr count */
> + atomic_t xattr_size; /* current total user.* value bytes */
> +};
> +
> +static inline void simple_xattr_limits_init(struct simple_xattr_limits *limits)
> +{
> + atomic_set(&limits->nr_xattrs, 0);
> + atomic_set(&limits->xattr_size, 0);
> +}
> +
> int simple_xattrs_init(struct simple_xattrs *xattrs);
> struct simple_xattrs *simple_xattrs_alloc(void);
> struct simple_xattrs *simple_xattrs_lazy_alloc(struct simple_xattrs **xattrsp,
> @@ -132,6 +146,10 @@ int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
> struct simple_xattr *simple_xattr_set(struct simple_xattrs *xattrs,
> const char *name, const void *value,
> size_t size, int flags);
> +int simple_xattr_set_limited(struct simple_xattrs *xattrs,
> + struct simple_xattr_limits *limits,
> + const char *name, const void *value,
> + size_t size, int flags);
> ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,
> char *buffer, size_t size);
> int simple_xattr_add(struct simple_xattrs *xattrs,
>
> --
> 2.47.3
>
>