Skip to contentSkip to conversation

netdevsim: add TLS device offload emulation and test

PATCH Applied Jiayuan Chen 3 participants 6 messages Nov 19 – Nov 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover netdevsim: add TLS device offload emulation and test

Running kTLS over this already found a few bugs:

b17cf742eaad ("tls: device: fix out-of-bounds write in tls_append_frag()") ed642349d87d ("tls: fix the open record check in the max payload size setsockopt")

So I think it is worth sending a formal patchset. v1 [1] was asked to wait for a selftest that can also run against real hardware. That test, drivers/net/hw/tls_hw_offload.py, is in the tree now, so this can move forward.

The kTLS device offload path in net/tls/tls_device.c has no test coverage upstream -- selftests/net/tls.c is software only, and the offload code needs a driver that implements it.

So teach netdevsim to fake it. Patch 1 implements tlsdev_ops and advertises the TLS features. Patch 2 lets the existing hardware offload test, drivers/net/hw/tls_hw_offload.py, run on netdevsim as well, so the same test covers real devices and the netdevsim pair CI already uses.

No crypto is done, like the IPsec, MACsec and PSP emulation netdevsim already has: TX puts the plaintext record on the wire. That only works with netdevsim on both ends and offload on in both directions, which is what the netdevsim environment of the drivers/net tests gives. It still covers record assembly and the offload lifecycle.

[1] https://lore.kernel.org/netdev/[email protected]/

v2 -> v3:
- fix the build with CONFIG_IPV6=n (kernel test robot)
- address some of the issues Sashiko reported
v2: https://lore.kernel.org/netdev/[email protected]/
v1 -> v2:
- drop the netdevsim-only selftest, run the upstream tls_hw_offload.py
on netdevsim instead so the test also covers real hardware (Jakub)
- rebase on net-next
v1: https://lore.kernel.org/netdev/[email protected]/
RFC (July): https://lore.kernel.org/netdev/[email protected]/

Jiayuan Chen (2):
netdevsim: add TLS device offload emulation
selftests: drv-net: run tls_hw_offload on netdevsim

 drivers/net/Kconfig                           |   1 +
 drivers/net/netdevsim/Makefile                |   4 +
 drivers/net/netdevsim/netdev.c                |   9 +-
 drivers/net/netdevsim/netdevsim.h             |  34 ++
 drivers/net/netdevsim/tls.c                   | 453 ++++++++++++++++++
 .../drivers/net/hw/tls_hw_offload.py          |   5 +-
 6 files changed, 503 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/netdevsim/tls.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/2 netdevsim: add TLS device offload emulation

Implement tlsdev_ops and advertise NETIF_F_HW_TLS_TX/RX, so kTLS sockets routed over netdevsim take the device path in net/tls/tls_device.c instead of the software one. Both features are on by default, like the IPsec and MACsec emulation. A port holds up to 32 offload contexts, which is enough for the tests.

The point of this is code coverage and control path testing. Nothing is actually encrypted or decrypted, and no guarantees are made for the corner cases where the crypto would have had to be right.

TX puts the plaintext record on the wire, so the RX side has to be offloaded on netdevsim as well: otherwise the core runs the software AEAD over plaintext and fails the connection with -EBADMSG. The other way round, software TX into an offloaded RX, is real ciphertext and works.

The placeholder the stack leaves for the authentication tag comes from a page frag that is never zeroed, so clear it instead of putting stale page contents on the wire.

NETIF_F_RXCSUM comes along because netdev_fix_features() drops NETIF_F_HW_TLS_RX without it. NETDEVSIM can't be built in with TLS as a module since it calls tls_get_record().

---
 drivers/net/Kconfig               |   1 +
 drivers/net/netdevsim/Makefile    |   4 +
 drivers/net/netdevsim/netdev.c    |   9 +-
 drivers/net/netdevsim/netdevsim.h |  34 +++
 drivers/net/netdevsim/tls.c       | 453 ++++++++++++++++++++++++++++++
 5 files changed, 499 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/netdevsim/tls.c
drivers/net/Kconfig +1 -0
index ff79c466712df..cb4d4bb87afc2 100644
@@ -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
 	select NET_DEVLINK
 	select PAGE_POOL
 	select NET_SHAPER
drivers/net/netdevsim/Makefile +4 -0
index 87718204fb4de..c7f7621323b2b 100644
@@ -25,3 +25,7 @@ endif
 ifneq ($(CONFIG_MACSEC),)
 netdevsim-objs += macsec.o
 endif
+
+ifneq ($(CONFIG_TLS_DEVICE),)
+netdevsim-objs += tls.o
+endif
drivers/net/netdevsim/netdev.c +7 -2
index 0372a9bd63bbb..8a6f16a318ccd 100644
@@ -155,6 +155,8 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (dr)
 		goto out_drop_free;
 
+	nsim_do_tls(skb, ns, peer_ns);
+
 	rxq = skb_get_queue_mapping(skb);
 	if (rxq >= peer_dev->num_rx_queues)
 		rxq = rxq % peer_dev->num_rx_queues;
@@ -1097,10 +1099,11 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
 
 	nsim_macsec_init(ns);
 	nsim_ipsec_init(ns);
+	nsim_tls_init(ns);
 
 	err = register_netdevice(ns->netdev);
 	if (err)
-		goto err_ipsec_teardown;
+		goto err_teardown;
 	rtnl_unlock();
 
 	err = nsim_psp_init(ns);
@@ -1123,7 +1126,8 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
 		RCU_INIT_POINTER(peer->peer, NULL);
 	RCU_INIT_POINTER(ns->peer, NULL);
 	unregister_netdevice(ns->netdev);
-err_ipsec_teardown:
+err_teardown:
+	nsim_tls_teardown(ns);
 	nsim_ipsec_teardown(ns);
 	nsim_macsec_teardown(ns);
 	nsim_bpf_uninit(ns);
@@ -1226,6 +1230,7 @@ void nsim_destroy(struct netdevsim *ns)
 	RCU_INIT_POINTER(ns->peer, NULL);
 	unregister_netdevice(dev);
 	if (nsim_dev_port_is_pf(ns->nsim_dev_port)) {
+		nsim_tls_teardown(ns);
 		nsim_macsec_teardown(ns);
 		nsim_ipsec_teardown(ns);
 		nsim_bpf_uninit(ns);
drivers/net/netdevsim/netdevsim.h +34 -0
index 2aa7ea924396e..e53da201eb30b 100644
@@ -56,6 +56,19 @@ struct nsim_ipsec {
 	u32 tx;
 };
 
+struct nsim_tls {
+	struct list_head conns;
+	spinlock_t lock;	/* protects conns */
+	struct dentry *dfile;
+	u32 count;
+	u32 tx_conn;
+	u32 rx_conn;
+	atomic64_t tx_packets;
+	atomic64_t tx_bytes;
+	atomic64_t rx_packets;
+	atomic64_t rx_bytes;
+};
+
 #define NSIM_MACSEC_MAX_SECY_COUNT 3
 #define NSIM_MACSEC_MAX_RXSC_COUNT 1
 struct nsim_rxsc {
@@ -143,6 +156,7 @@ struct netdevsim {
 	bool bpf_map_accept;
 	struct nsim_ipsec ipsec;
 	struct nsim_macsec macsec;
+	struct nsim_tls tls;
 	struct nsim_vlan vlan;
 	struct {
 		u32 inject_error;
@@ -436,6 +450,26 @@ static inline bool nsim_ipsec_tx(struct netdevsim *ns, struct sk_buff *skb)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_TLS_DEVICE)
+void nsim_tls_init(struct netdevsim *ns);
+void nsim_tls_teardown(struct netdevsim *ns);
+void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns,
+		 struct netdevsim *peer_ns);
+#else
+static inline void nsim_tls_init(struct netdevsim *ns)
+{
+}
+
+static inline void nsim_tls_teardown(struct netdevsim *ns)
+{
+}
+
+static inline void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns,
+			       struct netdevsim *peer_ns)
+{
+}
+#endif
+
 #if IS_ENABLED(CONFIG_MACSEC)
 void nsim_macsec_init(struct netdevsim *ns);
 void nsim_macsec_teardown(struct netdevsim *ns);
drivers/net/netdevsim/tls.c new file +453 -0

453 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH net-next v3 1/2] netdevsim: add TLS device offload emulation

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…

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().

drivers/net/Kconfig config NETDEVSIM · line 610

Quoted 9 lines
drivers/net/Kconfig +1 -0
index ff79c466712df..cb4d4bb87afc2 100644
@@ -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
Quoted 15 lines
drivers/net/Kconfig +0 -0
 	select NET_DEVLINK
 	select PAGE_POOL
 	select NET_SHAPER
drivers/net/netdevsim/Makefile +4 -0
index 87718204fb4de..c7f7621323b2b 100644
@@ -25,3 +25,7 @@ endif
 ifneq ($(CONFIG_MACSEC),)
 netdevsim-objs += macsec.o
 endif
+
+ifneq ($(CONFIG_TLS_DEVICE),)
+netdevsim-objs += tls.o
+endif

[ ... ]

Quoted 6 lines
drivers/net/netdevsim/tls.c new file +0 -0
new file mode 100644
index 0000000000000..16c5508245d3a
@@ -0,0 +1,453 @@

[ ... ]

drivers/net/netdevsim/tls.c line 205

Quoted 11 lines
drivers/net/netdevsim/tls.c new file +11 -0
+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.

drivers/net/netdevsim/tls.c line 209

Quoted 4 lines
drivers/net/netdevsim/tls.c new file +4 -0
+
+	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.

Quoted 3 lines
drivers/net/netdevsim/tls.c new file +3 -0
+
+	return true;
+}

[ ... ]

drivers/net/netdevsim/tls.c line 241

Quoted 6 lines
drivers/net/netdevsim/tls.c new file +6 -0
+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?

Quoted 6 lines
drivers/net/netdevsim/tls.c new file +6 -0
+
+	if (!nsim_tls_tx(ns, skb))
+		return;
+
+	nsim_tls_rx(peer_ns, skb);
+}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119064902.242502-1-jiayuan.chen%40linux.dev
#3 lore raw

PATCH v3 2/2 selftests: drv-net: run tls_hw_offload on netdevsim

In reply to Jiayuan Chen

Now that netdevsim offers kTLS device offload, let the test run on it
too: drop nsim_test=False so the default netdevsim pair is used when no NETIF is set.

The only thing netdevsim can't give is ethtool -S: nsim_ethtool_ops in drivers/net/netdevsim/ethtool.c has no get_sset_count or get_strings, so the command fails and every case died taking the NIC counter snapshot. That is a gap in netdevsim itself, not in the TLS emulation, and the NIC counters are optional in this test anyway, so skip the snapshot on netdevsim instead of adding ethtool stats to the driver. A netdevsim port passed in through NETIF still runs ethtool -S and fails, that is not supported for now.

  # ./tls_hw_offload.py
  # Interface: eth1, driver: netdevsim
  TAP version 13
  1..8
  ok 1 tls_hw_offload.test_tls_offload.tls12_aes128
  ok 2 tls_hw_offload.test_tls_offload.tls12_aes256
  ok 3 tls_hw_offload.test_tls_offload.tls12_aes128_ip6
  ok 4 tls_hw_offload.test_tls_offload_sizes.small_buf
  ok 5 tls_hw_offload.test_tls_offload_sizes.large_buf
  ok 6 tls_hw_offload.test_tls_offload_sizes.random_buf
  ok 7 tls_hw_offload.test_tls_offload_record_type.handshake
  ok 8 tls_hw_offload.test_tls_offload_record_type.alert
  # Totals: pass:8 fail:0 xfail:0 xpass:0 skip:0 error:0
---
 tools/testing/selftests/drivers/net/hw/tls_hw_offload.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/hw/tls_hw_offload.py +4 -1
index e720ce6547610..1197f17caa13c 100755
@@ -125,6 +125,9 @@ def read_nic_stats(cfg):
     # before/after-delta caveat as read_tls_stats(): these are device-wide,
     # so concurrent kTLS traffic on this NIC would perturb the deltas.
     stats = defaultdict(int)
+    # netdevsim has no ethtool -S, and the NIC counters below are optional
+    if cfg.get_local_nsim_dev():
+        return stats
     output = cmd(f"ethtool -S {cfg.ifname}").stdout
     for line in output.strip().split('\n'):
         key, sep, val = line.partition(':')
@@ -307,7 +310,7 @@ def test_tls_offload_record_type(cfg, record_type):
 
 def main() -> None:
     """Set up the DUT/peer environment and run the offload test suites."""
-    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+    with NetDrvEpEnv(__file__) as cfg:
         cfg.bin_local = cfg.test_dir / "tls_hw_offload"
         cfg.bin_remote = None
         cfg.tls_skip_reason = None
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH net-next v3 2/2] selftests: drv-net: run tls_hw_offload on netdevsim

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] In read_nic_stats() (tools/testing/selftests/drivers/net/hw/tls_hw_offload.py:128-131),…
- [Low] Several comments still describe a real-hardware-only setup, but after this patch the default run (no NETIF) uses a netdevsim pair that…

--

selftests: drv-net: run tls_hw_offload on netdevsim

This drops nsim_test=False from tls_hw_offload.py, so the test runs on the default netdevsim pair when NETIF is not set. It also makes read_nic_stats() skip the ethtool -S snapshot when a local netdevsim device was created by the environment.

tools/testing/selftests/drivers/net/hw/tls_hw_offload.py def read_nic_stats(cfg): · line 131

Quoted 12 lines
tools/testing/selftests/drivers/net/hw/tls_hw_offload.py +3 -0
index e720ce6547610..1197f17caa13c 100755
@@ -125,6 +125,9 @@ def read_nic_stats(cfg):
     # before/after-delta caveat as read_tls_stats(): these are device-wide,
     # so concurrent kTLS traffic on this NIC would perturb the deltas.
     stats = defaultdict(int)
+    # netdevsim has no ethtool -S, and the NIC counters below are optional
+    if cfg.get_local_nsim_dev():
+        return stats
     output = cmd(f"ethtool -S {cfg.ifname}").stdout

[Severity: Medium]
Does this guard check the right thing? The comment is about the driver, but get_local_nsim_dev() only returns self._ns. That is set only by create_local() when NETIF is not in the environment:

tools/testing/selftests/drivers/net/lib/py/env.py:NetDrvEpEnv.__init__() {
...
self._ns = None
...
if "NETIF" in self.env:
if nsim_test is True:
raise KsftXfailEx("Test only works on netdevsim")
self._check_env()
...
}

If NETIF names a netdevsim port, self._ns stays None. The test then falls through to cmd("ethtool -S ...") with the default fail=True. netdevsim has no get_sset_count, get_strings or get_ethtool_stats, so ethtool exits non-zero and cmd() raises CmdExitFailure. run_tls_test() does not catch it, so all 8 variants fail at the first snapshot. Any other TLS-offload netdev without ethtool stats would fail the same way.

The test header already says these counters are optional:

    # counters. Each counter is checked only when present.
    ...
    # Missing NIC crypto counters remain optional.

The get_local_nsim_dev() docstring also discourages this kind of use:

Using this method is discouraged, as it makes tests nsim-specific. Standard interfaces available on all HW should ideally be used.

