@@ -195,15 +195,9 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = {
195195};
196196#endif /* CONFIG_BPF_JIT */
197197
198- struct mptcp_sock * bpf_mptcp_sock_from_sock (struct sock * sk )
198+ struct mptcp_sock * bpf_mptcp_sock_from_subflow (struct sock * sk )
199199{
200- if (unlikely (!sk || !sk_fullsock (sk )))
201- return NULL ;
202-
203- if (sk -> sk_protocol == IPPROTO_MPTCP )
204- return mptcp_sk (sk );
205-
206- if (sk -> sk_protocol == IPPROTO_TCP && sk_is_mptcp (sk ))
200+ if (sk && sk_fullsock (sk ) && sk -> sk_protocol == IPPROTO_TCP && sk_is_mptcp (sk ))
207201 return mptcp_sk (mptcp_subflow_ctx (sk )-> conn );
208202
209203 return NULL ;
@@ -241,24 +235,27 @@ bpf_mptcp_subflow_ctx(const struct sock *sk)
241235
242236__bpf_kfunc static int
243237bpf_iter_mptcp_subflow_new (struct bpf_iter_mptcp_subflow * it ,
244- struct mptcp_sock * msk )
238+ struct sock * sk )
245239{
246240 struct bpf_iter_mptcp_subflow_kern * kit = (void * )it ;
247- struct sock * sk = ( struct sock * ) msk ;
241+ struct mptcp_sock * msk ;
248242
249243 BUILD_BUG_ON (sizeof (struct bpf_iter_mptcp_subflow_kern ) >
250244 sizeof (struct bpf_iter_mptcp_subflow ));
251245 BUILD_BUG_ON (__alignof__(struct bpf_iter_mptcp_subflow_kern ) !=
252246 __alignof__(struct bpf_iter_mptcp_subflow ));
253247
254- kit -> msk = msk ;
255- if (!msk )
248+ if (unlikely (!sk || !sk_fullsock (sk )))
256249 return - EINVAL ;
257250
258- if (!sock_owned_by_user_nocheck (sk ) &&
259- !spin_is_locked (& sk -> sk_lock .slock ))
251+ if (sk -> sk_protocol != IPPROTO_MPTCP )
260252 return - EINVAL ;
261253
254+ msk = mptcp_sk (sk );
255+
256+ msk_owned_by_me (msk );
257+
258+ kit -> msk = msk ;
262259 kit -> pos = & msk -> conn_list ;
263260 return 0 ;
264261}
@@ -280,23 +277,6 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it)
280277{
281278}
282279
283- __bpf_kfunc static struct
284- mptcp_sock * bpf_mptcp_sock_acquire (struct mptcp_sock * msk )
285- {
286- struct sock * sk = (struct sock * )msk ;
287-
288- if (sk && refcount_inc_not_zero (& sk -> sk_refcnt ))
289- return msk ;
290- return NULL ;
291- }
292-
293- __bpf_kfunc static void bpf_mptcp_sock_release (struct mptcp_sock * msk )
294- {
295- struct sock * sk = (struct sock * )msk ;
296-
297- WARN_ON_ONCE (!sk || !refcount_dec_not_one (& sk -> sk_refcnt ));
298- }
299-
300280__bpf_kfunc struct mptcp_subflow_context *
301281bpf_mptcp_subflow_ctx_by_pos (const struct mptcp_sched_data * data , unsigned int pos )
302282{
@@ -317,8 +297,6 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
317297BTF_ID_FLAGS (func , bpf_iter_mptcp_subflow_new , KF_ITER_NEW | KF_TRUSTED_ARGS )
318298BTF_ID_FLAGS (func , bpf_iter_mptcp_subflow_next , KF_ITER_NEXT | KF_RET_NULL )
319299BTF_ID_FLAGS (func , bpf_iter_mptcp_subflow_destroy , KF_ITER_DESTROY )
320- BTF_ID_FLAGS (func , bpf_mptcp_sock_acquire , KF_ACQUIRE | KF_RET_NULL )
321- BTF_ID_FLAGS (func , bpf_mptcp_sock_release , KF_RELEASE )
322300BTF_KFUNCS_END (bpf_mptcp_common_kfunc_ids )
323301
324302static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
0 commit comments