From: Koichiro Den <den@valinux.co.jp>
To: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>
Cc: Jon Mason <jdmason@kudzu.us>, Dave Jiang <dave.jiang@intel.com>,
Allen Hubbe <allenbh@gmail.com>,
ntb@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, regressions@lists.linux.dev,
yangqixiao <yangqixiao@inspur.com>
Subject: Re: [PATCH] ntb: ntb_tool: accept hexadecimal addresses in peer_mw_trans again
Date: Fri, 27 Nov 2026 17:01:52 +0900 [thread overview]
Message-ID: <awkzEjrVEz2jB1Ma@z790sl> (raw)
In-Reply-To: <20261126031506.165973-1-kaynak.oguzhan0@gmail.com>
On Thu, Nov 26, 2026 at 06:15:06AM +0300, Oguzhan KAYNAK wrote:
> 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<N> 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
>
> Parse the address with %lli again, which accepts any base, as before
> that commit. To keep the format and the argument type matching, which
> was the point of that commit, store it in a long long; it is passed on
> as u64 as before. A negative address is accepted and converted to u64,
> as it was before that commit. Keep %zu for the size.
>
> Found by running the NTB selftest against a virtual NTB device in
> QEMU; the fix was tested the same way (the unmodified selftest passes,
> and hexadecimal writes to peer_mw_trans0 succeed 10 out of 10 times).
>
> 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: regressions@lists.linux.dev
> Cc: yangqixiao <yangqixiao@inspur.com>
> Assisted-by: LLM
> Signed-off-by: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>
> ---
> drivers/ntb/test/ntb_tool.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> --- a/drivers/ntb/test/ntb_tool.c
> +++ b/drivers/ntb/test/ntb_tool.c
> @@ -928,7 +928,7 @@ static ssize_t tool_peer_mw_trans_write(
> size_t buf_size, wsize;
> char buf[TOOL_BUF_LEN];
> int ret, n;
> - u64 addr;
> + long long addr;
>
> buf_size = min(size, (sizeof(buf) - 1));
> if (copy_from_user(buf, ubuf, buf_size))
> @@ -936,7 +936,7 @@ static ssize_t tool_peer_mw_trans_write(
>
> buf[buf_size] = '\0';
>
> - n = sscanf(buf, "%llu:%zu", &addr, &wsize);
> + n = sscanf(buf, "%lli:%zu", &addr, &wsize);
Just to clarify, do we have any rule about negative values for the address part,
like in "-1:4096"? 21fbdc4d0b1e mentions "-1" as a possible input for the size
part, but doesn't mention it for the address part. (For either part, "-1" is
really odd, but that's not the point.) As you mention, your patch starts
accepting it for the address part again. Perhaps we should keep rejecting it
there?
If so, to cover the cases broguht up so far, perhaps it would be an option to
split the input at ":" with strsep() and use kstrtou64() with base 0 for the
address?
That said, this looks like a nice and small improvement to me.
Reviewed-by: Koichiro Den <den@valinux.co.jp>
Thanks!
Best regards,
Koichiro Den
> if (n != 2)
> return -EINVAL;
>
> --
> 2.34.1
>
prev parent reply other threads:[~2026-11-27 8:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 3:15 [PATCH] ntb: ntb_tool: accept hexadecimal addresses in peer_mw_trans again Oguzhan KAYNAK
2026-11-27 8:01 ` Koichiro Den [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awkzEjrVEz2jB1Ma@z790sl \
--to=den@valinux.co.jp \
--cc=allenbh@gmail.com \
--cc=dave.jiang@intel.com \
--cc=jdmason@kudzu.us \
--cc=kaynak.oguzhan0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntb@lists.linux.dev \
--cc=regressions@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=yangqixiao@inspur.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox