Re: [PATCH 6/8] nvme-tcp: Support KeyUpdate
From: Hannes Reinecke <hare@suse.de>
Date: 2025-08-18 12:52:18
Also in:
linux-doc, linux-nfs, linux-nvme, lkml
On 8/15/25 07:02, alistair23@gmail.com wrote:
quoted hunk ↗ jump to hunk
From: Alistair Francis <redacted> If the nvme_tcp_try_send() or nvme_tcp_try_recv() functions return EKEYEXPIRED then the underlying TLS keys need to be updated. This occurs on an KeyUpdate event. If the NVMe Target (TLS server) initiates a KeyUpdate this patch will allow the NVMe layer to process the KeyUpdate request and forward the request to userspace. Userspace must then update the key to keep the connection alive. This patch allows us to handle the NVMe target sending a KeyUpdate request without aborting the connection. At this time we don't support initiating a KeyUpdate. Link: https://datatracker.ietf.org/doc/html/rfc8446#section-4.6.3 Signed-off-by: Alistair Francis <redacted> --- drivers/nvme/host/tcp.c | 63 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index cc3332529355..0c14d3ad58af 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c@@ -171,6 +171,7 @@ struct nvme_tcp_queue { bool tls_enabled; u32 rcv_crc; u32 snd_crc; + key_serial_t user_key_serial; __le32 exp_ddgst; __le32 recv_ddgst; struct completion tls_complete;@@ -1313,6 +1314,7 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) struct nvme_tcp_request *req; unsigned int noreclaim_flag; int ret = 1; + enum nvme_ctrl_state state = nvme_ctrl_state(&(queue->ctrl->ctrl)); if (!queue->request) { queue->request = nvme_tcp_fetch_request(queue);@@ -1347,6 +1349,29 @@ static int nvme_tcp_try_send(struct nvme_tcp_queue *queue) done: if (ret == -EAGAIN) { ret = 0; + } else if (ret == -EKEYEXPIRED && + state != NVME_CTRL_CONNECTING && + state != NVME_CTRL_RESETTING) { + int qid = nvme_tcp_queue_id(queue); + + dev_dbg(queue->ctrl->ctrl.device, + "updating key for queue %d\n", qid); + + nvme_change_ctrl_state(&(queue->ctrl->ctrl), NVME_CTRL_RESETTING);
Rah. Don't do that. The 'resetting' state is tied to the resetting mechanism (LIVE->RESETTING->CONNECTING->LIVE) and is being relied on for the timeout handler. Setting it manually will confuse error handling. And really, having the key update in two places is a bit ... odd. I'd rather stop the I/O queue in nvme_tcp_io_work() once a EKEYEXPIRED error has been hit, and start the key update via nvme_tcp_start_tls() function directly from there. No need to change the controller state. Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich