From 07b4cc60a15582cafb0ca3691c81d247a1c1cd4e Mon Sep 17 00:00:00 2001 From: "randomizedcoder dave.seddon.ca@gmail.com" Date: Sat, 31 Oct 2026 09:15:18 -0700 Subject: [PATCH] Use mem_cgroup_from_sk in homa_rpc_alloc_server Since Linux 6.18, struct sock has an sk_memcg field only when CONFIG_MEMCG is set, so homa_rpc_alloc_server failed to compile in kernels without memory cgroups (such as x86_64 and i386 defconfig). Use mem_cgroup_from_sk, which returns NULL in that case. That function doesn't exist before 6.18, where sk_memcg is unconditional, so keep reading the field there. Co-Authored-By: Claude Opus 5.5 --- homa_rpc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homa_rpc.c b/homa_rpc.c index d129c0f3..bdbe8752 100644 --- a/homa_rpc.c +++ b/homa_rpc.c @@ -117,6 +117,7 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk, u64 id = homa_local_id(h->sender_id); struct homa_rpc_bucket *bucket; struct homa_rpc *srpc = NULL; + struct mem_cgroup *memcg; int msg_length; int err; @@ -140,8 +141,13 @@ struct homa_rpc *homa_rpc_alloc_server(struct homa_sock *hsk, } /* Initialize fields that don't require the socket lock. */ - if (hsk->sock.sk_memcg) { - struct mem_cgroup *old = set_active_memcg(hsk->sock.sk_memcg); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 18, 0) + memcg = hsk->sock.sk_memcg; +#else + memcg = mem_cgroup_from_sk(&hsk->sock); +#endif + if (memcg) { + struct mem_cgroup *old = set_active_memcg(memcg); srpc = kzalloc(sizeof(*srpc), GFP_ATOMIC | __GFP_ACCOUNT); set_active_memcg(old);