From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796422084; b=UcOhDVG9dihKOqFMFQiAqTNrk37IqbNyv2icunLcwtDJ3W+JDSkpdoBoP615F8VqK8Ki d4UR9ScW+4g5sYHshUh8k9L8xZFVg4RiR4N+OcSURYpR6WGr6M8+8U6H4pEu4Vp8MrEfB Z+q8TwFY2STtlMRtaw2dS4zKesncRr/PwpnOlxuLBfFjjlF9NCKg/vcoavePLltR+feyz +dcuU1p+AIK/ruNzU+SuT/+PLu19dvrFHmXgEU2u/tOQnY2hkud7Mnfc03OhoU6w3lS1h hP2i1/Klj808IodcitduNIGeWEHzWOhDrxWUmupwpO6D6IxJkS6vT70x//3xDRrZvrA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796422084; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=uOY6wlE9W9x+InwcsII0RtXCermU9dnOoMoYH4VGYZU=; b=RJF4E7pvwCd1loMjZKLuKj4j9H4TjEdfSLzk34rUpkT4E059L2FL/gKEoIsgWXMXEO8B cwcHPmRMXdJr46ryP22Ik3EWEzqxR6URCX2th59GsJTKFiP8WgkvkQ3fFf0zRYCkEG+9D vbDgJo7t0OCjMQFyXj0iYquWaAe80wAnYa6KdRJQkN3Ay3qqC8kc+TihHfBoAOk95YgeN m6Ks0u5a/DvgLxk5ruj8zzaceVIj4NOjObGRbEffIDjxrN06E/05svXgI7K79ai7iqT0o xVvBjLVmTryXC/5sHRQv1yCwAVcOAzXq74cc3JjLdkt0JtguctRFoP6I1zkk6Sy+jRQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=F3Pyorfq; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80CE606A322; Fri, 4 Dec 2026 22:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=F3Pyorfq Received: by smtp.kernel.org (Postfix) with ESMTPSA id D53901F00A1C; Fri, 4 Dec 2026 22:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796422083; bh=uOY6wlE9W9x+InwcsII0RtXCermU9dnOoMoYH4VGYZU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=F3Pyorfqu+2j5i+t2ltBIWrYa3IfPMJfrFaMxHP4QKcJkOie/J136WZujm/BjnzTo iJ0Tp0DK+JePtQOdbvUBYi51jmH49EEeIc5oUVRbomFvM6l24C4XBdYHyXksjBtgHA JgWzJW11z2fzJ0aVnFizBMGlour63CCFUd0XIY9PWhdZZ/1+jJCQr5M+mWiqkYDdqa 4+/05WtLraxgjKpMgjHZ6mwct9xnQ0YoJrn0OiZLlUsRfmVeqv8y9q2+O8238zE/yp uOe/4N3yKyep2Zn53xh22sS0ODBY0/DJ6v0jKZLgJTJWReBvZcDNauID5D4JYsNrO7 PwuMBw10g32Cw== Subject: Re: [PATCH net 09/10] selftests: drv-net: devmem: test unreadable kTLS RX From: netdev-bot+sashiko@kernel.org To: tavip@google.com Cc: netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, willemb@google.com, horms@kernel.org, andrew+netdev@lunn.ch, ncardwell@google.com, kuniyu@google.com, dsahern@kernel.org, idosch@nvidia.com, john.fastabend@gmail.com, jakub@cloudflare.com, jiayuan.chen@linux.dev, sd@queasysnail.net, shuah@kernel.org, almasrymina@google.com, sdf@fomichev.me, kaiyuanz@google.com, ilias.apalodimas@linaro.org, hawk@kernel.org, mcroce@microsoft.com, herbert@gondor.apana.org.au, ecree.xilinx@gmail.com, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org Date: Fri, 04 Dec 2026 22:08:01 +0000 Message-ID: <179642208138.3146.6982302182502396226@kernel.org> In-Reply-To: <62d1a0251d6eef295df7215f274cce53dec2d6e9.1796329894.git.tavip@google.com> References: <62d1a0251d6eef295df7215f274cce53dec2d6e9.1796329894.git.tavip@google.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider. Critical: 0 · High: 0 · Medium: 1 · 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] selftests: drv-net: hardcoded UDMABUF_CREATE breaks non- generic arches - [Low] In run_rx_tls() (tools/testing/selftests/drivers/net/hw/devmem_lib.py), the assertion… - [Low] selftests: drv-net: devmem: check_rx_tls() missing ksft_disruptive decorator -- selftests: drv-net: devmem: test unreadable kTLS RX This adds a devmem.py test that queues unreadable devmem fragments on a TCP socket, then installs TLS_RX on that socket. It checks that the first recv() fails with EFAULT. The devmem RX queue is bound directly from Python so that the test owns the TCP socket. > diff --git a/tools/testing/selftests/drivers/net/hw/devmem_lib.py b/tools/testing/selftests/drivers/net/hw/devmem_lib.py > index 71b916c161969..75199a01ca3fc 100644 > --- a/tools/testing/selftests/drivers/net/hw/devmem_lib.py > +++ b/tools/testing/selftests/drivers/net/hw/devmem_lib.py [ ... ] > @@ -314,3 +320,203 @@ def run_rx_hds(cfg): [ ... ] > +def run_rx_tls(cfg): > + """Verify kTLS RX rejects queued unreadable devmem skbs with EFAULT.""" [ ... ] > + try: > + conn.setsockopt(SOL_TLS, TLS_RX, crypto_info) > + except OSError as e: > + if e.errno in (errno.ENOENT, errno.EOPNOTSUPP): > + raise KsftSkipEx("TLS_CIPHER_AES_GCM_128 unavailable") from e > + raise > + > + with ksft_raises(OSError) as cm: > + conn.recv(64) > + ksft_eq(cm.exception.errno, errno.EFAULT) > + ksft_eq(conn.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR), 0) [Severity: Low] Can this SO_ERROR check in run_rx_tls() ever fail? When TLS_RX is armed while the unreadable devmem skb is queued, the parser is aborted in tls_strp_copyin(): net/tls/tls_strp.c:tls_strp_copyin() { ... if (unlikely(!skb_frags_readable(in_skb))) { tls_strp_abort_strp(strp, -EFAULT); desc->error = -EFAULT; return 0; } ... } tls_strp_abort_strp() sets strp->stopped and reports the error to user space only through sk->sk_err. The recv(64) then goes through tls_sw_recvmsg()->tls_rx_rec_wait() with has_copied false, so it returns sock_error(sk): net/tls/tls_sw.c:tls_rx_rec_wait() { ... if (sk->sk_err) { if (has_copied) return -READ_ONCE(sk->sk_err); return sock_error(sk); } ... } sock_error() does xchg(&sk->sk_err, 0). By the time getsockopt(SO_ERROR) runs, sk_err has already been cleared. SO_ERROR then falls back to sk_err_soft, which is also 0 for this flow. The check reads 0 no matter what the kernel did. The assertion looks like it backs up the "rejects the record cleanly" wording in the commit message. It doesn't say anything about the state of the socket after the error, though. For example, the strparser stays stopped for good. Would it make more sense to check that SO_ERROR == EFAULT before the recv(), to show that the error was latched during setsockopt(TLS_RX)? Another option is to check how a second recv() behaves. If neither is wanted, could this line be dropped? The main EFAULT check above is still meaningful. > + conn.close() [ ... ] > @@ -314,3 +320,203 @@ def run_rx_hds(cfg): > cmd(f"dd if=/dev/zero bs={size} count=1 2>/dev/null | " > f"{socat}", host=cfg.remote, shell=True) > ksft_eq(ncdevmem.ret, 0, f"HDS failed for payload size {size}") > + > + > +SOL_TLS = 282 > +TLS_RX = 2 > +TLS_1_2_VERSION = 0x0303 > +TLS_CIPHER_AES_GCM_128 = 51 > +TCP_ULP = 31 > +UDMABUF_FLAGS_CLOEXEC = 0x01 > +UDMABUF_CREATE = 0x40187542 > +NUM_DEVMEM_PAGES = 16000 > + > + > +class _Udmabuf: > + """Small udmabuf wrapper for Python socket protocol tests.""" > + > + def __init__(self, size=None): > + if size is None: > + size = os.sysconf("SC_PAGE_SIZE") * NUM_DEVMEM_PAGES > + self.size = size > + self.dmabuf_fd = -1 > + self.devfd = -1 > + self.memfd = -1 > + try: > + self.memfd = os.memfd_create("devmem-test", os.MFD_ALLOW_SEALING) > + os.ftruncate(self.memfd, size) > + fcntl.fcntl(self.memfd, fcntl.F_ADD_SEALS, fcntl.F_SEAL_SHRINK) > + try: > + self.devfd = os.open("/dev/udmabuf", os.O_RDONLY) > + except OSError as e: > + if e.errno in (errno.ENOENT, errno.ENODEV, errno.EACCES): > + raise KsftSkipEx(f"/dev/udmabuf unavailable: {e}") from e > + raise > + req = bytearray(struct.pack("IIQQ", self.memfd, > + UDMABUF_FLAGS_CLOEXEC, 0, size)) > + self.dmabuf_fd = fcntl.ioctl(self.devfd, UDMABUF_CREATE, req) > + except BaseException: > + self.close() > + raise > + > + def close(self): > + """Close file descriptors.""" > + for attr in ("dmabuf_fd", "devfd", "memfd"): > + fd = getattr(self, attr, -1) > + if fd >= 0: > + os.close(fd) > + setattr(self, attr, -1) > + > + > +def _restore_hds(ethnl, ifindex, orig_split, has_thresh, orig_thresh): > + req = {'header': {'dev-index': ifindex}, 'tcp-data-split': 'unknown'} > + if has_thresh: > + req['hds-thresh'] = orig_thresh > + ethnl.rings_set(req) > + cur = ethnl.rings_get({'header': {'dev-index': ifindex}}) > + if cur.get('tcp-data-split') != orig_split: > + ethnl.rings_set({'header': {'dev-index': ifindex}, > + 'tcp-data-split': orig_split}) > + > + > +def _setup_devmem_rx_queue(cfg): > + """Isolate and bind one devmem RX queue; return its queue ID.""" > + require_devmem(cfg) > + ethnl = EthtoolFamily() > + channels = ethnl.channels_get({'header': {'dev-index': cfg.ifindex}}) > + qcnt = channels.get('rx-count', 0) + channels.get('combined-count', 0) > + if qcnt < 2: > + raise KsftSkipEx("Test requires at least 2 RX queues") > + > + rxq = qcnt - 1 > + ubuf = _Udmabuf() > + defer(ubuf.close) > + > + rings = ethnl.rings_get({'header': {'dev-index': cfg.ifindex}}) > + orig_split = rings.get('tcp-data-split', 'unknown') > + has_thresh = 'hds-thresh' in rings > + orig_thresh = rings.get('hds-thresh', 0) > + req = {'header': {'dev-index': cfg.ifindex}, 'tcp-data-split': 'enabled'} [Severity: Low] Should check_rx_tls() be marked @ksft_disruptive, like check_rx(), check_tx() and check_tx_chunks() in this file? run_rx_tls() calls _setup_devmem_rx_queue(), which changes the NIC configuration in several ways: - it flips tcp-data-split and hds-thresh through ethnl.rings_set(), and restores them again in _restore_hds() - it rewrites the RSS indirection table with ethtool -X - it binds a devmem RX queue Some devmem capable drivers bounce the interface on a ring change. bnxt_set_ringparam() calls bnxt_close_nic() and bnxt_open_nic() when the device is running. gve does something similar through gve_adjust_config(). Either way NETIF can go down briefly. drivers/net/README.rst says tests that may disconnect NETIF must be annotated with @ksft_disruptive, so that runs with DISRUPTIVE=False on single-interface hosts skip them. As written, this test still runs in that mode. It can drop the connection the harness relies on to reach the remote. > + if has_thresh: > + req['hds-thresh'] = 0 > + ethnl.rings_set(req) > + defer(_restore_hds, ethnl, cfg.ifindex, orig_split, has_thresh, > + orig_thresh) > + > + ethtool(f"-X {cfg.ifname} equal {rxq}") > + defer(ethtool, f"-X {cfg.ifname} default") > + > + netdevnl = NetdevFamily() > + netdevnl.bind_rx({ > + "ifindex": cfg.ifindex, > + "fd": ubuf.dmabuf_fd, > + "queues": [{"type": "rx", "id": rxq}], > + }) > + defer(netdevnl.close) > + return rxq > + > + > +def _steer_tcp_flow(cfg, port, rxq, src_port): > + proto = f"tcp{cfg.addr_ipver}" > + spec5 = (f"flow-type {proto} src-ip {cfg.remote_addr} dst-ip {cfg.addr} " > + f"src-port {src_port} dst-port {port} queue {rxq}") > + spec3 = (f"flow-type {proto} dst-ip {cfg.addr} dst-port {port} " > + f"queue {rxq}") > + try: > + out = ethtool(f"-N {cfg.ifname} {spec5}").stdout > + except CmdExitFailure: > + out = ethtool(f"-N {cfg.ifname} {spec3}").stdout > + rule_id = int(re.search(r"ID (\d+)", out).group(1)) > + defer(ethtool, f"-N {cfg.ifname} delete {rule_id}") > + return rule_id > + > + > +def _remote_py(cfg, script, bg=False): > + cfg.require_cmd("python3", local=False, remote=True) > + b64 = base64.b64encode(script.encode("utf-8")).decode("ascii") > + py_cmd = f"python3 -c 'import base64; exec(base64.b64decode(\"{b64}\"))'" > + if bg: > + return bkg(py_cmd, host=cfg.remote, exit_wait=True) > + return cmd(py_cmd, host=cfg.remote) > + > + > +def _listen_tcp(cfg, port): > + af = socket.AF_INET6 if cfg.addr_ipver == "6" else socket.AF_INET > + srv = socket.socket(af, socket.SOCK_STREAM) > + defer(srv.close) > + srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > + srv.settimeout(5.0) > + srv.bind((cfg.addr, port)) > + srv.listen(1) > + return srv, af > + > + > +def _tcp_inq(sock): > + buf = fcntl.ioctl(sock.fileno(), termios.FIONREAD, b"\x00\x00\x00\x00") > + return struct.unpack("i", buf)[0] > + > + > +def run_rx_tls(cfg): > + """Verify kTLS RX rejects queued unreadable devmem skbs with EFAULT.""" > + rxq = _setup_devmem_rx_queue(cfg) > + port = rand_port() > + srv, af = _listen_tcp(cfg, port) > + > + sender_script = f""" > +import socket > +s = socket.socket({int(af)}, socket.SOCK_STREAM) > +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > +s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) > +s.bind(("{cfg.remote_addr}", 0)) > +s.connect(("{cfg.addr}", {port})) > +s.sendall(b"\\x17\\x03\\x03\\x00\\x20" + (b"\\x05" * 8)) > +s.recv(1) > +s.sendall(b"\\x11" * 24) > +try: > + s.recv(1) > +except OSError: > + pass > +s.close() > +""" > + with _remote_py(cfg, sender_script, bg=True): > + conn, peer = srv.accept() > + defer(conn.close) > + conn.settimeout(5.0) > + > + ksft_busy_wait(lambda: _tcp_inq(conn) >= 13, deadline=5, > + comment="Timed out waiting for TLS header") > + ksft_eq(len(conn.recv(13, socket.MSG_PEEK)), 13) > + > + _steer_tcp_flow(cfg, port, rxq, peer[1]) > + conn.sendall(b"G") > + > + ksft_busy_wait(lambda: _tcp_inq(conn) >= 37, deadline=5, > + comment="Timed out waiting for devmem TLS payload") > + ksft_eq(_tcp_inq(conn), 37) > + > + try: > + conn.setsockopt(socket.IPPROTO_TCP, TCP_ULP, b"tls\x00") > + except OSError as e: > + if e.errno in (errno.ENOENT, errno.EOPNOTSUPP): > + raise KsftSkipEx("TLS ULP is not available") from e > + raise > + > + crypto_info = struct.pack("=HH8s16s4s8s", > + TLS_1_2_VERSION, > + TLS_CIPHER_AES_GCM_128, > + b"\x01" * 8, > + b"\x02" * 16, > + b"\x03" * 4, > + b"\x04" * 8) > + try: > + conn.setsockopt(SOL_TLS, TLS_RX, crypto_info) > + except OSError as e: > + if e.errno in (errno.ENOENT, errno.EOPNOTSUPP): > + raise KsftSkipEx("TLS_CIPHER_AES_GCM_128 unavailable") from e > + raise > + > + with ksft_raises(OSError) as cm: > + conn.recv(64) > + ksft_eq(cm.exception.errno, errno.EFAULT) > + ksft_eq(conn.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR), 0) > + conn.close() [Severity: Medium] Will this ioctl number work on all architectures? UDMABUF_CREATE is hardcoded here with the asm-generic _IOW() encoding. The uapi header defines it as _IOW('u', 0x42, struct udmabuf_create). The direction bits of that macro depend on the architecture. On powerpc, mips, sparc and alpha, _IOC_WRITE is 4U and _IOC_DIRSHIFT is 29. On parisc, _IOC_WRITE is 2U. On all of these the kernel's value is 0x80187542, not 0x40187542. udmabuf_ioctl() switches on the kernel-compiled UDMABUF_CREATE and returns -ENOTTY for anything else. So _Udmabuf.__init__() fails with OSError(ENOTTY) on every run on those architectures. The skip handling does not cover this case. Only the os.open() of /dev/udmabuf is turned into KsftSkipEx. ncdevmem is built against the real linux/udmabuf.h, so require_devmem() succeeds before we get here. The result is a hard failure on otherwise working setups, for example ppc64le with a devmem capable NIC. The next patch in the series also uses _Udmabuf(), so it has the same problem. Could the request number be derived from the per-arch _IOC layout, for example keyed on platform.machine(), instead of using a fixed constant? Or is there a better way to get the value from the real header? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1796329894.git.tavip%40google.com