From: netdev-bot+sashiko@kernel.org
To: jiayuan.chen@linux.dev
Cc: netdev@vger.kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, john.fastabend@gmail.com, sd@queasysnail.net,
shuah@kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH net-next v3 1/2] netdevsim: add TLS device offload emulation
Date: Fri, 20 Nov 2026 06:51:22 +0000 [thread overview]
Message-ID: <179515748266.3136.5201206680474625164@kernel.org> (raw)
In-Reply-To: <20261119064902.242502-2-jiayuan.chen@linux.dev>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new NETDEVSIM dependency `depends on TLS || TLS=n` in
drivers/net/Kconfig is broader than the link requirement.
- [Low] The new TLS byte counters in drivers/net/netdevsim/tls.c add
skb->len, which is the whole L2 frame including Ethernet/IP/TCP…
- [Low] nsim_do_tls() comments "Leave what nsim_do_psp() has handled
alone", but the check it uses is the generic skb->encapsulation bit.
- [Low] nsim_tls_tx() (drivers/net/netdevsim/tls.c) checks again at
ndo_start_xmit time whether an skb is one of its own plaintext…
--
netdevsim: add TLS device offload emulation
This patch implements tlsdev_ops in netdevsim and advertises
NETIF_F_HW_TLS_TX/RX, so kTLS sockets over netdevsim take the device
offload path. No crypto is done: TX puts plaintext records on the wire
with the tag placeholder zeroed, and RX offload is emulated by matching
the tuple installed at tls_dev_add() time. A Kconfig dependency on TLS is
added because the new code calls tls_get_record().
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index ff79c466712df..cb4d4bb87afc2 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -607,6 +607,7 @@ config NETDEVSIM
> depends on INET
> depends on PSAMPLE || PSAMPLE=n
> depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
> + depends on TLS || TLS=n
[Severity: Low]
Is this dependency broader than needed? tls.o is only built when
CONFIG_TLS_DEVICE is set (see the Makefile hunk below). With TLS_DEVICE=n,
netdevsim.h supplies empty inline stubs for nsim_tls_init(),
nsim_tls_teardown() and nsim_do_tls(), so nothing in netdevsim links
against the tls module.
With TLS=m and TLS_DEVICE=n, NETDEVSIM is still capped at m. An existing
NETDEVSIM=y config would then be silently demoted to m.
The commit message says:
"NETDEVSIM can't be built in with TLS as a module since it calls
tls_get_record()."
That only holds when TLS_DEVICE=y. TLS_DEVICE is a bool that depends on
TLS, so would something like this express the actual requirement?
depends on TLS || !TLS_DEVICE
> select NET_DEVLINK
> select PAGE_POOL
> select NET_SHAPER
> diff --git a/drivers/net/netdevsim/Makefile b/drivers/net/netdevsim/Makefile
> index 87718204fb4de..c7f7621323b2b 100644
> --- a/drivers/net/netdevsim/Makefile
> +++ b/drivers/net/netdevsim/Makefile
> @@ -25,3 +25,7 @@ endif
> ifneq ($(CONFIG_MACSEC),)
> netdevsim-objs += macsec.o
> endif
> +
> +ifneq ($(CONFIG_TLS_DEVICE),)
> +netdevsim-objs += tls.o
> +endif
[ ... ]
> diff --git a/drivers/net/netdevsim/tls.c b/drivers/net/netdevsim/tls.c
> new file mode 100644
> index 0000000000000..16c5508245d3a
> --- /dev/null
> +++ b/drivers/net/netdevsim/tls.c
> @@ -0,0 +1,453 @@
[ ... ]
> +static bool nsim_tls_tx(struct netdevsim *ns, struct sk_buff *skb)
> +{
> + /* Not ours: the software fallback has already encrypted it. Clear
> + * the decrypted mark the sending stack left so the peer's stack
> + * decrypts it.
> + */
> + if (!skb->decrypted || !tls_is_skb_tx_device_offloaded(skb) ||
> + rcu_dereference_bh(tls_get_ctx(skb->sk)->netdev) != ns->netdev) {
> + skb->decrypted = 0;
> + return false;
> + }
[Severity: Low]
Can this re-check race with tls_device_down()? The core has already
classified this skb as a device-offloaded plaintext record in
validate_xmit_skb()->tls_validate_xmit_skb(). But tls_device_down()
flips both fields read here before it waits for in-flight transmits:
net/tls/tls_device.c:tls_device_down() {
...
WRITE_ONCE(ctx->sk->sk_validate_xmit_skb, tls_validate_xmit_skb_sw);
...
rcu_assign_pointer(ctx->netdev, NULL);
...
synchronize_net();
...
}
Suppose a record that tls_validate_xmit_skb() already passed reaches
nsim_tls_tx() after the flip. It would take the "not ours" branch, which
clears skb->decrypted and skips nsim_tls_tx_zero_tags().
The peer would then get plaintext marked as not decrypted, carrying the
stale tag placeholder bytes. A peer socket with RX offloaded would fall
back to software decrypt and fail the connection with -EBADMSG, rather
than carrying on with the software fallback as tls_device_down() intends.
With netdevsim's default qdisc, dev_deactivate_many() calls
synchronize_net() before NETDEV_DOWN, and that closes the window. With a
noqueue root qdisc, sync_needed stays false:
net/sched/sch_generic.c:dev_deactivate_many() {
...
/* Wait for outstanding qdisc enqueuing calls. */
if (sync_needed)
synchronize_net();
...
}
So a qdisc-less __dev_queue_xmit() that has already passed
validate_xmit_skb() could still be running when tls_device_down() flips
the state.
Real drivers such as mlx5 have the same window by core design. The
tls_device_down() comment says unencrypted packets may be in flight until
synchronize_net(). With real crypto, though, the connection would not be
lost here.
> +
> + nsim_tls_tx_zero_tags(skb);
> + atomic64_inc(&ns->tls.tx_packets);
> + atomic64_add(skb->len, &ns->tls.tx_bytes);
[Severity: Low]
Should tx_bytes count TLS payload bytes rather than skb->len? skb->len
here is the whole frame, including the Ethernet, IP and TCP headers.
netdevsim also advertises NETIF_F_TSO, so tx_packets counts TSO
super-skbs rather than wire packets. The same applies to rx_packets and
rx_bytes in nsim_tls_rx().
Documentation/networking/tls-offload.rst defines tx_tls_encrypted_bytes
and rx_tls_decrypted_bytes as "number of TLS payload bytes". The PSP
emulation in the same driver counts payload only:
drivers/net/netdevsim/psp.c:nsim_do_psp() {
...
psp_len = skb->len - skb_inner_transport_offset(skb);
atomic64_inc(&ns->psp.tx_packets);
atomic64_add(psp_len, &ns->psp.tx_bytes);
...
}
These counters are only exposed through the debugfs "tls" file, and
nothing in the tree reads them yet.
> +
> + return true;
> +}
[ ... ]
> +void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns,
> + struct netdevsim *peer_ns)
> +{
> + /* Leave what nsim_do_psp() has handled alone. */
> + if (skb->encapsulation)
> + return;
[Severity: Low]
The comment mentions nsim_do_psp(), but skb->encapsulation is a generic
bit. psp_dev_encapsulate() sets it, and so do tunnel drivers that use
iptunnel_handle_offloads() (VXLAN, GENEVE, GRE). Doesn't that mean any
encapsulated skb also skips the "not ours" path in nsim_tls_tx() that
clears skb->decrypted?
This matters for software fallback output. complete_skb() in
net/tls/tls_device_fallback.c builds the ciphertext skb with
skb_copy_header(), so it still carries decrypted=1.
Consider a socket offloaded on netdevsim whose route later moves to a
tunnel on top of netdevsim:
- the tunnel device runs the software fallback;
- at netdevsim, tls_validate_xmit_skb() passes the skb because
dev == ctx->netdev;
- nsim_do_tls() returns early here;
- the peer receives decapsulated ciphertext still marked decrypted.
A peer whose RX context is also offloaded on netdevsim would accept that
ciphertext as plaintext. A peer with software RX ignores the bit and
decrypts correctly.
The setup is contrived, but should this check be limited to PSP-handled
skbs, or should the comment say that all encapsulated traffic is skipped?
> +
> + if (!nsim_tls_tx(ns, skb))
> + return;
> +
> + nsim_tls_rx(peer_ns, skb);
> +}
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119064902.242502-1-jiayuan.chen%40linux.dev
next prev parent reply other threads:[~2026-11-20 6:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 6:48 [PATCH net-next v3 0/2] netdevsim: add TLS device offload emulation and test Jiayuan Chen
2026-11-19 6:48 ` [PATCH net-next v3 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen
2026-11-20 6:51 ` netdev-bot+sashiko [this message]
2026-11-19 6:48 ` [PATCH net-next v3 2/2] selftests: drv-net: run tls_hw_offload on netdevsim Jiayuan Chen
2026-11-20 6:51 ` netdev-bot+sashiko
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=179515748266.3136.5201206680474625164@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sd@queasysnail.net \
--cc=shuah@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.