public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Rishikesh Jethwani <rjethwani@purestorage.com>
Cc: netdev@vger.kernel.org, saeedm@nvidia.com, tariqt@nvidia.com,
	mbloch@nvidia.com, borisp@nvidia.com, john.fastabend@gmail.com,
	kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com,
	edumazet@google.com, leon@kernel.org
Subject: Re: [RFC PATCH v7 2/4] tls: add hardware offload key update support
Date: Mon, 23 Feb 2026 15:40:50 +0100	[thread overview]
Message-ID: <aZxm8hSrVMkEIc2O@krikkit> (raw)
In-Reply-To: <20260205231558.139818-3-rjethwani@purestorage.com>

2026-02-05, 16:15:56 -0700, Rishikesh Jethwani wrote:
> Add TLS KeyUpdate (rekey) support for hardware offload connections,
> enabling key rotation on established TLS 1.3 connections without
> tearing down the hardware offload.
> 
> Key changes:
> 
> 1. Rekey API: Extended tls_set_device_offload() and
>    tls_set_device_offload_rx() with new_crypto_info parameter to
>    distinguish initial setup from key updates. During rekey, the old
>    HW context is deleted (tls_dev_del) and a new one is added
>    (tls_dev_add) with the updated key material.

I don't think the commit message needs that level of detail. You'll
probably want to look through the git log for net/ to get an idea of
what commit messages typically look like for kernel networking.


> 2. Graceful degradation: If hardware key update fails, the connection
>    gracefully degrades to software.

In do_tls_setsockopt_conf you have:

