netdevsim: add TLS device offload emulation and test
Subsystems (4)
cover netdevsim: add TLS device offload emulation and test
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 adds a selftest.
No crypto is done: TX puts the plaintext record on the wire, RX just sets skb->decrypted. That only works netdevsim to netdevsim, but it covers record assembly and the offload lifecycle. Real ciphertext, and more on top of it, can come later.
Jiayuan Chen (2):
netdevsim: add TLS device offload emulation
selftests: netdevsim: add a kTLS device offload test
drivers/net/Kconfig | 1 + drivers/net/netdevsim/Makefile | 4 + drivers/net/netdevsim/netdev.c | 5 + drivers/net/netdevsim/netdevsim.h | 35 ++ drivers/net/netdevsim/tls.c | 418 +++++++++++++++ .../drivers/net/netdevsim/.gitignore | 2 + .../selftests/drivers/net/netdevsim/Makefile | 7 + .../selftests/drivers/net/netdevsim/tls.sh | 271 ++++++++++ .../drivers/net/netdevsim/tls_offload.c | 498 ++++++++++++++++++ 9 files changed, 1241 insertions(+) create mode 100644 drivers/net/netdevsim/tls.c create mode 100644 tools/testing/selftests/drivers/net/netdevsim/.gitignore create mode 100755 tools/testing/selftests/drivers/net/netdevsim/tls.sh create mode 100644 tools/testing/selftests/drivers/net/netdevsim/tls_offload.c
Signature · 1 line
2.43.0
RFC PATCH 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.
No crypto is done: TX puts the plaintext record on the wire and RX just sets skb->decrypted, so both ends have to be netdevsim. 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, and NETDEVSIM now depends on TLS since it calls tls_get_record().
--- drivers/net/Kconfig | 1 + drivers/net/netdevsim/Makefile | 4 + drivers/net/netdevsim/netdev.c | 5 + drivers/net/netdevsim/netdevsim.h | 35 +++ drivers/net/netdevsim/tls.c | 418 ++++++++++++++++++++++++++++++ 5 files changed, 463 insertions(+) create mode 100644 drivers/net/netdevsim/tls.c
drivers/net/Kconfig +1 -0
@@ -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
@@ -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 +5 -0
@@ -151,6 +151,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;
@@ -1066,6 +1068,7 @@ 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)
@@ -1093,6 +1096,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)RCU_INIT_POINTER (ns->peer,NULL );unregister_netdevice (ns->netdev); err_ipsec_teardown: +nsim_tls_teardown (ns);nsim_ipsec_teardown (ns);nsim_macsec_teardown (ns);nsim_bpf_uninit (ns);
@@ -1195,6 +1199,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 +35 -0
@@ -56,6 +56,20 @@ 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; +atomic64_t resyncs; +}; +#define NSIM_MACSEC_MAX_SECY_COUNT 3#define NSIM_MACSEC_MAX_RXSC_COUNT 1struct nsim_rxsc {
@@ -141,6 +155,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;
@@ -435,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 +418 -0
418 lines not on this page · raw message
Signature · 1 line
2.43.0
RFC PATCH 2/2 selftests: netdevsim: add a kTLS device offload test
In reply to Jiayuan ChenRun kTLS over a linked netdevsim pair, one port per netns. The test reads /proc/net/tls_stat around the setsockopt() calls and fails unless both directions landed on the device path, so it cannot quietly pass on the software one. It then does a bulk transfer both ways, small MSG_MORE writes, splice() with TLS_TX_ZEROCOPY_RO, and a run with the record limit at its minimum so that whole records pack several to a segment, checking the payload each time, plus the ethtool off/on path.
# ./tls.sh PASS: tls-hw-tx-offload advertised and on by default PASS: tls-hw-rx-offload advertised and on by default PASS: per-port debugfs tls file exists PASS: offloaded TLS data transfer PASS: tx and rx contexts installed on both ports PASS: both ends used the device path PASS: no silent fallback to the software path PASS: no decrypt errors PASS: driver counted offloaded packets both ways PASS: all offload contexts released on close PASS: no device contexts left behind PASS: offload declined once the feature is off PASS: software path used when offload is off PASS: offload works again after re-enabling
passed: 14 failed: 0
--- .../drivers/net/netdevsim/.gitignore | 2 + .../selftests/drivers/net/netdevsim/Makefile | 7 + .../selftests/drivers/net/netdevsim/tls.sh | 271 ++++++++++ .../drivers/net/netdevsim/tls_offload.c | 498 ++++++++++++++++++ 4 files changed, 778 insertions(+) create mode 100644 tools/testing/selftests/drivers/net/netdevsim/.gitignore create mode 100755 tools/testing/selftests/drivers/net/netdevsim/tls.sh create mode 100644 tools/testing/selftests/drivers/net/netdevsim/tls_offload.c
tools/testing/selftests/drivers/net/netdevsim/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +tls_offload
tools/testing/selftests/drivers/net/netdevsim/Makefile +7 -0
@@ -1,5 +1,7 @@ # SPDX-License-Identifier: GPL-2.0+ OR MIT +CFLAGS += $(KHDR_INCLUDES) + TEST_PROGS := \ devlink.sh \ devlink_in_netns.sh \
@@ -15,9 +17,14 @@ TEST_PROGS := \ peer.sh \ psample.sh \ tc-mq-visibility.sh \ + tls.sh \ udp_tunnel_nic.sh \ # end of TEST_PROGS +TEST_GEN_FILES := \ + tls_offload +# end of TEST_GEN_FILES + TEST_FILES := \ ethtool-common.sh # end of TEST_FILES
tools/testing/selftests/drivers/net/netdevsim/tls.sh new file +271 -0
271 lines not on this page · raw message
tools/testing/selftests/drivers/net/netdevsim/tls_offload.c new file +498 -0
498 lines not on this page · raw message
Signature · 1 line
2.43.0