]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
Fix sock_exceed_buf_limit not being triggered in __sk_mem_raise_allocated
authorTengteng Yang <yangtengteng@bytedance.com>
Tue, 27 May 2025 03:04:19 +0000 (11:04 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 19 Jun 2025 13:32:14 +0000 (15:32 +0200)
[ Upstream commit 8542d6fac25c03b4bf36b2d762cfe60fda8491bb ]

When a process under memory pressure is not part of any cgroup and
the charged flag is false, trace_sock_exceed_buf_limit was not called
as expected.

This regression was introduced by commit 2def8ff3fdb6 ("sock:
Code cleanup on __sk_mem_raise_allocated()"). The fix changes the
default value of charged to true while preserving existing logic.

Fixes: 2def8ff3fdb6 ("sock: Code cleanup on __sk_mem_raise_allocated()")
Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Signed-off-by: Tengteng Yang <yangtengteng@bytedance.com>
Link: https://patch.msgid.link/20250527030419.67693-1-yangtengteng@bytedance.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/sock.c

index 0842dc9189bf809972bb5aa765096cce278efeee..3c5386c76d6fe47848354e8b3804ad16b36e3678 100644 (file)
@@ -3157,16 +3157,16 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
 {
        struct mem_cgroup *memcg = mem_cgroup_sockets_enabled ? sk->sk_memcg : NULL;
        struct proto *prot = sk->sk_prot;
-       bool charged = false;
+       bool charged = true;
        long allocated;
 
        sk_memory_allocated_add(sk, amt);
        allocated = sk_memory_allocated(sk);
 
        if (memcg) {
-               if (!mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge()))
+               charged = mem_cgroup_charge_skmem(memcg, amt, gfp_memcg_charge());
+               if (!charged)
                        goto suppress_allocation;
-               charged = true;
        }
 
        /* Under limit. */
@@ -3251,7 +3251,7 @@ suppress_allocation:
 
        sk_memory_allocated_sub(sk, amt);
 
-       if (charged)
+       if (memcg && charged)
                mem_cgroup_uncharge_skmem(memcg, amt);
 
        return 0;