From: sashiko-bot@kernel.org
To: "Janne Grunau" <j@jannau.net>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT
Date: Wed, 19 Aug 2026 15:06:44 +0000 [thread overview]
Message-ID: <20260819150644.DE4181F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819-iommu-apple-dart-aperture-v1-2-252703f381aa@jannau.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Undefined behavior via invalid bit shift when parsing a 1-byte DMA window starting at address 0.
--
--- Patch [2]: [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT ---
commit ce65194c53df34be71115a91f5d6328ad1a90109
Author: Janne Grunau <j@jannau.net>
iommu: apple-dart: Support specifying the DMA aperture in the DT
This commit adds support for restricting the DMA aperture via the Device Tree
using the iommus args. Devices can specify the start and end of the aperture
if the DART device node specifies #iommu-cells = <5>.
> diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c
> --- a/drivers/iommu/apple-dart.c
> +++ b/drivers/iommu/apple-dart.c
> @@ -590,6 +600,7 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
> {
> struct apple_dart *dart = cfg->stream_maps[0].dart;
> struct io_pgtable_cfg pgtbl_cfg;
> + u32 ias = min_t(u32, dart->ias, fls64(cfg->dma_max));
> int ret = 0;
> int i, j;
[ ... ]
> @@ -623,10 +634,10 @@ static int apple_dart_finalize_domain(struct apple_dart_domain *dart_domain,
> goto done;
> }
>
> + dart_domain->mask = DMA_BIT_MASK(pgtbl_cfg.ias);
[Severity: Low]
Does this code trigger undefined behavior if a 1-byte DMA window starting at
address 0 is provided in the device tree?
If a device tree is configured with length = 1 and dma_min = 0,
apple_dart_of_xlate() calculates dma_max as 0:
apple_dart_of_xlate()
dma_max = dma_min + length - 1; /* 0 + 1 - 1 = 0 */
This means cfg->dma_max will be 0 here, making fls64(cfg->dma_max) 0,
and resulting in ias = 0.
If ias is 0, this expands to DMA_BIT_MASK(0), which performs an invalid bit
shift (~0ULL >> 64).
Since size 0 (!length) is explicitly rejected in apple_dart_of_xlate(),
should size 1 also be handled to avoid this edge case?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819-iommu-apple-dart-aperture-v1-0-252703f381aa@jannau.net?part=2
prev parent reply other threads:[~2026-08-19 15:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 14:52 [PATCH 0/2] iommu: apple-dart: device specific DMA aperture support Janne Grunau
2026-08-19 14:52 ` [PATCH 1/2] dt-bindings: iommu: dart: Support specifying the DMA aperture Janne Grunau
2026-08-19 14:52 ` [PATCH 2/2] iommu: apple-dart: Support specifying the DMA aperture in the DT Janne Grunau
2026-08-19 15:06 ` sashiko-bot [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=20260819150644.DE4181F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=j@jannau.net \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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