+		} else if (update && ctx->tx_conf == TLS_HW) {
+			/* HW rekey failed - return the actual error.
+			 * Cannot fall back to SW for an existing HW connection.
+			 */
 			goto err_crypto_info;

which doesn't look very graceful.

>  For TX, TLS_TX_DEV_CLOSED is set
>    and sk_validate_xmit_skb switches to tls_validate_xmit_skb_sw for
>    software encryption. For RX, TLS_RX_DEV_DEGRADED and TLS_RX_DEV_CLOSED
>    are set for software decryption. tx_conf/rx_conf remains TLS_HW.
> 
> 3. Record sequence management: During TX rekey, old pending records
>    are deleted and unacked_record_sn is reset to the new rec_seq.

So what happens if we need to retransmit them? We just give up?

There was quite some discussion about how rekey would work with HW
offload back when I implemented rekey for SW, which got recorded in
the cover letter and committed as da3e3186ef13 ("Merge branch
'tls1.3-key-updates'"). I would expect to either see those things
implemented in this series, or a justification for why they need to be
done differently (it's possible that things turn out different in
practice from what we discussed back then).

> 4. SW context refactoring: Split tls_set_sw_offload() into
>    tls_sw_ctx_init() and tls_sw_ctx_finalize() to allow the HW offload
>    RX path to initialize SW context first, attempt HW setup, then
>    finalize (memzero new_crypto_info, call tls_finish_key_update).

To ease reviews, maybe extract the refactoring into another patch to
separate it from the actual rekey implementation.

> 5. Added TLS_TX_DEV_CLOSED flag to track TX hardware context state,
>    to avoid double tls_dev_del call, symmetric with existing
>    TLS_RX_DEV_CLOSED.

AFAICT this bit is equivalent to having
    sk->sk_validate_xmit_skb == tls_validate_xmit_skb_sw

Do we need the bit or can we just check sk_validate_xmit_skb?

> This removes the rekey rejection checks added in the previous patch,
> replacing them with full rekey support including graceful degradation.

(nit: this precision is probably not needed)


[...]
> diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
> index 459963c254f4..4aaa51a35f1f 100644
[...]
>  	crypto_info = &ctx->crypto_send.info;
> -	if (crypto_info->version != TLS_1_2_VERSION &&
> -	    crypto_info->version != TLS_1_3_VERSION) {
> +	src_crypto_info = new_crypto_info ?: crypto_info;
> +	if (src_crypto_info->version != TLS_1_2_VERSION &&
> +	    src_crypto_info->version != TLS_1_3_VERSION) {
>  		rc = -EOPNOTSUPP;
>  		goto release_netdev;
>  	}
>  
> -	cipher_desc = get_cipher_desc(crypto_info->cipher_type);
> +	cipher_desc = get_cipher_desc(src_crypto_info->cipher_type);

This shouldn't be necessary, since do_tls_setsockopt_conf checks that
we're not changing cipher type during a rekey.


>  	/* Avoid offloading if the device is down
>  	 * We don't want to offload new flows after
> @@ -1182,29 +1194,91 @@ int tls_set_device_offload(struct sock *sk)
>  		goto release_lock;
>  	}
>  
> -	ctx->priv_ctx_tx = offload_ctx;
> +	if (!new_crypto_info) {
> +		ctx->priv_ctx_tx = offload_ctx;
> +	} else {
> +		char *key = crypto_info_key(src_crypto_info, cipher_desc);
> +
> +		offload_ctx = tls_offload_ctx_tx(ctx);
> +
> +		rc = crypto_aead_setkey(offload_ctx->aead_send, key,
> +					cipher_desc->key);
> +		if (rc)
> +			goto release_lock;
> +
> +		/* For rekey, delete old HW context before adding new one. */

As in the other patch, some unnecessary comments.

[...]
> +		memcpy(ctx->tx.iv + cipher_desc->salt, iv, cipher_desc->iv);
> +		memcpy(ctx->tx.rec_seq, rec_seq, cipher_desc->rec_seq);
> +
> +		spin_lock_irqsave(&offload_ctx->lock, flags);
> +		/* Delete old records, can't be retransmitted with new key */
> +		delete_all_records(offload_ctx);
> +
> +		/* Update unacked_record_sn for the new key's rec_seq.
> +		 * This is critical for SW fallback encryption to use
> +		 * the correct record sequence number after rekey.

The whole comment should probably be removed, but if it stays, it
should explain why this is critical, rather than just asserting that
it is. (but I guess this code will need to be changed to handle
unacked records anyway)

[...]
>  	dev_put(netdev);
>  
>  	return 0;
>  
>  release_lock:
>  	up_read(&device_offload_lock);
> +	if (new_crypto_info)
> +		goto release_netdev;

nit: not super elegant, but I'm not sure we can do much better :/

>  	clean_acked_data_disable(tcp_sk(sk));
>  	crypto_free_aead(offload_ctx->aead_send);
>  free_offload_ctx:
> @@ -1217,17 +1291,33 @@ int tls_set_device_offload(struct sock *sk)
>  	return rc;
>  }
>  

-- 
Sabrina

  reply	other threads:[~2026-02-23 14:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05 23:15 [RFC PATCH v7 0/4] tls: Add TLS 1.3 hardware offload support Rishikesh Jethwani
2026-02-05 23:15 ` [RFC PATCH v7 1/4] tls: add " Rishikesh Jethwani
2026-02-23 14:34   ` Sabrina Dubroca
2026-02-23 21:33     ` Rishikesh Jethwani
2026-02-05 23:15 ` [RFC PATCH v7 2/4] tls: add hardware offload key update support Rishikesh Jethwani
2026-02-23 14:40   ` Sabrina Dubroca [this message]
2026-02-05 23:15 ` [RFC PATCH v7 3/4] mlx5: TLS 1.3 hardware offload support Rishikesh Jethwani
2026-02-05 23:15 ` [RFC PATCH v7 4/4] selftests: drivers: net: hw: add TLS hardware offload test Rishikesh Jethwani

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aZxm8hSrVMkEIc2O@krikkit \
    --to=sd@queasysnail.net \
    --cc=borisp@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rjethwani@purestorage.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox