From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35DF030171C for ; Thu, 23 Apr 2026 06:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926003; cv=none; b=PBynYcHnsOElfTA8F6c0SgHfrFjM/mgC6UGbdmT+gRtTXo2oAOIvbkFjJtwioeGjlHizTO2UCRf6jcpAghY2BmYFPO0raeaUER7F/XM9y9lHkIW/ZMe5XT0zWnK+1CHz5K3r/sNmRxwgQEztEusmESNOlbxd9HVn1a2h8KbOlQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926003; c=relaxed/simple; bh=3u9/3dvh6cvM/AUfPKvbb9xFdL6jcX0UBH9JwUxiCpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHpOyFJjuklPOzP+Nq7WP9WBXsWhkekWYd/fq82fBEJY6XRBm9ntLAAvyzj3QievyDJNDFXpBBPUHOEqGO9hk0/tKJ5eEVYex0e2oy9/Pa8D8UQc/xcutHC/rU1QibZnicKFbyUVVT37TwZbupmncSd1QVdxodd2FTLpYOnH7HM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YyH+pO3b; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YyH+pO3b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 949C2C2BCAF; Thu, 23 Apr 2026 06:33:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926003; bh=3u9/3dvh6cvM/AUfPKvbb9xFdL6jcX0UBH9JwUxiCpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YyH+pO3bKsr9rcF5ymaUr4kETuKkRoU+t05KYVtCcSp3oRTqEuBDOyUo7CucgszU8 4wv8qf3GCag5aIXvD4JBOcTswfy9c17RKJLjf+aF8sW+NIntS8n5y6LRVBICUiPmEn 5NP36d3K3U1784tY8gExUhFtZRwbJG+4xf+z6sop/nLQyRet+7h4dd/X+2msTCeL2z akILI2snG5pTQm+dZsw1882uL9lUxQLt3AYl170r5wqZnGhrPyL6ODiDkObrWzO81b MZuvtekUq/iPmN33YrTB9bmrmGdZTPjmubUp8TAe4BZg1r2ncJskErUQR9L0wWWGj7 8KqJM6tUm/7nQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 01/16] tls: add per-protocol cache to support mptcp Date: Thu, 23 Apr 2026 14:32:54 +0800 Message-ID: <748900d9e3cd4711bf19e5f7438c9be62af4eb39.1776924681.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The TLS ULP uses a single global array to cache base protocol operations. When MPTCP sockets enable TLS, they overwrite this global cache with mptcp_prot, causing active TCP TLS sockets to use MPTCP-specific ops. This leads to type confusion and kernel panics. Fix by replacing the global cache with a per-protocol linked list. Each protocol (TCP, MPTCP, etc.) now has its own cached operations, stored in struct tls_proto and referenced from tls_context. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- include/net/tls.h | 16 ++++++ include/net/tls_toe.h | 3 +- net/tls/tls.h | 3 +- net/tls/tls_main.c | 126 ++++++++++++++++++++++++++++-------------- net/tls/tls_toe.c | 5 +- 5 files changed, 106 insertions(+), 47 deletions(-) diff --git a/include/net/tls.h b/include/net/tls.h index ebd2550280ae..0551f294800b 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -220,6 +220,20 @@ struct tls_prot_info { u16 tail_size; }; =20 +enum { + TLSV4, + TLSV6, + TLS_NUM_PROTS, +}; + +struct tls_proto { + refcount_t refcnt; + struct list_head list; + const struct proto *prot; + struct proto prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; + struct proto_ops proto_ops[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; +}; + struct tls_context { /* read-only cache line */ struct tls_prot_info prot_info; @@ -257,6 +271,8 @@ struct tls_context { struct proto *sk_proto; struct sock *sk; =20 + struct tls_proto *proto; + void (*sk_destruct)(struct sock *sk); =20 union tls_crypto_context crypto_send; diff --git a/include/net/tls_toe.h b/include/net/tls_toe.h index b3aa7593ce2c..b73029364b2c 100644 --- a/include/net/tls_toe.h +++ b/include/net/tls_toe.h @@ -69,7 +69,8 @@ struct tls_toe_device { struct kref kref; }; =20 -int tls_toe_bypass(struct sock *sk); +int tls_toe_bypass(struct sock *sk, + struct tls_proto *proto); int tls_toe_hash(struct sock *sk); void tls_toe_unhash(struct sock *sk); =20 diff --git a/net/tls/tls.h b/net/tls/tls.h index e8f81a006520..c9e839642c31 100644 --- a/net/tls/tls.h +++ b/net/tls/tls.h @@ -136,7 +136,8 @@ struct tls_rec { int __net_init tls_proc_init(struct net *net); void __net_exit tls_proc_fini(struct net *net); =20 -struct tls_context *tls_ctx_create(struct sock *sk); +struct tls_context *tls_ctx_create(struct sock *sk, + struct tls_proto *proto); void tls_ctx_free(struct sock *sk, struct tls_context *ctx); void update_sk_prot(struct sock *sk, struct tls_context *ctx); =20 diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index fd39acf41a61..dad07f5e4541 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -52,12 +52,6 @@ MODULE_DESCRIPTION("Transport Layer Security Support"); MODULE_LICENSE("Dual BSD/GPL"); MODULE_ALIAS_TCP_ULP("tls"); =20 -enum { - TLSV4, - TLSV6, - TLS_NUM_PROTS, -}; - #define CHECK_CIPHER_DESC(cipher,ci) \ static_assert(cipher ## _IV_SIZE <=3D TLS_MAX_IV_SIZE); \ static_assert(cipher ## _SALT_SIZE <=3D TLS_MAX_SALT_SIZE); \ @@ -119,23 +113,54 @@ CHECK_CIPHER_DESC(TLS_CIPHER_SM4_CCM, tls12_crypto_in= fo_sm4_ccm); CHECK_CIPHER_DESC(TLS_CIPHER_ARIA_GCM_128, tls12_crypto_info_aria_gcm_128); CHECK_CIPHER_DESC(TLS_CIPHER_ARIA_GCM_256, tls12_crypto_info_aria_gcm_256); =20 -static const struct proto *saved_tcpv6_prot; -static DEFINE_MUTEX(tcpv6_prot_mutex); -static const struct proto *saved_tcpv4_prot; -static DEFINE_MUTEX(tcpv4_prot_mutex); -static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFI= G]; -static struct proto_ops tls_proto_ops[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_N= UM_CONFIG]; +static LIST_HEAD(tls_proto_list); +static DEFINE_MUTEX(tls_proto_mutex); static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], const struct proto *base); =20 +static struct tls_proto *tls_proto_find(const struct proto *prot) +{ + struct tls_proto *proto, *ret =3D NULL; + + rcu_read_lock(); + list_for_each_entry_rcu(proto, &tls_proto_list, list) { + if (proto->prot =3D=3D prot) { + if (refcount_inc_not_zero(&proto->refcnt)) + ret =3D proto; + break; + } + } + rcu_read_unlock(); + return ret; +} + +static void tls_proto_cleanup(void) +{ + struct tls_proto *prot, *tmp; + + mutex_lock(&tls_proto_mutex); + list_for_each_entry_safe(prot, tmp, &tls_proto_list, list) { + if (refcount_dec_and_test(&prot->refcnt)) { + list_del_rcu(&prot->list); + synchronize_rcu(); + kfree(prot); + } + } + mutex_unlock(&tls_proto_mutex); +} + void update_sk_prot(struct sock *sk, struct tls_context *ctx) { int ip_ver =3D sk->sk_family =3D=3D AF_INET6 ? TLSV6 : TLSV4; + struct tls_proto *proto =3D ctx->proto; + + if (!proto) + return; =20 WRITE_ONCE(sk->sk_prot, - &tls_prots[ip_ver][ctx->tx_conf][ctx->rx_conf]); + &proto->prots[ip_ver][ctx->tx_conf][ctx->rx_conf]); WRITE_ONCE(sk->sk_socket->ops, - &tls_proto_ops[ip_ver][ctx->tx_conf][ctx->rx_conf]); + &proto->proto_ops[ip_ver][ctx->tx_conf][ctx->rx_conf]); } =20 int wait_on_pending_writer(struct sock *sk, long *timeo) @@ -327,6 +352,14 @@ void tls_ctx_free(struct sock *sk, struct tls_context = *ctx) if (!ctx) return; =20 + if (ctx->proto) { + if (refcount_dec_and_test(&ctx->proto->refcnt)) { + list_del_rcu(&ctx->proto->list); + synchronize_rcu(); + kfree(ctx->proto); + } + } + memzero_explicit(&ctx->crypto_send, sizeof(ctx->crypto_send)); memzero_explicit(&ctx->crypto_recv, sizeof(ctx->crypto_recv)); mutex_destroy(&ctx->tx_lock); @@ -910,7 +943,8 @@ static int tls_disconnect(struct sock *sk, int flags) return -EOPNOTSUPP; } =20 -struct tls_context *tls_ctx_create(struct sock *sk) +struct tls_context *tls_ctx_create(struct sock *sk, + struct tls_proto *proto) { struct inet_connection_sock *icsk =3D inet_csk(sk); struct tls_context *ctx; @@ -921,6 +955,7 @@ struct tls_context *tls_ctx_create(struct sock *sk) =20 mutex_init(&ctx->tx_lock); ctx->sk_proto =3D READ_ONCE(sk->sk_prot); + ctx->proto =3D proto; ctx->sk =3D sk; /* Release semantic of rcu_assign_pointer() ensures that * ctx->sk_proto is visible before changing sk->sk_prot in @@ -968,35 +1003,31 @@ static void build_proto_ops(struct proto_ops ops[TLS= _NUM_CONFIG][TLS_NUM_CONFIG] #endif } =20 -static void tls_build_proto(struct sock *sk) +static struct tls_proto *tls_build_proto(struct sock *sk) { int ip_ver =3D sk->sk_family =3D=3D AF_INET6 ? TLSV6 : TLSV4; struct proto *prot =3D READ_ONCE(sk->sk_prot); + struct tls_proto *proto; =20 - /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */ - if (ip_ver =3D=3D TLSV6 && - unlikely(prot !=3D smp_load_acquire(&saved_tcpv6_prot))) { - mutex_lock(&tcpv6_prot_mutex); - if (likely(prot !=3D saved_tcpv6_prot)) { - build_protos(tls_prots[TLSV6], prot); - build_proto_ops(tls_proto_ops[TLSV6], - sk->sk_socket->ops); - smp_store_release(&saved_tcpv6_prot, prot); - } - mutex_unlock(&tcpv6_prot_mutex); - } + mutex_lock(&tls_proto_mutex); + proto =3D tls_proto_find(prot); + if (proto) + goto out; =20 - if (ip_ver =3D=3D TLSV4 && - unlikely(prot !=3D smp_load_acquire(&saved_tcpv4_prot))) { - mutex_lock(&tcpv4_prot_mutex); - if (likely(prot !=3D saved_tcpv4_prot)) { - build_protos(tls_prots[TLSV4], prot); - build_proto_ops(tls_proto_ops[TLSV4], - sk->sk_socket->ops); - smp_store_release(&saved_tcpv4_prot, prot); - } - mutex_unlock(&tcpv4_prot_mutex); - } + proto =3D kzalloc(sizeof(*proto), GFP_KERNEL); + if (!proto) + goto out; + + proto->prot =3D prot; + refcount_set(&proto->refcnt, 2); + build_protos(proto->prots[ip_ver], prot); + build_proto_ops(proto->proto_ops[ip_ver], + sk->sk_socket->ops); + list_add_rcu(&proto->list, &tls_proto_list); + +out: + mutex_unlock(&tls_proto_mutex); + return proto; } =20 static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], @@ -1046,14 +1077,19 @@ static void build_protos(struct proto prot[TLS_NUM_= CONFIG][TLS_NUM_CONFIG], =20 static int tls_init(struct sock *sk) { + struct tls_proto *proto; struct tls_context *ctx; int rc =3D 0; =20 - tls_build_proto(sk); + proto =3D tls_build_proto(sk); + if (!proto) + return -ENOMEM; =20 #ifdef CONFIG_TLS_TOE - if (tls_toe_bypass(sk)) + if (tls_toe_bypass(sk, proto)) { + refcount_dec(&proto->refcnt); return 0; + } #endif =20 /* The TLS ulp is currently supported only for TCP sockets @@ -1062,13 +1098,16 @@ static int tls_init(struct sock *sk) * to modify the accept implementation to clone rather then * share the ulp context. */ - if (sk->sk_state !=3D TCP_ESTABLISHED) + if (sk->sk_state !=3D TCP_ESTABLISHED) { + refcount_dec(&proto->refcnt); return -ENOTCONN; + } =20 /* allocate tls context */ write_lock_bh(&sk->sk_callback_lock); - ctx =3D tls_ctx_create(sk); + ctx =3D tls_ctx_create(sk, proto); if (!ctx) { + refcount_dec(&proto->refcnt); rc =3D -ENOMEM; goto out; } @@ -1264,6 +1303,7 @@ static int __init tls_register(void) =20 static void __exit tls_unregister(void) { + tls_proto_cleanup(); tcp_unregister_ulp(&tcp_tls_ulp_ops); tls_strp_dev_exit(); tls_device_cleanup(); diff --git a/net/tls/tls_toe.c b/net/tls/tls_toe.c index 825669e1ab47..3c63f9b4c8af 100644 --- a/net/tls/tls_toe.c +++ b/net/tls/tls_toe.c @@ -54,7 +54,8 @@ static void tls_toe_sk_destruct(struct sock *sk) tls_ctx_free(sk, ctx); } =20 -int tls_toe_bypass(struct sock *sk) +int tls_toe_bypass(struct sock *sk, + struct tls_proto *proto) { struct tls_toe_device *dev; struct tls_context *ctx; @@ -63,7 +64,7 @@ int tls_toe_bypass(struct sock *sk) spin_lock_bh(&device_spinlock); list_for_each_entry(dev, &device_list, dev_list) { if (dev->feature && dev->feature(dev)) { - ctx =3D tls_ctx_create(sk); + ctx =3D tls_ctx_create(sk, proto); if (!ctx) goto out; =20 --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D53F1DC9B5 for ; Thu, 23 Apr 2026 06:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926005; cv=none; b=QBa8iJqoyUomiLC8Cs1F4AE1vM5L6lKVNyQcRn3LlXMBUXArgKcclEtmAiMYafnIK08zlVAZwrjNDHmxxQ0ikybCLmsqptZJQZe32Wl//ET+l1ErcNy9hG1RvP7MkjEHys5TxEVGAKpxqRidIGwiZzRARkgSurEziVIbKRfjT24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926005; c=relaxed/simple; bh=/O6QlbSkTSJjtvbkPwAGD3BhvPBlY68ni6Rluy7yOzs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RVrwOCaxESjnFkMySLxM2M35uHx2ueLEkSvfNWzo7wSNA7VRRbsGg3MyOFfDMifD9hafqvjqsKZoMf5AIyj10TTPnrU4zwFa9NNW0N7cBf0VojkpWADn+L8j1GPGC9aTYkpChLN8UDCKxzOrEIA44ivoYCmz8WgXAtQwQs4ksnM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bp5yb73W; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bp5yb73W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0BE7C2BCB2; Thu, 23 Apr 2026 06:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926004; bh=/O6QlbSkTSJjtvbkPwAGD3BhvPBlY68ni6Rluy7yOzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bp5yb73WhpPHQh7jhSj/rsOYWDxxRpyGMawyAAVou4t5nNi+H7/patS3XMvXDPRUc tkAQDVa/3J65kPeyMkk+g46eyFFLzFIbsBFBIH5WYX5dZc886uHiI5q1a6j+FyiVrz 5qGahs4ClhZCzHeO+CYLyibgiyM9MspLkzeOmUq3HkC0tvuqWn9PS0tJk5vhrO38WS AiKPMyCdGvEO5DmDLtdG1erF92roKEXgapfEZvWZadoGNlCaG5o3wfaCl8/BiT0oFu WxkbIC0o9qv9Syr539jfRYz9fbdhyw266/73Ire4n9QovI4plMJDSerqnGp19hjUrM FIOiU2RrHUIFg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 02/16] tls: introduce struct tls_prot_ops Date: Thu, 23 Apr 2026 14:32:55 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang To extend MPTCP support based on TCP TLS, a tls_prot_ops structure has been introduced for TLS, encapsulating TCP-specific helpers within this structure. Add registering, validating and finding functions for this structure to add, validate and find a tls_prot_ops on the global list tls_prot_ops_list. Register TCP-specific structure tls_tcp_ops in tls_init(). Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- include/net/tls.h | 19 +++++++++ net/tls/tls_main.c | 102 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/include/net/tls.h b/include/net/tls.h index 0551f294800b..0865932d8cc7 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -220,6 +220,25 @@ struct tls_prot_info { u16 tail_size; }; =20 +struct tls_prot_ops { + int protocol; + struct module *owner; + struct list_head list; + + int (*inq)(struct sock *sk); + int (*sendmsg_locked)(struct sock *sk, struct msghdr *msg, size_t size); + struct sk_buff *(*recv_skb)(struct sock *sk, u32 *off); + bool (*lock_is_held)(struct sock *sk); + int (*read_sock)(struct sock *sk, read_descriptor_t *desc, + sk_read_actor_t recv_actor); + void (*read_done)(struct sock *sk, size_t len); + u32 (*get_skb_seq)(struct sk_buff *skb); + __poll_t (*poll)(struct file *file, struct socket *sock, + struct poll_table_struct *wait); + bool (*epollin_ready)(const struct sock *sk); + void (*check_app_limited)(struct sock *sk); +}; + enum { TLSV4, TLSV6, diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index dad07f5e4541..1ee891405cde 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -115,6 +115,8 @@ CHECK_CIPHER_DESC(TLS_CIPHER_ARIA_GCM_256, tls12_crypto= _info_aria_gcm_256); =20 static LIST_HEAD(tls_proto_list); static DEFINE_MUTEX(tls_proto_mutex); +static LIST_HEAD(tls_prot_ops_list); +static DEFINE_SPINLOCK(tls_prot_ops_lock); static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], const struct proto *base); =20 @@ -149,6 +151,18 @@ static void tls_proto_cleanup(void) mutex_unlock(&tls_proto_mutex); } =20 +static struct tls_prot_ops *tls_prot_ops_find(int protocol) +{ + struct tls_prot_ops *ops; + + list_for_each_entry_rcu(ops, &tls_prot_ops_list, list) { + if (ops->protocol =3D=3D protocol) + return ops; + } + + return NULL; +} + void update_sk_prot(struct sock *sk, struct tls_context *ctx) { int ip_ver =3D sk->sk_family =3D=3D AF_INET6 ? TLSV6 : TLSV4; @@ -1275,6 +1289,87 @@ static struct tcp_ulp_ops tcp_tls_ulp_ops __read_mos= tly =3D { .get_info_size =3D tls_get_info_size, }; =20 +static int tls_validate_prot_ops(const struct tls_prot_ops *ops) +{ + if (!ops->inq || !ops->sendmsg_locked || + !ops->recv_skb || !ops->lock_is_held || + !ops->read_sock || !ops->read_done || + !ops->get_skb_seq || + !ops->poll || !ops->epollin_ready || + !ops->check_app_limited) { + pr_err("%d does not implement required ops\n", ops->protocol); + return -EINVAL; + } + + return 0; +} + +static int tls_register_prot_ops(struct tls_prot_ops *ops) +{ + int ret; + + ret =3D tls_validate_prot_ops(ops); + if (ret) + return ret; + + spin_lock(&tls_prot_ops_lock); + rcu_read_lock(); + if (tls_prot_ops_find(ops->protocol)) { + rcu_read_unlock(); + spin_unlock(&tls_prot_ops_lock); + return -EEXIST; + } + rcu_read_unlock(); + list_add_tail_rcu(&ops->list, &tls_prot_ops_list); + spin_unlock(&tls_prot_ops_lock); + + pr_debug("tls_prot_ops %d registered\n", ops->protocol); + return 0; +} + +static void tls_unregister_prot_ops(struct tls_prot_ops *ops) +{ + spin_lock(&tls_prot_ops_lock); + list_del_rcu(&ops->list); + synchronize_rcu(); + spin_unlock(&tls_prot_ops_lock); +} + +static struct sk_buff *tls_tcp_recv_skb(struct sock *sk, u32 *off) +{ + return tcp_recv_skb(sk, tcp_sk(sk)->copied_seq, off); +} + +static bool tls_tcp_lock_is_held(struct sock *sk) +{ + return sock_owned_by_user_nocheck(sk); +} + +static u32 tls_tcp_get_skb_seq(struct sk_buff *skb) +{ + return TCP_SKB_CB(skb)->seq; +} + +static bool tls_tcp_epollin_ready(const struct sock *sk) +{ + return tcp_epollin_ready(sk, INT_MAX); +} + +static struct tls_prot_ops tls_tcp_ops =3D { + .protocol =3D IPPROTO_TCP, + .owner =3D THIS_MODULE, + .inq =3D tcp_inq, + .sendmsg_locked =3D tcp_sendmsg_locked, + .recv_skb =3D tls_tcp_recv_skb, + .lock_is_held =3D tls_tcp_lock_is_held, + .read_sock =3D tcp_read_sock, + .read_done =3D tcp_read_done, + .get_skb_seq =3D tls_tcp_get_skb_seq, + .poll =3D tcp_poll, + .epollin_ready =3D tls_tcp_epollin_ready, + .check_app_limited =3D tcp_rate_check_app_limited, +}; + static int __init tls_register(void) { int err; @@ -1291,9 +1386,15 @@ static int __init tls_register(void) if (err) goto err_strp; =20 + err =3D tls_register_prot_ops(&tls_tcp_ops); + if (err) + goto err_dev; + tcp_register_ulp(&tcp_tls_ulp_ops); =20 return 0; +err_dev: + tls_device_cleanup(); err_strp: tls_strp_dev_exit(); err_pernet: @@ -1304,6 +1405,7 @@ static int __init tls_register(void) static void __exit tls_unregister(void) { tls_proto_cleanup(); + tls_unregister_prot_ops(&tls_tcp_ops); tcp_unregister_ulp(&tcp_tls_ulp_ops); tls_strp_dev_exit(); tls_device_cleanup(); --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17F101DC9B5 for ; Thu, 23 Apr 2026 06:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926007; cv=none; b=dWCn5cGpiOw3uDeJJEW30dTMA6+Tywf9TP073LHhKlB9LcZk3IG5xUJRkUewkbtQ/Pdrh0B0Sg2EwiNS2JB2EgGm80xX/t84AcZStsjeUuo29OdZ27sYHoPm9wX7Iq81w9Gph9YdiSV0aDytdpJrwxH+xwvP+o12vyoaU+UxAbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926007; c=relaxed/simple; bh=6PF98KCtOvGmgw3ysWDZqbAt+r1mE72fyjV7TZc/gqo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FnW2QbLKeRjiQzn2ED0t88ZDNBaBlF1T/L3yjURRJV+qrLwq6StnV20zCBS4Dcg8iA0eX15jqjdPEUFa7jSKfO+AbgHiKlx2/au72/9kHqn1HGAfyIDVx2TylQv0q4TYJUiOUtQzwfzyz+d7bmS3KsI3W9y3MPf52dDhEasV4cc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cjmWxxP/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cjmWxxP/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7940FC2BCB2; Thu, 23 Apr 2026 06:33:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926006; bh=6PF98KCtOvGmgw3ysWDZqbAt+r1mE72fyjV7TZc/gqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjmWxxP/fOIZNIadhU+zyg6DAKvCycw+H1PuEqE8zXraUPSRhY4sOln7WgrfjKL8D NCbqSyzqLVwkB27KbujJwfmVNbqNJeI+VhL+1AzmA7tw09bDQlldE3VtjMdk2LhM62 VKYbEG36IC7sdF02PrEGv9SnrOzVBhtqlkTsk04VV6p+sPSvENzjkkkKoBsNUqwSYl wWGDDQdHEP9N1uGSDI/eywDolmRvrWQAZyYRqn1ANvmvkCS8wzNcIMDHxgylbUiZPp Q2JmKObQQGf+hrAALDyjtngvK+JkWO4vYd066slP5d4s/NW/eHF4jCY5YN4sDrPiht /aaQIcTjD0shA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 03/16] tls: add tls_prot_ops pointer to tls_proto Date: Thu, 23 Apr 2026 14:32:56 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang A pointer to struct tls_prot_ops, named 'ops', has been added to struct tls_proto. In tls_build_proto(), proto->ops is assigned either 'tls_mptcp_ops' or 'tls_tcp_ops' based on the socket protocol. Fix module reference counting bug where each socket release called module_put() without matching get for existing tls_proto. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- include/net/tls.h | 1 + net/tls/tls_main.c | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/include/net/tls.h b/include/net/tls.h index 0865932d8cc7..ee24f9d24324 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -249,6 +249,7 @@ struct tls_proto { refcount_t refcnt; struct list_head list; const struct proto *prot; + const struct tls_prot_ops *ops; struct proto prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; struct proto_ops proto_ops[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; }; diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 1ee891405cde..68308a42899b 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -145,6 +145,7 @@ static void tls_proto_cleanup(void) if (refcount_dec_and_test(&prot->refcnt)) { list_del_rcu(&prot->list); synchronize_rcu(); + module_put(prot->ops->owner); kfree(prot); } } @@ -367,9 +368,11 @@ void tls_ctx_free(struct sock *sk, struct tls_context = *ctx) return; =20 if (ctx->proto) { + module_put(ctx->proto->ops->owner); if (refcount_dec_and_test(&ctx->proto->refcnt)) { list_del_rcu(&ctx->proto->list); synchronize_rcu(); + module_put(ctx->proto->ops->owner); kfree(ctx->proto); } } @@ -1021,6 +1024,7 @@ static struct tls_proto *tls_build_proto(struct sock = *sk) { int ip_ver =3D sk->sk_family =3D=3D AF_INET6 ? TLSV6 : TLSV4; struct proto *prot =3D READ_ONCE(sk->sk_prot); + struct tls_prot_ops *ops; struct tls_proto *proto; =20 mutex_lock(&tls_proto_mutex); @@ -1028,11 +1032,22 @@ static struct tls_proto *tls_build_proto(struct soc= k *sk) if (proto) goto out; =20 + rcu_read_lock(); + ops =3D tls_prot_ops_find(sk->sk_protocol); + if (!ops || !try_module_get(ops->owner)) { + rcu_read_unlock(); + goto out; + } + rcu_read_unlock(); + proto =3D kzalloc(sizeof(*proto), GFP_KERNEL); - if (!proto) + if (!proto) { + module_put(ops->owner); goto out; + } =20 proto->prot =3D prot; + proto->ops =3D ops; refcount_set(&proto->refcnt, 2); build_protos(proto->prots[ip_ver], prot); build_proto_ops(proto->proto_ops[ip_ver], @@ -1099,9 +1114,15 @@ static int tls_init(struct sock *sk) if (!proto) return -ENOMEM; =20 + if (!try_module_get(proto->ops->owner)) { + refcount_dec(&proto->refcnt); + return -ENOENT; + } + #ifdef CONFIG_TLS_TOE if (tls_toe_bypass(sk, proto)) { refcount_dec(&proto->refcnt); + module_put(proto->ops->owner); return 0; } #endif @@ -1114,6 +1135,7 @@ static int tls_init(struct sock *sk) */ if (sk->sk_state !=3D TCP_ESTABLISHED) { refcount_dec(&proto->refcnt); + module_put(proto->ops->owner); return -ENOTCONN; } =20 @@ -1122,6 +1144,7 @@ static int tls_init(struct sock *sk) ctx =3D tls_ctx_create(sk, proto); if (!ctx) { refcount_dec(&proto->refcnt); + module_put(proto->ops->owner); rc =3D -ENOMEM; goto out; } --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 017211DC9B5 for ; Thu, 23 Apr 2026 06:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926009; cv=none; b=NUsIPNGur9FV+7BvSNR8UWepPd203VBgXoDVfb/z5lHfDnYGLaaVnne3cppKyqpmwFJM4oM0NO++hD14qayC62h4zq5lAl41l39zFWPzwxY/ACbdyUjSRMxijzbxW0lAEPW5AvIGKHbMmfGkqNqQWgz7d3pESE4v5ayJ9n3Nljk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926009; c=relaxed/simple; bh=XBl7QhZuYO+GloVqdLIVLDocOg/voRz7QXEe2A/8g1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nFGxBB7CEE3Uu9/Y1f0dS++SoCcsEhvM52mfyh5t8h7aNyDJ4ZTu0kxyBRog0G76V8YioMcRo4Ed1QbE38z9Tcyokuh/OT/7S+HVfJN4IT6rqsdTMucS1rRZBttH2m5uhJPcCosMG0Fy72AGmkVtWQrjC9TAiVuZHo7VcY27JDM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jEm5xaHO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jEm5xaHO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BA77C2BCB2; Thu, 23 Apr 2026 06:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926008; bh=XBl7QhZuYO+GloVqdLIVLDocOg/voRz7QXEe2A/8g1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jEm5xaHO+/GxuV93LWD6OEPwhlFWMnu/HHFRKpx3XQq8FUEST90Zy0hc+uIZayonJ dn6f/K5HAh+E8GmseIjVO9IJ3qukWk/Z7VYR050cNGzMOQqW4ebpNZ+SrUQ29VRio1 wK4eGQOfog8/YGvn0HQMbXSvaNoajGjeKdF4KAXytA/3eRaSRbvN//wHMDZwHsu+vX GVrMB5LOfpKZV0lu57UvZ9uJtW+tMJCThxS3bYKNwLgffSc0Q5Hztkws1F1rqD6CZ+ CFIRP+5fbtPRwKbXySy33lKS/2CH4KtPsPkJxS+HsA+lgnYlLUroCe1PG16jExJt1T 33LkAm2b+f3BA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 04/16] tls: replace direct protocol calls with tls_proto->ops Date: Thu, 23 Apr 2026 14:32:57 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The places originally calling TLS-specific helpers have now been modified to indirectly invoke them via 'ops' pointer in tls_proto. Make TLS code protocol-agnostic. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- net/tls/tls_main.c | 10 ++++++---- net/tls/tls_strp.c | 33 ++++++++++++++++++++++----------- net/tls/tls_sw.c | 7 +++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 68308a42899b..5cb344ae2721 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -228,13 +228,13 @@ int tls_push_sg(struct sock *sk, ctx->splicing_pages =3D true; while (1) { /* is sending application-limited? */ - tcp_rate_check_app_limited(sk); + ctx->proto->ops->check_app_limited(sk); p =3D sg_page(sg); retry: bvec_set_page(&bvec, p, size, offset); iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size); =20 - ret =3D tcp_sendmsg_locked(sk, &msg, size); + ret =3D ctx->proto->ops->sendmsg_locked(sk, &msg, size); =20 if (ret !=3D size) { if (ret > 0) { @@ -459,14 +459,16 @@ static __poll_t tls_sk_poll(struct file *file, struct= socket *sock, u8 shutdown; int state; =20 - mask =3D tcp_poll(file, sock, wait); + tls_ctx =3D tls_get_ctx(sk); + if (!tls_ctx || !tls_ctx->proto || !tls_ctx->proto->ops) + return 0; + mask =3D tls_ctx->proto->ops->poll(file, sock, wait); =20 state =3D inet_sk_state_load(sk); shutdown =3D READ_ONCE(sk->sk_shutdown); if (unlikely(state !=3D TCP_ESTABLISHED || shutdown & RCV_SHUTDOWN)) return mask; =20 - tls_ctx =3D tls_get_ctx(sk); ctx =3D tls_sw_ctx_rx(tls_ctx); psock =3D sk_psock_get(sk); =20 diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c index 98e12f0ff57e..94407b639820 100644 --- a/net/tls/tls_strp.c +++ b/net/tls/tls_strp.c @@ -120,6 +120,7 @@ struct sk_buff *tls_strp_msg_detach(struct tls_sw_conte= xt_rx *ctx) int tls_strp_msg_cow(struct tls_sw_context_rx *ctx) { struct tls_strparser *strp =3D &ctx->strp; + struct tls_context *tls_ctx; struct sk_buff *skb; =20 if (strp->copy_mode) @@ -132,7 +133,8 @@ int tls_strp_msg_cow(struct tls_sw_context_rx *ctx) tls_strp_anchor_free(strp); strp->anchor =3D skb; =20 - tcp_read_done(strp->sk, strp->stm.full_len); + tls_ctx =3D tls_get_ctx(strp->sk); + tls_ctx->proto->ops->read_done(strp->sk, strp->stm.full_len); strp->copy_mode =3D 1; =20 return 0; @@ -376,6 +378,7 @@ static int tls_strp_copyin(read_descriptor_t *desc, str= uct sk_buff *in_skb, =20 static int tls_strp_read_copyin(struct tls_strparser *strp) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); read_descriptor_t desc; =20 desc.arg.data =3D strp; @@ -383,13 +386,14 @@ static int tls_strp_read_copyin(struct tls_strparser = *strp) desc.count =3D 1; /* give more than one skb per call */ =20 /* sk should be locked here, so okay to do read_sock */ - tcp_read_sock(strp->sk, &desc, tls_strp_copyin); + ctx->proto->ops->read_sock(strp->sk, &desc, tls_strp_copyin); =20 return desc.error; } =20 static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); struct skb_shared_info *shinfo; struct page *page; int need_spc, len; @@ -398,7 +402,7 @@ static int tls_strp_read_copy(struct tls_strparser *str= p, bool qshort) * to read the data out. Otherwise the connection will stall. * Without pressure threshold of INT_MAX will never be ready. */ - if (likely(qshort && !tcp_epollin_ready(strp->sk, INT_MAX))) + if (likely(qshort && !ctx->proto->ops->epollin_ready(strp->sk))) return 0; =20 shinfo =3D skb_shinfo(strp->anchor); @@ -434,12 +438,13 @@ static int tls_strp_read_copy(struct tls_strparser *s= trp, bool qshort) static bool tls_strp_check_queue_ok(struct tls_strparser *strp) { unsigned int len =3D strp->stm.offset + strp->stm.full_len; + struct tls_context *ctx =3D tls_get_ctx(strp->sk); struct sk_buff *first, *skb; u32 seq; =20 first =3D skb_shinfo(strp->anchor)->frag_list; skb =3D first; - seq =3D TCP_SKB_CB(first)->seq; + seq =3D ctx->proto->ops->get_skb_seq(first); =20 /* Make sure there's no duplicate data in the queue, * and the decrypted status matches. @@ -449,7 +454,7 @@ static bool tls_strp_check_queue_ok(struct tls_strparse= r *strp) len -=3D skb->len; skb =3D skb->next; =20 - if (TCP_SKB_CB(skb)->seq !=3D seq) + if (ctx->proto->ops->get_skb_seq(skb) !=3D seq) return false; if (skb_cmp_decrypted(first, skb)) return false; @@ -460,11 +465,11 @@ static bool tls_strp_check_queue_ok(struct tls_strpar= ser *strp) =20 static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, in= t len) { - struct tcp_sock *tp =3D tcp_sk(strp->sk); + struct tls_context *ctx =3D tls_get_ctx(strp->sk); struct sk_buff *first; u32 offset; =20 - first =3D tcp_recv_skb(strp->sk, tp->copied_seq, &offset); + first =3D ctx->proto->ops->recv_skb(strp->sk, &offset); if (WARN_ON_ONCE(!first)) return; =20 @@ -483,6 +488,7 @@ static void tls_strp_load_anchor_with_queue(struct tls_= strparser *strp, int len) =20 bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); struct strp_msg *rxm; struct tls_msg *tlm; =20 @@ -490,7 +496,7 @@ bool tls_strp_msg_load(struct tls_strparser *strp, bool= force_refresh) DEBUG_NET_WARN_ON_ONCE(!strp->stm.full_len); =20 if (!strp->copy_mode && force_refresh) { - if (unlikely(tcp_inq(strp->sk) < strp->stm.full_len)) { + if (unlikely(ctx->proto->ops->inq(strp->sk) < strp->stm.full_len)) { WRITE_ONCE(strp->msg_ready, 0); memset(&strp->stm, 0, sizeof(strp->stm)); return false; @@ -511,9 +517,10 @@ bool tls_strp_msg_load(struct tls_strparser *strp, boo= l force_refresh) /* Called with lock held on lower socket */ static int tls_strp_read_sock(struct tls_strparser *strp) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); int sz, inq; =20 - inq =3D tcp_inq(strp->sk); + inq =3D ctx->proto->ops->inq(strp->sk); if (inq < 1) return 0; =20 @@ -556,6 +563,8 @@ void tls_strp_check_rcv(struct tls_strparser *strp) /* Lower sock lock held */ void tls_strp_data_ready(struct tls_strparser *strp) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); + /* This check is needed to synchronize with do_tls_strp_work. * do_tls_strp_work acquires a process lock (lock_sock) whereas * the lock held here is bh_lock_sock. The two locks can be @@ -563,7 +572,7 @@ void tls_strp_data_ready(struct tls_strparser *strp) * allows a thread in BH context to safely check if the process * lock is held. In this case, if the lock is held, queue work. */ - if (sock_owned_by_user_nocheck(strp->sk)) { + if (ctx->proto->ops->lock_is_held(strp->sk)) { queue_work(tls_strp_wq, &strp->work); return; } @@ -583,10 +592,12 @@ static void tls_strp_work(struct work_struct *w) =20 void tls_strp_msg_done(struct tls_strparser *strp) { + struct tls_context *ctx =3D tls_get_ctx(strp->sk); + WARN_ON(!strp->stm.full_len); =20 if (likely(!strp->copy_mode)) - tcp_read_done(strp->sk, strp->stm.full_len); + ctx->proto->ops->read_done(strp->sk, strp->stm.full_len); else tls_strp_flush_anchor_copy(strp); =20 diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 94d2ae0daa8c..af8b60ddcc00 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1963,13 +1963,14 @@ tls_read_flush_backlog(struct sock *sk, struct tls_= prot_info *prot, size_t len_left, size_t decrypted, ssize_t done, size_t *flushed_at) { + struct tls_context *tls_ctx =3D tls_get_ctx(sk); size_t max_rec; =20 if (len_left <=3D decrypted) return false; =20 max_rec =3D prot->overhead_size - prot->tail_size + TLS_MAX_PAYLOAD_SIZE; - if (done - *flushed_at < SZ_128K && tcp_inq(sk) > max_rec) + if (done - *flushed_at < SZ_128K && tls_ctx->proto->ops->inq(sk) > max_re= c) return false; =20 *flushed_at =3D done; @@ -2455,6 +2456,7 @@ int tls_rx_msg_size(struct tls_strparser *strp, struc= t sk_buff *skb) size_t cipher_overhead; size_t data_len =3D 0; int ret; + u32 seq; =20 /* Verify that we have a full TLS header, or wait for more data */ if (strp->stm.offset + prot->prepend_size > skb->len) @@ -2497,8 +2499,9 @@ int tls_rx_msg_size(struct tls_strparser *strp, struc= t sk_buff *skb) goto read_failure; } =20 + seq =3D tls_ctx->proto->ops->get_skb_seq(skb); tls_device_rx_resync_new_rec(strp->sk, data_len + TLS_HEADER_SIZE, - TCP_SKB_CB(skb)->seq + strp->stm.offset); + seq + strp->stm.offset); return data_len + TLS_HEADER_SIZE; =20 read_failure: --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 787CD1DC9B5 for ; Thu, 23 Apr 2026 06:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926010; cv=none; b=nKxm3lodHAsJMVoiyHP0B4XTjboSSgk5/GKJaDduF/Ki3pYqH2MX0G/TJ7DpSXVogphtaOq1d0OJMszlIG6NvMzk4LMOPGqkshF9KYyKXjgEvPFoBUM2qIAu+EuzE7vxBCMWRSfZ+tRrHjA3A3tUh6ZkY/jNaWFzvo1Ua3XP3xk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926010; c=relaxed/simple; bh=gFNaHC4jX1G27NDSP4EeMEXhgxH8h7Jo8CcgYg/VRTI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aGZsTshzMA2oaRAqm7WEYLSMrI10O5IAOeJ2uyAsTBCT8n7AQEsagsLO23eYG0+VleVywGErfvim24UJfvNjHV9yrv720ayCK0Ik6owhAYOGtSlpxCdVqRXbM0/dg0D+VC3M1kD+D5PaYGxu7dxTpohrfnKHQbnb0Eo06MM0wbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eLDzfQMu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eLDzfQMu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 444EEC2BCB7; Thu, 23 Apr 2026 06:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926010; bh=gFNaHC4jX1G27NDSP4EeMEXhgxH8h7Jo8CcgYg/VRTI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eLDzfQMuu32LAOSr86pjvbVPwE/yW4JAxRGgEuK2WgwPMLHdNPweSYgffESmjRPCB +6cEX6f/DES7GBwboB2hWgfazUr2mv37bsTPQ/kkzCsYDeN8FW8wptchwed96plYWA DKd3E4B17fSJMpRZ1U+4zT7kJeDH3d80ShaD59vNUdB3AFR5aatDk18ymA9EKsoUNV wwbF0xihmCcdTIks+5cqUgZ9pk/e5EpU5FoG3IU+f3voWPASB9RQskoUjg7dpGDmRU rp4TAfFJTrW2QP54zQUpmtns0e7ZZdQGofTvGxidsaNlPhP6ClF4ZTTx6pvFALoTxi F5lcXC7aAQXuQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Gang Yan , Geliang Tang Subject: [PATCH mptcp-next v16 05/16] mptcp: update mptcp_check_readable Date: Thu, 23 Apr 2026 14:32:58 +0800 Message-ID: <79e867ea83ae7db0da0c0b0b80246f28dc90cca1.1776924681.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Gang Yan This patch makes mptcp_check_readable() aligned with TCP, and renames it to mptcp_stream_is_readable(). It will be used in the case of KTLS, because 'prot' will be modified, tls_sw_sock_is_readable() is expected to be called from prot->sock_is_readable(). Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan --- net/mptcp/protocol.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 0db50e3715c3..5d4f0bc08973 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3262,9 +3262,11 @@ void __mptcp_unaccepted_force_close(struct sock *sk) __mptcp_destroy_sock(sk); } =20 -static __poll_t mptcp_check_readable(struct sock *sk) +static bool mptcp_stream_is_readable(struct sock *sk) { - return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0; + if (mptcp_epollin_ready(sk)) + return true; + return sk_is_readable(sk); } =20 static void mptcp_check_listen_stop(struct sock *sk) @@ -4327,7 +4329,8 @@ static __poll_t mptcp_poll(struct file *file, struct = socket *sock, mask |=3D EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; =20 if (state !=3D TCP_SYN_SENT && state !=3D TCP_SYN_RECV) { - mask |=3D mptcp_check_readable(sk); + if (mptcp_stream_is_readable(sk)) + mask |=3D EPOLLIN | EPOLLRDNORM; if (shutdown & SEND_SHUTDOWN) mask |=3D EPOLLOUT | EPOLLWRNORM; else --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A67F30171C for ; Thu, 23 Apr 2026 06:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926012; cv=none; b=OGWlCrKzJPsRtNXMFTwT7Jqu8mubrOOQ4hv1DNvJvMod/AIA/KzyMYacKTBWArxybFglZFyP59m1q/m969sIk/HgXa+1+mW30WSsCr2vRheBu8usjVef62L6c3haPGIwIis+EewlT8LcjvlutN2CKJ/tbQB/WadRd74vVrDVJyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926012; c=relaxed/simple; bh=avPQ+vzX0v3e1/TlpTEiwOkcWMTbw+GtTRxqHN/sQhA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lf4VWo4GZWOBIBegzyxHL8uFTp0MdAVTen2oEVOnzYF034CW+SFbK5NyQrdOBI4gZNarMz0LDcqfPuQ/YdVbIjAjfGOse91udhdm2WRa3URThs5wzfCbctmscpsMfa4zyXMpN5jH2vVaHR6Ajh1lqD1t8qpJ/0te4epjqu9ohbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hyB3xXEQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hyB3xXEQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06719C2BCAF; Thu, 23 Apr 2026 06:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926012; bh=avPQ+vzX0v3e1/TlpTEiwOkcWMTbw+GtTRxqHN/sQhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyB3xXEQSx/a3z4mjy6TWmFu9SBqbVDwtN6CnYcNIaUjqJK7cNhY2/3cFDxZ21oSX Nl/luIPld+WI0Xe7CveYk/yLCs/1O3Tw30TFGpa/MtwA3g3C1zePcwhfSrDaO8odZ3 i4qY4+FivmhsIKvJrbDwaOwdYiLVblvR2Fb6zGIyEPKSdWwCpcqS/NTBLjkHW3DNFm if2X+w2Rf9kDcbZjoVjd0YObsKcUNn5RpgMSlOQ9Q0ApvS7zXqZWHvPGoBIGMEVDwP 2zFOafmHkg77wxrCanNdDNUWd5NWRorz+tTMCmfPaukUd7ne6MgGFdVav9/X2U3iFg 0SnECtBed8W4w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 06/16] mptcp: implement tls_mptcp_ops Date: Thu, 23 Apr 2026 14:32:59 +0800 Message-ID: <3e20cd9e52c761e72f2e03910c1b8aa3f4bc61d0.1776924681.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch implements the MPTCP-specific struct tls_prot_ops, named 'tls_mptcp_ops'. Note that there is a slight difference between mptcp_inq() and mptcp_inq_hint(), it does not return 1 when the socket is closed or shut down; instead, it returns 0. Otherwise, it would break the condition "inq < 1" in tls_strp_read_sock(). Passing an MPTCP socket to tcp_sock_rate_check_app_limited() can trigger a crash. Here, an MPTCP version of check_app_limited() is implemented, which calls tcp_sock_rate_check_app_limited() for each subflow. When MPTCP implements lock_is_held interface, it not only checks sock_owned_by_user_nocheck(sk) as TCP does, but also needs to check whether the MPTCP data lock is held. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- include/net/mptcp.h | 2 + include/net/tcp.h | 1 + net/ipv4/tcp.c | 9 +++- net/mptcp/protocol.c | 108 ++++++++++++++++++++++++++++++++++++++++--- net/mptcp/protocol.h | 1 + net/tls/tls_main.c | 13 ++++++ 6 files changed, 126 insertions(+), 8 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 4cf59e83c1c5..02564eceeb7e 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -132,6 +132,8 @@ struct mptcp_pm_ops { void (*release)(struct mptcp_sock *msk); } ____cacheline_aligned_in_smp; =20 +extern struct tls_prot_ops tls_mptcp_ops; + #ifdef CONFIG_MPTCP void mptcp_init(void); =20 diff --git a/include/net/tcp.h b/include/net/tcp.h index ecbadcb3a744..6d5ced8edcc7 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -852,6 +852,7 @@ static inline int tcp_bound_to_half_wnd(struct tcp_sock= *tp, int pktsize) =20 /* tcp.c */ void tcp_get_info(struct sock *, struct tcp_info *); +void tcp_sock_rate_check_app_limited(struct tcp_sock *tp); void tcp_rate_check_app_limited(struct sock *sk); =20 /* Read 'sendfile()'-style from a TCP socket */ diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index b8e33c91d05f..c7bd98f16ab6 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1100,9 +1100,9 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msgh= dr *msg, int *copied, } =20 /* If a gap is detected between sends, mark the socket application-limited= . */ -void tcp_rate_check_app_limited(struct sock *sk) +void tcp_sock_rate_check_app_limited(struct tcp_sock *tp) { - struct tcp_sock *tp =3D tcp_sk(sk); + struct sock *sk =3D (struct sock *)tp; =20 if (/* We have less than one packet to send. */ tp->write_seq - tp->snd_nxt < tp->mss_cache && @@ -1115,6 +1115,11 @@ void tcp_rate_check_app_limited(struct sock *sk) tp->app_limited =3D (tp->delivered + tcp_packets_in_flight(tp)) ? : 1; } + +void tcp_rate_check_app_limited(struct sock *sk) +{ + tcp_sock_rate_check_app_limited(tcp_sk(sk)); +} EXPORT_SYMBOL_GPL(tcp_rate_check_app_limited); =20 int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 5d4f0bc08973..765004a49561 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -24,11 +24,12 @@ #include #include #include +#include #include #include "protocol.h" #include "mib.h" =20 -static unsigned int mptcp_inq_hint(const struct sock *sk); +static unsigned int mptcp_inq_hint(struct sock *sk); =20 #define CREATE_TRACE_POINTS #include @@ -1895,7 +1896,7 @@ static void mptcp_rps_record_subflows(const struct mp= tcp_sock *msk) } } =20 -static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) +static int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_= t len) { struct mptcp_sock *msk =3D mptcp_sk(sk); struct page_frag *pfrag; @@ -1907,8 +1908,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) msg->msg_flags &=3D MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_FASTOPEN | MSG_EOR; =20 - lock_sock(sk); - mptcp_rps_record_subflows(msk); =20 if (unlikely(inet_test_bit(DEFER_CONNECT, sk) || @@ -2024,7 +2023,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msgh= dr *msg, size_t len) } =20 out: - release_sock(sk); return copied; =20 do_error: @@ -2035,6 +2033,17 @@ static int mptcp_sendmsg(struct sock *sk, struct msg= hdr *msg, size_t len) goto out; } =20 +static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) +{ + int ret; + + lock_sock(sk); + ret =3D mptcp_sendmsg_locked(sk, msg, len); + release_sock(sk); + + return ret; +} + static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied); =20 static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb) @@ -2265,7 +2274,7 @@ static bool mptcp_move_skbs(struct sock *sk) return enqueued; } =20 -static unsigned int mptcp_inq_hint(const struct sock *sk) +static int mptcp_inq(struct sock *sk) { const struct mptcp_sock *msk =3D mptcp_sk(sk); const struct sk_buff *skb; @@ -2280,6 +2289,16 @@ static unsigned int mptcp_inq_hint(const struct sock= *sk) return (unsigned int)hint_val; } =20 + return 0; +} + +static unsigned int mptcp_inq_hint(struct sock *sk) +{ + unsigned int inq =3D mptcp_inq(sk); + + if (inq) + return inq; + if (sk->sk_state =3D=3D TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN)) return 1; =20 @@ -4711,3 +4730,80 @@ int __init mptcp_proto_v6_init(void) return err; } #endif + +static bool mptcp_lock_is_held(struct sock *sk) +{ + return sock_owned_by_user_nocheck(sk) || + mptcp_data_is_locked(sk); +} + +static void mptcp_read_done(struct sock *sk, size_t len) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct sk_buff *skb; + size_t left; + u32 offset; + + msk_owned_by_me(msk); + + if (sk->sk_state =3D=3D TCP_LISTEN) + return; + + left =3D len; + while (left && (skb =3D mptcp_recv_skb(sk, &offset)) !=3D NULL) { + int used; + + used =3D min_t(size_t, skb->len - offset, left); + msk->bytes_consumed +=3D used; + MPTCP_SKB_CB(skb)->offset +=3D used; + MPTCP_SKB_CB(skb)->map_seq +=3D used; + left -=3D used; + + if (skb->len > offset + used) + break; + + mptcp_eat_recv_skb(sk, skb); + } + + mptcp_rcv_space_adjust(msk, len - left); + + /* Clean up data we have read: This will do ACK frames. */ + if (left !=3D len) + mptcp_cleanup_rbuf(msk, len - left); +} + +static u32 mptcp_get_skb_seq(struct sk_buff *skb) +{ + return MPTCP_SKB_CB(skb)->map_seq - MPTCP_SKB_CB(skb)->offset; +} + +static void mptcp_check_app_limited(struct sock *sk) +{ + struct mptcp_sock *msk =3D mptcp_sk(sk); + struct mptcp_subflow_context *subflow; + + mptcp_for_each_subflow(msk, subflow) { + struct sock *ssk =3D mptcp_subflow_tcp_sock(subflow); + bool slow; + + slow =3D lock_sock_fast(ssk); + tcp_sock_rate_check_app_limited(tcp_sk(ssk)); + unlock_sock_fast(ssk, slow); + } +} + +struct tls_prot_ops tls_mptcp_ops =3D { + .protocol =3D IPPROTO_MPTCP, + .owner =3D THIS_MODULE, + .inq =3D mptcp_inq, + .sendmsg_locked =3D mptcp_sendmsg_locked, + .recv_skb =3D mptcp_recv_skb, + .lock_is_held =3D mptcp_lock_is_held, + .read_sock =3D mptcp_read_sock, + .read_done =3D mptcp_read_done, + .get_skb_seq =3D mptcp_get_skb_seq, + .poll =3D mptcp_poll, + .epollin_ready =3D mptcp_epollin_ready, + .check_app_limited =3D mptcp_check_app_limited, +}; +EXPORT_SYMBOL(tls_mptcp_ops); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 661600f8b573..1c604a1ded6f 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -380,6 +380,7 @@ struct mptcp_sock { =20 #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock) #define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock) +#define mptcp_data_is_locked(sk) spin_is_locked(&(sk)->sk_lock.slock) =20 #define mptcp_for_each_subflow(__msk, __subflow) \ list_for_each_entry(__subflow, &((__msk)->conn_list), node) diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 5cb344ae2721..0cd406c1b9af 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -1415,9 +1415,19 @@ static int __init tls_register(void) if (err) goto err_dev; =20 +#ifdef CONFIG_MPTCP + err =3D tls_register_prot_ops(&tls_mptcp_ops); + if (err) + goto err_prot_ops; +#endif + tcp_register_ulp(&tcp_tls_ulp_ops); =20 return 0; +#ifdef CONFIG_MPTCP +err_prot_ops: + tls_unregister_prot_ops(&tls_tcp_ops); +#endif err_dev: tls_device_cleanup(); err_strp: @@ -1430,6 +1440,9 @@ static int __init tls_register(void) static void __exit tls_unregister(void) { tls_proto_cleanup(); +#ifdef CONFIG_MPTCP + tls_unregister_prot_ops(&tls_mptcp_ops); +#endif tls_unregister_prot_ops(&tls_tcp_ops); tcp_unregister_ulp(&tcp_tls_ulp_ops); tls_strp_dev_exit(); --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2139130171C for ; Thu, 23 Apr 2026 06:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926015; cv=none; b=oflimn9RtzjbDoNXGAsTOmgyAJ0E+O61pX5LqOFY4yKXY2fsXyyW6ErxMuNfZnRDJdUj4Ku1F0+rygUjrYV8MF6edBABwnn9InknNTjELN4CZp5i8o0grR430sz8riwDS94NWiYtrsm+0eiz82YstXMDNf4vE/CgaSiFGDxp9lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926015; c=relaxed/simple; bh=6GzcsaFMq28d0FWn520aOq92c8IsBigTgiZ49vjCiME=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ioiw5i/JXjJ1hCswy01cB434r0o02CJRTtdrrSw+RTF+g0CeD/78dSbXRcnucNokUOkjnKGL8Exb7MtXEFo8hFGTT1pMEIaMFz44WcBmWWUD3kROPEBUaoPmuENbWCTQpzfOuNSuQsxXHOb9Z0wDlutepofh4KQ0OxM3EbELG1A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Erf/AtWQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Erf/AtWQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B06FC2BCAF; Thu, 23 Apr 2026 06:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926014; bh=6GzcsaFMq28d0FWn520aOq92c8IsBigTgiZ49vjCiME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Erf/AtWQiYK9cwyLhhz2JMUJrLvfmx/u6zH5VrlV18pg8n8UUCJ06zf31DY4PzS6F LrRV/tIRrmZ8zXG8VcWdLaxqf/qEUJFxRV7//KxmFta5uCjFQl01ZNXm1isMwaNrkM fBwIqlMTBOZfnv6BIhO/FKrNIHiYW6oJayqsnVAkxv1AYL0D00PGU1AS8eAjrZZX0c ZxcAns18PL8JCVt3h5lJdG9DAcee1CWbvfUV53hYudrCLT3pxsDuxt/nhDMHnxfiJl Cjvjvc+wGN6mgKeoaLnU2DRZXv85jJ329xeMFEdxvL59pleds4Vpz44sVJ22DNJpF0 jrXjj/35aY6Vg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 07/16] tls: disable device offload for mptcp sockets Date: Thu, 23 Apr 2026 14:33:00 +0800 Message-ID: <6240207baff6bfea8fc3931deedb018b23f0d973.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang MPTCP TLS hardware offload is not yet implemented. Return -EOPNOTSUPP when attempting to enable device offload on MPTCP sockets. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- net/tls/tls_device.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 99c8eff9783e..6744c2494740 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1074,6 +1074,9 @@ int tls_set_device_offload(struct sock *sk) ctx =3D tls_get_ctx(sk); prot =3D &ctx->prot_info; =20 + if (sk->sk_protocol =3D=3D IPPROTO_MPTCP) + return -EOPNOTSUPP; + if (ctx->priv_ctx_tx) return -EEXIST; =20 @@ -1196,6 +1199,9 @@ int tls_set_device_offload_rx(struct sock *sk, struct= tls_context *ctx) struct net_device *netdev; int rc =3D 0; =20 + if (sk->sk_protocol =3D=3D IPPROTO_MPTCP) + return -EOPNOTSUPP; + if (ctx->crypto_recv.info.version !=3D TLS_1_2_VERSION) return -EOPNOTSUPP; =20 --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DABA30171C for ; Thu, 23 Apr 2026 06:33:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926016; cv=none; b=HzZfoTGPqKMIp98WlbEDRehJ+AeERzzi2zPBnUzUTK4ousHYY/GIiuMUDjqANJvJ6iJumFgZszuKwn1yWzh3HpP9iY6FTeY3HGuVsVlM7IQw8NtNuSSA95GglAlN8jKeHXTxrmLRYMiCvMv6vBwIJDh4DBKax1XNjOH1IHJsX98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926016; c=relaxed/simple; bh=7D0Bu4UipZQMQi6IGVY3++Gf4Bnap7b6RCqetXd/DI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hENMYDBlnGZrYSJvRWLKEHfUp9pvTZ+97JVdtfBzIYtSj0HLWI7n/pn5Trts75SCFQ4rmYcvh1S0PQjEqesjKxFr+hJVpdn1fhJTQGhiL96Q9xPn2+vVDb0ThYm2xBTKkbwlUW7u+CKu8MgaUlAqgc/ejEeWzHEm2pKZVJCVpiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uijddktK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uijddktK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FCD6C2BCB2; Thu, 23 Apr 2026 06:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926016; bh=7D0Bu4UipZQMQi6IGVY3++Gf4Bnap7b6RCqetXd/DI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uijddktK1iGyoHM1sy0AjZvFG2Hnz7owyApX9LNpuu2jy87pxS9f/7KqSZCtIPFHf 6RIxFGGnRKf+BczfvyI4PsatNQtnyonyFRUVaiKDDZElVJn2f4REe9B3r/nhmk+VrP /GsdqAiDIb4xg1SmSymEu/hs1akVLnwfYjU/j7bbo72bO/UuPL+NOaE97vs77erXH4 MnURWQgXcaFX2JEAWy5BpD9+xS8T9zXofQ77eRtrcLHrqn9R4utaGQ5sw9uJqfIMYv fVwJooUdJxTg4WtghnR/U4ooeP3W740bQKPXb4RlO7SO9p2nF868QWUqmxZctRWOL5 HnhLJp8Vqtzog== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 08/16] mptcp: update ulp getsockopt for tls support Date: Thu, 23 Apr 2026 14:33:01 +0800 Message-ID: <75247e374c9bf6a4e7ceb7a40bf8e52846ce1904.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch extracts TCP_ULP getsockopt operation into a tcp_sock_get_ulp() helper so that it can also be used in MPTCP. TCP_ULP was obtained by calling mptcp_getsockopt_first_sf_only() to get ULP of the first subflow. Now that the mechanism has changed, a new helper mptcp_getsockopt_tcp_ulp() is added to get ULP of msk. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- include/linux/tcp.h | 1 + net/ipv4/tcp.c | 36 ++++++++++++++++++++++-------------- net/mptcp/sockopt.c | 18 ++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/include/linux/tcp.h b/include/linux/tcp.h index 6982f10e826b..2bb1cbd3eeab 100644 --- a/include/linux/tcp.h +++ b/include/linux/tcp.h @@ -653,6 +653,7 @@ void tcp_sock_set_quickack(struct sock *sk, int val); int tcp_sock_set_syncnt(struct sock *sk, int val); int tcp_sock_set_user_timeout(struct sock *sk, int val); int tcp_sock_set_maxseg(struct sock *sk, int val); +int tcp_sock_get_ulp(struct sock *sk, sockptr_t optval, sockptr_t optlen); =20 static inline bool dst_tcp_usec_ts(const struct dst_entry *dst) { diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index c7bd98f16ab6..44b71a5e8ed7 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4490,6 +4490,27 @@ struct sk_buff *tcp_get_timestamping_opt_stats(const= struct sock *sk, return stats; } =20 +int tcp_sock_get_ulp(struct sock *sk, sockptr_t optval, sockptr_t optlen) +{ + struct inet_connection_sock *icsk =3D inet_csk(sk); + int len; + + if (copy_from_sockptr(&len, optlen, sizeof(int))) + return -EFAULT; + len =3D min_t(unsigned int, len, TCP_ULP_NAME_MAX); + if (!icsk->icsk_ulp_ops) { + len =3D 0; + if (copy_to_sockptr(optlen, &len, sizeof(int))) + return -EFAULT; + return 0; + } + if (copy_to_sockptr(optlen, &len, sizeof(int))) + return -EFAULT; + if (copy_to_sockptr(optval, icsk->icsk_ulp_ops->name, len)) + return -EFAULT; + return 0; +} + int do_tcp_getsockopt(struct sock *sk, int level, int optname, sockptr_t optval, sockptr_t optlen) { @@ -4599,20 +4620,7 @@ int do_tcp_getsockopt(struct sock *sk, int level, return 0; =20 case TCP_ULP: - if (copy_from_sockptr(&len, optlen, sizeof(int))) - return -EFAULT; - len =3D min_t(unsigned int, len, TCP_ULP_NAME_MAX); - if (!icsk->icsk_ulp_ops) { - len =3D 0; - if (copy_to_sockptr(optlen, &len, sizeof(int))) - return -EFAULT; - return 0; - } - if (copy_to_sockptr(optlen, &len, sizeof(int))) - return -EFAULT; - if (copy_to_sockptr(optval, icsk->icsk_ulp_ops->name, len)) - return -EFAULT; - return 0; + return tcp_sock_get_ulp(sk, optval, optlen); =20 case TCP_FASTOPEN_KEY: { u64 key[TCP_FASTOPEN_KEY_BUF_LENGTH / sizeof(u64)]; diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 79db15903e7a..11e071b0994e 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -1393,6 +1393,23 @@ static int mptcp_put_int_option(struct mptcp_sock *m= sk, char __user *optval, return 0; } =20 +static int mptcp_getsockopt_tcp_ulp(struct sock *sk, char __user *optval, + int __user *optlen) +{ + int ret, len; + + if (copy_from_sockptr(&len, USER_SOCKPTR(optlen), sizeof(int))) + return -EFAULT; + + if (len < 0) + return -EINVAL; + + lock_sock(sk); + ret =3D tcp_sock_get_ulp(sk, USER_SOCKPTR(optval), USER_SOCKPTR(optlen)); + release_sock(sk); + return ret; +} + static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, char __user *optval, int __user *optlen) { @@ -1400,6 +1417,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock= *msk, int optname, =20 switch (optname) { case TCP_ULP: + return mptcp_getsockopt_tcp_ulp(sk, optval, optlen); case TCP_CONGESTION: case TCP_INFO: case TCP_CC_INFO: --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4ABE430171C for ; Thu, 23 Apr 2026 06:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926079; cv=none; b=bB/laLD0GrUWKfGUEgqRPKhQvAyrMxqDZOxZAVEkFLeMv/bZgYICnoBuZGhs2iPvb5tjEzrpKPbB3ucuiu45r7Stz1EO571gt3GKD37b+CNKVxfkNfPdk6SdHSP3K+fFe+KaLcioV7J8rhc/g23ZI1No/O6lhHPlTZ97JioEboA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926079; c=relaxed/simple; bh=EhuN2ix8luIrR6qxurBNcW7UV7TUgzkTHK6yaJIOG7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UXi95cBwG6X2478aM2mtrGWj8LK5B0YFVgC3sJs3jjeelIVNuRgRERxgyRl0M809b5bkD06VwbthAtEe4QQ0Y+uHC2BN98U5nH8POLln0QkSXNNvel+S1fEdA+VULO8uvh8OJxyY9x21nI6Zu8mC+JOv7OuyYB1Nd4g8lJprgkc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N4pprQdt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="N4pprQdt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88339C2BCAF; Thu, 23 Apr 2026 06:33:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926079; bh=EhuN2ix8luIrR6qxurBNcW7UV7TUgzkTHK6yaJIOG7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N4pprQdtM6DlE7ooKPerGBc+hqxOMowufUkQJDSAqOjdSqYBoU+22ofhZjC8i3Gnr bdyGGDRzRo0NSZbu6KTSxFxxr6QLPNFvLer03+V07D5R065Q6kUal/8+gjpgaLgpT7 hsnoXa+LDS23aUvtwZOxw/Q7/GCEsen3eS53pHu7xHUtwEQHlHvYNEQFT++wcszAES 9Z4JNc/dF9vcfvf1goyipOW7Fa7KBskGeu7bGZedTv04xSEYXGXNHUWwHon5cT7+dv f5BX9GgXG9mEWGvTTKXSY5fTxDqzzA1i/aXkB/VL0q785WMCHmizvrr4jzh6brWTPc +u5N7Sfh6CcbQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 09/16] mptcp: enable ulp setsockopt for tls support Date: Thu, 23 Apr 2026 14:33:02 +0800 Message-ID: <91a651f218d4adddfc8d2e44c21d72510438d390.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Allow MPTCP sockets to set the TCP_ULP socket option to enable TLS. Add mptcp_setsockopt_tcp_ulp() which validates the socket state (must not be CLOSE or LISTEN), only accepts "tls" as the ULP name, and then calls tcp_set_ulp(). Include TCP_ULP in the list of supported options in supported_sockopt(), and handle it in setsockopt_sol_tcp() instead of returning -EOPNOTSUPP. Call tcp_cleanup_ulp() in mptcp_destroy_common() to release ULP module's reference count. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 1 + net/mptcp/sockopt.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 765004a49561..8f29bca7cf6f 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3635,6 +3635,7 @@ static void mptcp_destroy(struct sock *sk) /* allow the following to close even the initial subflow */ msk->free_first =3D 1; mptcp_destroy_common(msk); + tcp_cleanup_ulp(sk); sk_sockets_allocated_dec(sk); } =20 diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 11e071b0994e..1059efbd4f8f 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "protocol.h" =20 #define MIN_INFO_OPTLEN_SIZE 16 @@ -567,6 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optn= ame) case TCP_FASTOPEN_CONNECT: case TCP_FASTOPEN_KEY: case TCP_FASTOPEN_NO_COOKIE: + case TCP_ULP: return true; } =20 @@ -815,6 +817,37 @@ static int mptcp_setsockopt_all_sf(struct mptcp_sock *= msk, int level, return ret; } =20 +static int mptcp_setsockopt_tcp_ulp(struct sock *sk, sockptr_t optval, + unsigned int optlen) +{ + char name[TCP_ULP_NAME_MAX]; + int err =3D 0; + size_t len; + int val; + + if (optlen < 1) + return -EINVAL; + + len =3D min_t(long, TCP_ULP_NAME_MAX - 1, optlen); + val =3D strncpy_from_sockptr(name, optval, len); + if (val < 0) + return -EFAULT; + name[val] =3D 0; + + if (strcmp(name, "tls")) + return -EOPNOTSUPP; + + sockopt_lock_sock(sk); + if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) { + err =3D -ENOTCONN; + goto out; + } + err =3D tcp_set_ulp(sk, name); +out: + sockopt_release_sock(sk); + return err; +} + static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, sockptr_t optval, unsigned int optlen) { @@ -823,7 +856,7 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *= msk, int optname, =20 switch (optname) { case TCP_ULP: - return -EOPNOTSUPP; + return mptcp_setsockopt_tcp_ulp(sk, optval, optlen); case TCP_CONGESTION: return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen); case TCP_DEFER_ACCEPT: --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6274730171C for ; Thu, 23 Apr 2026 06:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926081; cv=none; b=XKI0SL9iRxtO5CYYzHQ1DMIUXZlxdNmWyHjn44OY7z3SA9dQRYMgc83NXGlZJ54NKpyzVHgJWnKI7EZETsdEENIYSuKOjAoTB9TZLhlRL/GzjFECchi4g68cFpoHLGt9wIUIWXar9YaU0wgSh8QApC7aZzwvdVHAWUIgJSE2XtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926081; c=relaxed/simple; bh=J0NJGf88lWcWV1rrjAAaDmhfdWlaoFxKlanO6HSL9Q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rEMGP6PJmTlld1vLb+MxkYNO0uvfWf812fSOf7U/IM0LqcaZ3gSDqaWY5iGze77+28Er79kO8L33ETRVPyjWMEf/OqAc88Fpu96AHMWsF6MqlyxZv4/Ck9fgMgfXfQnU9K6qswwFz69MjKyG6IsgrhwMzlfMAfwSfrPBmpyYkcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i+HO7f3V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i+HO7f3V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AE0EC2BCB7; Thu, 23 Apr 2026 06:34:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926081; bh=J0NJGf88lWcWV1rrjAAaDmhfdWlaoFxKlanO6HSL9Q4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+HO7f3VswJAGRWISIw+voWilsTb1agnIHKXV4Ho7wILRh/YeaAQw+iqjqZCRAr97 GAaBjFpyVkW7QZCejumT1DOh5MzKJ6AyzwtYeKmsT4e7IsYuzLAcAyF6VGr4IktZ83 mJBY6NayVcPoIQWLgIPaOepNvfIOKbsLQi7djEmGQy1O/96jWa9sS+YZThJiPHYfm2 vIUGKbmcvu7uwq7bmIvdSozAK3LkVTTAOUAsFT8be4ogOeaSMEnib2DckAaKv6O2VJ t+gJTXzQGZxLn2tItL66/C3hc3Of+KC3EEQHTe09lWT7CuOAlb3kxXsfEmF2PLxV4O ln8n5lwoTUh0w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 10/16] selftests: mptcp: connect: use espintcp for ulp test Date: Thu, 23 Apr 2026 14:33:03 +0800 Message-ID: <2394160f654f1563ba2ef10ef3c93d1483fafb2f.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang With KTLS being implemented, "tls" should no longer be used in sock_test_tcpulp(), it breaks mptcp_connect.sh tests. Another ULP name, "espintcp", is set instead in this patch. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index cbe573c4ab3a..299a7a02d6f5 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -285,11 +285,11 @@ static void sock_test_tcpulp(int sock, int proto, uns= igned int line) if (buflen > 0) { if (strcmp(buf, "mptcp") !=3D 0) xerror("unexpected ULP '%s' for proto %d at line %u", buf, proto, line); - ret =3D do_ulp_so(sock, "tls"); + ret =3D do_ulp_so(sock, "espintcp"); if (ret =3D=3D 0) X("setsockopt"); } else if (proto =3D=3D IPPROTO_MPTCP) { - ret =3D do_ulp_so(sock, "tls"); + ret =3D do_ulp_so(sock, "espintcp"); if (ret !=3D -1) X("setsockopt"); } --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CA9E1DC9B5 for ; Thu, 23 Apr 2026 06:34:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926083; cv=none; b=NuMM+gCEten8iIwh//l6HkeWPmkPWRIoAFvoddQMBwatG4/ByJ+rEp6x8Xot42tHGtIwTq5VILMKoUyqQ5PZ5cDSednM06BNqDujERyf1Sudu4hD+lOt9s3VfqgFkOMnU9vX4MeSj9gROtfoHYTzH+lULlBFrs5mfRY3w6sVzJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926083; c=relaxed/simple; bh=chlFBKYEAzL7kssHooVT1Lp3GlDAUDFlXX5zPHrJDZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mS+DPOOmZw0PFCmtRVWYUXqmUj/FOQ34EFA0O+qoZy6DHUpX1Eew+tlaZm+YRO+dZBEuQTJdbpU7wAWK3kFbS6DZppaVeUSdvZXSTmXKnBrAl24VVhEftHhmLOiW/45QtMwPxZN2TBnuoW0oWUErNidZtGr5hHFtD7+UDFOZRPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OrMxmiyr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OrMxmiyr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AA84C2BCAF; Thu, 23 Apr 2026 06:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926083; bh=chlFBKYEAzL7kssHooVT1Lp3GlDAUDFlXX5zPHrJDZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OrMxmiyrykppogbWwNRlYPalY4boy4UhVEv0aZ/zOaKmyMBXWgizVTPm8b6CWADpo 37Brqd+PAifxJX3JrLwrSESesa3kIPQtthpSMHUFDx1Bbgg4BcKI1QkhHUNABONi4S XcniY9/L/SlgyHAYjBXE/Dz4SVd/dvDAprkC48wh0UlOUMtswkk0QQaMW3XoiNRhUy /xt9h/klzJE6BefJkyVv7QYiv9Itw8brjTtlTTsc71kkwRi7iqdOxmL3ieA8hLal5+ ZAm14vLKE+8HHj4McV7ApCHN/P3i6aa3yl2GJZN66nBcJYnBUIb5tfagvh7dvFNfsh 78SQsOZbIj5KA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 11/16] selftests: tls: add mptcp variant for testing Date: Thu, 23 Apr 2026 14:33:04 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang To enable easy MPTCP socket creation in MPTCP TLS tests, two protocol parameters (cli_proto and srv_proto) have been added to ulp_sock_pair(). These are passed as third arguments of socket(): 0 creates TCP sockets, IPPROTO_MPTCP creates MPTCP sockets. A new variant "mptcp" is added both in FIXTURE_VARIANT(tls) to control whether to create MPTCP sockets or not for tests. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/tls.c | 44 +++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index 9e2ccea13d70..80e8071993c0 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -26,6 +26,10 @@ #define TLS_PAYLOAD_MAX_LEN 16384 #define SOL_TLS 282 =20 +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif + static int fips_enabled; =20 struct tls_crypto_info_keys { @@ -108,8 +112,9 @@ static void memrnd(void *s, size_t n) *byte++ =3D rand(); } =20 -static void ulp_sock_pair(struct __test_metadata *_metadata, - int *fd, int *cfd, bool *notls) +static void __ulp_sock_pair(struct __test_metadata *_metadata, + int *fd, int *cfd, bool *notls, + int cli_proto, int srv_proto) { struct sockaddr_in addr; socklen_t len; @@ -122,8 +127,8 @@ static void ulp_sock_pair(struct __test_metadata *_meta= data, addr.sin_addr.s_addr =3D htonl(INADDR_ANY); addr.sin_port =3D 0; =20 - *fd =3D socket(AF_INET, SOCK_STREAM, 0); - sfd =3D socket(AF_INET, SOCK_STREAM, 0); + *fd =3D socket(AF_INET, SOCK_STREAM, cli_proto); + sfd =3D socket(AF_INET, SOCK_STREAM, srv_proto); =20 ret =3D bind(sfd, &addr, sizeof(addr)); ASSERT_EQ(ret, 0); @@ -153,6 +158,12 @@ static void ulp_sock_pair(struct __test_metadata *_met= adata, ASSERT_EQ(ret, 0); } =20 +static void ulp_sock_pair(struct __test_metadata *_metadata, + int *fd, int *cfd, bool *notls) +{ + __ulp_sock_pair(_metadata, fd, cfd, notls, 0, 0); +} + /* Produce a basic cmsg */ static int tls_send_cmsg(int fd, unsigned char record_type, void *data, size_t len, int flags) @@ -310,6 +321,7 @@ FIXTURE_VARIANT(tls) uint16_t tls_version; uint16_t cipher_type; bool nopad, fips_non_compliant; + bool mptcp; }; =20 FIXTURE_VARIANT_ADD(tls, 12_aes_gcm) @@ -395,6 +407,23 @@ FIXTURE_VARIANT_ADD(tls, 12_aria_gcm_256) .cipher_type =3D TLS_CIPHER_ARIA_GCM_256, }; =20 +static bool is_mptcp_enable(struct __test_metadata *_metadata) +{ + char buf[16] =3D { 0 }; + ssize_t n; + int fd; + + fd =3D open("/proc/sys/net/mptcp/enabled", O_RDONLY); + if (fd < 0) + return false; + + n =3D read(fd, buf, sizeof(buf) - 1); + close(fd); + if (n <=3D 0) + return false; + return (atoi(buf) =3D=3D 1); +} + FIXTURE_SETUP(tls) { struct tls_crypto_info_keys tls12; @@ -404,10 +433,15 @@ FIXTURE_SETUP(tls) if (fips_enabled && variant->fips_non_compliant) SKIP(return, "Unsupported cipher in FIPS mode"); =20 + if (variant->mptcp && !is_mptcp_enable(_metadata)) + SKIP(return, "no MPTCP support"); + tls_crypto_info_init(variant->tls_version, variant->cipher_type, &tls12, 0); =20 - ulp_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls); + __ulp_sock_pair(_metadata, &self->fd, &self->cfd, &self->notls, + variant->mptcp ? IPPROTO_MPTCP : 0, + variant->mptcp ? IPPROTO_MPTCP : 0); =20 if (self->notls) return; --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97FF01DC9B5 for ; Thu, 23 Apr 2026 06:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926085; cv=none; b=Vk97303XJDQWfWc2Szd4gTdowE+S+eih2MaG830qAllOm11jqmJhlEEQQefAjLR1KvyCUx6Ksr7P4crpXLSkq376lBpWBbv+etit3dQKbse5macpQvbZvNIRDXTuWbu6UoQX3GNllKaUfNyydBRAfN/n8hwcx0ScyU/lJYe97M8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926085; c=relaxed/simple; bh=Rt+LtTO66E1MVl7IlHvROCv5WAm4TeN8BijU7rCSxc4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ULeGfPrdqN++ymJeOard4O23LV3TaQEpPl3IENgzqBCfeSOVDvymf2lLIRmhxjBi/jQfPB+/ySTlD/9cOTWaxKdnD/+BGO8kstgZ9ldsG+3WVF5osBdEfrN7rG+e9N+sc9jdEr/LY1luP9Z9qjKRPSwVhSLFt+3gYia71qnL62A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=arNAw/JV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="arNAw/JV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B277CC2BCB2; Thu, 23 Apr 2026 06:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926085; bh=Rt+LtTO66E1MVl7IlHvROCv5WAm4TeN8BijU7rCSxc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=arNAw/JVHD89/8qnSAUL64Uk7Zhvo5ioEAY/V+nyd5U7DmXnWHy6OExHC3w94Jh34 DTsF8kB0Q2IN8wjWXcuP5kRETkDT17hoHrzfFsnDWXBhvmfW5ROUNUd4xT979JjmWX AJu/ESAmdbZ6DotNpr2sKRB8x2qzAC9n3b+OFExRLKPrKGbA6j4Oo8YoxbkP7gxjS5 pGdWAXPhAC9nBDvqXDTssXs6/EDsX4UBnZ+Kjhpv23DLJZoidOshbvxigVoRP8JKTV koaRpyAtDc6eW+aRFbyGwvQCMeQRbK6BoVfICqL+oewnRZZT2iE7c9XdF7i8igq4kU S/KI0hoY7jSyA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 12/16] selftests: tls: increase pollin timeouts for mptcp Date: Thu, 23 Apr 2026 14:33:05 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang MPTCP requires longer timeouts in pollin test due to subflow establishment delays and slower state transitions. Increase timeout values to prevent false failures: # RUN tls.13_sm4_ccm_mptcp.pollin ... # tls.c:1411:pollin:Expected poll(&fd, 1, 20) (0) =3D=3D 1 (1) # tls.c:1412:pollin:Expected fd.revents & POLLIN (0) =3D=3D 1 (1) # pollin: Test failed # FAIL tls.13_sm4_ccm_mptcp.pollin not ok 357 tls.13_sm4_ccm_mptcp.pollin Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/tls.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index 80e8071993c0..0dc6514c2c3f 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1319,6 +1319,7 @@ TEST_F(tls, bidir) =20 TEST_F(tls, pollin) { + int timeout =3D variant->mptcp ? 100 : 20; char const *test_str =3D "test_poll"; struct pollfd fd =3D { 0, 0, 0 }; char buf[10]; @@ -1328,11 +1329,11 @@ TEST_F(tls, pollin) fd.fd =3D self->cfd; fd.events =3D POLLIN; =20 - EXPECT_EQ(poll(&fd, 1, 20), 1); + EXPECT_EQ(poll(&fd, 1, timeout), 1); EXPECT_EQ(fd.revents & POLLIN, 1); EXPECT_EQ(recv(self->cfd, buf, send_len, MSG_WAITALL), send_len); /* Test timing out */ - EXPECT_EQ(poll(&fd, 1, 20), 0); + EXPECT_EQ(poll(&fd, 1, timeout), 0); } =20 TEST_F(tls, poll_wait) --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC4361DC9B5 for ; Thu, 23 Apr 2026 06:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926087; cv=none; b=ZvlentQhMjmvlS550XYupSUH0rNuk9icecPQnxXBU5Sxc/+dztD18aFn0ymgcvJfHx2Usm52Tt86WHgoFlmhoLX9hgLhGXe0g8H2FdxUer+6DMV/92bRNmWDk+bwtNv/AL0jcutz26O5BHAy8JHPOAWVaajThp0xpr31EHlBT0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926087; c=relaxed/simple; bh=z/yvkHNvige9dyxFq56fUlVbkED7pVLPlli991d36f0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bX3LFC09S8TzSjVYKsPWYSKsdlBC5yAmAvHxxcMXzGeoqq3LmkOrFcY32/E2GmJqhWwopJ6oGvWcq4xe7/7td0wsoEpm9edfOwf9x1ElWMEgk+2JONYFNQcKsvK2dyXB3SPL0nkhejYRZ3BwtcvkthigGN5Vy/ASPvDCuZvhlLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sIW8hT78; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sIW8hT78" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7810C2BCB5; Thu, 23 Apr 2026 06:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926087; bh=z/yvkHNvige9dyxFq56fUlVbkED7pVLPlli991d36f0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sIW8hT78qfuof1zYbAZsmqWaPvYBbvIF6WIKXBqclSgaPSGBx3U/t+toOTqwCAxzp f2Lh+D+iGY9FqpL1h7lVyCyb53feOxS16wXGEIiUOUe/grpY3gP0R5fAT6j9MaQ+DY uQ3zzp+DgXwZ9+b/V1VjCAdPNJal4krQOil03qCVKB06f2j7O3Lw0D6JGXGSxJyZmA jOitXHla8GOJmXZFpDWzvjdNzhzc7NT1UriZks1+Kl6pBVjqHLg3Ymvp2o5BAeMVUW 35KeuZnf0hPtS1M17XwbvSVArONnVMEJl7a5x4PmtozUBn+Wzah0OqNQUBwaiFGuzR TpZ3OCffmSKzQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 13/16] selftests: tls: increase nonblocking data size for mptcp Date: Thu, 23 Apr 2026 14:33:06 +0800 Message-ID: <229ef19648e7a99125bc4322c6f5f54483866ef1.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Increase the data size in nonblocking tests to accommodate MPTCP's multi-subflow behavior and ensure sufficient data for testing, avoiding the following errors: # RUN tls.12_aria_gcm_mptcp.nonblocking ... # tls.c:1534:nonblocking:Expected 0 (0) !=3D eagain (0) # nonblocking: Test failed Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/tls.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index 0dc6514c2c3f..bf8ecfdfdd18 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1425,6 +1425,9 @@ TEST_F(tls, nonblocking) int flags; int res; =20 + if (variant->mptcp) + data *=3D 4; + flags =3D fcntl(self->fd, F_GETFL, 0); fcntl(self->fd, F_SETFL, flags | O_NONBLOCK); fcntl(self->cfd, F_SETFL, flags | O_NONBLOCK); --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A48D1DC9B5 for ; Thu, 23 Apr 2026 06:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926121; cv=none; b=MfnFi/Q7Morfudrur518t6e5ZQx8DdWOuqcFYb0UMH9SPdOXcNUgBt4dKeAdeAG8PoFZOwFDPhthrWQofxlGiPgl9zcOLuUipblJv85XRd/pmHuMeRXTA8msyaQSqI4v3ZNj1tiXDNXSTSYRIxJm/fqpTWey9RSt6JYLpSYXlVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926121; c=relaxed/simple; bh=fByAMZzWgvnfXRFuH3lT99tlGAl0B4kYTI+9/p3oMeI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uURvx/gVoqSW+Y2g5E0HAP1VGW+9+5ZdOWJJS39FD3pqqMbSWekXpM9fm2/NhAP/UpnHcr/1v7nyGHhH3RkLE+ArqfuoZh/7dYH2BKZkTT8wDN4MMw5HbrS4w/jmdWvy3GTVWOBMMkNkFydyfSWoNa808lk12VPEKaAdkTz5lkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HRk8Ykjo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HRk8Ykjo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4234C2BCAF; Thu, 23 Apr 2026 06:34:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926121; bh=fByAMZzWgvnfXRFuH3lT99tlGAl0B4kYTI+9/p3oMeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HRk8YkjoNYEzbBRidgBmgoCOf88B6sFvSO+/YA1R1a2gWAs3DAuViI+7glz9gWuUa OXzMo2O3IGaFmrYNtSZ9gySsWYJZvpcMMCQ6oReeixcps0ge0BbhbvXBRl8JrxfQz5 oRxB1YkDDcFgiPp4AS0PYIIYrZGj2MgfZ0ee1Lm7+HWeSQKKHqerctWjHbwQnaT2er 2hTY5PgERmqQwKkYT0/gQQa4tbmMdArWMA0UiFRMjvAiqhbV3zE/0YyLSd8vtn45Fr ZXvYU50ETqgfQ2gIegkJo/vL9cgsIIG6PeaO4ABM9WWWznseNyM24Ip7je0qA1Z75v uVkojkyrJ9wVw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 14/16] selftests: tls: wait close in shutdown_reuse for mptcp Date: Thu, 23 Apr 2026 14:33:07 +0800 Message-ID: <051e6ecc9e8a192f23ece64e052897effddb1fa8.1776924682.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang In shutdown_reuse tests, add a delay after shutdown to wait for MPTCP sockets to reach TCP_CLOSE state before reuse via bind(), avoiding the following errors: # RUN tls.12_aes_gcm_mptcp.shutdown_reuse ... # tls.c:1790:shutdown_reuse:Expected ret (-1) =3D=3D 0 (0) # shutdown_reuse: Test failed # FAIL tls.12_aes_gcm_mptcp.shutdown_reuse not ok 14 tls.12_aes_gcm_mptcp.shutdown_reuse # RUN tls.13_aes_gcm_mptcp.shutdown_reuse ... # tls.c:1790:shutdown_reuse:Expected ret (-1) =3D=3D 0 (0) # shutdown_reuse: Test failed # FAIL tls.13_aes_gcm_mptcp.shutdown_reuse not ok 15 tls.13_aes_gcm_mptcp.shutdown_reuse # RUN tls.12_chacha_mptcp.shutdown_reuse ... # OK tls.12_chacha_mptcp.shutdown_reuse ok 16 tls.12_chacha_mptcp.shutdown_reuse # RUN tls.13_chacha_mptcp.shutdown_reuse ... # OK tls.13_chacha_mptcp.shutdown_reuse ok 17 tls.13_chacha_mptcp.shutdown_reuse # RUN tls.13_sm4_gcm_mptcp.shutdown_reuse ... # tls.c:1790:shutdown_reuse:Expected ret (-1) =3D=3D 0 (0) # shutdown_reuse: Test failed # FAIL tls.13_sm4_gcm_mptcp.shutdown_reuse not ok 18 tls.13_sm4_gcm_mptcp.shutdown_reuse This TCP_CLOSE check is just for MPTCP, because it should not slow down plain TCP tests. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/tls.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index bf8ecfdfdd18..8bedc2cde763 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -30,6 +30,10 @@ #define IPPROTO_MPTCP 262 #endif =20 +#ifndef TCP_CLOSE +#define TCP_CLOSE 7 +#endif + static int fips_enabled; =20 struct tls_crypto_info_keys { @@ -1698,6 +1702,25 @@ TEST_F(tls, shutdown_unsent) shutdown(self->cfd, SHUT_RDWR); } =20 +static bool wait_for_tcp_close(struct __test_metadata *_metadata, + int fd, int max) +{ + struct tcp_info info; + socklen_t len; + int i, ret; + + for (i =3D 0; i < max; i++) { + len =3D sizeof(info); + ret =3D getsockopt(fd, IPPROTO_TCP, TCP_INFO, &info, &len); + ASSERT_EQ(ret, 0); + if (info.tcpi_state =3D=3D TCP_CLOSE) + return true; + usleep(1000); + } + + return false; +} + TEST_F(tls, shutdown_reuse) { struct sockaddr_in addr; @@ -1707,6 +1730,9 @@ TEST_F(tls, shutdown_reuse) shutdown(self->cfd, SHUT_RDWR); close(self->cfd); =20 + if (variant->mptcp) + EXPECT_TRUE(wait_for_tcp_close(_metadata, self->fd, 1000)); + addr.sin_family =3D AF_INET; addr.sin_addr.s_addr =3D htonl(INADDR_ANY); addr.sin_port =3D 0; --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E7A91DC9B5 for ; Thu, 23 Apr 2026 06:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926123; cv=none; b=uvsR0+LclZOl1tw5cdwkAMYJ8clN4LvGm9W/5BybI8XPdWLUnwTgCSfpK2snCxlyGQ8X8YpYOhqcyccgmfZCS2jx+Pe0k+uqKGTYj5hLeExzOeC3BlDUOtBlWKhJ10b/VaLI4FVcpZUY/TeJ2bM2zNeANf3k4gmIamkhaZ8t6pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926123; c=relaxed/simple; bh=VmQM9a+zK9JXLT/ZqXNqPpS4ogJdqKXImO7k8ArmbHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Dko7hIIsGPsTKdkcDYb6Y2FJQDfk+GWz4K0b8hDbyLRcx8q+u1LFbLNTAE5TPn36E2PzE3oAAUau9GC5o+HPW7VEfArB+djm0Xv5XnENMPDMiwlW+MYon8V2/NMqTr6Tzpuv3TsMrPQRJwT+0cdoQEKTVT2ibbsQJqtwy08vED8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oAHsEEw4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oAHsEEw4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9682FC2BCB2; Thu, 23 Apr 2026 06:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926122; bh=VmQM9a+zK9JXLT/ZqXNqPpS4ogJdqKXImO7k8ArmbHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oAHsEEw4l6N80Qwi5P8WCjYE8RTl3+/7Bpi/ukmmOzXfz46ZME6MJ1k7+bBa5HZRY SLF0tDxF3W05LpeD/p+dl0aycum3TUBj4D1PnSgxV5QLuE36TJsXUNuZ358PGTWghT eDwE5OCmTCzoVWPrL+hTTtfi6KKLSbfj/3lZSPzBChZlcFOhrOCe4kbWJEe9vRxDeI w5o287ZeiFUZh/nKI20i2MeAw83o2wNhTPnJdl2ec8YA98jmEuTts0oze5LFF7YcqW BVeyljLnEB38tFScRlcQqTZBTjTFvWByVB/yb8OSLkXJG0ND7+UygjenFCH7BTmskf Mvmf15uZDD1fg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 15/16] selftests: tls: add mptcp test cases Date: Thu, 23 Apr 2026 14:33:08 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch introduces MPTCP test cases for the TLS fixture. These "mptcp" variants are configured to create MPTCP sockets specifically for MPTCP TLS testing purposes. The default limit of 1024 for file descriptor values is too low for the newly added MPTCP tests, causing accept() to fail when the fd number exceeds 1024. Raise the limit to 4096 to avoid test failures. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/tls.c | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index 8bedc2cde763..c7922b9f6812 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -411,6 +411,102 @@ FIXTURE_VARIANT_ADD(tls, 12_aria_gcm_256) .cipher_type =3D TLS_CIPHER_ARIA_GCM_256, }; =20 +FIXTURE_VARIANT_ADD(tls, 12_aes_gcm_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_AES_GCM_128, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_aes_gcm_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_AES_GCM_128, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 12_chacha_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_CHACHA20_POLY1305, + .fips_non_compliant =3D true, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_chacha_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_CHACHA20_POLY1305, + .fips_non_compliant =3D true, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_sm4_gcm_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_SM4_GCM, + .fips_non_compliant =3D true, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_sm4_ccm_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_SM4_CCM, + .fips_non_compliant =3D true, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 12_aes_ccm_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_AES_CCM_128, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_aes_ccm_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_AES_CCM_128, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 12_aes_gcm_256_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_AES_GCM_256, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_aes_gcm_256_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_AES_GCM_256, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 13_nopad_mptcp) +{ + .tls_version =3D TLS_1_3_VERSION, + .cipher_type =3D TLS_CIPHER_AES_GCM_128, + .nopad =3D true, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 12_aria_gcm_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_ARIA_GCM_128, + .mptcp =3D true, +}; + +FIXTURE_VARIANT_ADD(tls, 12_aria_gcm_256_mptcp) +{ + .tls_version =3D TLS_1_2_VERSION, + .cipher_type =3D TLS_CIPHER_ARIA_GCM_256, + .mptcp =3D true, +}; + static bool is_mptcp_enable(struct __test_metadata *_metadata) { char buf[16] =3D { 0 }; --=20 2.51.0 From nobody Tue May 5 11:27:58 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 349D41DC9B5 for ; Thu, 23 Apr 2026 06:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926125; cv=none; b=gYp7OHChI20PyGDpxtan5KKF7V/m825mdtnQUvUe6p5Khtk4txwKdcP9lgiGsshBEm2lBF0j8bSSkzr7dZP0bGurgxtI+GNRTk5/8V8yYumcuFIU6GSJ/aClgYJQW2B7M6SIed7GHPkN2vY0zemon+V0qG4DKP8VlIhuaTPniBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776926125; c=relaxed/simple; bh=IYmzj3X50jh3wdEINOsNrgDyrehEPz9IfS4ohbE91QQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kocidFg895Vo8D5aUkLlPrGeSOxY4N9tJMrLfiVq05xKlHwgtKczDnWnDWBLGUFfDvHjUIY99TWgM1XCMyJ0xowge3G85tJn4DplW0+e++EcfJoPbA6wEV6AFzP+hv163MZ3gCD7o37gf4xuQ5pDkenw7abbXd8lsssgJId4YKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d8sngqbz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d8sngqbz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70F28C2BCB2; Thu, 23 Apr 2026 06:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776926124; bh=IYmzj3X50jh3wdEINOsNrgDyrehEPz9IfS4ohbE91QQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d8sngqbzX8jKfaGOc43OCgElRyQEbJHCaWsDoFPTD4J9+nba+GhHggo69ugiEKAFb lkppre1O2O7qLlgsvjZUtwDiPDIfpwPfpM7RGYpt8BhnfSwfY6ez5S+WWzYcKMWva5 Rjnya4LSRE7eckfGQP34/qT1sy37B3q6a6pyTMK0o5RZiz5CpFtfyIZNeYD6/5sucy jigqi7Q3BnZoGUl8K/YZorrPbpbWXjh10O/7PfY7MeIIGkSB8cJ8awvZfVwiY9BvbN GR8KZl3yv7vkdZ5PiJgSBdpdteDOuYjFI/q2AX8zPqEUYZcOh00BWqmsmG9rY7ZpQR INQbcJGscrYRA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [PATCH mptcp-next v16 16/16] selftests: mptcp: cover mptcp tls tests Date: Thu, 23 Apr 2026 14:33:09 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The mptcp tests for tls.c is available now, this patch adds mptcp_tls.sh to test it in the MPTCP CI by default. Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/.gitignore | 1 + tools/testing/selftests/net/mptcp/Makefile | 2 + tools/testing/selftests/net/mptcp/config | 5 ++ .../testing/selftests/net/mptcp/mptcp_tls.sh | 62 +++++++++++++++++++ tools/testing/selftests/net/mptcp/tls.c | 1 + 5 files changed, 71 insertions(+) create mode 100755 tools/testing/selftests/net/mptcp/mptcp_tls.sh create mode 120000 tools/testing/selftests/net/mptcp/tls.c diff --git a/tools/testing/selftests/net/mptcp/.gitignore b/tools/testing/s= elftests/net/mptcp/.gitignore index 833279fb34e2..f6defec6eeb5 100644 --- a/tools/testing/selftests/net/mptcp/.gitignore +++ b/tools/testing/selftests/net/mptcp/.gitignore @@ -4,4 +4,5 @@ mptcp_diag mptcp_inq mptcp_sockopt pm_nl_ctl +tls *.pcap diff --git a/tools/testing/selftests/net/mptcp/Makefile b/tools/testing/sel= ftests/net/mptcp/Makefile index 22ba0da2adb8..f7c959a25b3b 100644 --- a/tools/testing/selftests/net/mptcp/Makefile +++ b/tools/testing/selftests/net/mptcp/Makefile @@ -14,6 +14,7 @@ TEST_PROGS :=3D \ mptcp_connect_splice.sh \ mptcp_join.sh \ mptcp_sockopt.sh \ + mptcp_tls.sh \ pm_netlink.sh \ simult_flows.sh \ userspace_pm.sh \ @@ -25,6 +26,7 @@ TEST_GEN_FILES :=3D \ mptcp_inq \ mptcp_sockopt \ pm_nl_ctl \ + tls \ # end of TEST_GEN_FILES =20 TEST_FILES :=3D \ diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selft= ests/net/mptcp/config index 59051ee2a986..e8e852e0a842 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -34,3 +34,8 @@ CONFIG_NFT_SOCKET=3Dm CONFIG_NFT_TPROXY=3Dm CONFIG_SYN_COOKIES=3Dy CONFIG_VETH=3Dy +CONFIG_TLS=3Dm +CONFIG_CRYPTO_ARIA=3Dm +CONFIG_CRYPTO_CCM=3Dm +CONFIG_CRYPTO_CHACHA20POLY1305=3Dm +CONFIG_CRYPTO_SM4_GENERIC=3Dm diff --git a/tools/testing/selftests/net/mptcp/mptcp_tls.sh b/tools/testing= /selftests/net/mptcp/mptcp_tls.sh new file mode 100755 index 000000000000..ea366d149a20 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptcp_tls.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(dirname "${0}")/mptcp_lib.sh" + +ret=3D0 +ns1=3D"" + +# This function is used in the cleanup trap +#shellcheck disable=3DSC2317,SC2329 +cleanup() +{ + if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then + kill "$pid" 2>/dev/null + wait "$pid" 2>/dev/null + fi + + mptcp_lib_ns_exit "$ns1" +} + +init() +{ + local max=3D"${1:-4}" + + mptcp_lib_ns_init ns1 + + mptcp_lib_pm_nl_set_limits "$ns1" "$max" "$max" + + local i + for i in $(seq 1 "$max"); do + mptcp_lib_pm_nl_add_endpoint "$ns1" \ + "127.0.0.1" flags signal port 1000"$i" + done +} + +trap cleanup EXIT + +mptcp_lib_check_mptcp +# Temporarily set max to '0' to disable multipath testing, +# as it depends on "mptcp: fix stall because of data_ready" series of fixe= s. +# It will be re-enabled together with that series later as a squash-to pat= ch. +init 0 + +ip netns exec "$ns1" ./tls -v 12_aes_gcm_mptcp \ + -v 13_aes_gcm_mptcp \ + -v 12_chacha_mptcp \ + -v 13_chacha_mptcp \ + -v 13_sm4_gcm_mptcp \ + -v 13_sm4_ccm_mptcp \ + -v 12_aes_ccm_mptcp \ + -v 13_aes_ccm_mptcp \ + -v 12_aes_gcm_256_mptcp \ + -v 13_aes_gcm_256_mptcp \ + -v 13_nopad_mptcp \ + -v 12_aria_gcm_mptcp \ + -v 12_aria_gcm_256_mptcp & +pid=3D$! +wait $pid +ret=3D$? + +mptcp_lib_result_print_all_tap +exit $ret diff --git a/tools/testing/selftests/net/mptcp/tls.c b/tools/testing/selfte= sts/net/mptcp/tls.c new file mode 120000 index 000000000000..724b1f047c89 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/tls.c @@ -0,0 +1 @@ +../tls.c \ No newline at end of file --=20 2.51.0