Skip to content

Commit 9531e4a

Browse files
edumazetdavem330
authored andcommitted
mptcp: annotate data-races around msk->rmem_fwd_alloc
msk->rmem_fwd_alloc can be read locklessly. Add mptcp_rmem_fwd_alloc_add(), similar to sk_forward_alloc_add(), and appropriate READ_ONCE()/WRITE_ONCE() annotations. Fixes: 6511882 ("mptcp: allocate fwd memory separately on the rx and tx path") Signed-off-by: Eric Dumazet <[email protected]> Cc: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5e6300e commit 9531e4a

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

net/mptcp/protocol.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
134134
__kfree_skb(skb);
135135
}
136136

137+
static void mptcp_rmem_fwd_alloc_add(struct sock *sk, int size)
138+
{
139+
WRITE_ONCE(mptcp_sk(sk)->rmem_fwd_alloc,
140+
mptcp_sk(sk)->rmem_fwd_alloc + size);
141+
}
142+
137143
static void mptcp_rmem_charge(struct sock *sk, int size)
138144
{
139-
mptcp_sk(sk)->rmem_fwd_alloc -= size;
145+
mptcp_rmem_fwd_alloc_add(sk, -size);
140146
}
141147

142148
static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
@@ -177,7 +183,7 @@ static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
177183
static void __mptcp_rmem_reclaim(struct sock *sk, int amount)
178184
{
179185
amount >>= PAGE_SHIFT;
180-
mptcp_sk(sk)->rmem_fwd_alloc -= amount << PAGE_SHIFT;
186+
mptcp_rmem_charge(sk, amount << PAGE_SHIFT);
181187
__sk_mem_reduce_allocated(sk, amount);
182188
}
183189

@@ -186,7 +192,7 @@ static void mptcp_rmem_uncharge(struct sock *sk, int size)
186192
struct mptcp_sock *msk = mptcp_sk(sk);
187193
int reclaimable;
188194

189-
msk->rmem_fwd_alloc += size;
195+
mptcp_rmem_fwd_alloc_add(sk, size);
190196
reclaimable = msk->rmem_fwd_alloc - sk_unused_reserved_mem(sk);
191197

192198
/* see sk_mem_uncharge() for the rationale behind the following schema */
@@ -341,7 +347,7 @@ static bool mptcp_rmem_schedule(struct sock *sk, struct sock *ssk, int size)
341347
if (!__sk_mem_raise_allocated(sk, size, amt, SK_MEM_RECV))
342348
return false;
343349

344-
msk->rmem_fwd_alloc += amount;
350+
mptcp_rmem_fwd_alloc_add(sk, amount);
345351
return true;
346352
}
347353

@@ -3258,7 +3264,7 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)
32583264
* inet_sock_destruct() will dispose it
32593265
*/
32603266
sk_forward_alloc_add(sk, msk->rmem_fwd_alloc);
3261-
msk->rmem_fwd_alloc = 0;
3267+
WRITE_ONCE(msk->rmem_fwd_alloc, 0);
32623268
mptcp_token_destroy(msk);
32633269
mptcp_pm_free_anno_list(msk);
32643270
mptcp_free_local_addr_list(msk);
@@ -3522,7 +3528,8 @@ static void mptcp_shutdown(struct sock *sk, int how)
35223528

35233529
static int mptcp_forward_alloc_get(const struct sock *sk)
35243530
{
3525-
return READ_ONCE(sk->sk_forward_alloc) + mptcp_sk(sk)->rmem_fwd_alloc;
3531+
return READ_ONCE(sk->sk_forward_alloc) +
3532+
READ_ONCE(mptcp_sk(sk)->rmem_fwd_alloc);
35263533
}
35273534

35283535
static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)

0 commit comments

Comments
 (0)