Would a driver-agnostic check be simpler? For example, run ethtool -S with fail=False and return the empty stats dict on a non-zero exit. That would cover the default nsim pair, NETIF=netdevsim and any stats-less driver, with about the same amount of code. The commit message mentions the NETIF case but doesn't say why the environment check was chosen over a capability check.

[ ... ]

tools/testing/selftests/drivers/net/hw/tls_hw_offload.py def test_tls_offload_record_type(cfg, record_type): · line 313

Quoted 6 lines
tools/testing/selftests/drivers/net/hw/tls_hw_offload.py +1 -1
@@ -307,7 +310,7 @@ def test_tls_offload_record_type(cfg, record_type):
 
 def main() -> None:
     """Set up the DUT/peer environment and run the offload test suites."""
-    with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
+    with NetDrvEpEnv(__file__) as cfg:

[Severity: Low]
This isn't a bug, but with netdevsim now the default environment, a few comments still describe a real-hardware-only setup. Should they be updated?

The comment in read_tls_stats() says:

# sock_net(sk)). The test runs on a real NIC in the host namespace, so

The header of tls_hw_offload.c says:

* Tests kTLS hardware offload between two physical nodes using

The run_tls_test() docstring says the remote:

source/sink and may run any kernel without HW offload. Both sides run

On netdevsim this isn't true. drivers/net/netdevsim/tls.c says:

/* Emulated kTLS offload. No crypto is performed: TX puts the record on the
* wire as plaintext, so the RX side has to be offloaded on netdevsim as
* well, otherwise the core runs the software AEAD over plaintext and fails
* the connection with -EBADMSG.

So on the default nsim path, the peer has to receive with HW offload. If its RX offload were turned off, the test would fail, even though the docstring says that setup is allowed.

Quoted 3 lines
tools/testing/selftests/drivers/net/hw/tls_hw_offload.py +0 -0
         cfg.bin_local = cfg.test_dir / "tls_hw_offload"
         cfg.bin_remote = None
         cfg.tls_skip_reason = None
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119064902.242502-1-jiayuan.chen%40linux.dev
maintainer Applied
#5 lore raw
In reply to Jiayuan Chen
Quoted 27 lines · Jiayuan Chen

Running kTLS over this already found a few bugs:

b17cf742eaad ("tls: device: fix out-of-bounds write in tls_append_frag()") ed642349d87d ("tls: fix the open record check in the max payload size setsockopt")

So I think it is worth sending a formal patchset. v1 [1] was asked to wait for a selftest that can also run against real hardware. That test, drivers/net/hw/tls_hw_offload.py, is in the tree now, so this can move forward.

The kTLS device offload path in net/tls/tls_device.c has no test coverage upstream -- selftests/net/tls.c is software only, and the offload code needs a driver that implements it.

So teach netdevsim to fake it. Patch 1 implements tlsdev_ops and advertises the TLS features. Patch 2 lets the existing hardware offload test, drivers/net/hw/tls_hw_offload.py, run on netdevsim as well, so the same test covers real devices and the netdevsim pair CI already uses.

No crypto is done, like the IPsec, MACsec and PSP emulation netdevsim already has: TX puts the plaintext record on the wire. That only works with netdevsim on both ends and offload on in both directions, which is what the netdevsim environment of the drivers/net tests gives. It still covers record assembly and the offload lifecycle.

[1] https://lore.kernel.org/netdev/[email protected]/

Quoted 10 lines

v2 -> v3:
- fix the build with CONFIG_IPV6=n (kernel test robot)
- address some of the issues Sashiko reported
v2: https://lore.kernel.org/netdev/[email protected]/
v1 -> v2:
- drop the netdevsim-only selftest, run the upstream tls_hw_offload.py on netdevsim instead so the test also covers real hardware (Jakub)
- rebase on net-next
v1: https://lore.kernel.org/netdev/[email protected]/
RFC (July): https://lore.kernel.org/netdev/[email protected]/

Applied, thanks!

Paolo