From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796141832; b=FZyf0aUNOXpeeOEj3TpcAZL43Ixvila8yf3eELDw2Sz8zz32gCQ7iafNb+Cu1+uGOD3R iYy7+W9vx7RktIXmzTz6P2+vROr9RGWkpm3bAsUITXvtwVTKpT5V2oaWKMQySqEgIYsQy DzuY8Wic1MtkkF4bry/qA14F2ugUx0GaB3ZJxhMxqHS1Lqvpt+3FtiFeHuFsY5QHqIPd5 ezJZiYWRTE12OhzgzXMWGpAVF5wcgqiVE2AFXtu5rx+q/M4yzXZZHRsJfXly5EuhDOOGw 6BwuERhQsZXlgMoDciAQs3d9NWUWB3M2umRb7GgdDWfWmu9UK+2pbHdZYAryH4JNcVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796141832; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=Riyxnq/j95EFIBYX7Z8A3ptRsZgw9tCBmzs9In3jyX4=; b=DpXAnGVt0xS6JBLB5aiaBW421PYKnPmxxo3BhpSRFK6eT3BqZ3LCwpGJPDhjj+LEocXS bSehD1w8s3Hmc0B9ggCrUdVarD+GV6tMJ/YbYXp05X5eeQrgDW2QoQRh30FHXxYBG8vmY qzJMs7i4Pvq90Jsd6av101eV6t9VuWhF0qGAJtZ+DOPaoRVPGR96Lvk9uNlbE4Gt9R8AK VtZdqPB0Rwj7118oh54gyJo8uR1tM8jrep9WvPWWwfs3B+Vqaepaax6lehh8VVkA5d5wr 6XEKIVp/6QynM/oFQYmI3okyj91dVLPFZxXna6p/sghPECXuaheu26aWujoWyivhGDg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BMd9vGo0; arc=none smtp.remote-ip=209.85.128.50 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDA9F606A322 for ; Tue, 1 Dec 2026 16:17:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EDA9F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=BMd9vGo0 Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4bb64c99d2fso106719595e9.3 for ; Tue, 01 Dec 2026 08:17:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796141830; x=1796746630; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Riyxnq/j95EFIBYX7Z8A3ptRsZgw9tCBmzs9In3jyX4=; b=BMd9vGo0nxNtt3qCFMP4VmDNSsHIJ5vQFUKxyk8LE1mM2GmjfV7Np/KxKOuNkHdPVm l9UYVbR548gia40KZEiI/FLi461oteiXj3cPBSXd7aCi+FxQaDwEekVqY/+wkGugYzWK yRQPPaJ9KXwkU8cBuuqfnsQ3J4hr2aLEKAhF1BPDfP5Fg7FAOiFylyRPmwIST0q4fMgo T+ocKVt+/cVKOwWwtg/Jb6joPKhWnuoVCTEkDkAc5aOWidKbIhSVnWKpAUMEI97nkhID s49MC4EDGoNS73n0hCrV4WWWom/iRiIA3sZUh4qcdWToQ5rM1qoaqajI1i307hVxSPK1 cP3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796141830; x=1796746630; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Riyxnq/j95EFIBYX7Z8A3ptRsZgw9tCBmzs9In3jyX4=; b=XsytBEZLT4h2rjhtm/9ttBULgFdU75Ns0UIXL73TYYiQkSqlzZSkrkEjkvZr7I8Jko OSEgpsdKwuhYZ9sMNwiBpbBI8PZvGn6Rp1FBx1U/D2jD9uHP2mJgYZjId002KoSEclO2 SnZVkXF1OlUINqGElo3v4FWkSomGOviTxEAncgxrT/Een0eI95cLMtKkhMUVZMVLhVvb GuvOzztSNu/AoGWlqg8UKSsGGLGWr01DIY6vRID7MH3KG0ZM++fKYTWlaIpKOC7Mnj// l+GoqUfi74gfVs0YtjU6EeEY27ZJAeuWYVDFhJSw25YrEiVRTKejLV87bTzIVHaH54WV qCDw== X-Forwarded-Encrypted: i=1; AL+hErGgGdmd3y5mxkXp2XpjgsmC+BDX5SUUIbGZD1sdeNGxN4oynmBleakaaE8COCRngYsu6XSoyWCY/I+FTUE=@vger.kernel.org X-Gm-Message-State: APuU4Z/3/f9+6ravgUf8BZE4JUS2xVCADGfwB2IXkMRB7qGxhrXHp82S 6ib09zlthfF7KyEJKBQkdN/HttjiDlFcTskfovQbbrmvuZyLFq8EWlgI X-Gm-Gg: AZFdTZc7nhQx31KfQ/fMdVEXcP1syPG5z3oyNOCH9RF47V+lOvWxnZZQy1i/Cf3eZsh Ke8tr6JK9N90NBIMm4gcjleTMa0zpXD9RxyUqVtHSHD35jWkKfnW2cGdSR5oiphJvkZDYr7azfN JTjPtaCcVI7h6JeXoEF6wvOjVRce5jb/sl7A8Sa9AwzbOpyos3kkgIyVRdqZMC3eBGnhyiyfssb h8e09mgWeF5XNkEsFpNlbp0ypDEao4UI7PnFDdHFvRiZZZ3BLiMzx3+G1jkcvdnm8UDtwAbue4x shRuC79MJUvXX/aK50k+hczzHxufWao8UmEWN2jkG31QRIJwGkhfqSIV+PS3zqfg02lVVmpU2BF 4K6gsgptltdIYtOFhxs2r6cOVlk2xq5uyAvRyzXyIMr7G+jw6lHiLnQr7WCiyqTTaZQ/pnsS0sQ OGnwiZRXc6WS7pk4NtPRvpJzNPMzDhesPwFZRKjqTDeP6XB0q4HQZsiE7qG8vkvatwF44t20PN+ Scc5N531NbT27mqD20zJzalq2qwpQx5PQIE5RM4TGrgbdHWV4V9ZyT4APSuuvcdRA+9d0vXHGSg qVJVgs5/lR6tfWvW/kCxK4CuACCM128UXzV96hVEphADX7XndfIEHTYAEjVKsXcJvk4cD98ozjG RMsx+DngXdxi4cBNndD0CYtbvkAD1bf5/+2SyI/5OdMB7k1vZ/NQZr6zS3OBa7PT7JBe+WIqePb NzkRgOjJOF52kq X-Received: by 2002:a05:600c:34c9:b0:4a3:5d64:df91 with SMTP id 5b1f17b1804b1-4bb88810d28mr823087145e9.18.1796141830069; Tue, 01 Dec 2026 08:17:10 -0800 (PST) Received: from localhost.localdomain ([31.223.101.75]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb905f1489sm705182455e9.0.2026.12.01.08.17.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 08:17:09 -0800 (PST) From: Oguzhan KAYNAK To: Jon Mason , Dave Jiang , Allen Hubbe Cc: Koichiro Den , ntb@lists.linux.dev, linux-kernel@vger.kernel.org, regressions@lists.linux.dev, Oguzhan KAYNAK , stable@vger.kernel.org, yangqixiao Subject: [PATCH v3] ntb: ntb_tool: accept hexadecimal addresses in peer_mw_trans again Date: Tue, 1 Dec 2026 19:16:58 +0300 Message-Id: <20261201161658.6286-1-kaynak.oguzhan0@gmail.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit 21fbdc4d0b1e ("ntb/ntb_tool: correct sscanf format for u64 and size_t in tool_peer_mw_trans_write") changed the format of the peer_mw_trans parser from "%lli:%zi" to "%llu:%zu". Unlike %lli, the kernel's vsscanf() parses %llu in base 10 only, so an address written in hexadecimal is read as 0, the ':' in the format no longer matches, and the write fails with -EINVAL. This breaks the usage documented at the top of ntb_tool.c ("echo 0xADD0BA5E:16384 > $DBG_DIR/peer0/peer_mw_trans0") and the NTB selftest. tools/testing/selftests/ntb/ntb_test.sh writes back the "DMA Address" that mw_trans prints with %pad, i.e. in hexadecimal. As the address format comes from ntb_tool itself, the first memory window test fails this way independent of the NTB hardware driver: Running mw0 tests on: 0000:00:04.0 / 0000:00:05.0 ntb_test.sh: line 117: echo: write error: Invalid argument Split the input at the ':' and parse both fields with kstrtou64() and kstrtoul() in base 0. Both fields again take decimal, 0x-prefixed hexadecimal and 0-prefixed octal, as they did with "%lli:%zi" before that commit and as every other number ntb_tool reads does (kstrto*() with base 0, or %lli). Unlike with "%lli:%zi", a negative value, whitespace around a number and anything after a number (except the newline from echo) are rejected; a malformed size no longer reads as 0 and unmaps the window. Document the rule next to the usage example. Found by running the NTB selftest against a virtual NTB device in QEMU; the fix was tested the same way: the unmodified selftest passes, hexadecimal addresses and sizes are accepted ("0x1000:0x1000" maps 4096 bytes), and "-1:16384", "0x1000:-1", "0x1000:16384x", "0x1000:", "0x1000" and ":16384" are rejected. I directed an AI coding assistant (an LLM), which analysed the regression, drafted the fix and this changelog, and wrote and ran the QEMU tests; I reviewed and tested the result. Fixes: 21fbdc4d0b1e ("ntb/ntb_tool: correct sscanf format for u64 and size_t in tool_peer_mw_trans_write") Cc: stable@vger.kernel.org Cc: yangqixiao Suggested-by: Koichiro Den Signed-off-by: Oguzhan KAYNAK --- Notes: v3: - Parse the size with kstrtoul(base 0) as well, so "0x1000:0x1000" maps 0x1000 bytes instead of reading the size as 0 and unmapping, and anything after the size is rejected (Koichiro Den). - Both fields now use base 0, as before 21fbdc4d0b1e and as the rest of ntb_tool; document that in the usage comment (Koichiro Den, Dave Jiang). - Describe the AI assistance in the changelog instead of the tag used in v1 and v2, following Documentation/process/generated-content.rst. v2: - Keep rejecting a negative address: split at ':' with strsep() and parse the address with kstrtou64(base 0) instead of going back to %lli (Koichiro Den). v2: https://lore.kernel.org/all/20261127154157.3541-1-kaynak.oguzhan0@gmail.com/ v1: https://lore.kernel.org/all/20261126031506.165973-1-kaynak.oguzhan0@gmail.com/ drivers/ntb/test/ntb_tool.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c index 7a88014..7a0f497 100644 --- a/drivers/ntb/test/ntb_tool.c +++ b/drivers/ntb/test/ntb_tool.c @@ -168,6 +168,8 @@ * root@peer# head -c 7 $DBG_DIR/peer0/mw0 * * # Map outbound memory window/check it settings (on peer device) + * # (address:size; like the other numbers here, each may be decimal, + * # 0x-prefixed hexadecimal or 0-prefixed octal; a size of 0 unmaps) * root@peer# echo 0xADD0BA5E:16384 > $DBG_DIR/peer0/peer_mw_trans0 * root@peer# cat $DBG_DIR/peer0/peer_mw_trans0 * @@ -926,8 +928,10 @@ static ssize_t tool_peer_mw_trans_write(struct file *filep, struct tool_mw *outmw = outmw_wrap->mw; size_t buf_size, wsize; char buf[TOOL_BUF_LEN]; - int ret, n; + char *addr_str, *size_str; + unsigned long val; u64 addr; + int ret; buf_size = min(size, (sizeof(buf) - 1)); if (copy_from_user(buf, ubuf, buf_size)) @@ -935,10 +939,20 @@ static ssize_t tool_peer_mw_trans_write(struct file *filep, buf[buf_size] = '\0'; - n = sscanf(buf, "%llu:%zu", &addr, &wsize); - if (n != 2) + size_str = buf; + addr_str = strsep(&size_str, ":"); + if (!size_str) return -EINVAL; + ret = kstrtou64(addr_str, 0, &addr); + if (ret) + return ret; + + ret = kstrtoul(size_str, 0, &val); + if (ret) + return ret; + wsize = val; + tool_free_peer_mw(outmw->tc, outmw->widx); if (wsize) { ret = tool_setup_peer_mw(outmw->tc, outmw_wrap->pidx, -- 2.34.1