Article View: linux.kernel.netdev
Article #17331Re: [PATCH net-next v2 2/3] i2c: xiic: add KUnit coverage for register access modes
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 16:33
Date: Mon, 16 Nov 2026 16:33
137 lines
13265 bytes
13265 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
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] The new KUnit test in
drivers/i2c/busses/tests/i2c_xiic_kunit.c (xiic_register_access(),…
--
i2c: xiic: add KUnit coverage for register access modes
This commit adds a KUnit suite that runs the xiic driver's private
xiic_setreg*() and xiic_getreg*() accessors against kmalloc-backed memory
instead of MMIO. It covers both byte orders, with native-width and forced
32-bit access. The test file is included directly into i2c-xiic.c and is
enabled by a new I2C_XILINX_KUNIT_TEST bool option that requires built-in
KUnit.
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index 275aaa7f35833..014281fa2be5c 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -1322,6 +1322,20 @@ config I2C_XILINX
> This driver can also be built as a module. If so, the module
> will be called xilinx_i2c.
>
> +config I2C_XILINX_KUNIT_TEST
> + bool "KUnit tests for Xilinx I2C register accesses" if !KUNIT_ALL_TESTS
> + depends on I2C_XILINX && KUNIT=y
> + default KUNIT_ALL_TESTS
> + help
> + Test the Xilinx I2C driver's register accessors with both byte orders
> + and with native-width or forced 32-bit accesses. KUnit is a kernel
> + unit testing framework. These tests use memory-backed registers and
> + do not require an I2C controller.
[ ... ]
> diff --git a/drivers/i2c/busses/tests/i2c_xiic_kunit.c b/drivers/i2c/busses/tests/i2c_xiic_kunit.c
> new file mode 100644
> index 0000000000000..b4c818d8bac78
> --- /dev/null
> +++ b/drivers/i2c/busses/tests/i2c_xiic_kunit.c
[ ... ]
> +static void xiic_register_access(struct kunit *test)
> +{
[ ... ]
> + i2c = kunit_kzalloc(test, sizeof(*i2c), GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, i2c);
> + mem = kunit_kmalloc(test, 0x200, GFP_KERNEL);
> + KUNIT_ASSERT_NOT_NULL(test, mem);
> + /* Aligned RAM stands in for MMIO. No hardware is accessed. */
> + i2c->base = (void __force __iomem *)(mem + sizeof(u32));
[Severity: Medium]
Is it safe to push kmalloc memory through ioread*() and iowrite*() here?
xiic_setreg32(), xiic_getreg32() and the 8/16-bit helpers call
iowrite32(), ioread32be() and similar directly on i2c->base. Those
accessors are only required to work on cookies returned by ioremap() or
pci_iomap().
On x86-64 this works, because the generic iomap code treats these
addresses as plain MMIO. But I2C_XILINX_KUNIT_TEST only depends on
I2C_XILINX && KUNIT=y and defaults to KUNIT_ALL_TESTS, and I2C_XILINX only
needs HAS_IOMEM. As a result, the option can be enabled on architectures
where RAM can't be accessed this way.
On UML, tools/testing/kunit/configs/arch_uml.config sets
CONFIG_KUNIT_UML_PCI=y. That pulls in UML_PCI -> UML_IOMEM_EMULATION ->
INDIRECT_IOMEM and enables HAS_IOMEM. The accessors then end up in
lib/logic_iomem.c:
lib/logic_iomem.c:get_area() {
...
if (WARN_ON((a & IOREMAP_MASK) != IOREMAP_BIAS))
return NULL;
...
}
INDIRECT_IOMEM_FALLBACK is never selected, so the fallback
real_raw_read*() and real_raw_write*() helpers WARN a second time, return
~0 and drop the writes.
Wouldn't that mean two WARNs per accessor call? Across 22 offsets and 4
parameters that is about 2100 WARNs per run. Every expectation would fail,
and with panic_on_warn=1 the kernel would panic. A plain kunit.py run with
--kconfig_add CONFIG_I2C_XILINX=y looks like it would hit this.
On s390 with PCI, __raw_readl() and __raw_writel() map to zpci_read_u32()
and zpci_write_u32(). The test would then issue real zPCI load and store
instructions on a heap address. Without MIO, the address is decoded as an
iomap index plus a PCI offset:
arch/s390/pci/pci_insn.c:zpci_load_fh() {
...
struct zpci_iomap_entry *entry = &zpci_iomap_start[ZPCI_IDX(addr)];
u64 req = ZPCI_CREATE_REQ(READ_ONCE(entry->fh), entry->bar, len);
return __zpci_load(data, req, ZPCI_OFFSET(addr));
}
Could this fail with zpci errors, or reach an unrelated function's BAR if
an iomap entry happens to match?
On sparc64, __raw_readl() in arch/sparc/include/asm/io_64.h uses lduwa
with ASI_PHYS_BYPASS_EC_E. That treats the kernel virtual pointer as a
physical address and bypasses the caches.
Because of this, the "No hardware is accessed" comment, the
"memory-backed registers" Kconfig help text and the changelog only hold
on architectures like x86-64. The rest of the series doesn't seem to
change this Kconfig entry or the test file.
There seem to be two ways to fix this. One is to restrict the option by
architecture, for example depends on !UML && !S390 && !SPARC64, or an
allow-list. The other is to route register access through a hook that the
test can replace with a memory-backed implementation. With either one, the
comment and help text should be updated to match.
> + i2c->endianness = param->endianness;
> + i2c->force_32bit_access = param->force_32bit_access;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112163333.12523-1-ahmadexp%40gmail.com
Technical Details
Message-ID:
<179484681740.3136.17781028072212776292@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364556-linux-kernel-netdev=dewy.ruReferences:
<20261112163333.12523-3-ahmadexp@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364556-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next v2 2/3] i2c: xiic: add KUnit coverage for register access modes Date: Mon, 16 Nov 2026 16:33:37 +0000 Organization: Usenet Network Message-ID: <179484681740.3136.17781028072212776292@kernel.org> References: <20261112163333.12523-3-ahmadexp@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2111639"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:W+09RFYoskW72RBGzYPHSA8Ad5E= sha256:PZoBPbnWBIca0xxmgzni2zBHTq7HCqAowCfGWnSw8YI= sha1:9y2SvbNdppd3bi4/K0h6gtnZTCg= sha256:dJo0eD2zIQoEAYI847OB4Y/mc9coEHGm4yZ/LU1d+Fw= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 26984114CE5; Mon, 16 Nov 2026 19:33:56 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ypTO6gHsFOAJ; Mon, 16 Nov 2026 19:33:52 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-364556-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 243AF114CE2; Mon, 16 Nov 2026 19:33:43 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 2A9B026F01; Mon, 16 Nov 2026 16:33:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794846820; b=LnSz5NcdiKckguN55pDY7T/7252DIv7qGJUlgovVG61bilLDA/7WbIyLGoAxnxUIRBMb 9IftDf2J49Hg3r19OxwNlRnSD14MCGQ0MZ7zAVFw9R+/HQc6EKfpLCKq5TLP4hl7bcQzp 7VjmGW+Uta0U3enzaUJBvt+Nr/sj8/iIc4vRpkLl5l3MEk1jvM/b4gvxklmB2xUBgq7KB kF5tiiM8ITA1pNFwYpxaNy1UeBU+Ifm+WFLoVa32u7KCVe6lMv7OHYEumMILD7Mw8/KX7 ArG13cGqj5wgQt0wGcB7SbhwR2K6AExNXIFoIlqFu4wKvpy+lADfr+7J+BQphiW3OoA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794846820; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=lAsf+sMMq5bVx/eFBObeO8BbOzzotZiN0ESA48dI7mg=; b=exUnzU8Ipgu9X0vpZF7umrRU066CG8IKquNPKWxaQ5bYw4RtzGLQBXt1+Hr9ANfUoEAL RAEPztVGC7p3SeScOyKxjuHfHDuGTf8Aojny43wOcNRGmb2mUpTwrPqfNzHHkEP9eHDeu QIM4QXcHpkfCl5eMtOUZQmTBi1uGaq0CllBoYUR1vRfm/rDek78iYEZ175nARigRWNZHs EmgRMfkOg0s91VBRw4rjl0GwBeWe5DJ97Uh1h4mseOMVEgwWfC+09IkPMx5KtwqEqkCnf LXzzldJtgiuvVAGytRtc2tHuHBh3LhYPmudJWpNxgSr9nypOC6Hk+VjwPq/7Xn5triA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NS5mYxsJ; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B1B606A329; Mon, 16 Nov 2026 16:33:40 +0000 (UTC) X-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=NS5mYxsJ X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794846818; b=nlCN0QTLXsBxGCtBwmxqJAyQXpgBwBq1daHNl0l/q6/VZv+U5l4TxWsIir1SL6mi0OTZ gqhtJ2CIedys3CtXFIJXEPW72TR5j1tWfbZa9yFHwXOaw8GAfmmAq/cnnpjys5FS9j0vh sjz9ib3IAzyw6vPgRa/WQuT0GHPGAhRksb9k2mBhv6tHhAef3dv9ojyfDBAIP1WZHiLc7 7tVlsy85YaFmmi5GcyQuGMTAfluwEDuXTFpHxEyU3A7lVbmRtkW/rwdPh2zaCDtj6lWaV Y4XYKat6dkLoYu17eLHLUj10zky1cKI9X4BKfrUiAk3RY936Y9HTB9BWZMBiOJ3ECCg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794846818; 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=lAsf+sMMq5bVx/eFBObeO8BbOzzotZiN0ESA48dI7mg=; b=ET2QjEUkQuQwN8CXNibcmp54zRsEQenhVRcUpb9qOG8LqaEmtzrB5oVGKu5Ekw0YVodx 9iADqns0fEUGI7bC8U1/xSQv3WEpdHPyhal9kOtPsGV0hdscvVlhqq132gQ6xmRGGeHHI 40jehYAp9UkHP+AOFZUGRRK1htL0yOx56REuK4KMDqomIb6ZoHgxNVzL7Xd+eXgrbjqjb WPr9wEurcCH4Ouo5OClTKMdlnY/qd9UWIhfAkQI8iGeOBlmLvfn1sdbUN2BRHVwgb8ESS ng/gH5l4pn8B1Lbr4JopJ4r9i3MBtCLbVEZ3Csms3ABevym6KStoH0vQo7SXYnO/5SQ== X-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=NS5mYxsJ; arc=none smtp.remote-ip=100.103.45.18 X-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 C931E606A31C; Mon, 16 Nov 2026 16:33:38 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9BF81F000C4; Mon, 16 Nov 2026 16:33:37 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794846818; bh=lAsf+sMMq5bVx/eFBObeO8BbOzzotZiN0ESA48dI7mg=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=NS5mYxsJUyb5qdQX2jRqFMtqo8hreun+NiWu2e7s4itUbj4RgMszUIL/B4VIGMvnJ LkNL0gnC54IReO6iiL/Rj4H609ggPT3pMbZGfp6gdSHjzNjXaTH7SueYJe//3IHINV uGe5cq12+pSAye5OSZWbo4i/29l9WPUCZlOKRbCtZ0jwsMunyvQzVRpA1pja0vElWu oLApev6cmdh6e4kmXc9Yi40gVQtmYxVpywSeK75BwcwfZeWGvf5o08FmWX6OYp+qUG 3h84P+2QT4qP67HTYmh7Em10WgPaLrjFBufa68BQ5Fk6m7yVbEFxGR4VaaG6Rw92cN Pbo7D9gQI6rKw== X-Cc: netdev@vger.kernel.org, vadim.fedorenko@linux.dev, andi.shyti@kernel.org, linux-i2c@vger.kernel.org, michal.simek@amd.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kuba@kernel.org X-In-Reply-To: <20261112163333.12523-3-ahmadexp@gmail.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list