* [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue
@ 2026-12-02 15:56 Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 1/3] nvme-tcp: use an aligned buffer for the TLS record type Martin Belanger via B4 Relay
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Martin Belanger via B4 Relay @ 2026-12-02 15:56 UTC (permalink / raw)
To: stable; +Cc: kbusch, sagi, hch, martin.nvme.dev, hare, linux-nvme, axboe
Backport of the three patches that failed to apply to 7.3-stable
(FAILED mails of 2026-12-02). Patch 1 had a context conflict next to
nvme_tcp_cpu_queues. Patches 2 and 3 then apply cleanly.
Tested on v7.3.7 with records injected on a live TLS queue:
NewSessionTickets, close_notify and a warning alert no longer start
error recovery, and the data read back matches. A fatal alert and a
KeyUpdate still start error recovery, as upstream.
---
Martin Belanger (3):
nvme-tcp: use an aligned buffer for the TLS record type
nvme-tcp: move the TLS record read loop into a helper
nvme-tcp: consume TLS records without application data
drivers/nvme/host/tcp.c | 170 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 136 insertions(+), 34 deletions(-)
---
base-commit: c75c928bb4af01748aa107d9fb254e7ac79c49a9
change-id: 20261202-live-stable-7-3-1aa1809f2f3a
Best regards,
--
Martin Belanger <martin.nvme.dev@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 7.3.y 1/3] nvme-tcp: use an aligned buffer for the TLS record type
2026-12-02 15:56 [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Martin Belanger via B4 Relay
@ 2026-12-02 15:56 ` Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 2/3] nvme-tcp: move the TLS record read loop into a helper Martin Belanger via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Martin Belanger via B4 Relay @ 2026-12-02 15:56 UTC (permalink / raw)
To: stable; +Cc: kbusch, sagi, hch, martin.nvme.dev, hare, linux-nvme, axboe
From: Martin Belanger <martin.belanger@dell.com>
commit 1193566c35ead643e954ff8356bb54b1cd78378a upstream.
The buffers that receive the TLS record type are char arrays.
put_cmsg() and tls_get_record_type() access them as struct cmsghdr,
which needs a stricter alignment than a char array has.
Use a union with struct cmsghdr, sized with CMSG_SPACE(), as
svc_tcp_recv_cmsg() and xs_tls_read_record() in sunrpc do.
Fixes: 2837966ab2a8 ("nvme-tcp: control message handling for recvmsg()")
Cc: stable@vger.kernel.org
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
[ Martin: resolved a context conflict next to nvme_tcp_cpu_queues ]
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
---
drivers/nvme/host/tcp.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 6204943ea404..61be80df51ae 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -76,6 +76,12 @@ MODULE_PARM_DESC(tls_handshake_timeout,
/* TLS records read while waiting for the ICResp, the ICResp included */
#define NVME_TCP_ICRESP_MAX_RECORDS 8
+/* control message buffer for the TLS record type */
+union nvme_tcp_tls_cmsg {
+ struct cmsghdr cmsg;
+ u8 buf[CMSG_SPACE(sizeof(u8))];
+};
+
static atomic_t nvme_tcp_cpu_queues[NR_CPUS];
enum nvme_tcp_send_state {
@@ -1646,11 +1652,11 @@ static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
.iov_base = buf,
.iov_len = sizeof(buf),
};
- char cbuf[CMSG_LEN(sizeof(char))] = {};
+ union nvme_tcp_tls_cmsg u = {};
/* kTLS fails a control record read without a cmsg buffer */
struct msghdr drain = {
- .msg_control = cbuf,
- .msg_controllen = sizeof(cbuf),
+ .msg_control = &u,
+ .msg_controllen = sizeof(u),
};
ret = kernel_recvmsg(queue->sock, &drain, &iov, 1, sizeof(buf),
@@ -1675,7 +1681,7 @@ static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
static int nvme_tcp_recv_icresp(struct nvme_tcp_queue *queue,
struct nvme_tcp_icresp_pdu *icresp)
{
- char cbuf[CMSG_LEN(sizeof(char))];
+ union nvme_tcp_tls_cmsg u;
struct msghdr msg;
struct kvec iov;
u8 ctype;
@@ -1683,12 +1689,12 @@ static int nvme_tcp_recv_icresp(struct nvme_tcp_queue *queue,
for (i = 0; i < NVME_TCP_ICRESP_MAX_RECORDS; i++) {
memset(&msg, 0, sizeof(msg));
- memset(cbuf, 0, sizeof(cbuf));
+ memset(&u, 0, sizeof(u));
iov.iov_base = icresp;
iov.iov_len = sizeof(*icresp);
if (nvme_tcp_queue_tls(queue)) {
- msg.msg_control = cbuf;
- msg.msg_controllen = sizeof(cbuf);
+ msg.msg_control = &u;
+ msg.msg_controllen = sizeof(u);
}
msg.msg_flags = MSG_WAITALL;
ret = kernel_recvmsg(queue->sock, &msg, &iov, 1,
@@ -1696,8 +1702,7 @@ static int nvme_tcp_recv_icresp(struct nvme_tcp_queue *queue,
if (ret <= 0 || !nvme_tcp_queue_tls(queue))
return ret;
- ctype = tls_get_record_type(queue->sock->sk,
- (struct cmsghdr *)cbuf);
+ ctype = tls_get_record_type(queue->sock->sk, &u.cmsg);
if (ctype == TLS_RECORD_TYPE_DATA)
return ret;
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 7.3.y 2/3] nvme-tcp: move the TLS record read loop into a helper
2026-12-02 15:56 [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 1/3] nvme-tcp: use an aligned buffer for the TLS record type Martin Belanger via B4 Relay
@ 2026-12-02 15:56 ` Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 3/3] nvme-tcp: consume TLS records without application data Martin Belanger via B4 Relay
2026-12-03 13:47 ` [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Martin Belanger via B4 Relay @ 2026-12-02 15:56 UTC (permalink / raw)
To: stable; +Cc: kbusch, sagi, hch, martin.nvme.dev, hare, linux-nvme, axboe
From: Martin Belanger <martin.belanger@dell.com>
commit 76afef5e29221e68f9a19df767f94b092c31e974 upstream.
Move the read loop out of nvme_tcp_skip_tls_record() into a new
helper, nvme_tcp_drain_tls_record(). The next patch uses the helper
to read TLS records that arrive on a live queue.
No functional change.
Cc: stable@vger.kernel.org
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
---
drivers/nvme/host/tcp.c | 60 +++++++++++++++++++++++++++++++------------------
1 file changed, 38 insertions(+), 22 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 61be80df51ae..2c81f2332050 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -1622,31 +1622,16 @@ static int nvme_tcp_recv_tls_alert(struct nvme_tcp_queue *queue,
}
/*
- * Discard a TLS record that arrived in place of the ICResp. A peer may send
- * a NewSessionTicket as soon as the handshake completes.
+ * Read the rest of a TLS record whose first part was read into @msg.
*
- * Returns 0 when the record was discarded and the ICResp can be read, or a
- * negative errno if the connection cannot continue.
+ * Returns the bytes read, or a negative errno.
*/
-static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
- struct msghdr *msg, u8 ctype, int len)
+static int nvme_tcp_drain_tls_record(struct nvme_tcp_queue *queue,
+ struct msghdr *msg, int flags)
{
u8 buf[NVME_TCP_TLS_REC_CHUNK];
- int ret;
+ int ret, drained = 0;
- switch (ctype) {
- case TLS_RECORD_TYPE_HANDSHAKE:
- break;
- case TLS_RECORD_TYPE_ALERT:
- ret = nvme_tcp_recv_tls_alert(queue, msg, len);
- return ret ? : -ENOTCONN;
- default:
- pr_err("queue %d: unhandled TLS record %u\n",
- nvme_tcp_queue_id(queue), ctype);
- return -ENOTCONN;
- }
-
- /* the ICResp is in a later record, drain this one first */
while (!(msg->msg_flags & MSG_EOR)) {
struct kvec iov = {
.iov_base = buf,
@@ -1660,16 +1645,47 @@ static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
};
ret = kernel_recvmsg(queue->sock, &drain, &iov, 1, sizeof(buf),
- 0);
+ flags);
if (ret <= 0) {
pr_warn("queue %d: failed to drain TLS record: %d\n",
nvme_tcp_queue_id(queue), ret);
return ret ? : -ECONNRESET;
}
+ drained += ret;
msg->msg_flags = drain.msg_flags;
}
- return 0;
+ return drained;
+}
+
+/*
+ * Discard a TLS record that arrived in place of the ICResp. A peer may send
+ * a NewSessionTicket as soon as the handshake completes.
+ *
+ * Returns 0 when the record was discarded and the ICResp can be read, or a
+ * negative errno if the connection cannot continue.
+ */
+static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
+ struct msghdr *msg, u8 ctype, int len)
+{
+ int ret;
+
+ switch (ctype) {
+ case TLS_RECORD_TYPE_HANDSHAKE:
+ break;
+ case TLS_RECORD_TYPE_ALERT:
+ ret = nvme_tcp_recv_tls_alert(queue, msg, len);
+ return ret ? : -ENOTCONN;
+ default:
+ pr_err("queue %d: unhandled TLS record %u\n",
+ nvme_tcp_queue_id(queue), ctype);
+ return -ENOTCONN;
+ }
+
+ /* the ICResp is in a later record, drain this one first */
+ ret = nvme_tcp_drain_tls_record(queue, msg, 0);
+
+ return ret < 0 ? ret : 0;
}
/*
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 7.3.y 3/3] nvme-tcp: consume TLS records without application data
2026-12-02 15:56 [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 1/3] nvme-tcp: use an aligned buffer for the TLS record type Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 2/3] nvme-tcp: move the TLS record read loop into a helper Martin Belanger via B4 Relay
@ 2026-12-02 15:56 ` Martin Belanger via B4 Relay
2026-12-03 13:47 ` [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Martin Belanger via B4 Relay @ 2026-12-02 15:56 UTC (permalink / raw)
To: stable; +Cc: kbusch, sagi, hch, martin.nvme.dev, hare, linux-nvme, axboe
From: Martin Belanger <martin.belanger@dell.com>
commit 687e743e4089b2a854982b321cb2d681ae5d6136 upstream.
A peer may send a TLS record without application data at any time
after the handshake: a NewSessionTicket, a KeyUpdate or an alert.
tls_sw_read_sock() cannot pass such a record to nvme_tcp_recv_skb().
It returns -EINVAL and leaves the record at the head of the receive
queue. nvme_tcp_try_recv() then starts error recovery, and the
controller reconnects.
TLS 1.3 allows a server to send a NewSessionTicket at any time after
the handshake (RFC 8446, section 4.6.1). Alerts can also arrive at any
time.
On -EINVAL, read the record with recvmsg(), which reports the record
type. Discard handshake messages other than KeyUpdate. Log alerts, and
fail the queue on a fatal alert. Fail the queue on a KeyUpdate, which
nvme-tcp cannot answer, and on any other record type. recvmsg() takes
the socket lock, so release it around the read.
Handle these records in one helper, also for the records that arrive
ahead of the ICResp. A warning alert ahead of the ICResp no longer fails
the connection.
On a poll queue, nvme_tcp_poll() and nvme_tcp_io_work() can both see
the record while the socket lock is released. A queue flag makes sure
that only one of them reads it.
svc_tcp_recvfrom() in sunrpc handles -EINVAL from read_sock() the same
way.
Fixes: be8e82caa685 ("nvme-tcp: enable TLS handshake upcall")
Cc: stable@vger.kernel.org
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
---
drivers/nvme/host/tcp.c | 113 +++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 97 insertions(+), 16 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 2c81f2332050..56ac49f6abbb 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -121,6 +121,7 @@ enum nvme_tcp_queue_flags {
NVME_TCP_Q_LIVE = 1,
NVME_TCP_Q_POLLING = 2,
NVME_TCP_Q_IO_CPU_SET = 3,
+ NVME_TCP_Q_TLS_RECORD = 4,
};
#define NVME_TCP_OPT_NR_QUEUES(opts) ((opts)->nr_io_queues + \
@@ -1441,6 +1442,8 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue)
return ret;
}
+static int nvme_tcp_recv_tls_record(struct nvme_tcp_queue *queue);
+
static int nvme_tcp_try_recv(struct nvme_tcp_queue *queue)
{
struct socket *sock = queue->sock;
@@ -1453,10 +1456,31 @@ static int nvme_tcp_try_recv(struct nvme_tcp_queue *queue)
lock_sock(sk);
queue->nr_cqe = 0;
consumed = sock->ops->read_sock(sk, &rd_desc, nvme_tcp_recv_skb);
+ /*
+ * kTLS cannot pass a TLS record without application data to
+ * nvme_tcp_recv_skb(). It returns -EINVAL and leaves the record at
+ * the head of the receive queue. recvmsg() takes the socket lock,
+ * so read the record without it.
+ */
+ if (unlikely(consumed == -EINVAL && nvme_tcp_queue_tls(queue) &&
+ queue->rd_enabled)) {
+ /*
+ * On a poll queue, nvme_tcp_poll() and nvme_tcp_io_work() can
+ * both get here for the same record. Only one of them reads it.
+ */
+ if (test_and_set_bit(NVME_TCP_Q_TLS_RECORD, &queue->flags)) {
+ consumed = 0;
+ } else {
+ release_sock(sk);
+ consumed = nvme_tcp_recv_tls_record(queue);
+ lock_sock(sk);
+ clear_bit(NVME_TCP_Q_TLS_RECORD, &queue->flags);
+ }
+ }
/*
* nvme_tcp_recv_skb() handles its own errors, so a queue that is
- * still enabled failed inside read_sock(). Handle it before
- * release_sock() processes the backlog.
+ * still enabled failed inside read_sock() or while reading a TLS
+ * record. Handle it before release_sock() processes the backlog.
*/
if (unlikely(consumed < 0 && consumed != -EAGAIN &&
queue->rd_enabled)) {
@@ -1659,33 +1683,88 @@ static int nvme_tcp_drain_tls_record(struct nvme_tcp_queue *queue,
}
/*
- * Discard a TLS record that arrived in place of the ICResp. A peer may send
- * a NewSessionTicket as soon as the handshake completes.
+ * Consume a TLS record without application data. The first @len bytes of
+ * the record were read into @msg and @data.
*
- * Returns 0 when the record was discarded and the ICResp can be read, or a
- * negative errno if the connection cannot continue.
+ * A KeyUpdate needs new keys that nothing here can supply. Other handshake
+ * messages, such as a NewSessionTicket, are discarded.
+ *
+ * Returns the bytes read after the first @len, or a negative errno if the
+ * connection cannot continue.
*/
-static int nvme_tcp_skip_tls_record(struct nvme_tcp_queue *queue,
- struct msghdr *msg, u8 ctype, int len)
+static int nvme_tcp_consume_tls_record(struct nvme_tcp_queue *queue,
+ struct msghdr *msg, u8 ctype,
+ const u8 *data, int len, int flags)
{
int ret;
switch (ctype) {
case TLS_RECORD_TYPE_HANDSHAKE:
+ if (data[0] == TLS_HANDSHAKE_KEYUPDATE) {
+ dev_err(queue->ctrl->ctrl.device,
+ "queue %d: TLS KeyUpdate is not supported\n",
+ nvme_tcp_queue_id(queue));
+ return -EKEYEXPIRED;
+ }
break;
case TLS_RECORD_TYPE_ALERT:
ret = nvme_tcp_recv_tls_alert(queue, msg, len);
- return ret ? : -ENOTCONN;
+ if (ret)
+ return ret;
+ break;
default:
- pr_err("queue %d: unhandled TLS record %u\n",
- nvme_tcp_queue_id(queue), ctype);
- return -ENOTCONN;
+ dev_err(queue->ctrl->ctrl.device,
+ "queue %d: unexpected TLS record %u\n",
+ nvme_tcp_queue_id(queue), ctype);
+ return -EPROTO;
}
- /* the ICResp is in a later record, drain this one first */
- ret = nvme_tcp_drain_tls_record(queue, msg, 0);
+ return nvme_tcp_drain_tls_record(queue, msg, flags);
+}
+
+/*
+ * Read the TLS record that read_sock() could not pass to
+ * nvme_tcp_recv_skb(). The caller must not hold the socket lock.
+ *
+ * Returns the bytes consumed, or a negative errno if the connection cannot
+ * continue.
+ */
+static int nvme_tcp_recv_tls_record(struct nvme_tcp_queue *queue)
+{
+ u8 buf[NVME_TCP_TLS_REC_CHUNK];
+ union nvme_tcp_tls_cmsg u = {};
+ struct kvec iov = {
+ .iov_base = buf,
+ .iov_len = sizeof(buf),
+ };
+ struct msghdr msg = {
+ .msg_control = &u,
+ .msg_controllen = sizeof(u),
+ };
+ int len, ret;
+ u8 ctype;
+
+ len = kernel_recvmsg(queue->sock, &msg, &iov, 1, sizeof(buf),
+ MSG_DONTWAIT);
+ if (len <= 0)
+ goto fail;
+
+ ctype = tls_get_record_type(queue->sock->sk, &u.cmsg);
+ ret = nvme_tcp_consume_tls_record(queue, &msg, ctype, buf, len,
+ MSG_DONTWAIT);
+ if (ret < 0) {
+ len = ret;
+ goto fail;
+ }
+
+ return len + ret;
+
+fail:
+ /* read_sock() left a whole record, so none of it can be missing */
+ if (len == -EAGAIN)
+ return -EPROTO;
- return ret < 0 ? ret : 0;
+ return len ? : -ECONNRESET;
}
/*
@@ -1722,7 +1801,9 @@ static int nvme_tcp_recv_icresp(struct nvme_tcp_queue *queue,
if (ctype == TLS_RECORD_TYPE_DATA)
return ret;
- ret = nvme_tcp_skip_tls_record(queue, &msg, ctype, ret);
+ /* the ICResp is in a later record */
+ ret = nvme_tcp_consume_tls_record(queue, &msg, ctype,
+ (const u8 *)icresp, ret, 0);
if (ret < 0)
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue
2026-12-02 15:56 [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Martin Belanger via B4 Relay
` (2 preceding siblings ...)
2026-12-02 15:56 ` [PATCH 7.3.y 3/3] nvme-tcp: consume TLS records without application data Martin Belanger via B4 Relay
@ 2026-12-03 13:47 ` Sasha Levin
3 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2026-12-03 13:47 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, kbusch, sagi, hch, martin.nvme.dev, hare, linux-nvme,
axboe, Martin Belanger via B4 Relay
> Backport of the three patches that failed to apply to 7.3-stable
> (FAILED mails of 2026-12-02).
Queued the series for 7.3, and your 6.18 and 6.12 series for 6.18 and
6.12, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 13:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 15:56 [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 1/3] nvme-tcp: use an aligned buffer for the TLS record type Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 2/3] nvme-tcp: move the TLS record read loop into a helper Martin Belanger via B4 Relay
2026-12-02 15:56 ` [PATCH 7.3.y 3/3] nvme-tcp: consume TLS records without application data Martin Belanger via B4 Relay
2026-12-03 13:47 ` [PATCH 7.3.y 0/3] nvme-tcp: consume TLS records without application data on a live queue Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox