Skip to content

Commit c56c31a

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
mptcp: add bpf_iter_task for mptcp_sock
To make sure the mptcp_subflow bpf_iter is running in the MPTCP context. This patch adds a simplified version of tracking for it: 1. Add a 'struct task_struct *bpf_iter_task' field to struct mptcp_sock. 2. Do a WRITE_ONCE(msk->bpf_iter_task, current) before calling a MPTCP BPF hook, and WRITE_ONCE(msk->bpf_iter_task, NULL) after the hook returns. 3. In bpf_iter_mptcp_subflow_new(), check "READ_ONCE(msk->bpf_scheduler_task) == current" to confirm the correct task, return -EINVAL if it doesn't match. Also creates helpers for setting, clearing and checking that value. Suggested-by: Mat Martineau <[email protected]> Signed-off-by: Geliang Tang <[email protected]>
1 parent 1d0c702 commit c56c31a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

net/mptcp/protocol.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,7 @@ static void __mptcp_init_sock(struct sock *sk)
27262726
msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
27272727

27282728
WRITE_ONCE(msk->first, NULL);
2729+
WRITE_ONCE(msk->bpf_iter_task, NULL);
27292730
inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
27302731
WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
27312732
WRITE_ONCE(msk->allow_infinite_fallback, true);

net/mptcp/protocol.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ struct mptcp_sock {
327327
struct list_head conn_list;
328328
struct list_head rtx_queue;
329329
struct mptcp_data_frag *first_pending;
330+
struct task_struct *bpf_iter_task;
330331
struct list_head join_list;
331332
struct sock *first; /* The mptcp ops can safely dereference, using suitable
332333
* ONCE annotation, the subflow outside the socket
@@ -1291,4 +1292,19 @@ mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_re
12911292
static inline void mptcp_join_cookie_init(void) {}
12921293
#endif
12931294

1295+
static inline void mptcp_set_bpf_iter_task(struct mptcp_sock *msk)
1296+
{
1297+
WRITE_ONCE(msk->bpf_iter_task, current);
1298+
}
1299+
1300+
static inline void mptcp_clear_bpf_iter_task(struct mptcp_sock *msk)
1301+
{
1302+
WRITE_ONCE(msk->bpf_iter_task, NULL);
1303+
}
1304+
1305+
static inline struct task_struct *mptcp_get_bpf_iter_task(struct mptcp_sock *msk)
1306+
{
1307+
return READ_ONCE(msk->bpf_iter_task);
1308+
}
1309+
12941310
#endif /* __MPTCP_PROTOCOL_H */

0 commit comments

Comments
 (0)