From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 CE149372B2B for ; Thu, 21 May 2026 09:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355813; cv=none; b=ftA37url+MIgb5ohyWKOkCq9oR/asOw6T6OQhGiNRvabv/1sfgfJOOj4wT/y3cDHLJyovOuvGHl6TYJ2sJS5o0jYzqiLTgLlte0fyHW3kfwEn5cjquC+mJpejZFY2OnnICeC0ayMDfUKXS3eL8OGz283W2IZBklN9M8pobE0R0c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355813; c=relaxed/simple; bh=SK7o0RKpah/74MrovwlBpx/5nq1PfO4MHGCKDZ+h76k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IppTwek3QcV28jn21pLRtkNzzkTAbc/hKjuIQghjwTB88wOD+IXWu3o4NWUOwBn4LHaoJeuaHq3w5+ZxjI8PS0B0lp4iEw3tjQGsq1fGvjMNUGHTBFB8XJRqDL350HLiWCYEASXlAgkIzerJOwoBatmQfNRTV96frB1T7aqgukg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OTGbXah1; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OTGbXah1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DF731F00A3B; Thu, 21 May 2026 09:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355811; bh=is5KJMg9mMegWAjEy4+61Xe+MY4/re5fvurQyThmxno=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OTGbXah1EaOAsmd4PrIPZuovthgV6HpJ0TIzC330DmdcqEj3TzEy83sL3znsciIry LXVztnC3QiGlxoU4VHbqlH08and0m8FR3Y/FrUFn2v1ZtF9JbLC3BlRnpEpeDbZ3oq 5AjHSDjwYoLsi5eynS4u5KHK3FdBZ9TnwQaX2N8o5V8dChZ/yDSsjZdvS4to120P4M PsiCU8NvujFr0I4Twd/Oe0kmb8eosPrURkv4bwMRxxdDUWFIQEV0iy6EoO3QbWc0mV YDP/WniGd2Ak86lYtSu+XTcQsJMePOQrniL3oHm7k5+EJkeSYh9jy1h8RJAPksL5fT qcB/wKSb/q0+A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 01/15] tls: add per-protocol cache to support mptcp Date: Thu, 21 May 2026 17:29:39 +0800 Message-ID: <2fb57d7b3cdd2dcd88b3eb95516fa4a4467d939f.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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 | 11 ++++ include/net/tls_toe.h | 3 +- net/tls/tls.h | 3 +- net/tls/tls_main.c | 136 +++++++++++++++++++++++++++++------------- net/tls/tls_toe.c | 7 ++- 5 files changed, 116 insertions(+), 44 deletions(-) diff --git a/include/net/tls.h b/include/net/tls.h index ebd2550280ae..d8a7fbda4fec 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -220,6 +220,15 @@ struct tls_prot_info { u16 tail_size; }; =20 +struct tls_proto { + refcount_t refcnt; + struct list_head list; + int ip_ver; + const struct proto *prot; + struct proto prots[TLS_NUM_CONFIG][TLS_NUM_CONFIG]; + struct proto_ops proto_ops[TLS_NUM_CONFIG][TLS_NUM_CONFIG]; +}; + struct tls_context { /* read-only cache line */ struct tls_prot_info prot_info; @@ -257,6 +266,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 12f44cb649c9..3a16047c3a8f 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..30dd95fff53e 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -119,23 +119,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_SPINLOCK(tls_proto_lock); 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, + int ip_ver) +{ + struct tls_proto *proto, *ret =3D NULL; + + spin_lock_bh(&tls_proto_lock); + list_for_each_entry(proto, &tls_proto_list, list) { + if (proto->prot =3D=3D prot && proto->ip_ver =3D=3D ip_ver) { + if (refcount_inc_not_zero(&proto->refcnt)) + ret =3D proto; + break; + } + } + spin_unlock_bh(&tls_proto_lock); + return ret; +} + +static void tls_proto_cleanup(void) +{ + struct tls_proto *prot, *tmp; + + spin_lock_bh(&tls_proto_lock); + list_for_each_entry_safe(prot, tmp, &tls_proto_list, list) { + list_del(&prot->list); + kfree(prot); + } + spin_unlock_bh(&tls_proto_lock); +} + 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 + /* Ensure sk->sk_socket->ops is not visible before icsk_ulp_data. + * Pairs with the rcu_assign_pointer() release in tls_ctx_create(). + */ + smp_store_release(&sk->sk_socket->ops, + &proto->proto_ops[ctx->tx_conf][ctx->rx_conf]); WRITE_ONCE(sk->sk_prot, - &tls_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->prots[ctx->tx_conf][ctx->rx_conf]); } =20 int wait_on_pending_writer(struct sock *sk, long *timeo) @@ -314,6 +345,16 @@ static void tls_write_space(struct sock *sk) ctx->sk_write_space(sk); } =20 +static void tls_proto_put(struct tls_proto *proto) +{ + if (refcount_dec_and_test(&proto->refcnt)) { + spin_lock_bh(&tls_proto_lock); + list_del(&proto->list); + spin_unlock_bh(&tls_proto_lock); + kfree(proto); + } +} + /** * tls_ctx_free() - free TLS ULP context * @sk: socket to with @ctx is attached @@ -327,6 +368,11 @@ void tls_ctx_free(struct sock *sk, struct tls_context = *ctx) if (!ctx) return; =20 + if (ctx->proto) { + tls_proto_put(ctx->proto); + ctx->proto =3D NULL; + } + memzero_explicit(&ctx->crypto_send, sizeof(ctx->crypto_send)); memzero_explicit(&ctx->crypto_recv, sizeof(ctx->crypto_recv)); mutex_destroy(&ctx->tx_lock); @@ -910,17 +956,24 @@ 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; =20 + if (!refcount_inc_not_zero(&proto->refcnt)) + return NULL; + ctx =3D kzalloc_obj(*ctx, GFP_ATOMIC); - if (!ctx) + if (!ctx) { + tls_proto_put(proto); return NULL; + } =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 +1021,32 @@ 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); - } + proto =3D tls_proto_find(prot, ip_ver); + 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_obj(*proto, GFP_KERNEL); + if (!proto) + goto out; + + spin_lock_bh(&tls_proto_lock); + proto->ip_ver =3D ip_ver; + proto->prot =3D prot; + refcount_set(&proto->refcnt, 1); + build_protos(proto->prots, prot); + build_proto_ops(proto->proto_ops, + sk->sk_socket->ops); + list_add(&proto->list, &tls_proto_list); + + spin_unlock_bh(&tls_proto_lock); +out: + return proto; } =20 static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], @@ -1046,13 +1096,16 @@ 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)) return 0; #endif =20 @@ -1062,12 +1115,14 @@ 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) { + tls_proto_put(proto); 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) { rc =3D -ENOMEM; goto out; @@ -1265,6 +1320,7 @@ static int __init tls_register(void) static void __exit tls_unregister(void) { tcp_unregister_ulp(&tcp_tls_ulp_ops); + tls_proto_cleanup(); tls_strp_dev_exit(); tls_device_cleanup(); unregister_pernet_subsys(&tls_proc_ops); diff --git a/net/tls/tls_toe.c b/net/tls/tls_toe.c index 825669e1ab47..d4cd3974414a 100644 --- a/net/tls/tls_toe.c +++ b/net/tls/tls_toe.c @@ -48,13 +48,16 @@ static void tls_toe_sk_destruct(struct sock *sk) struct inet_connection_sock *icsk =3D inet_csk(sk); struct tls_context *ctx =3D tls_get_ctx(sk); =20 + WRITE_ONCE(sk->sk_prot, ctx->sk_proto); + ctx->sk_destruct(sk); /* Free ctx */ rcu_assign_pointer(icsk->icsk_ulp_data, NULL); 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 +66,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 47700376462 for ; Thu, 21 May 2026 09:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355814; cv=none; b=dL8RG9lqFeR21ARUjTTcvYERz5fSoJuNpgIMOCvrJYtHS1aEurw6wjy5FxyanJDBvsqyErktUWN9vn+Mh4RbtwtJ1yHVx+Zr/EkTMJu7UfWJd6rNwEX90PgvBntzB7cjWgAoV1nNoJKiR9E/Q1sSQ6g25rQklGResHc5jx2Ioxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355814; c=relaxed/simple; bh=xZKQkXN/uQsI9B0V7nsk3uVnZebXJ7YR4xQ0BW4ijF0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tPK6eniS2qI8m7DQbvRjo02TlX5/ZfOTH+PmIdRgzNI5t2dFnUdoxhdohiwxsjxwWIYaJePaGGcoRYzHQHYXYMYaxKwd9sOapYJLiNrWEtepk6LCu8OpnGfUNK9O/YDMvgA17ab8B2xM1Os7SHtSPQe/taz80Wowi0m+o3g/Llc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ffb/eRGo; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ffb/eRGo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F22AB1F000E9; Thu, 21 May 2026 09:30:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355813; bh=E/l36cGMAx/PIN1/dhkMyEcP9K6BP5u2PM+/XbU15d8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ffb/eRGo2D7WjVAmnWdaxJxXG9ZdHzPa8sy1kXlD2bUy3Iint2Z2e+kEUPkdhibfg ZUk0wCsLku04+UdWHm2m04ahHy2KfB6ggFW4kKTimW92Qa4RGrzPV98WB2MB7g9ZsQ MEBTCs9NOws7uw9TT2y31syak7ZH/2P3nWo7qv+XSfNFvMazr2ZZu8eCodKAVqdQbV Ua8qSjoDFKCbuCoX2Hcuk8WdpHoqEPWHuOnDgJXmmbrERRBuvERINu0ctYojvv3x1E Ff8P8J239RFfFDQTX4dGoMAOHSD/VcytaDgRsFgMx7hI65F5trTuwjuKyw9F3OZBOt MAUhcmzJqxgFw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 02/15] tls: introduce struct tls_prot_ops Date: Thu, 21 May 2026 17:29:40 +0800 Message-ID: <2dabeca91e31bd148049b46696ca0d37e234b22a.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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_register(). 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, 120 insertions(+), 1 deletion(-) diff --git a/include/net/tls.h b/include/net/tls.h index d8a7fbda4fec..fa67ff40394d 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 { + struct module *owner; + int protocol; + 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); +}; + struct tls_proto { refcount_t refcnt; struct list_head list; diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 30dd95fff53e..63bde77317c3 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -120,6 +120,7 @@ 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 LIST_HEAD(tls_proto_list); +static LIST_HEAD(tls_prot_ops_list); static DEFINE_SPINLOCK(tls_proto_lock); static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], const struct proto *base); @@ -153,6 +154,22 @@ static void tls_proto_cleanup(void) spin_unlock_bh(&tls_proto_lock); } =20 +static struct tls_prot_ops *tls_prot_ops_find(int protocol) +{ + struct tls_prot_ops *ops, *ret =3D NULL; + + spin_lock_bh(&tls_proto_lock); + list_for_each_entry(ops, &tls_prot_ops_list, list) { + if (ops->protocol =3D=3D protocol) { + ret =3D ops; + break; + } + } + spin_unlock_bh(&tls_proto_lock); + + return ret; +} + void update_sk_prot(struct sock *sk, struct tls_context *ctx) { struct tls_proto *proto =3D ctx->proto; @@ -1291,6 +1308,82 @@ 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; + + if (tls_prot_ops_find(ops->protocol)) + return -EEXIST; + + spin_lock(&tls_proto_lock); + list_add_tail(&ops->list, &tls_prot_ops_list); + spin_unlock(&tls_proto_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_proto_lock); + list_del(&ops->list); + spin_unlock(&tls_proto_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 { + .owner =3D THIS_MODULE, + .protocol =3D IPPROTO_TCP, + .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; @@ -1303,13 +1396,19 @@ static int __init tls_register(void) if (err) goto err_pernet; =20 - err =3D tls_device_init(); + err =3D tls_register_prot_ops(&tls_tcp_ops); if (err) goto err_strp; =20 + err =3D tls_device_init(); + if (err) + goto err_ops; + tcp_register_ulp(&tcp_tls_ulp_ops); =20 return 0; +err_ops: + tls_unregister_prot_ops(&tls_tcp_ops); err_strp: tls_strp_dev_exit(); err_pernet: @@ -1320,6 +1419,7 @@ static int __init tls_register(void) static void __exit tls_unregister(void) { tcp_unregister_ulp(&tcp_tls_ulp_ops); + tls_unregister_prot_ops(&tls_tcp_ops); tls_proto_cleanup(); tls_strp_dev_exit(); tls_device_cleanup(); --=20 2.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 884DA36A372 for ; Thu, 21 May 2026 09:30:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355816; cv=none; b=am+copzqblIBvF0rXASVvFS+BcgCeGY86gHthXVRnaFUGIL7mPb6NoJokxu7Js+p+8SNpXmxlDivJ+zPMU89ut0aPocpDL1iN/jEin2oR4VUm6fLxii71PxOppuC93YD88ZHBh/Dtj0bPi6teCuod94VGmJ/6hii3uWxa0vl6/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355816; c=relaxed/simple; bh=onmk/NJi+yECT2j59oXMoNdbezw8oVvB8cG0lqa5Hzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lX61X2fFerU1mX+2B/ZxWwgaGb950LZnDb8MSK8HGkVZmr7TSqot2zxy/ZpD1T9MvmoXzwzY0NRfmHDwBSTvYWk/s3YRkxyj0gdEh74rNQXccAIqxwIWgXCBOUpVAZMLNchO8+Ra8N1EeRspT/sbjjwldPtPwqsBqP3BXtz8el0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lrh+LV+1; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lrh+LV+1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD1361F00A3B; Thu, 21 May 2026 09:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355815; bh=rb7FoepQBKAkxFyva2VRBwsB3TrlHCO6f6y/SfJ3Iew=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lrh+LV+1dNGQRSFWlOcTRdTHM1mIhd8uty0HpWVR+aUsCAtHBFgZIBNijWpd1OHSL diMAStyOufWWNRnrGKTfLltToqa3pnInkOrpAGawRQ3M0s7qLqGPHwXLjFg7qMl96V 2YadO+NAMu/L7lzFmLmI93MU3q+VNqTCf3FC8bm3rZybNfGOEDE1MLzAwKIuAN2gvI 0YGsTsyzwK9Ua35GtgJlAT2IMA4qS9DAUN6N37PCsV4fduzes58kW6YWDeGkOcfjTr qaq/RDHdL0/FMqGq/nvTI47BFNMqU65AUpC5i/fZNEVAfB9c3cL03Y/jwJQOsRMrAc 37tHbswxZl32g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 03/15] tls: add tls_prot_ops pointer to tls_proto Date: Thu, 21 May 2026 17:29:41 +0800 Message-ID: <8b56336a3f5a6b8b1b2fac182acefec394422182.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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. The places originally calling TLS-specific helpers have now been modified to indirectly invoke them via 'ops' pointer in tls_proto. In tls_build_proto(), proto->ops is assigned either 'tls_mptcp_ops' or 'tls_tcp_ops' based on the socket protocol. 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 | 19 ++++++++++++++----- net/tls/tls_strp.c | 33 ++++++++++++++++++++++----------- net/tls/tls_sw.c | 6 ++++-- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/include/net/tls.h b/include/net/tls.h index fa67ff40394d..c15d36896814 100644 --- a/include/net/tls.h +++ b/include/net/tls.h @@ -244,6 +244,7 @@ struct tls_proto { struct list_head list; int ip_ver; const struct proto *prot; + const struct tls_prot_ops *ops; struct proto prots[TLS_NUM_CONFIG][TLS_NUM_CONFIG]; struct proto_ops proto_ops[TLS_NUM_CONFIG][TLS_NUM_CONFIG]; }; diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 63bde77317c3..6df4503e0e9d 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -236,13 +236,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) { @@ -368,6 +368,7 @@ static void tls_proto_put(struct tls_proto *proto) spin_lock_bh(&tls_proto_lock); list_del(&proto->list); spin_unlock_bh(&tls_proto_lock); + module_put(proto->ops->owner); kfree(proto); } } @@ -472,14 +473,14 @@ 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); + 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 @@ -1042,19 +1043,27 @@ static struct tls_proto *tls_build_proto(struct soc= k *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 proto =3D tls_proto_find(prot, ip_ver); if (proto) goto out; =20 + ops =3D tls_prot_ops_find(sk->sk_protocol); + if (!ops || !try_module_get(ops->owner)) + goto out; + proto =3D kzalloc_obj(*proto, GFP_KERNEL); - if (!proto) + if (!proto) { + module_put(ops->owner); goto out; + } =20 spin_lock_bh(&tls_proto_lock); proto->ip_ver =3D ip_ver; proto->prot =3D prot; + proto->ops =3D ops; refcount_set(&proto->refcnt, 1); build_protos(proto->prots, prot); build_proto_ops(proto->proto_ops, diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c index c72e88317627..869e2916db5a 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 =3D tls_get_ctx(strp->sk); struct sk_buff *skb; =20 if (strp->copy_mode) @@ -132,7 +133,7 @@ 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->proto->ops->read_done(strp->sk, strp->stm.full_len); strp->copy_mode =3D 1; =20 return 0; @@ -376,6 +377,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 +385,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 +401,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 +437,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 +453,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 +464,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 +487,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 +495,8 @@ 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 964ebc268ee4..9517f5cb091b 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1987,7 +1987,8 @@ tls_read_flush_backlog(struct sock *sk, struct tls_pr= ot_info *prot, 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_get_ctx(sk)->proto->ops->inq(sk) > max_rec) return false; =20 *flushed_at =3D done; @@ -2516,7 +2517,8 @@ int tls_rx_msg_size(struct tls_strparser *strp, struc= t sk_buff *skb) } =20 tls_device_rx_resync_new_rec(strp->sk, data_len + TLS_HEADER_SIZE, - TCP_SKB_CB(skb)->seq + strp->stm.offset); + tls_ctx->proto->ops->get_skb_seq(skb) + + strp->stm.offset); return data_len + TLS_HEADER_SIZE; =20 read_failure: --=20 2.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8056715E8B for ; Thu, 21 May 2026 09:30:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355818; cv=none; b=qNekDBasOIj1X9zr3uDvVgZBxHxzHw+3zCvCCWuVc43U6OjCWICHWnBd1e8PlHDEBNAWQkShLEq6VlEToT27BogkAVthZW1oSlc7F02opd+Qf3P+KCWbHnMEGnxV+kYfxKQedJmaVAh9XMYjMwBjygiWSVYt3UsRvkrHNQnUR+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355818; c=relaxed/simple; bh=QZcqk7MR7wdDmplYMQxEXzAQLtnPXnYRFCFqR7Dcz0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NkskoGD0Qp3AJBOQFZKqBYp0igA7xXfKLBZvL0gywixdImgavggkZI+xSOu5Yarif3smESgF77pFAwhpeDazPbw5rpH5xTC9/fkyRleNSYpbEGuo+fWYnlKDq1kas6lx/fJz0WqM+xFpw6jSYXjR2/EerN7qz7ovU8XyQKWx3Gg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H726t3oN; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H726t3oN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B92401F000E9; Thu, 21 May 2026 09:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355817; bh=LA4mZqUMFsnjmZO2jsCJMgKZNRE5xKZzbra1tRMV0Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=H726t3oNN01NFQ+War6y8zNLnpuCXV2K2Wg+sgc0uYWOSm9zqmNlZE03yj10jI5M3 U/owuVsGwlJ9mEW3BUBI4zoIy3FV+LJbTEJdxx3RU2QURDNkFDzmgTytKekZkejuOM 48EqxJefKuT5jge2fRa/OrvBj84X3j5h9/gbjmgmF7qDuMAM/lSmeR79DyMMRUqkuU xtmPLc7EGh+q6V6icrK6z1RAw0TMJ2c+9Y6n94TCj6EZgho4M9Pc1h6zJPBkZRA4Yi Z3crscEheXGjdPI7dq0jBNV+Hey8uUL7+ZsH82+LkjEnlDt07WznGDvD5HvhUkfMGW LgJbECtckaJkg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Gang Yan , Geliang Tang Subject: [RFC mptcp-next v19 04/15] mptcp: update mptcp_check_readable Date: Thu, 21 May 2026 17:29:42 +0800 Message-ID: X-Mailer: git-send-email 2.53.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 ce8372fb3c6a..a36ef97155a7 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3276,9 +3276,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) @@ -4342,7 +4344,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 662EB34E777 for ; Thu, 21 May 2026 09:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355820; cv=none; b=HFLW/cEhVTx9e5KuoE7jTuG+QOXw56EzpUpuV8FSeBYNG5068L29p17ZXhRUH19ds5z5v9zzopz19+DOew1tT/ECg0nORVnffT/IJR6XI2VHBuCNUoAuA/Vjh3kIePy8E1Hc1IlHmeVMCOv+mL0VAOs/ngdw+YLb/mM9yAdOXUQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355820; c=relaxed/simple; bh=b7nhkfiY6tkSWKUtQhIzrPiDERZDt9I3w2eA6FIQTBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uhs1XwL3pjmzUzWp3KjgLG9Oiuiu8OzQaOe4v1u8Hmdl9O2fDjR+gKjt2ncQopgStYTEXO8Bdo1XAKgw01Uja4monkeI3/HfGFkzDXCWoUz4dPXQci5lAB7hE6+5vUhGUlfovmXGiyI+hMsvWfzSMnmVIJUVBIh2s4Bge2wXZQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OytvW2a8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OytvW2a8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8EDF1F00A3B; Thu, 21 May 2026 09:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355819; bh=HR8eiBpEgsunfrDWdNQAXbb23s1tHiH5jbsstw33kB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OytvW2a8UgE6B+PJjtMWn5hIkNLNLjYsf/yP7eCqiNG/uXIhpni6MJmxEsd+DoZMw zaNglbD4T1LrYrSLUN5WtN6i0/kxFK4IqYL8QAlsRw62gfcGF9qyeIE5QqEiU5YKV8 fnQ7KoNyE2EDQf+RzhKVygNBAQ12Q150IR1xoKW/xIF3582ZZK6ichA5mvtEZ8JLxA L1TqKuxuRJPL4rnCsGt/rGXh4EmY4oPmhZxUxnfePKYNx1JBOcrooE8uN0oHKDm/x6 IYmMwKjg9KQ+mIZPpnbYgtR3JXk9bpWNrfTwbFzDQy+u23FJHUkBZ/hLzN/XUzj6Y2 M5Uh0I3JyPCXA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 05/15] mptcp: implement tls_mptcp_ops Date: Thu, 21 May 2026 17:29:43 +0800 Message-ID: <253b88077519ea25338cfa689b26cd7576fb2f7a.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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'. 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. This is required because TLS may call lock_is_held from softirq context with bh_lock_sock held. Checking both conditions ensures TLS always defers to workqueue when the MPTCP data lock is held, avoiding deadlock. 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 | 121 +++++++++++++++++++++++++++++++++++++++++-- net/mptcp/protocol.h | 1 + net/tls/tls_main.c | 13 +++++ 6 files changed, 141 insertions(+), 6 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 f063eccbbba3..1c8201f69ef1 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -849,6 +849,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 a058f350a759..bdad459e6605 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1097,9 +1097,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 && @@ -1112,6 +1112,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 a36ef97155a7..505eac23f35d 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "protocol.h" #include "mib.h" @@ -1909,7 +1910,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; @@ -1921,8 +1922,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) || @@ -2038,7 +2037,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: @@ -2049,6 +2047,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) @@ -4726,3 +4735,107 @@ int __init mptcp_proto_v6_init(void) return err; } #endif + +static int mptcp_inq(struct sock *sk) +{ + const struct mptcp_sock *msk =3D mptcp_sk(sk); + const struct sk_buff *skb; + + if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) + return 0; + + skb =3D skb_peek(&sk->sk_receive_queue); + if (skb) { + u64 answ =3D READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq; + + if (answ >=3D INT_MAX) + answ =3D INT_MAX; + + /* Subtract 1, if FIN was received */ + if (answ && + (sk->sk_state =3D=3D TCP_CLOSE || + (sk->sk_shutdown & RCV_SHUTDOWN))) + answ--; + + return (int)answ; + } + + return 0; +} + +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 { + .owner =3D THIS_MODULE, + .protocol =3D IPPROTO_MPTCP, + .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 6df4503e0e9d..fcf4bc399cf9 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -1409,6 +1409,12 @@ static int __init tls_register(void) if (err) goto err_strp; =20 +#ifdef CONFIG_MPTCP + err =3D tls_register_prot_ops(&tls_mptcp_ops); + if (err) + goto err_tcp; +#endif + err =3D tls_device_init(); if (err) goto err_ops; @@ -1417,6 +1423,10 @@ static int __init tls_register(void) =20 return 0; err_ops: +#ifdef CONFIG_MPTCP + tls_unregister_prot_ops(&tls_mptcp_ops); +err_tcp: +#endif tls_unregister_prot_ops(&tls_tcp_ops); err_strp: tls_strp_dev_exit(); @@ -1428,6 +1438,9 @@ static int __init tls_register(void) static void __exit tls_unregister(void) { tcp_unregister_ulp(&tcp_tls_ulp_ops); +#ifdef CONFIG_MPTCP + tls_unregister_prot_ops(&tls_mptcp_ops); +#endif tls_unregister_prot_ops(&tls_tcp_ops); tls_proto_cleanup(); tls_strp_dev_exit(); --=20 2.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 5F933372ECE for ; Thu, 21 May 2026 09:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355822; cv=none; b=S7vH9bzS8dOZTbpBq5Ad3ImiQuijet49OnWNSsog+9kfy8/7CT6PI5G9oegbBnJN4de/v3hirgLy4M/4BUCjancEFQZNa72ik3mycSeTIgk3apHfbC78PbPCr5mFUwlnNZHlNbKEPbC0OAoWaCYPk2cIHxVizYQoHTXZL23bvYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355822; c=relaxed/simple; bh=hrtN9uQddVM0lcmO9wc2o6AU3IK9pMQ70Z6iH5TPITU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mxJ9016VWBpSHL1g610jFCIY1KneqlV6N5AfR7p4dnml2kQuafc6oTlp/rbbDvHgdqe4iP0Xazw2jBvfGv9iWthHXyHH4SPaP7bH8338qo7IiwxByvWjHyIsDbjLiKC48xbDFFMq0onvnwVcpmWAf1v6CDL1IDur4cjCS1NrBUQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n2afZhzD; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n2afZhzD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9A3FD1F000E9; Thu, 21 May 2026 09:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355821; bh=NkVnihIy31dIAYz2JOSqK3T3ETJqUTTxorUyuRboKN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=n2afZhzDdiZT9BIcFHZQkwAb/5Pjn1ryJNuVTeaG7CaJaTZRJUuQ6fUwoJJ06jdVC JoCGOsD85uHUk7zhGp4zq5agLJItmOJeGHvwRNndSg8qzcTBvXmOVceg4IZT4J4BVv 3xdkIffOf8S33lIdy6SrjKxldgSP6KdZoKlSe4nAQeQ0mNKUdC2vxRVuSs1paDPuzH pmhJcuN5yFOYCFKUxDI5LNP3iOzB/sAlrsBve1mxY5Oz/UCfYLgjGFXykokwVnnhiB rf9/5oxNFH5EIgkRvaN/9Vla0nvwxXgXxz5kJZqQO4opBTvUVDwofVTOa55Zp1p38T 9uik8hTqhzmoA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 06/15] tls: disable device offload for mptcp sockets Date: Thu, 21 May 2026 17:29:44 +0800 Message-ID: <0cc056536f7c3686926bc5a99d3306bf7ab52529.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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 741aef09bfd3..06f45edffb5f 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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 1745937701C for ; Thu, 21 May 2026 09:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355824; cv=none; b=PkK6xrVneV1hbB1KvJpf/y+LkaHfHzVoZJFOa0JFAVVVan1hp2+2h2bBcyTZ0MQZVHD2YNwcNUCfemIPaAHgkZaTKXCJLB4505pJDvjg3CtTbnbKeTr8NDjurWBfLeeFoTM1JfvG2Umr0cijaHJ1CG44XUg0UwD8u/Mj0kw8oiQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355824; c=relaxed/simple; bh=PRsRtQMbqPSJTuLPkh6J0qJ8JmoMlCxZRynscVYYKZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pzDHaq2gM4poytw5NTPwdsvOPPno05QL3DaKPrdYJyAxKKnbpu2uSHIGxKQrXqQ/ER0xpoK9x82N4kd8IWRkLi1rDFO9rCAK3eWGjT2YPrMlVoKz2aUyhxDN3rz+W8QZt003iZVcHV85oIxbO504ix/pfpe2YlkT8tU1vx/nAe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RSENQgBB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RSENQgBB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7CEE1F00A3C; Thu, 21 May 2026 09:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355822; bh=yeBAIObCCD0rLzFh95LhJ65L8e7GY3s3EbDpIRbF86c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RSENQgBB2t6R556Kno+4MEPJonca7VcCP4/dHJFIdV48+BFvi+CJhxDX5ppJFlrLf Q42NNL7H5fqrJ+JD5bSd84PA41ENcmkSTHeTgRvTfEMryN42hX6mfx95IIwhxCVm2V j/gga6imeHwamq7+g11vlRuqeYpnSnt2C2tfC3pbaI9Qtibmoc7UL7bj0J9vy7RZuO qmqS4NpE2j9uhz4qBJvyoZ3531tv4YvQek4bYOz34Rzy5dTg+HLkaAhmPW1D0EoVrV vy6mjYGeig14yQW/w5phRKRJCGsdUUUAF6GD4Eu48SWtvUZByFf1D+CPNxYFwaBG36 K76AtY04JMwHw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 07/15] mptcp: update ulp getsockopt for tls support Date: Thu, 21 May 2026 17:29:45 +0800 Message-ID: X-Mailer: git-send-email 2.53.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 8a6807082672..0026b6798b2f 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 bdad459e6605..8e41ce029985 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -4486,6 +4486,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) { @@ -4595,20 +4616,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 87b5796d0135..ee1e71c178fa 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -1403,6 +1403,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) { @@ -1410,6 +1427,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 2447A376A10 for ; Thu, 21 May 2026 09:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355826; cv=none; b=AJqa+hZmUVJyB+dWX4EW7lrhV0ImNJg1kL31w0iXa5A5htimwR0GsHQ2L1lVfK91a5asskwZdpqlwHaEste6PXQ34te5NJ6s2ls6ope0B1yxt/rT00+8qWJJrZrRRTPgFxHPeYN9p0uaUTDJTN3M81BivTL8wLM5L+uDBm578NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355826; c=relaxed/simple; bh=NuWjWY7Q5T1hYxmP3Yj55SeP5llNdvWWdVmUAI/frm4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPiBAcZ4vp4/dbkwj1uFt3dbQVoEcgppfTdN8bBw0rWepwSzyU1MfxJJJdIQcdqdqWiGPkKXLgzdUgI1+LmR/BQLCNFPaB0tK7O+DQ1XVDvmkCsKtWumw/lMKv9Pr/9uC8AwNvi9A5+EY1r4Dvg8bU/2+XAQ5kjETbtdeR5hls4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z33W7+90; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z33W7+90" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 506C81F000E9; Thu, 21 May 2026 09:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355824; bh=putIHX1AtnfG1C3wmO7MHUYjFwRdFcEnc6YQS6tTcJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Z33W7+90QBtE7vcWaI+7seiuYWEKOL5u/vZJwA5E/A0xkii4v+tKNRjhSI+ZD+qHJ dw2HELCkyZxqlRaFGcIuVNnJrfi92uEbKEF6Ly0QYPZqD5iOD+FfcIoFLSFKDkkIVM I85VleHPADI3moEZAofDN4DGyHOxcqR1AoU4ZfFlLlD2UbznrtUkmI9ZES9eoOYlFX ZK+931XCpPLyQ6FVy3yPg5wzhDBea10cdT2yTCan8IM57NAKca0KUDJZqjk8WGO/EO nHY72E2YnB2JvaIMrs8+cmxht9OzWu65Xob8t85zr7ADFv+ZLzK42Enphlbn+jYQBh vP7Gjz1EN8IVg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 08/15] mptcp: enable ulp setsockopt for tls support Date: Thu, 21 May 2026 17:29:46 +0800 Message-ID: X-Mailer: git-send-email 2.53.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 | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 505eac23f35d..06e037fe8807 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -3640,6 +3640,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 ee1e71c178fa..8fcd736fae37 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 @@ -573,6 +574,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 @@ -825,6 +827,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) { @@ -833,7 +866,9 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *= msk, int optname, =20 switch (optname) { case TCP_ULP: - return -EOPNOTSUPP; + if (__mptcp_check_fallback(msk)) + 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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 28C8536894B for ; Thu, 21 May 2026 09:30:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355828; cv=none; b=FT38Rr6ooLdKUpRM1HyMm6Q7BLdKxxzLSbP2AkvCC5vO3sFUpjvU35XKXRTNhF3Opc5PmSJHK91rdThCI5MszbsLuRonAF354TPEV4nQK/P3vf+c+bz3LPPIoVk7BJUTp9myksoyZupd1THmAgFj5xq0+BGnZ9ZKy43BEPQydOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355828; c=relaxed/simple; bh=OCzCFIYgoiaMAiBtegDy0QtVK07qEClmWwfRNS5E42k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gthMO66RVF/XuiOiw/Ol+6+wGH4rxGISdi6m4wGvcigfeRBcLBnwekA1r0o/Sad7DUWG50F1/4PdTjVVd/Oa5GtB1bJBxt06o9fhRXuKFUMPqUTYifjaBf7vpIqS/Xl/i3O5sXpMBaBuJc2C2o0VLFP0nWQ04Vrscfmc87KeYtY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D118cHDI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D118cHDI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38FAF1F00A3B; Thu, 21 May 2026 09:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355826; bh=QNlJojqgfv7GMPK4dZE0g55fgVzitfoZ+67FCVoT7PA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D118cHDIyCU/XSKhofzecvEQUR+66lJBxtdUyU1qbfIDrVdN94si/6Ibr1SPuuv0Q M9walc1tWjw8aBzcvlBqTxOa4ueIhtRFeHywwUpwQppv5w+Ycw8aNfEwj5HLCU3z8L sHwTTM5dEGwg+nBoO8Jj9n19NmCUaSBuJr5n64NmpOburmXrqxbDgkeLGZiIcB9G5n +miAhJ/Lc8DmFo8OOcJxTI3rYurZ34UMP0ZsqlApEurdF9I5Z5UhkOgQlL5UTWIgKJ JAhjhhtsei0XiENh1VF2f6zOKR3/l3kZhqb94xBRT4CWam2QVToiyl33rLbNz6sr22 1930n7mheTNIA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 09/15] selftests: mptcp: connect: use espintcp for ulp test Date: Thu, 21 May 2026 17:29:47 +0800 Message-ID: <54c0535d1cee8bea5a02cf8733c90444efc683df.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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/config | 1 + tools/testing/selftests/net/mptcp/mptcp_connect.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selft= ests/net/mptcp/config index 59051ee2a986..b9960f227796 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -34,3 +34,4 @@ CONFIG_NFT_SOCKET=3Dm CONFIG_NFT_TPROXY=3Dm CONFIG_SYN_COOKIES=3Dy CONFIG_VETH=3Dy +CONFIG_XFRM_ESPINTCP=3Dm 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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8DA46352024 for ; Thu, 21 May 2026 09:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355829; cv=none; b=TL4rlVof0eX/Ix3IuuSaybWkCE4UzJqolTCMy3pwlCk23oGRDDBD0H87vaTLjSuwmOXgIlysYdKDKOtHM799WAHTCQKZZ5ADKSP8PQ50IaKhWDVGOeUjho37HjyJnafr9RVO9eSKHO7lsj2Zaab4nKQ0WImteIsCX7bicSIoFHg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355829; c=relaxed/simple; bh=O/mPy7YMI2rfmGxYYjB7zOoDVVL6GYPqE+o45Afmlw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IQxYxJAPtcmI21jCMc1nEAfR1iH5ad+y2xICnonxfjbaPS58rF68J0+HbzOjESCVtL8nOMumgVphBZz9QwI/jkdDYSa8unrdjJfrxK5ukQNMO8Ry0205i+BSBDfOkkrKbwpJ9OxG/2LOzt/Oz5q1iYRenE5Nupuy+JP6slOgmxc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jDvVfSxB; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jDvVfSxB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23CF81F000E9; Thu, 21 May 2026 09:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355828; bh=nQZjQ5QWCD0eg9hbBobRUdZaUwAS3MrkpUTwtZyVaIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jDvVfSxBiw9ZZV5HJPNovZjCRYyJXSvcSd3Y9WsX/8gA8A2gmIRi8j6db/P1O35XM KKKrVIfFZusWjNXUmr05U2QsKx5N0Jrmavx6EEMCpuwA/dVjxqkUzo+5jcMZ4skiDT KqXbIbFEDOlI3heqqUFeGYLAHPgBw3Bx+8oKi89E4gkWJ7UI4UMQd3GjUcnHmV2u7z y1dziCEy58v9QdFHEBtggH4QDrcM5IiVidnanp0P8xbOZ4KRLzUl/cPYsBdG3t212f cThOBvZKDUt+s7lShYJpLmgCdOGURYsChJVLJgaARFyw7Roub61LJ/bY8CCqmvn2cA 8TgndFYlbETvQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 10/15] selftests: tls: add mptcp variant for testing Date: Thu, 21 May 2026 17:29:48 +0800 Message-ID: <1c5c0d55d97b90bbb47e3e55861e964599a69119.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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. Add is_mptcp_enable() to check if MPTCP is enabled on the system. The function takes a struct __test_metadata * parameter to satisfy the test framework's callback signature, even though the parameter is unused. 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 30a236b8e9f7..580375ce66d3 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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C4599369D6F for ; Thu, 21 May 2026 09:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355831; cv=none; b=Jo2H2vNFMB8AeDrxaYC7gvtouO9lOMmdPjS2TpppMvnSX2Ys6+xFxteAkCe7zY25LQb8TU7m60gfVlqRNRsewWPi/IeuHfEy3uSl1p0y7sZEVmRC4X7HJdU3KyEgYADyg9QtPNd8AC8EBKbjbO9Myx6j5UM+oSu7hxVTwmnNEIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355831; c=relaxed/simple; bh=jSnV4eJfWWkKWj394ezkN5pDT8eQ9OzKtEU03h6LuF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ly6iy4bIFwx8bsskjptPV0vmVpJTo3UVejW2jBNr50S5ChPmKmeb0qQVEzhd7X3xU25WSBE6EDkGjnjtXo7QhZYEGZZDqwf4vZMVfxT1B0kpgch6jIdlwg31+WgtNbg9p/TwmIIkstWeFO3jHRFbMQXWkptzR1NgGSYpVMykowE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fAXporFy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fAXporFy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E95EB1F00A3B; Thu, 21 May 2026 09:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355830; bh=edtL2WNPQXZY+2/vRKc4X+C0emiTO9ixMbmXZcXYqOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fAXporFy1iVwj6Lwhki4nX40/YBwf4LnXgrw71+SsAx/ex3RFyqcUXL707rCKo4VV qpF2wRM6uLno8/aQSV7knKJTN9x7vrAkYSmkgw5P0xg9IJkhDbuDlAH9foxcb+yiHG ANGkXlNGEtgkv48o8wTWqEazKu0b6Kvh8DJVTOaKx4Cid9/DrPMiYq+tFSjCLRHSG0 dWUzwXQsNa8qESsq6HcSeJbCe/SyFPCSc2EKsKRgWMYRujjxLHXYs2CsjbF0h8poto aJW9ZPHk77IrI7CoC5q5JtsxIPLqwimpKy5+li7E0W2RxiuNeXh/5EZBW3DtQPAKgy LevlM+Q5iyj4A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 11/15] selftests: tls: increase pollin timeouts for mptcp Date: Thu, 21 May 2026 17:29:49 +0800 Message-ID: <7430c61cf1d274223801c746ed9493a3239f6bdc.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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 580375ce66d3..1608711177a2 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1362,6 +1362,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]; @@ -1371,11 +1372,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E3C772DB7AE for ; Thu, 21 May 2026 09:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355833; cv=none; b=Wyo2aqfVsR73Oyq3/cJ3giB4osuxtNyY1f58ZVu2sVvmHJdtkqgG38cG6cfFudcNv+IHgzTct76FiYSRHJ8bKZIvLLv2QZxG+5smOFGpnYdDdx+QXc5r7T7E8Zj86wSunE/xgS/jZS4jO4Pz2GGr0iu5YeN1IGZiRNYxpFLnChQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355833; c=relaxed/simple; bh=kORFGVNN9Zd1G9CO5QmKrhWdpjMlH7oeSEymEXKh0kw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lTZmIRJzfIp/3OOOh7UnUwr9rqp9DrexYPP4TnHZudWcdMz/QEVgLVkizoVoHH4GlTnS52QBxwGNngg8uEfWu1km/zxit11EoNDdYmOQFC7IuCpChU0neWa48dvw1uXK/7HXA966CFYgI7pZGIspfRUGQKRXaUr3mgT2rHQibFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V2n3zja0; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="V2n3zja0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0C6151F000E9; Thu, 21 May 2026 09:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355832; bh=g3qduNCoMfJcMfmRzI8HY6WG1nmo2aYnX3DYxcXj3PU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=V2n3zja0mAma8a8ARIrytFzuuTQgdhf9UcJfUrNnIIsh/7TFzcy93qFBzhy5DMzc2 9EEacfq4b4mSTEIKFrQZtRO4mi4AIdEy6n/lT91JfHAgv48YH8BufzlnXCI74xfFXL SdCI731/EgRzBXrQtPHwpcVo2xCf39HWWLIGnIcXqHXU03iXlJynhJufHMjyNYY9Jg 5svIkY38h0TNYdgueCQSOBCfFHczCWJSkSELUep4H+7PfDp6iYYDsz9Q0h7QA9O61Z sI8QzCiAGUp9JNBF7N3c8DPgbC9Rc4Vn55lk/GTsUojrABUPw7GCfoP98gBYDnaKuc tN+ZmVIcX7lhA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 12/15] selftests: tls: increase nonblocking data size for mptcp Date: Thu, 21 May 2026 17:29:50 +0800 Message-ID: <42544c6dd1e6ca461b7aea168ab18152f600681d.1779355169.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.53.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 1608711177a2..0a1b0faa3957 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1468,6 +1468,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D7BD1369990 for ; Thu, 21 May 2026 09:30:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355836; cv=none; b=HRw8crILDjhwLCm1hR/p6gz31udcjhkjyNdrG/XWljko0/93BgYd0wNFTOuXTRBep6R2WHhQ30PVlaOaRkYkUvI5lSJeAR2VyT5vlXzTKedH4MQhAdQZtsuNct7SetB8vV3J1dOwzt9/XHI97I2uftOU74i0m9jW6GotVAROxeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355836; c=relaxed/simple; bh=di5qFRo5ayNBzXYinj8icX33yh+Rs9A0TnIZ/nvGZ84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TeJu/fqlobgIP2zaOwbwvkU7ngubb6ifpx2hB7wSdZStnwuolsW2+UeFmWiagk/Pln5x9+Z5eZFYxRZDo5MILiQd6sVtnV8PhRMGxmqEA18RV6+DUvFx3kWLg7GZ3fEBqBkT7TgyoqHzO9RRD4ylz9gVStzKscQar3kowctgXA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AyCnJzg9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AyCnJzg9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E8DD1F00A3B; Thu, 21 May 2026 09:30:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355834; bh=rQ6ILHJEcxdGfLlAydq+aX8qlH+3iXptwWHurZopQ0w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AyCnJzg9K3YJ6qdgpoBstYxleB2aO+z5z1qsz+xzfdnht5MCvXX32dRDRk1mVV97a Ss5zpqIZ2/lnilNI2lT3ouW8ncqPO6LuZ9hS7zBMLins5vHYMHhiDF06Ob32Ch55or Cm3H/x7W1RejYTPUyW6YgoqHWdY/ZWmIDAryB4t6sUA244x5sjcIEzCFqnnJhAvNuq HIXfHp+EEIqHw3ilKBNLPuXY6EVacgWhBgHNFAMaNI3Mt24PiRQ1dMccjch0XGoqnu y/8JFec9JgF8n3TMsEBd9u7WOsfYslzv9qbLbvhcpqSU54N4aWCNNfYuzoGZs4SEkT Wdm3YlVGpBINw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 13/15] selftests: tls: retry bind on EINVAL in shutdown_reuse Date: Thu, 21 May 2026 17:29:51 +0800 Message-ID: X-Mailer: git-send-email 2.53.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 the shutdown_reuse test, after shutdown and close, bind() may fail with EINVAL for MPTCP sockets due to asynchronous state transition of the top-level MPTCP socket. The subflow may have reached TCP_CLOSE, but the MPTCP socket state hasn't been updated yet. Retry bind() on EINVAL for up to 1000 iterations (1 second) to allow the MPTCP socket to complete its state transition. This fixes the following intermittent failures: # 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 is only done for MPTCP variants to avoid slowing 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/ne= t/tls.c index 0a1b0faa3957..8a95235a7ae8 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -1744,6 +1744,7 @@ TEST_F(tls, shutdown_unsent) TEST_F(tls, shutdown_reuse) { struct sockaddr_in addr; + int i =3D 0; int ret; =20 shutdown(self->fd, SHUT_RDWR); @@ -1754,7 +1755,13 @@ TEST_F(tls, shutdown_reuse) addr.sin_addr.s_addr =3D htonl(INADDR_ANY); addr.sin_port =3D 0; =20 +retry: ret =3D bind(self->fd, &addr, sizeof(addr)); + if (variant->mptcp && + ret < 0 && errno =3D=3D EINVAL && i++ < 1000) { + usleep(1000); + goto retry; + } EXPECT_EQ(ret, 0); ret =3D listen(self->fd, 10); EXPECT_EQ(ret, -1); --=20 2.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D3A8B377547 for ; Thu, 21 May 2026 09:30:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355838; cv=none; b=LjOAC7ofAtoGwSKBLEysT4u+6JoVAbO7tqMAisCjdPTPvwUClwWSZgJJwhtj3rzmJE8popu1vP2HKFYeuANHEEj31I1HdQ8g6NcyMswWnQwQx/nKcRZrYJAX9irOtdvDkBAyDyrFpBTqPqQfebDDZa6fL594suUY4dFlq3ZX+zw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355838; c=relaxed/simple; bh=7BXIjBXfu091b0K+WkyidOeEciLAPbj0T7jcyoiIzNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dJGvN9FnJKGzSVFs9SSNyvLwNeLQqQigDQXoVAiARuUz+NarQM4ZDgdfybOP/eXsRHUez32JPiqQs0xYLQIXjqOr377ICKAZ70fpr2J5d2rqOy3AK6r9S7w/bayrvzRqUfO4pmUSe+ATtd7rLWPk/Hyfp3lBPfkcW0V3N53F4YQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lHothe8W; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lHothe8W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31B451F00A3D; Thu, 21 May 2026 09:30:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355836; bh=/OfjqLHITOGIKIkxQ1ndV2WutsnKjXnopxNQgA/4jb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lHothe8WW9mdy4REHnIrQ2currk7Pr8RLsGcXcK4giheJ55LZVIbEbt0+YgJ8aQIA V+G9IK7t7T54yC4D9nHGB487dKUOmvjmu96OJzhgu/wiOaQjin6Rf4VqiTmX8qR24Y 0650FCCKokheIBxrPV/u3EAnOjEtjzJj0TxezqEnOBvsso0bI8Kevh/Z7Zc6UZHcv3 jDbFnagnM+6zlccEw6+b4WC9r1R4mQ3uw5IPEqLb6jD1ZrPXrQJU9/o52MEdbsOZnH 0BYj3fu/ZOuYhZwxYLO5QGBYiYvsj4I8BNRuy5Ul10ZJCkho+mn97o+CVvQBZhviCi 4j7LfoliSzx2g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 14/15] selftests: tls: add mptcp test cases Date: Thu, 21 May 2026 17:29:52 +0800 Message-ID: X-Mailer: git-send-email 2.53.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. 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 8a95235a7ae8..aed676ff3505 100644 --- a/tools/testing/selftests/net/tls.c +++ b/tools/testing/selftests/net/tls.c @@ -407,6 +407,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.53.0 From nobody Mon May 25 18:05:08 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 6559E377544 for ; Thu, 21 May 2026 09:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355839; cv=none; b=KEA+OC5knI888GcWQNfQNzQOg69geqSvspOM1sztljdeJV9KxIESz91KGgBC9cBVO9o9DyAJkYLQG3HReBNe2zuYPWbmGtBuazpz3JG9QFlU4TZSx2YCi9K5ABJuwbypZ0L/Oiw7WAIU/JYvy/aUTx9nYBCq4ZbgGwNabX4fbHI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779355839; c=relaxed/simple; bh=PhY3qPROuBdMTe1mar1KsTe9/5NIW6utDlbwPTZG1zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHtGcIQ+df6XHAI/o6eJxGG8QJjcBadz0SQI0H2hXhaVRcRwGl7bw+s7Gmw3z5SKWF3ZPCI3qRRy/OENBtLShWIS5yXSewjtgPQIv5nH+FJzUDTDB72T6ShjGY7yYXkKCR/TYNC9wmDsY/mppltM0dGmaNdKG7hS5MPTcKak9mc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=br/eA6e8; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="br/eA6e8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6AB11F000E9; Thu, 21 May 2026 09:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779355838; bh=sWJEjWDeKaIU9OOSzE2K4YtJUgEwYbriDt4DkdnV7u0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=br/eA6e83d+O+oA4pSIZcmbMpPiQmACPOs+A0EyNhN/LagK1MipN7rjaWx1TCI3SX x5xjoX725ki5Fqe2ZQ7/IE6XdjqX3UX3XqIT9XYf4NEkAuOiDILgtnkIh60P3w4s45 pC/rEcI0PiWh3KOB3ZxYCBvciQUhpKbq9y10l9jQw4fVRU5ucki9Wl041y5gEjUvbC EvMT3BiBRlgn3riE/ODh3seX9MRcpKI7+vmpSQunm7PQuvdM9E3heTYVqx0niIIhVV jJx0wMMEj+wq/5cP8jryodGcbsv42egClUBZs4J5AlaG/l8LlP/hDqWx8AaMtbPcHj mIWiF+VVRLUow== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Gang Yan Subject: [RFC mptcp-next v19 15/15] selftests: mptcp: cover mptcp tls tests Date: Thu, 21 May 2026 17:29:53 +0800 Message-ID: X-Mailer: git-send-email 2.53.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 | 64 +++++++++++++++++++ tools/testing/selftests/net/mptcp/tls.c | 1 + 5 files changed, 73 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 b9960f227796..395f1d5b020a 100644 --- a/tools/testing/selftests/net/mptcp/config +++ b/tools/testing/selftests/net/mptcp/config @@ -35,3 +35,8 @@ CONFIG_NFT_TPROXY=3Dm CONFIG_SYN_COOKIES=3Dy CONFIG_VETH=3Dy CONFIG_XFRM_ESPINTCP=3Dm +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..04a0cb6ab0f3 --- /dev/null +++ b/tools/testing/selftests/net/mptcp/mptcp_tls.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +. "$(dirname "${0}")/mptcp_lib.sh" + +ret=3D0 +ns1=3D"" +pid=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 +} + +mptcp_lib_check_mptcp + +trap cleanup EXIT + +# 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.53.0