Skip to content

Commit 61ae44e

Browse files
geliangtangintel-lab-lkp
authored andcommitted
sock: add sock_krfree_s helper
This patch adds the rcu version of sock_kfree_s() helper, named sock_krfree_s(), to free the memory using kfree_rcu_mightsleep() and adjust the socket's option memory buffer. This new helper is first used in MPTCP. Signed-off-by: Geliang Tang <[email protected]>
1 parent 00eff4a commit 61ae44e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

include/net/sock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,7 @@ void *sock_kmemdup(struct sock *sk, const void *src,
18361836
int size, gfp_t priority);
18371837
void sock_kfree_s(struct sock *sk, void *mem, int size);
18381838
void sock_kzfree_s(struct sock *sk, void *mem, int size);
1839+
void sock_krfree_s(struct sock *sk, void *mem, int size);
18391840
void sk_send_sigurg(struct sock *sk);
18401841

18411842
static inline void sock_replace_proto(struct sock *sk, struct proto *proto)

net/core/sock.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2862,29 +2862,37 @@ EXPORT_SYMBOL(sock_kmemdup);
28622862
* condition entirely.
28632863
*/
28642864
static inline void __sock_kfree_s(struct sock *sk, void *mem, int size,
2865-
const bool nullify)
2865+
const bool nullify, const bool rcu)
28662866
{
28672867
if (WARN_ON_ONCE(!mem))
28682868
return;
28692869
if (nullify)
28702870
kfree_sensitive(mem);
2871+
else if (rcu)
2872+
kfree_rcu_mightsleep(mem);
28712873
else
28722874
kfree(mem);
28732875
atomic_sub(size, &sk->sk_omem_alloc);
28742876
}
28752877

28762878
void sock_kfree_s(struct sock *sk, void *mem, int size)
28772879
{
2878-
__sock_kfree_s(sk, mem, size, false);
2880+
__sock_kfree_s(sk, mem, size, false, false);
28792881
}
28802882
EXPORT_SYMBOL(sock_kfree_s);
28812883

28822884
void sock_kzfree_s(struct sock *sk, void *mem, int size)
28832885
{
2884-
__sock_kfree_s(sk, mem, size, true);
2886+
__sock_kfree_s(sk, mem, size, true, false);
28852887
}
28862888
EXPORT_SYMBOL(sock_kzfree_s);
28872889

2890+
void sock_krfree_s(struct sock *sk, void *mem, int size)
2891+
{
2892+
__sock_kfree_s(sk, mem, size, false, true);
2893+
}
2894+
EXPORT_SYMBOL(sock_krfree_s);
2895+
28882896
/* It is almost wait_for_tcp_memory minus release_sock/lock_sock.
28892897
I think, these locks should be removed for datagram sockets.
28902898
*/

net/mptcp/pm_userspace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,10 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
337337

338338
release_sock(sk);
339339

340-
kfree_rcu_mightsleep(match);
341340
/* Adjust sk_omem_alloc like sock_kfree_s() does, to match
342341
* with allocation of this memory by sock_kmemdup()
343342
*/
344-
atomic_sub(sizeof(*match), &sk->sk_omem_alloc);
343+
sock_krfree_s(sk, match, sizeof(*match));
345344

346345
err = 0;
347346
out:

0 commit comments

Comments
 (0)