From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796224042; b=wca5/N7ke29ze1I/z1BshAC/uOixH1dsxaxuJavhllA3ePuooAKxPlVcCkDrnaZ2KS0u EP7nX0lPmPLO3SxnPDonmaVaIjFXH/Ai7BuZeFlsfkYT6jLzxTAzhKVaUdxeiRp6gE431 jkJp1nnKCrN2OVHSx+i5CKO5117izmE6PL6iP9jktv0zCzwjeayE/oc+IgKM6u7C7Iv+t hz11gNiEVORDaJwLZm3LMwqo7Bp7lzMvOfwNveo++lanqrjKqpXVc7NmCz4BPy82Xd7v1 BHvd1QOUiyfmwxoRaCPKzn+6SGy4MXjuComBbgLIdpy00GmgtothmXPi+nZgEo+DWkw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796224042; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=+4FppXTSFkYF9pAiZN9c9y+daXk87rgp9xtJQ/Gb6UE=; b=of2BLaJFkHvk8OCdBklZKk5qqj2wyBk80MLwgDtZcUT0gWtYNdXRBEIoxJFkFIP6zO// XQSh8LieJVjmcJZQHRU/8ZTy8Vnw2qmdYV4wavJwl9uyYvRSaTBuOH/kCmVjk/RV3z01o 8T6De6eg+Ik/QhJLxulpzvFMYnoQTHyXtTQwQADn+htBXBueEQmbLKqb0xup0u1DulfvY RA4wEL60YhmbhI7x+Jbaawi4p7DC2eyfw+1QaBzhgVeuYkc1BpmRaEbFJ7rPE1PcoZwjA YnJDmjfplrG7mbTxNFSbEl9JSJBfd3mztBvOzqobNJMqNOEyP5gA1hpICXhFDhMdjKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YeKN5Hm5; arc=none smtp.remote-ip=198.175.65.10 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03159606A31A; Wed, 2 Dec 2026 15:07:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 03159606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=YeKN5Hm5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796224041; x=1827760041; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=+4FppXTSFkYF9pAiZN9c9y+daXk87rgp9xtJQ/Gb6UE=; b=YeKN5Hm5vsqtOL+46F3joMVkzRVi8Bpt5oS2nv1VWSOVTlQd15Y/HAsy IltXniiCaznaADgoAjk+3AFK/AKkgr/rXA4s1DRc15AL0Q17eAG4wEM+J Tzk+THJipFXAxRGI6CffcDttvsTjs3M6MSxtYcPQQkQafeyiU+zMwBVu6 DpoIHL1SJT0woX/Ptx3yJw/mKpacrsFvpwbakKWie6csIGX/l3lzE5zK2 qju2CSyiEKO8SN/n12sFmh2saGKkh7dPq1MEXO6kZz23wH+3L4JNmZU7/ 7jnmdAuEjtQ/5+vRHAHSSX9dHofVMiTHJaNXyrOwFwMAO63Pnx8RV68UU w==; X-CSE-ConnectionGUID: iE7a0oeoSl+RKHkTTxqiiQ== X-CSE-MsgGUID: ESvqffWPQaSQQyqWtQwG0w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5088273" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5088273" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 07:07:20 -0800 X-CSE-ConnectionGUID: tgjeo1E0ReOYO1Qb80wg1Q== X-CSE-MsgGUID: +gOGZ3flQuCyzJXYHkk6yg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="14071442" Received: from jjgreens-desk24.amr.corp.intel.com (HELO [10.125.108.34]) ([10.125.108.34]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 07:07:19 -0800 Message-ID: Date: Wed, 2 Dec 2026 08:07:18 -0700 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] ntb: ntb_tool: accept hexadecimal addresses in peer_mw_trans again To: Oguzhan KAYNAK , Jon Mason , Allen Hubbe Cc: Koichiro Den , ntb@lists.linux.dev, linux-kernel@vger.kernel.org, regressions@lists.linux.dev, stable@vger.kernel.org, yangqixiao References: <20261201161658.6286-1-kaynak.oguzhan0@gmail.com> From: Dave Jiang Content-Language: en-US In-Reply-To: <20261201161658.6286-1-kaynak.oguzhan0@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 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 Reviewed-by: Dave Jiang > --- > > 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,