* [PATCH net-next v2 0/2] netdevsim: add TLS device offload emulation and test
@ 2026-11-17 14:06 Jiayuan Chen
2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen
2026-11-17 14:06 ` [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim Jiayuan Chen
0 siblings, 2 replies; 7+ messages in thread
From: Jiayuan Chen @ 2026-11-17 14:06 UTC (permalink / raw)
To: netdev, kuba
Cc: Jiayuan Chen, Andrew Lunn, David S. Miller, Eric Dumazet,
Paolo Abeni, John Fastabend, Sabrina Dubroca, Shuah Khan,
linux-kernel, linux-kselftest
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, RX just sets
skb->decrypted. 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/20260901154914.11637-3-jiayuan.chen@linux.dev/
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/20260901154914.11637-1-jiayuan.chen@linux.dev/
RFC (July): https://lore.kernel.org/netdev/20260728125658.390500-1-jiayuan.chen@linux.dev/
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 | 477 ++++++++++++++++++
.../drivers/net/hw/tls_hw_offload.py | 5 +-
6 files changed, 527 insertions(+), 3 deletions(-)
create mode 100644 drivers/net/netdevsim/tls.c
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation 2026-11-17 14:06 [PATCH net-next v2 0/2] netdevsim: add TLS device offload emulation and test Jiayuan Chen @ 2026-11-17 14:06 ` Jiayuan Chen 2026-11-18 8:15 ` kernel test robot ` (2 more replies) 2026-11-17 14:06 ` [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim Jiayuan Chen 1 sibling, 3 replies; 7+ messages in thread From: Jiayuan Chen @ 2026-11-17 14:06 UTC (permalink / raw) To: netdev, kuba Cc: Jiayuan Chen, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, John Fastabend, Sabrina Dubroca, Shuah Khan, linux-kernel, linux-kselftest 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. 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 and RX just sets skb->decrypted, 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. A record the core has already encrypted itself, through the software fallback, is left alone except for the decrypted mark the sending stack put on the skb: with no wire in between that would reach the peer as is, so it is cleared and the peer's stack decrypts. The one thing a device would still do is write the authentication tag, and the placeholder the stack leaves for it comes from a page frag that is never zeroed, so clear it instead of putting stale page contents on the wire. Records are located with tls_get_record(), the way the real drivers do it; on RX, where there is no socket yet, connections are matched on the tuple from ->tls_dev_add() the way the hardware does. 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(). Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> --- 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 | 477 ++++++++++++++++++++++++++++++ 5 files changed, 523 insertions(+), 2 deletions(-) create mode 100644 drivers/net/netdevsim/tls.c 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 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/netdev.c b/drivers/net/netdevsim/netdev.c index 0372a9bd63bbb..8a6f16a318ccd 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -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); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 2aa7ea924396e..5c14033ab507f 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -56,6 +56,19 @@ struct nsim_ipsec { u32 tx; }; +struct nsim_tls { + struct list_head conns; + spinlock_t lock; /* protects conns and the counters below */ + 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); diff --git a/drivers/net/netdevsim/tls.c b/drivers/net/netdevsim/tls.c new file mode 100644 index 0000000000000..cad9b262da441 --- /dev/null +++ b/drivers/net/netdevsim/tls.c @@ -0,0 +1,477 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/ipv6.h> +#include <linux/list.h> +#include <linux/skbuff.h> +#include <linux/slab.h> +#include <linux/tcp.h> +#include <net/ip.h> +#include <net/ipv6.h> +#include <net/tcp.h> +#include <net/tls.h> + +#include "netdevsim.h" + +/* Emulated kTLS offload. No crypto is performed: TX puts the record on the + * wire as plaintext and RX marks it decrypted, 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. + */ + +#define NSIM_TLS_MAX_CONN 32 + +/* netdev_fix_features() drops NETIF_F_HW_TLS_RX unless the device also does + * RX checksums, which every offload capable NIC does. + */ +#define NSIM_TLS_FEATURES (NETIF_F_HW_TLS_TX | NETIF_F_HW_TLS_RX | \ + NETIF_F_RXCSUM) + +struct nsim_tls_conn { + struct list_head list; + struct rcu_head rcu; + + /* Identity as seen on the wire, from the point of view of the port + * the offload was installed on: l* is this side, r* is the peer. + */ + struct in6_addr laddr; + struct in6_addr raddr; + __be16 lport; + __be16 rport; + u16 family; + + enum tls_offload_ctx_dir dir; + u32 start_sn; + bool started; + u16 cipher_type; + const struct tls_context *tls_ctx; +}; + +struct nsim_tls_tuple { + struct in6_addr saddr; + struct in6_addr daddr; + __be16 sport; + __be16 dport; + u32 seq; +}; + +/* Parse the tuple from the frame the way a NIC would. The xmit skb is not + * always a well formed local TCP skb (AF_PACKET, tc redirect); use + * skb_header_pointer() so a non-linear or truncated header cannot be misread. + */ +static bool nsim_tls_parse(const struct sk_buff *skb, + struct nsim_tls_tuple *t) +{ + int off = skb_network_offset(skb); + const struct tcphdr *th; + struct tcphdr _th; + + switch (skb->protocol) { + case htons(ETH_P_IP): { + const struct iphdr *iph; + struct iphdr _iph; + + iph = skb_header_pointer(skb, off, sizeof(_iph), &_iph); + if (!iph || iph->version != 4 || iph->ihl < 5 || + iph->protocol != IPPROTO_TCP || ip_is_fragment(iph)) + return false; + ipv6_addr_set_v4mapped(iph->saddr, &t->saddr); + ipv6_addr_set_v4mapped(iph->daddr, &t->daddr); + off += iph->ihl * 4; + break; + } + case htons(ETH_P_IPV6): { + const struct ipv6hdr *ip6h; + struct ipv6hdr _ip6h; + __be16 frag_off; + u8 nexthdr; + int thoff; + + ip6h = skb_header_pointer(skb, off, sizeof(_ip6h), &_ip6h); + if (!ip6h) + return false; + + nexthdr = ip6h->nexthdr; + thoff = ipv6_skip_exthdr(skb, off + sizeof(_ip6h), &nexthdr, + &frag_off); + if (thoff < 0 || nexthdr != IPPROTO_TCP || frag_off) + return false; + + t->saddr = ip6h->saddr; + t->daddr = ip6h->daddr; + off = thoff; + break; + } + default: + return false; + } + + th = skb_header_pointer(skb, off, sizeof(_th), &_th); + if (!th) + return false; + t->sport = th->source; + t->dport = th->dest; + t->seq = ntohl(th->seq); + + return true; +} + +/* No socket on RX yet, so match the tuple installed at ->tls_dev_add(), the + * way the hardware does. + */ +static bool nsim_tls_rx_offloaded(struct netdevsim *ns, + const struct nsim_tls_tuple *t) +{ + struct nsim_tls_conn *conn; + + list_for_each_entry_rcu(conn, &ns->tls.conns, list) { + if (conn->dir != TLS_OFFLOAD_CTX_DIR_RX || + conn->lport != t->dport || conn->rport != t->sport || + !ipv6_addr_equal(&conn->laddr, &t->daddr) || + !ipv6_addr_equal(&conn->raddr, &t->saddr)) + continue; + + /* start_sn is the socket's copied_seq when the offload was + * installed, so a segment before it only carries bytes TCP + * has already received: tcp_data_queue() drops or trims those + * whatever we flag. The check only keeps a pre-offload stream + * from being reported decrypted, so asking once is enough, + * and it also avoids the sequence space wrapping past a fixed + * start_sn 2G later. + */ + if (!READ_ONCE(conn->started)) { + if (before(t->seq, conn->start_sn)) + return false; + WRITE_ONCE(conn->started, true); + } + + return true; + } + + return false; +} + +/* The stack leaves an uninitialized, tag sized gap at the tail of each record + * for the device to write the auth tag into. We do not encrypt, so zero it + * to avoid leaking that memory onto the wire. Nothing tells the device where + * the tag is, so walk the records with tls_get_record() and clear the end of + * each one's last frag. Every segment of a record and any retransmit of it + * share these pages, which is why the record is cleared rather than the skb; + * nothing consumes the placeholder, so a clone seeing the write is harmless. + */ +static void nsim_tls_tx_zero_tags(struct sk_buff *skb) +{ + struct tls_context *ctx = tls_get_ctx(skb->sk); + const struct tcphdr *th = tcp_hdr(skb); + struct tls_offload_context_tx *tx_ctx; + u32 seq, end, tag_size; + unsigned long flags; + unsigned int off; + + off = skb_transport_offset(skb) + __tcp_hdrlen(th); + if (off >= skb->len) + return; + + tag_size = ctx->prot_info.tag_size; + seq = ntohl(th->seq); + end = seq + skb->len - off; + tx_ctx = tls_offload_ctx_tx(ctx); + + spin_lock_irqsave(&tx_ctx->lock, flags); + while (before(seq, end)) { + struct tls_record_info *record; + skb_frag_t *frag; + u64 rcd_sn; + + record = tls_get_record(tx_ctx, seq, &rcd_sn); + if (!record || tls_record_is_start_marker(record)) + break; + + frag = &record->frags[record->num_frags - 1]; + memset(skb_frag_address(frag) + skb_frag_size(frag) - tag_size, + 0, tag_size); + + seq = record->end_seq; + } + spin_unlock_irqrestore(&tx_ctx->lock, flags); +} + +/* Stand in for the inline encryption the hardware would do on the way out. + * The stack has already framed the record and we do not encrypt, so + * skb->decrypted is not cleared for our own records and the tag is all that + * is left to deal with. The socket is right here, so identify the connection + * the way the real drivers do. + */ +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 (!tls_is_skb_tx_device_offloaded(skb) || + rcu_dereference_bh(tls_get_ctx(skb->sk)->netdev) != ns->netdev) { + skb->decrypted = 0; + return false; + } + + nsim_tls_tx_zero_tags(skb); + atomic64_inc(&ns->tls.tx_packets); + atomic64_add(skb->len, &ns->tls.tx_bytes); + + return true; +} + +/* Stand in for the inline decryption the peer's hardware would do, since we + * are about to hand the skb to its stack. + */ +static void nsim_tls_rx(struct netdevsim *ns, struct sk_buff *skb) +{ + struct nsim_tls_tuple t; + + /* Not every port registers the offload, and one that does not never + * initializes the list head, so gate on the count. It is the + * cheaper test anyway. + */ + if (!READ_ONCE(ns->tls.count)) + return; + + if (!nsim_tls_parse(skb, &t)) + return; + + if (!nsim_tls_rx_offloaded(ns, &t)) + return; + + skb->decrypted = 1; + atomic64_inc(&ns->tls.rx_packets); + atomic64_add(skb->len, &ns->tls.rx_bytes); +} + +/* netdevsim has no wire: nsim_start_xmit() hands the skb straight to the + * peer's receive path, so this one call site stands in for the hardware of + * both ports. It has to run before nsim_forward_skb() moves the skb over, + * which resets the headers. + */ +void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns, + struct netdevsim *peer_ns) +{ + /* nsim_do_psp() ran first and may have wrapped the record stream, so + * this is no longer a plain TLS over TCP packet. No NIC chains the + * two inline offloads either, so leave it alone. + */ + if (skb->encapsulation) + return; + + /* Only what this port just "encrypted" may skip decryption on the + * peer. Everything else - a software kTLS sender because the TX + * feature is off, a frame injected on the tuple - really is + * ciphertext or not TLS at all, and the core has to deal with it. + */ + if (!nsim_tls_tx(ns, skb)) + return; + + nsim_tls_rx(peer_ns, skb); +} + +static int nsim_tls_dev_add(struct net_device *netdev, struct sock *sk, + enum tls_offload_ctx_dir direction, + struct tls_crypto_info *crypto_info, + u32 start_offload_tcp_sn) +{ + struct netdevsim *ns = netdev_priv(netdev); + struct nsim_tls_conn *conn; + int ret = 0; + + /* Mirror the cipher support of a typical offload capable NIC. */ + switch (crypto_info->cipher_type) { + case TLS_CIPHER_AES_GCM_128: + case TLS_CIPHER_AES_GCM_256: + break; + default: + return -EOPNOTSUPP; + } + + conn = kzalloc_obj(*conn); + if (!conn) + return -ENOMEM; + + if (sk->sk_family == AF_INET6) { + conn->laddr = sk->sk_v6_rcv_saddr; + conn->raddr = sk->sk_v6_daddr; + } else { + ipv6_addr_set_v4mapped(sk->sk_rcv_saddr, &conn->laddr); + ipv6_addr_set_v4mapped(sk->sk_daddr, &conn->raddr); + } + conn->family = sk->sk_family; + conn->lport = htons(inet_sk(sk)->inet_num); + conn->rport = sk->sk_dport; + conn->dir = direction; + conn->start_sn = start_offload_tcp_sn; + conn->cipher_type = crypto_info->cipher_type; + conn->tls_ctx = tls_get_ctx(sk); + + spin_lock_bh(&ns->tls.lock); + if (ns->tls.count >= NSIM_TLS_MAX_CONN) { + ret = -ENOSPC; + goto out_unlock; + } + list_add_tail_rcu(&conn->list, &ns->tls.conns); + WRITE_ONCE(ns->tls.count, ns->tls.count + 1); + if (direction == TLS_OFFLOAD_CTX_DIR_TX) + ns->tls.tx_conn++; + else + ns->tls.rx_conn++; +out_unlock: + spin_unlock_bh(&ns->tls.lock); + + if (ret) + kfree(conn); + + return ret; +} + +static void nsim_tls_dev_del(struct net_device *netdev, + struct tls_context *tls_ctx, + enum tls_offload_ctx_dir direction) +{ + struct netdevsim *ns = netdev_priv(netdev); + struct nsim_tls_conn *conn; + + spin_lock_bh(&ns->tls.lock); + list_for_each_entry(conn, &ns->tls.conns, list) { + if (conn->tls_ctx != tls_ctx || conn->dir != direction) + continue; + + list_del_rcu(&conn->list); + WRITE_ONCE(ns->tls.count, ns->tls.count - 1); + if (direction == TLS_OFFLOAD_CTX_DIR_TX) + ns->tls.tx_conn--; + else + ns->tls.rx_conn--; + spin_unlock_bh(&ns->tls.lock); + + kfree_rcu(conn, rcu); + return; + } + spin_unlock_bh(&ns->tls.lock); + + netdev_err(netdev, "TLS %s context not found on del\n", + direction == TLS_OFFLOAD_CTX_DIR_TX ? "tx" : "rx"); +} + +/* Never reached, the emulation never asks for a resync, but the core insists + * on it for NETIF_F_HW_TLS_RX. + */ +static int nsim_tls_dev_resync(struct net_device *netdev, struct sock *sk, + u32 seq, u8 *rcd_sn, + enum tls_offload_ctx_dir direction) +{ + return 0; +} + +static const struct tlsdev_ops nsim_tlsdev_ops = { + .tls_dev_add = nsim_tls_dev_add, + .tls_dev_del = nsim_tls_dev_del, + .tls_dev_resync = nsim_tls_dev_resync, +}; + +static ssize_t nsim_tls_dbg_read(struct file *filp, char __user *buffer, + size_t count, loff_t *ppos) +{ + struct netdevsim *ns = filp->private_data; + struct nsim_tls_conn *conn; + size_t bufsize; + char *buf, *p; + int len; + + /* Two full IPv6 addresses and ports fit in 160 bytes a line. */ + bufsize = (NSIM_TLS_MAX_CONN * 160) + 200; + buf = kzalloc(bufsize, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + p = buf; + + spin_lock_bh(&ns->tls.lock); + p += scnprintf(p, bufsize - (p - buf), + "conn count=%u tx=%u rx=%u\n", + ns->tls.count, ns->tls.tx_conn, ns->tls.rx_conn); + p += scnprintf(p, bufsize - (p - buf), + "tx_packets=%llu tx_bytes=%llu rx_packets=%llu rx_bytes=%llu\n", + atomic64_read(&ns->tls.tx_packets), + atomic64_read(&ns->tls.tx_bytes), + atomic64_read(&ns->tls.rx_packets), + atomic64_read(&ns->tls.rx_bytes)); + + list_for_each_entry(conn, &ns->tls.conns, list) { + if (conn->family == AF_INET6) + p += scnprintf(p, bufsize - (p - buf), + "%s [%pI6c]:%u -> [%pI6c]:%u cipher=%u sn=%u\n", + conn->dir == TLS_OFFLOAD_CTX_DIR_TX ? + "tx" : "rx", + &conn->laddr, ntohs(conn->lport), + &conn->raddr, ntohs(conn->rport), + conn->cipher_type, conn->start_sn); + else + p += scnprintf(p, bufsize - (p - buf), + "%s %pI4:%u -> %pI4:%u cipher=%u sn=%u\n", + conn->dir == TLS_OFFLOAD_CTX_DIR_TX ? + "tx" : "rx", + &conn->laddr.s6_addr32[3], + ntohs(conn->lport), + &conn->raddr.s6_addr32[3], + ntohs(conn->rport), + conn->cipher_type, conn->start_sn); + } + spin_unlock_bh(&ns->tls.lock); + + len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf); + + kfree(buf); + + return len; +} + +static const struct file_operations nsim_tls_dbg_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = nsim_tls_dbg_read, + .llseek = default_llseek, +}; + +void nsim_tls_init(struct netdevsim *ns) +{ + INIT_LIST_HEAD(&ns->tls.conns); + spin_lock_init(&ns->tls.lock); + + ns->netdev->tlsdev_ops = &nsim_tlsdev_ops; + ns->netdev->features |= NSIM_TLS_FEATURES; + ns->netdev->hw_features |= NSIM_TLS_FEATURES; + + ns->tls.dfile = debugfs_create_file("tls", 0400, + ns->nsim_dev_port->ddir, ns, + &nsim_tls_dbg_fops); +} + +void nsim_tls_teardown(struct netdevsim *ns) +{ + struct nsim_tls_conn *conn, *tmp; + u32 left; + + debugfs_remove_recursive(ns->tls.dfile); + + spin_lock_bh(&ns->tls.lock); + left = ns->tls.count; + list_for_each_entry_safe(conn, tmp, &ns->tls.conns, list) { + list_del_rcu(&conn->list); + kfree_rcu(conn, rcu); + } + WRITE_ONCE(ns->tls.count, 0); + ns->tls.tx_conn = 0; + ns->tls.rx_conn = 0; + spin_unlock_bh(&ns->tls.lock); + + if (left) + netdev_err(ns->netdev, + "tearing down TLS offload with %u connections left\n", + left); +} -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation 2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen @ 2026-11-18 8:15 ` kernel test robot 2026-11-18 14:32 ` netdev-bot+sashiko 2026-11-18 22:15 ` kernel test robot 2 siblings, 0 replies; 7+ messages in thread From: kernel test robot @ 2026-11-18 8:15 UTC (permalink / raw) To: Jiayuan Chen, netdev, kuba Cc: llvm, oe-kbuild-all, Jiayuan Chen, Andrew Lunn, Eric Dumazet, Paolo Abeni, John Fastabend, Sabrina Dubroca, Shuah Khan, linux-kernel, linux-kselftest Hi Jiayuan, kernel test robot noticed the following build errors: [auto build test ERROR on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Jiayuan-Chen/netdevsim-add-TLS-device-offload-emulation/20261117-220630 base: net-next/main patch link: https://lore.kernel.org/r/20261117140642.4008-2-jiayuan.chen%40linux.dev patch subject: [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation config: x86_64-randconfig-1004-20261118 (https://download.01.org/0day-ci/archive/20261118/202611181558.YOFWJh8M-lkp@intel.com/config) compiler: clang version 22.1.8 (https://github.com/llvm/llvm-project ca7933e47d3a3451d81e72ac174dcb5aa28b59d1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261118/202611181558.YOFWJh8M-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202611181558.YOFWJh8M-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/net/netdevsim/tls.c:298:21: error: no member named 'skc_v6_rcv_saddr' in 'struct sock_common' 298 | conn->laddr = sk->sk_v6_rcv_saddr; | ~~~~^~~~~~~~~~~~~~~ include/net/sock.h:404:37: note: expanded from macro 'sk_v6_rcv_saddr' 404 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr | ^ >> drivers/net/netdevsim/tls.c:299:21: error: no member named 'skc_v6_daddr' in 'struct sock_common' 299 | conn->raddr = sk->sk_v6_daddr; | ~~~~^~~~~~~~~~~ include/net/sock.h:403:34: note: expanded from macro 'sk_v6_daddr' 403 | #define sk_v6_daddr __sk_common.skc_v6_daddr | ^ 2 errors generated. vim +298 drivers/net/netdevsim/tls.c 274 275 static int nsim_tls_dev_add(struct net_device *netdev, struct sock *sk, 276 enum tls_offload_ctx_dir direction, 277 struct tls_crypto_info *crypto_info, 278 u32 start_offload_tcp_sn) 279 { 280 struct netdevsim *ns = netdev_priv(netdev); 281 struct nsim_tls_conn *conn; 282 int ret = 0; 283 284 /* Mirror the cipher support of a typical offload capable NIC. */ 285 switch (crypto_info->cipher_type) { 286 case TLS_CIPHER_AES_GCM_128: 287 case TLS_CIPHER_AES_GCM_256: 288 break; 289 default: 290 return -EOPNOTSUPP; 291 } 292 293 conn = kzalloc_obj(*conn); 294 if (!conn) 295 return -ENOMEM; 296 297 if (sk->sk_family == AF_INET6) { > 298 conn->laddr = sk->sk_v6_rcv_saddr; > 299 conn->raddr = sk->sk_v6_daddr; 300 } else { 301 ipv6_addr_set_v4mapped(sk->sk_rcv_saddr, &conn->laddr); 302 ipv6_addr_set_v4mapped(sk->sk_daddr, &conn->raddr); 303 } 304 conn->family = sk->sk_family; 305 conn->lport = htons(inet_sk(sk)->inet_num); 306 conn->rport = sk->sk_dport; 307 conn->dir = direction; 308 conn->start_sn = start_offload_tcp_sn; 309 conn->cipher_type = crypto_info->cipher_type; 310 conn->tls_ctx = tls_get_ctx(sk); 311 312 spin_lock_bh(&ns->tls.lock); 313 if (ns->tls.count >= NSIM_TLS_MAX_CONN) { 314 ret = -ENOSPC; 315 goto out_unlock; 316 } 317 list_add_tail_rcu(&conn->list, &ns->tls.conns); 318 WRITE_ONCE(ns->tls.count, ns->tls.count + 1); 319 if (direction == TLS_OFFLOAD_CTX_DIR_TX) 320 ns->tls.tx_conn++; 321 else 322 ns->tls.rx_conn++; 323 out_unlock: 324 spin_unlock_bh(&ns->tls.lock); 325 326 if (ret) 327 kfree(conn); 328 329 return ret; 330 } 331 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation 2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen 2026-11-18 8:15 ` kernel test robot @ 2026-11-18 14:32 ` netdev-bot+sashiko 2026-11-18 22:15 ` kernel test robot 2 siblings, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-18 14:32 UTC (permalink / raw) To: jiayuan.chen Cc: netdev, kuba, andrew+netdev, davem, edumazet, pabeni, john.fastabend, sd, shuah, linux-kernel, linux-kselftest Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 3 · Low: 2 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] The RX-side 'decryption' emulation does not decide whether the peer sees skb->decrypted=1 for offloaded TLS records. - [Medium] netdevsim: unguarded IPv6 sock fields in nsim_tls_dev_add() break IPV6=n build - [Medium] netdevsim: non-TLS TCP segments treated as TLS records in nsim_tls_tx() - [Low] The comment on struct nsim_tls's lock in drivers/net/netdevsim/netdevsim.h:61 reads 'protects conns and the… - [Low] nsim_tls_tx_zero_tags() rewrites payload bytes (the auth-tag placeholder at the end of each record's last frag) without checking… -- netdevsim: add TLS device offload emulation This adds kTLS device offload emulation to netdevsim. It implements tlsdev_ops and advertises NETIF_F_HW_TLS_TX/RX. TX passes plaintext records through and zeroes the auth tag placeholder. RX marks skbs decrypted when they match the tuple installed at ->tls_dev_add(). > diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h > index 2aa7ea924396e..5c14033ab507f 100644 > --- a/drivers/net/netdevsim/netdevsim.h > +++ b/drivers/net/netdevsim/netdevsim.h > @@ -56,6 +56,19 @@ struct nsim_ipsec { > u32 tx; > }; > > +struct nsim_tls { > + struct list_head conns; > + spinlock_t lock; /* protects conns and the counters below */ > + 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; > +}; [Severity: Low] This isn't a bug, but is this comment accurate? The lock doesn't cover the datapath: - nsim_tls_tx() and nsim_tls_rx() update the atomic64 counters below it without ns->tls.lock. - nsim_tls_rx() reads count with READ_ONCE(). - nsim_tls_rx_offloaded() walks conns under RCU with list_for_each_entry_rcu(). The lock seems to serialize only the writers (nsim_tls_dev_add(), nsim_tls_dev_del() and nsim_tls_teardown()) and the debugfs snapshot. Could the comment say that instead? [ ... ] > diff --git a/drivers/net/netdevsim/tls.c b/drivers/net/netdevsim/tls.c > new file mode 100644 > index 0000000000000..cad9b262da441 > --- /dev/null > +++ b/drivers/net/netdevsim/tls.c > @@ -0,0 +1,477 @@ [ ... ] > +static void nsim_tls_tx_zero_tags(struct sk_buff *skb) > +{ [ ... ] > + spin_lock_irqsave(&tx_ctx->lock, flags); > + while (before(seq, end)) { > + struct tls_record_info *record; > + skb_frag_t *frag; > + u64 rcd_sn; > + > + record = tls_get_record(tx_ctx, seq, &rcd_sn); > + if (!record || tls_record_is_start_marker(record)) > + break; > + > + frag = &record->frags[record->num_frags - 1]; > + memset(skb_frag_address(frag) + skb_frag_size(frag) - tag_size, > + 0, tag_size); [Severity: Low] Can this memset leave a bad TCP checksum when the checksum has already been computed in software? netdevsim puts NETIF_F_HW_CSUM in hw_features. So "ethtool -K <dev> tx off" can be run while TLS TX offloads are installed. That leads to: - netdev_fix_features() drops NETIF_F_HW_TLS_TX and TSO. - tls_dev_event() does not tear down existing contexts on NETDEV_FEAT_CHANGE. - tls_validate_xmit_skb() keeps passing the skb through, because dev still matches tls_ctx->netdev. validate_xmit_skb() then computes the checksum in software, through skb_csum_hwoffload_help() or software GSO, over the stale placeholder bytes. After that, this path rewrites them: nsim_start_xmit() nsim_do_tls() nsim_tls_tx() nsim_tls_tx_zero_tags() memset(..., 0, tag_size) The skb is no longer CHECKSUM_PARTIAL, and the netdevsim RX path does not mark it CHECKSUM_UNNECESSARY. The peer's TCP would see a checksum mismatch and drop the segment that carries the tag. The retransmit would have a correct checksum, since the pages already hold zeros. The result is one drop and retransmit per record whenever the stale bytes were non-zero. Should this only touch the tag when skb->ip_summed == CHECKSUM_PARTIAL, or fix up the checksum after the memset? [ ... ] > +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 (!tls_is_skb_tx_device_offloaded(skb) || > + rcu_dereference_bh(tls_get_ctx(skb->sk)->netdev) != ns->netdev) { > + skb->decrypted = 0; > + return false; > + } > + > + nsim_tls_tx_zero_tags(skb); > + atomic64_inc(&ns->tls.tx_packets); > + atomic64_add(skb->len, &ns->tls.tx_bytes); > + > + return true; > +} > + > +/* Stand in for the inline decryption the peer's hardware would do, since we > + * are about to hand the skb to its stack. > + */ > +static void nsim_tls_rx(struct netdevsim *ns, struct sk_buff *skb) > +{ > + struct nsim_tls_tuple t; > + [Severity: Medium] Does this treat every skb from the offloaded socket as a TLS record? Once tls_set_device_offload() installs tls_validate_xmit_skb, tls_is_skb_tx_device_offloaded() is true for anything the socket sends. That includes pure ACKs, bare FINs, window probes and keepalives with no TCP payload. It also includes retransmits of bytes that were queued before TLS_TX was set up. nsim_tls_tx_zero_tags() detects these cases (off >= skb->len, or tls_get_record() returning NULL or the start marker), but it just returns. nsim_tls_tx() still bumps tx_packets/tx_bytes and returns true: nsim_do_tls() nsim_tls_tx() <- counts it, returns true nsim_tls_rx(peer_ns) nsim_tls_parse() <- no payload length check nsim_tls_rx_offloaded() WRITE_ONCE(conn->started, true) skb->decrypted = 1 On the peer, a zero length segment with seq at or after start_sn is enough to latch conn->started. The one-shot start_sn check can then be used up by an ACK that carries no record bytes at all. Pre-offload segments can also be marked decrypted and counted in rx_packets/rx_bytes. Their bytes are not device records, and the sending stack built them with skb->decrypted == 0. The debugfs counters on both ports therefore count control segments as offloaded TLS traffic. Real drivers skip these. For example, mlx5e_ktls_handle_tx_skb() returns early when there is no TCP payload. Could nsim_tls_tx_zero_tags() report whether it found a device record, with nsim_tls_tx() returning false otherwise? Or would checking the sender's skb->decrypted, together with a payload length check, be enough here? [ ... ] > + if (!READ_ONCE(ns->tls.count)) > + return; > + > + if (!nsim_tls_parse(skb, &t)) > + return; > + > + if (!nsim_tls_rx_offloaded(ns, &t)) > + return; > + > + skb->decrypted = 1; [Severity: Medium] Does the peer-side match here decide whether the peer sees skb->decrypted set on offloaded records? On the device-offloaded TX path, tls_push_data() adds MSG_SENDPAGE_DECRYPTED: net/tls/tls_device.c:tls_push_data() { ... flags |= MSG_SENDPAGE_DECRYPTED; ... } tcp_sendmsg_locked() then turns that into the skb bit: net/ipv4/tcp.c:tcp_sendmsg_locked() { ... skb->decrypted = !!(flags & MSG_SENDPAGE_DECRYPTED); ... } nsim_tls_tx() clears the bit only on the "not ours" path. nsim_tls_rx() only ever sets it and never clears it. skb_scrub_packet(), called from __dev_forward_skb(), doesn't touch it either. So every record skb from an offloaded sender seems to reach the peer stack with decrypted = 1, even when: - the peer has ns->tls.count == 0 (no RX offload installed, or the RX feature is off) - the tuple does not match in nsim_tls_rx_offloaded() - the seq is before conn->start_sn For example, records that reach the peer before its TLS_RX offload is installed would already be marked decrypted. That doesn't match the comment in nsim_do_tls(): /* Only what this port just "encrypted" may skip decryption on the * peer. ... or the one in nsim_tls_rx_offloaded(): * ... The check only keeps a pre-offload stream * from being reported decrypted, ... The commit message also says: on RX, where there is no socket yet, connections are matched on the tuple from ->tls_dev_add() the way the hardware does. For record skbs, the tuple match and the start_sn/started logic seem to change only the debugfs rx counters. The gate still applies to "ours" skbs that were built with decrypted = 0, such as retransmits of bytes queued before TX offload was installed. Would it make sense for nsim_do_tls() to clear skb->decrypted on its own records, and for nsim_tls_rx() to set it only on a match? [ ... ] > @@ -0,0 +1,477 @@ > +// SPDX-License-Identifier: GPL-2.0 > + > +#include <linux/ipv6.h> > +#include <linux/list.h> > +#include <linux/skbuff.h> > +#include <linux/slab.h> > +#include <linux/tcp.h> > +#include <net/ip.h> > +#include <net/ipv6.h> > +#include <net/tcp.h> > +#include <net/tls.h> > + > +#include "netdevsim.h" > + > +/* Emulated kTLS offload. No crypto is performed: TX puts the record on the > + * wire as plaintext and RX marks it decrypted, 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. > + */ > + > +#define NSIM_TLS_MAX_CONN 32 > + > +/* netdev_fix_features() drops NETIF_F_HW_TLS_RX unless the device also does > + * RX checksums, which every offload capable NIC does. > + */ > +#define NSIM_TLS_FEATURES (NETIF_F_HW_TLS_TX | NETIF_F_HW_TLS_RX | \ > + NETIF_F_RXCSUM) > + > +struct nsim_tls_conn { > + struct list_head list; > + struct rcu_head rcu; > + > + /* Identity as seen on the wire, from the point of view of the port > + * the offload was installed on: l* is this side, r* is the peer. > + */ > + struct in6_addr laddr; > + struct in6_addr raddr; > + __be16 lport; > + __be16 rport; > + u16 family; > + > + enum tls_offload_ctx_dir dir; > + u32 start_sn; > + bool started; > + u16 cipher_type; > + const struct tls_context *tls_ctx; > +}; > + > +struct nsim_tls_tuple { > + struct in6_addr saddr; > + struct in6_addr daddr; > + __be16 sport; > + __be16 dport; > + u32 seq; > +}; > + > +/* Parse the tuple from the frame the way a NIC would. The xmit skb is not > + * always a well formed local TCP skb (AF_PACKET, tc redirect); use > + * skb_header_pointer() so a non-linear or truncated header cannot be misread. > + */ > +static bool nsim_tls_parse(const struct sk_buff *skb, > + struct nsim_tls_tuple *t) > +{ > + int off = skb_network_offset(skb); > + const struct tcphdr *th; > + struct tcphdr _th; > + > + switch (skb->protocol) { > + case htons(ETH_P_IP): { > + const struct iphdr *iph; > + struct iphdr _iph; > + > + iph = skb_header_pointer(skb, off, sizeof(_iph), &_iph); > + if (!iph || iph->version != 4 || iph->ihl < 5 || > + iph->protocol != IPPROTO_TCP || ip_is_fragment(iph)) > + return false; > + ipv6_addr_set_v4mapped(iph->saddr, &t->saddr); > + ipv6_addr_set_v4mapped(iph->daddr, &t->daddr); > + off += iph->ihl * 4; > + break; > + } > + case htons(ETH_P_IPV6): { > + const struct ipv6hdr *ip6h; > + struct ipv6hdr _ip6h; > + __be16 frag_off; > + u8 nexthdr; > + int thoff; > + > + ip6h = skb_header_pointer(skb, off, sizeof(_ip6h), &_ip6h); > + if (!ip6h) > + return false; > + > + nexthdr = ip6h->nexthdr; > + thoff = ipv6_skip_exthdr(skb, off + sizeof(_ip6h), &nexthdr, > + &frag_off); > + if (thoff < 0 || nexthdr != IPPROTO_TCP || frag_off) > + return false; > + > + t->saddr = ip6h->saddr; > + t->daddr = ip6h->daddr; > + off = thoff; > + break; > + } > + default: > + return false; > + } > + > + th = skb_header_pointer(skb, off, sizeof(_th), &_th); > + if (!th) > + return false; > + t->sport = th->source; > + t->dport = th->dest; > + t->seq = ntohl(th->seq); > + > + return true; > +} > + > +/* No socket on RX yet, so match the tuple installed at ->tls_dev_add(), the > + * way the hardware does. > + */ > +static bool nsim_tls_rx_offloaded(struct netdevsim *ns, > + const struct nsim_tls_tuple *t) > +{ > + struct nsim_tls_conn *conn; > + > + list_for_each_entry_rcu(conn, &ns->tls.conns, list) { > + if (conn->dir != TLS_OFFLOAD_CTX_DIR_RX || > + conn->lport != t->dport || conn->rport != t->sport || > + !ipv6_addr_equal(&conn->laddr, &t->daddr) || > + !ipv6_addr_equal(&conn->raddr, &t->saddr)) > + continue; > + > + /* start_sn is the socket's copied_seq when the offload was > + * installed, so a segment before it only carries bytes TCP > + * has already received: tcp_data_queue() drops or trims those > + * whatever we flag. The check only keeps a pre-offload stream > + * from being reported decrypted, so asking once is enough, > + * and it also avoids the sequence space wrapping past a fixed > + * start_sn 2G later. > + */ > + if (!READ_ONCE(conn->started)) { > + if (before(t->seq, conn->start_sn)) > + return false; > + WRITE_ONCE(conn->started, true); > + } > + > + return true; > + } > + > + return false; > +} > + > +/* The stack leaves an uninitialized, tag sized gap at the tail of each record > + * for the device to write the auth tag into. We do not encrypt, so zero it > + * to avoid leaking that memory onto the wire. Nothing tells the device where > + * the tag is, so walk the records with tls_get_record() and clear the end of > + * each one's last frag. Every segment of a record and any retransmit of it > + * share these pages, which is why the record is cleared rather than the skb; > + * nothing consumes the placeholder, so a clone seeing the write is harmless. > + */ > +static void nsim_tls_tx_zero_tags(struct sk_buff *skb) > +{ > + struct tls_context *ctx = tls_get_ctx(skb->sk); > + const struct tcphdr *th = tcp_hdr(skb); > + struct tls_offload_context_tx *tx_ctx; > + u32 seq, end, tag_size; > + unsigned long flags; > + unsigned int off; > + > + off = skb_transport_offset(skb) + __tcp_hdrlen(th); > + if (off >= skb->len) > + return; > + > + tag_size = ctx->prot_info.tag_size; > + seq = ntohl(th->seq); > + end = seq + skb->len - off; > + tx_ctx = tls_offload_ctx_tx(ctx); > + > + spin_lock_irqsave(&tx_ctx->lock, flags); > + while (before(seq, end)) { > + struct tls_record_info *record; > + skb_frag_t *frag; > + u64 rcd_sn; > + > + record = tls_get_record(tx_ctx, seq, &rcd_sn); > + if (!record || tls_record_is_start_marker(record)) > + break; > + > + frag = &record->frags[record->num_frags - 1]; > + memset(skb_frag_address(frag) + skb_frag_size(frag) - tag_size, > + 0, tag_size); > + > + seq = record->end_seq; > + } > + spin_unlock_irqrestore(&tx_ctx->lock, flags); > +} > + > +/* Stand in for the inline encryption the hardware would do on the way out. > + * The stack has already framed the record and we do not encrypt, so > + * skb->decrypted is not cleared for our own records and the tag is all that > + * is left to deal with. The socket is right here, so identify the connection > + * the way the real drivers do. > + */ > +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 (!tls_is_skb_tx_device_offloaded(skb) || > + rcu_dereference_bh(tls_get_ctx(skb->sk)->netdev) != ns->netdev) { > + skb->decrypted = 0; > + return false; > + } > + > + nsim_tls_tx_zero_tags(skb); > + atomic64_inc(&ns->tls.tx_packets); > + atomic64_add(skb->len, &ns->tls.tx_bytes); > + > + return true; > +} > + > +/* Stand in for the inline decryption the peer's hardware would do, since we > + * are about to hand the skb to its stack. > + */ > +static void nsim_tls_rx(struct netdevsim *ns, struct sk_buff *skb) > +{ > + struct nsim_tls_tuple t; > + > + /* Not every port registers the offload, and one that does not never > + * initializes the list head, so gate on the count. It is the > + * cheaper test anyway. > + */ > + if (!READ_ONCE(ns->tls.count)) > + return; > + > + if (!nsim_tls_parse(skb, &t)) > + return; > + > + if (!nsim_tls_rx_offloaded(ns, &t)) > + return; > + > + skb->decrypted = 1; > + atomic64_inc(&ns->tls.rx_packets); > + atomic64_add(skb->len, &ns->tls.rx_bytes); > +} > + > +/* netdevsim has no wire: nsim_start_xmit() hands the skb straight to the > + * peer's receive path, so this one call site stands in for the hardware of > + * both ports. It has to run before nsim_forward_skb() moves the skb over, > + * which resets the headers. > + */ > +void nsim_do_tls(struct sk_buff *skb, struct netdevsim *ns, > + struct netdevsim *peer_ns) > +{ > + /* nsim_do_psp() ran first and may have wrapped the record stream, so > + * this is no longer a plain TLS over TCP packet. No NIC chains the > + * two inline offloads either, so leave it alone. > + */ > + if (skb->encapsulation) > + return; > + > + /* Only what this port just "encrypted" may skip decryption on the > + * peer. Everything else - a software kTLS sender because the TX > + * feature is off, a frame injected on the tuple - really is > + * ciphertext or not TLS at all, and the core has to deal with it. > + */ > + if (!nsim_tls_tx(ns, skb)) > + return; > + > + nsim_tls_rx(peer_ns, skb); > +} > + > +static int nsim_tls_dev_add(struct net_device *netdev, struct sock *sk, > + enum tls_offload_ctx_dir direction, > + struct tls_crypto_info *crypto_info, > + u32 start_offload_tcp_sn) > +{ > + struct netdevsim *ns = netdev_priv(netdev); > + struct nsim_tls_conn *conn; > + int ret = 0; > + > + /* Mirror the cipher support of a typical offload capable NIC. */ > + switch (crypto_info->cipher_type) { > + case TLS_CIPHER_AES_GCM_128: > + case TLS_CIPHER_AES_GCM_256: > + break; > + default: > + return -EOPNOTSUPP; > + } > + > + conn = kzalloc_obj(*conn); > + if (!conn) > + return -ENOMEM; > + > + if (sk->sk_family == AF_INET6) { > + conn->laddr = sk->sk_v6_rcv_saddr; > + conn->raddr = sk->sk_v6_daddr; > + } else { > + ipv6_addr_set_v4mapped(sk->sk_rcv_saddr, &conn->laddr); > + ipv6_addr_set_v4mapped(sk->sk_daddr, &conn->raddr); > + } > + conn->family = sk->sk_family; > + conn->lport = htons(inet_sk(sk)->inet_num); > + conn->rport = sk->sk_dport; > + conn->dir = direction; > + conn->start_sn = start_offload_tcp_sn; > + conn->cipher_type = crypto_info->cipher_type; > + conn->tls_ctx = tls_get_ctx(sk); > + > + spin_lock_bh(&ns->tls.lock); > + if (ns->tls.count >= NSIM_TLS_MAX_CONN) { > + ret = -ENOSPC; > + goto out_unlock; > + } > + list_add_tail_rcu(&conn->list, &ns->tls.conns); > + WRITE_ONCE(ns->tls.count, ns->tls.count + 1); > + if (direction == TLS_OFFLOAD_CTX_DIR_TX) > + ns->tls.tx_conn++; > + else > + ns->tls.rx_conn++; > +out_unlock: > + spin_unlock_bh(&ns->tls.lock); > + > + if (ret) > + kfree(conn); > + > + return ret; > +} > + > +static void nsim_tls_dev_del(struct net_device *netdev, > + struct tls_context *tls_ctx, > + enum tls_offload_ctx_dir direction) > +{ > + struct netdevsim *ns = netdev_priv(netdev); > + struct nsim_tls_conn *conn; > + > + spin_lock_bh(&ns->tls.lock); > + list_for_each_entry(conn, &ns->tls.conns, list) { > + if (conn->tls_ctx != tls_ctx || conn->dir != direction) > + continue; > + > + list_del_rcu(&conn->list); > + WRITE_ONCE(ns->tls.count, ns->tls.count - 1); > + if (direction == TLS_OFFLOAD_CTX_DIR_TX) > + ns->tls.tx_conn--; > + else > + ns->tls.rx_conn--; > + spin_unlock_bh(&ns->tls.lock); > + > + kfree_rcu(conn, rcu); > + return; > + } > + spin_unlock_bh(&ns->tls.lock); > + > + netdev_err(netdev, "TLS %s context not found on del\n", > + direction == TLS_OFFLOAD_CTX_DIR_TX ? "tx" : "rx"); > +} > + > +/* Never reached, the emulation never asks for a resync, but the core insists > + * on it for NETIF_F_HW_TLS_RX. > + */ > +static int nsim_tls_dev_resync(struct net_device *netdev, struct sock *sk, > + u32 seq, u8 *rcd_sn, > + enum tls_offload_ctx_dir direction) > +{ > + return 0; > +} > + > +static const struct tlsdev_ops nsim_tlsdev_ops = { > + .tls_dev_add = nsim_tls_dev_add, > + .tls_dev_del = nsim_tls_dev_del, > + .tls_dev_resync = nsim_tls_dev_resync, > +}; > + > +static ssize_t nsim_tls_dbg_read(struct file *filp, char __user *buffer, > + size_t count, loff_t *ppos) > +{ > + struct netdevsim *ns = filp->private_data; > + struct nsim_tls_conn *conn; > + size_t bufsize; > + char *buf, *p; > + int len; > + > + /* Two full IPv6 addresses and ports fit in 160 bytes a line. */ > + bufsize = (NSIM_TLS_MAX_CONN * 160) + 200; > + buf = kzalloc(bufsize, GFP_KERNEL); > + if (!buf) > + return -ENOMEM; > + > + p = buf; > + > + spin_lock_bh(&ns->tls.lock); > + p += scnprintf(p, bufsize - (p - buf), > + "conn count=%u tx=%u rx=%u\n", > + ns->tls.count, ns->tls.tx_conn, ns->tls.rx_conn); > + p += scnprintf(p, bufsize - (p - buf), > + "tx_packets=%llu tx_bytes=%llu rx_packets=%llu rx_bytes=%llu\n", > + atomic64_read(&ns->tls.tx_packets), > + atomic64_read(&ns->tls.tx_bytes), > + atomic64_read(&ns->tls.rx_packets), > + atomic64_read(&ns->tls.rx_bytes)); > + > + list_for_each_entry(conn, &ns->tls.conns, list) { > + if (conn->family == AF_INET6) > + p += scnprintf(p, bufsize - (p - buf), > + "%s [%pI6c]:%u -> [%pI6c]:%u cipher=%u sn=%u\n", > + conn->dir == TLS_OFFLOAD_CTX_DIR_TX ? > + "tx" : "rx", > + &conn->laddr, ntohs(conn->lport), > + &conn->raddr, ntohs(conn->rport), > + conn->cipher_type, conn->start_sn); > + else > + p += scnprintf(p, bufsize - (p - buf), > + "%s %pI4:%u -> %pI4:%u cipher=%u sn=%u\n", > + conn->dir == TLS_OFFLOAD_CTX_DIR_TX ? > + "tx" : "rx", > + &conn->laddr.s6_addr32[3], > + ntohs(conn->lport), > + &conn->raddr.s6_addr32[3], > + ntohs(conn->rport), > + conn->cipher_type, conn->start_sn); > + } > + spin_unlock_bh(&ns->tls.lock); > + > + len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf); > + > + kfree(buf); > + > + return len; > +} > + > +static const struct file_operations nsim_tls_dbg_fops = { > + .owner = THIS_MODULE, > + .open = simple_open, > + .read = nsim_tls_dbg_read, > + .llseek = default_llseek, > +}; > + > +void nsim_tls_init(struct netdevsim *ns) > +{ > + INIT_LIST_HEAD(&ns->tls.conns); > + spin_lock_init(&ns->tls.lock); > + > + ns->netdev->tlsdev_ops = &nsim_tlsdev_ops; > + ns->netdev->features |= NSIM_TLS_FEATURES; > + ns->netdev->hw_features |= NSIM_TLS_FEATURES; > + > + ns->tls.dfile = debugfs_create_file("tls", 0400, > + ns->nsim_dev_port->ddir, ns, > + &nsim_tls_dbg_fops); > +} > + > +void nsim_tls_teardown(struct netdevsim *ns) > +{ > + struct nsim_tls_conn *conn, *tmp; > + u32 left; > + > + debugfs_remove_recursive(ns->tls.dfile); > + > + spin_lock_bh(&ns->tls.lock); > + left = ns->tls.count; > + list_for_each_entry_safe(conn, tmp, &ns->tls.conns, list) { > + list_del_rcu(&conn->list); > + kfree_rcu(conn, rcu); > + } > + WRITE_ONCE(ns->tls.count, 0); > + ns->tls.tx_conn = 0; > + ns->tls.rx_conn = 0; > + spin_unlock_bh(&ns->tls.lock); > + > + if (left) > + netdev_err(ns->netdev, > + "tearing down TLS offload with %u connections left\n", > + left); > +} [Severity: Medium] Does this build with CONFIG_IPV6=n? sk_v6_rcv_saddr and sk_v6_daddr are aliases for skc_v6_rcv_saddr and skc_v6_daddr in struct sock_common. include/net/sock.h only defines those members inside #if IS_ENABLED(CONFIG_IPV6). Neither NETDEVSIM nor TLS/TLS_DEVICE depends on IPV6. They only depend on INET. So a config with INET=y, IPV6=n, TLS_DEVICE=y and NETDEVSIM=y or m adds tls.o to netdevsim, and nsim_tls_dev_add() then fails to compile. Other users in the tree guard these fields, for example netdevsim's own psp.c and nfp_net_tls_add() in the nfp kTLS code. Should the AF_INET6 branch here be wrapped in #if IS_ENABLED(CONFIG_IPV6) the same way? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117140642.4008-1-jiayuan.chen%40linux.dev ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation 2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen 2026-11-18 8:15 ` kernel test robot 2026-11-18 14:32 ` netdev-bot+sashiko @ 2026-11-18 22:15 ` kernel test robot 2 siblings, 0 replies; 7+ messages in thread From: kernel test robot @ 2026-11-18 22:15 UTC (permalink / raw) To: Jiayuan Chen, netdev, kuba Cc: oe-kbuild-all, Jiayuan Chen, Andrew Lunn, Eric Dumazet, Paolo Abeni, John Fastabend, Sabrina Dubroca, Shuah Khan, linux-kernel, linux-kselftest Hi Jiayuan, kernel test robot noticed the following build errors: [auto build test ERROR on net-next/main] url: https://github.com/intel-lab-lkp/linux/commits/Jiayuan-Chen/netdevsim-add-TLS-device-offload-emulation/20261117-220630 base: net-next/main patch link: https://lore.kernel.org/r/20261117140642.4008-2-jiayuan.chen%40linux.dev patch subject: [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation config: i386-buildonly-randconfig-1004-20261119 (https://download.01.org/0day-ci/archive/20261119/202611190536.FTvmv1cW-lkp@intel.com/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261119/202611190536.FTvmv1cW-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202611190536.FTvmv1cW-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from include/linux/tcp.h:19, from include/linux/ipv6.h:103, from drivers/net/netdevsim/tls.c:3: drivers/net/netdevsim/tls.c: In function 'nsim_tls_dev_add': >> include/net/sock.h:404:37: error: 'struct sock_common' has no member named 'skc_v6_rcv_saddr'; did you mean 'skc_rcv_saddr'? 404 | #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr | ^~~~~~~~~~~~~~~~ drivers/net/netdevsim/tls.c:298:35: note: in expansion of macro 'sk_v6_rcv_saddr' 298 | conn->laddr = sk->sk_v6_rcv_saddr; | ^~~~~~~~~~~~~~~ >> include/net/sock.h:403:45: error: 'struct sock_common' has no member named 'skc_v6_daddr'; did you mean 'skc_daddr'? 403 | #define sk_v6_daddr __sk_common.skc_v6_daddr | ^~~~~~~~~~~~ drivers/net/netdevsim/tls.c:299:35: note: in expansion of macro 'sk_v6_daddr' 299 | conn->raddr = sk->sk_v6_daddr; | ^~~~~~~~~~~ vim +404 include/net/sock.h 4dc6dc7162c08b9 Eric Dumazet 2009-07-15 382 68835aba4d9b74e Eric Dumazet 2010-11-30 383 #define sk_dontcopy_begin __sk_common.skc_dontcopy_begin 68835aba4d9b74e Eric Dumazet 2010-11-30 384 #define sk_dontcopy_end __sk_common.skc_dontcopy_end 4dc6dc7162c08b9 Eric Dumazet 2009-07-15 385 #define sk_hash __sk_common.skc_hash 5080546682bae3d Eric Dumazet 2013-10-02 386 #define sk_portpair __sk_common.skc_portpair 05dbc7b59481ca8 Eric Dumazet 2013-10-03 387 #define sk_num __sk_common.skc_num 05dbc7b59481ca8 Eric Dumazet 2013-10-03 388 #define sk_dport __sk_common.skc_dport 5080546682bae3d Eric Dumazet 2013-10-02 389 #define sk_addrpair __sk_common.skc_addrpair 5080546682bae3d Eric Dumazet 2013-10-02 390 #define sk_daddr __sk_common.skc_daddr 5080546682bae3d Eric Dumazet 2013-10-02 391 #define sk_rcv_saddr __sk_common.skc_rcv_saddr ^1da177e4c3f415 Linus Torvalds 2005-04-16 392 #define sk_family __sk_common.skc_family ^1da177e4c3f415 Linus Torvalds 2005-04-16 393 #define sk_state __sk_common.skc_state ^1da177e4c3f415 Linus Torvalds 2005-04-16 394 #define sk_reuse __sk_common.skc_reuse 055dc21a1d1d219 Tom Herbert 2013-01-22 395 #define sk_reuseport __sk_common.skc_reuseport 9fe516ba3fb29b6 Eric Dumazet 2014-06-27 396 #define sk_ipv6only __sk_common.skc_ipv6only 26abe14379f8e2f Eric W. Biederman 2015-05-08 397 #define sk_net_refcnt __sk_common.skc_net_refcnt 7c268eaeec6388b Kuniyuki Iwashima 2025-10-14 398 #define sk_bypass_prot_mem __sk_common.skc_bypass_prot_mem ^1da177e4c3f415 Linus Torvalds 2005-04-16 399 #define sk_bound_dev_if __sk_common.skc_bound_dev_if ^1da177e4c3f415 Linus Torvalds 2005-04-16 400 #define sk_bind_node __sk_common.skc_bind_node 8feaf0c0a5488b3 Arnaldo Carvalho de Melo 2005-08-09 401 #define sk_prot __sk_common.skc_prot 07feaebfcc10cd3 Eric W. Biederman 2007-09-12 402 #define sk_net __sk_common.skc_net efe4208f47f907b Eric Dumazet 2013-10-03 @403 #define sk_v6_daddr __sk_common.skc_v6_daddr efe4208f47f907b Eric Dumazet 2013-10-03 @404 #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr 33cf7c90fe2f97a Eric Dumazet 2015-03-11 405 #define sk_cookie __sk_common.skc_cookie 70da268b569d32a Eric Dumazet 2015-10-08 406 #define sk_incoming_cpu __sk_common.skc_incoming_cpu 8e5eb54d303b7cb Eric Dumazet 2015-10-08 407 #define sk_flags __sk_common.skc_flags ed53d0ab761f5c7 Eric Dumazet 2015-10-08 408 #define sk_rxhash __sk_common.skc_rxhash efe4208f47f907b Eric Dumazet 2013-10-03 409 5d4cc87414c5d11 Eric Dumazet 2024-02-16 410 __cacheline_group_begin(sock_write_rx); 43f51df41729559 Eric Dumazet 2021-11-15 411 9115e8cd2a0c6ea Eric Dumazet 2016-12-03 412 atomic_t sk_drops; 5d4cc87414c5d11 Eric Dumazet 2024-02-16 413 __s32 sk_peek_off; 7d452516b67add4 Eric Dumazet 2025-09-29 414 struct sk_buff_head sk_error_queue; b178bb3dfc30d95 Eric Dumazet 2010-11-16 415 struct sk_buff_head sk_receive_queue; fa438ccfdfd3f6d Eric Dumazet 2007-03-04 416 /* fa438ccfdfd3f6d Eric Dumazet 2007-03-04 417 * The backlog queue is special, it is always used with fa438ccfdfd3f6d Eric Dumazet 2007-03-04 418 * the per-socket spinlock held and requires low latency fa438ccfdfd3f6d Eric Dumazet 2007-03-04 419 * access. Therefore we special case it's implementation. b178bb3dfc30d95 Eric Dumazet 2010-11-16 420 * Note : rmem_alloc is in this structure to fill a hole b178bb3dfc30d95 Eric Dumazet 2010-11-16 421 * on 64bit arches, not because its logically part of b178bb3dfc30d95 Eric Dumazet 2010-11-16 422 * backlog. fa438ccfdfd3f6d Eric Dumazet 2007-03-04 423 */ fa438ccfdfd3f6d Eric Dumazet 2007-03-04 424 struct { b178bb3dfc30d95 Eric Dumazet 2010-11-16 425 atomic_t rmem_alloc; b178bb3dfc30d95 Eric Dumazet 2010-11-16 426 int len; fa438ccfdfd3f6d Eric Dumazet 2007-03-04 427 struct sk_buff *head; fa438ccfdfd3f6d Eric Dumazet 2007-03-04 428 struct sk_buff *tail; fa438ccfdfd3f6d Eric Dumazet 2007-03-04 429 } sk_backlog; b178bb3dfc30d95 Eric Dumazet 2010-11-16 430 #define sk_rmem_alloc sk_backlog.rmem_alloc 2c8c56e15df3d4c Eric Dumazet 2014-11-11 431 5d4cc87414c5d11 Eric Dumazet 2024-02-16 432 __cacheline_group_end(sock_write_rx); 5d4cc87414c5d11 Eric Dumazet 2024-02-16 433 5d4cc87414c5d11 Eric Dumazet 2024-02-16 434 __cacheline_group_begin(sock_read_rx); 5d4cc87414c5d11 Eric Dumazet 2024-02-16 435 /* early demux fields */ 5d4cc87414c5d11 Eric Dumazet 2024-02-16 436 struct dst_entry __rcu *sk_rx_dst; 5d4cc87414c5d11 Eric Dumazet 2024-02-16 437 int sk_rx_dst_ifindex; 5d4cc87414c5d11 Eric Dumazet 2024-02-16 438 u32 sk_rx_dst_cookie; 5d4cc87414c5d11 Eric Dumazet 2024-02-16 439 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim 2026-11-17 14:06 [PATCH net-next v2 0/2] netdevsim: add TLS device offload emulation and test Jiayuan Chen 2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen @ 2026-11-17 14:06 ` Jiayuan Chen 2026-11-18 14:32 ` netdev-bot+sashiko 1 sibling, 1 reply; 7+ messages in thread From: Jiayuan Chen @ 2026-11-17 14:06 UTC (permalink / raw) To: netdev, kuba Cc: Jiayuan Chen, Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni, John Fastabend, Sabrina Dubroca, Shuah Khan, linux-kernel, linux-kselftest 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. Everything the test checks on the DUT, device MIB counters, echo data and record types, works there as is. 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. # ./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 Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> --- tools/testing/selftests/drivers/net/hw/tls_hw_offload.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py index e720ce6547610..1197f17caa13c 100755 --- a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py +++ b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py @@ -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 -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim 2026-11-17 14:06 ` [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim Jiayuan Chen @ 2026-11-18 14:32 ` netdev-bot+sashiko 0 siblings, 0 replies; 7+ messages in thread From: netdev-bot+sashiko @ 2026-11-18 14:32 UTC (permalink / raw) To: jiayuan.chen Cc: netdev, kuba, andrew+netdev, davem, edumazet, pabeni, john.fastabend, sd, shuah, linux-kernel, linux-kselftest 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(), the `ethtool -S` skip is keyed on whether the env created netdevsim itself (`if cfg.get_local_nsim_dev(): return… - [Low] In netdevsim mode the comments in tls_hw_offload.py describe behaviour that no longer applies, and the patch doesn't update them. -- selftests: drv-net: run tls_hw_offload on netdevsim This commit lets tls_hw_offload.py run on the default netdevsim pair by dropping nsim_test=False from the NetDrvEpEnv call. netdevsim does not implement ethtool -S, so read_nic_stats() now returns an empty stats dict when the environment created the netdevsim device itself. > diff --git a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py > index e720ce6547610..1197f17caa13c 100755 > --- a/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py > +++ b/tools/testing/selftests/drivers/net/hw/tls_hw_offload.py > @@ -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 cover a netdevsim interface that is passed in through NETIF? get_local_nsim_dev() returns self._ns. That is only set when NetDrvEpEnv creates the netdevsim pair itself, i.e. when NETIF is not set. If NETIF names a netdevsim port (for example a hand-made pair with REMOTE_TYPE=netns), it returns None and the guard is false. The cmd() call below then runs with the default fail=True. nsim_ethtool_ops has no get_sset_count or get_strings, so ethtool -S exits non-zero. The resulting CmdExitFailure propagates out of run_tls_test(), and every case fails at the first NIC snapshot. This is the same failure the commit message says it fixes. Before the netdevsim TLS emulation existed, check_tls_support() skipped such a device because it had no tls-hw-*-offload. This failure path is new in this series. Would it work to run ethtool -S with fail=False and return the empty stats on a non-zero exit? That would handle any device without ETH_SS_STATS. It would also avoid get_local_nsim_dev(), whose docstring discourages its use because it makes tests nsim-specific. macsec.py does already use it to skip steps, though. > 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: [Severity: Low] Now that netdevsim mode is enabled here, are some of the existing comments in tls_hw_offload.py still accurate? The header comment in drivers/net/netdevsim/tls.c says no crypto is performed: /* Emulated kTLS offload. No crypto is performed: TX puts the record on the * wire as plaintext and RX marks it decrypted, 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 in nsim mode the peer's RX also has to use the netdevsim offload. The current run passes because the peer is also a netdevsim port with RX offload enabled. Several comments in the test say otherwise. The run_tls_test() docstring says: The DUT (local) is the kernel under test; the remote is just a traffic source/sink and may run any kernel without HW offload. Both sides run kTLS because TLS is pairwise, but verify_tls_counters() requires HW offload only in enabled DUT directions. The peer and the DUT's other direction may use SW kTLS. The comment in read_tls_stats() says: # sock_net(sk)). The test runs on a real NIC in the host namespace, so The comment above HW_NIC_COUNTERS says: # the NIC encrypted anything; a broken HW encrypt shows up instead as a # peer TlsDecryptError or an echo mismatch. On netdevsim, a peer TlsDecryptError would mean the peer did not get RX offload. It would not mean the DUT encrypted badly. The commit message also says: Everything the test checks on the DUT, device MIB counters, echo data and record types, works there as is. On netdevsim, though, the test only covers the kTLS device control and MIB paths, not encryption. Could the comments and the commit message be updated to describe the netdevsim case? > cfg.bin_local = cfg.test_dir / "tls_hw_offload" > cfg.bin_remote = None > cfg.tls_skip_reason = None -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117140642.4008-1-jiayuan.chen%40linux.dev ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-18 22:15 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-17 14:06 [PATCH net-next v2 0/2] netdevsim: add TLS device offload emulation and test Jiayuan Chen 2026-11-17 14:06 ` [PATCH net-next v2 1/2] netdevsim: add TLS device offload emulation Jiayuan Chen 2026-11-18 8:15 ` kernel test robot 2026-11-18 14:32 ` netdev-bot+sashiko 2026-11-18 22:15 ` kernel test robot 2026-11-17 14:06 ` [PATCH net-next v2 2/2] selftests: drv-net: run tls_hw_offload on netdevsim Jiayuan Chen 2026-11-18 14:32 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox