Re: [PATCH v18 41/42] SUNRPC: relocate struct rcu_head to the first field of struct rpc_xprt

From: Jeff Layton

Date: Fri Dec 05 2025 - 04:28:06 EST


On Fri, 2025-12-05 at 16:18 +0900, Byungchul Park wrote:
> While compiling Linux kernel with DEPT on, the following error was
> observed:
>
> ./include/linux/rcupdate.h:1084:17: note: in expansion of macro
> ‘BUILD_BUG_ON’
> 1084 | BUILD_BUG_ON(offsetof(typeof(*(ptr)), rhf) >= 4096); \
> | ^~~~~~~~~~~~
> ./include/linux/rcupdate.h:1047:29: note: in expansion of macro
> 'kvfree_rcu_arg_2'
> 1047 | #define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
> | ^~~~~~~~~~~~~~~~
> net/sunrpc/xprt.c:1856:9: note: in expansion of macro 'kfree_rcu'
> 1856 | kfree_rcu(xprt, rcu);
> | ^~~~~~~~~
> CC net/kcm/kcmproc.o
> make[4]: *** [scripts/Makefile.build:203: net/sunrpc/xprt.o] Error 1
>
> Since kfree_rcu() assumes 'offset of struct rcu_head in a rcu-managed
> struct < 4096', the offest of struct rcu_head in struct rpc_xprt should
> not exceed 4096 but does, due to the debug information added by DEPT.
>
> Relocate struct rcu_head to the first field of struct rpc_xprt from an
> arbitrary location to avoid the issue and meet the assumption.
>
> Reported-by: Yunseong Kim <ysk@xxxxxxxxxxx>
> Signed-off-by: Byungchul Park <byungchul@xxxxxx>
> ---
> include/linux/sunrpc/xprt.h | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
> index f46d1fb8f71a..666e42a17a31 100644
> --- a/include/linux/sunrpc/xprt.h
> +++ b/include/linux/sunrpc/xprt.h
> @@ -211,6 +211,14 @@ enum xprt_transports {
>
> struct rpc_sysfs_xprt;
> struct rpc_xprt {
> + /*
> + * Place struct rcu_head within the first 4096 bytes of struct
> + * rpc_xprt if sizeof(struct rpc_xprt) > 4096, so that
> + * kfree_rcu() can simply work assuming that. See the comment
> + * in kfree_rcu().
> + */
> + struct rcu_head rcu;
> +
> struct kref kref; /* Reference count */
> const struct rpc_xprt_ops *ops; /* transport methods */
> unsigned int id; /* transport id */
> @@ -317,7 +325,6 @@ struct rpc_xprt {
> #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
> struct dentry *debugfs; /* debugfs directory */
> #endif
> - struct rcu_head rcu;
> const struct xprt_class *xprt_class;
> struct rpc_sysfs_xprt *xprt_sysfs;
> bool main; /*mark if this is the 1st transport */

Seems fine to me.

Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>