mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>,
	Jon Mason <jdmason@kudzu.us>, Allen Hubbe <allenbh@gmail.com>
Cc: Koichiro Den <den@valinux.co.jp>,
	ntb@lists.linux.dev, linux-kernel@vger.kernel.org,
	regressions@lists.linux.dev, stable@vger.kernel.org,
	yangqixiao <yangqixiao@inspur.com>
Subject: Re: [PATCH v3] ntb: ntb_tool: accept hexadecimal addresses in peer_mw_trans again
Date: Wed, 2 Dec 2026 08:07:18 -0700	[thread overview]
Message-ID: <f83b2e82-b9cd-444c-b120-a8c5360c15f5@intel.com> (raw)
In-Reply-To: <20261201161658.6286-1-kaynak.oguzhan0@gmail.com>



On 12/1/26 9:16 AM, 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
> 
> 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 <yangqixiao@inspur.com>
> Suggested-by: Koichiro Den <den@valinux.co.jp>
> Signed-off-by: Oguzhan KAYNAK <kaynak.oguzhan0@gmail.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
> 
> 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,


      parent reply	other threads:[~2026-12-02 15:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:16 Oguzhan KAYNAK
2026-12-02 13:22 ` Koichiro Den
2026-12-02 15:07 ` Dave Jiang [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=f83b2e82-b9cd-444c-b120-a8c5360c15f5@intel.com \
    --to=dave.jiang@intel.com \
    --cc=allenbh@gmail.com \
    --cc=den@valinux.co.jp \
    --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

all inboxes | Powered by JetHome®