Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] iommu: size_t truncation of derived reserved region length on 32-bit systems
- [Medium] iommu: DT ABI breakage by rejecting iommu-addresses without reg
- [Medium] iommu: OOB read in of_iommu_derive_resv_regions when parsing malformed iommu-ranges
--
commit 08a09989ffefcbf5d38171159dcc911ca993ff18
Author: Vikash Garodia <vikash.garodia(a)oss.qualcomm.com>
iommu: of_iommu: Add support for "iommu-ranges" on a device node
Add support for "iommu-ranges" on device nodes to specify usable IOVA
ranges directly when there is no backing "reg". Introduce logic to derive
reserved regions outside of "iommu-ranges" and restrict "iommu-addresses"
to be paired with a "reg" property.
Link: https://lore.kernel.org/all/662f7093-fb0a-4564-9ca0-98e03e68ba9a@kernel.org
> diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c
> index a18bb60f6f3df..9766a6944d0e1 100644
> --- a/drivers/iommu/of_iommu.c
> +++ b/drivers/iommu/of_iommu.c
[ ... ]
> +static void of_iommu_derive_resv_regions(struct device *dev, struct list_head *list)
> +{
[ ... ]
> + maps = of_get_property(dev->of_node, "iommu-ranges", &size);
> + if (!maps)
> + return;
> +
> + end = maps + size / sizeof(__be32);
> +
> + while (maps < end) {
> + phys_addr_t iova, iova_end;
> + size_t length;
> +
> + maps = of_translate_dma_region(dev->of_node, maps, &iova, &length);
[Severity: Medium]
Could this result in an out-of-bounds read if the "iommu-ranges" property is
malformed?
The loop condition checks `maps < end`, but of_translate_dma_region()
implicitly reads `na + ns` cells from the maps array.
Does this loop need to ensure there are at least `na + ns` cells remaining
before calling the translation function to prevent reading past the buffer?
[ ... ]
> + list_for_each_entry_safe(pos, next_range, &ranges, node) {
> + if (pos->start > next) {
> + region = iommu_alloc_resv_region(next, pos->start - next, prot,
> + IOMMU_RESV_RESERVED, GFP_KERNEL);
[Severity: High]
Can the length argument overflow on 32-bit systems?
On 32-bit systems with 64-bit physical addresses (like ARM LPAE), address
differences can easily exceed 4GB. Because iommu_alloc_resv_region() takes
a 32-bit size_t length, passing a 64-bit gap size causes it to truncate.
Will this truncation result in a reservation of at most 4GB, leaving the
IOVA address space above that unprotected?
[ ... ]
> + region = iommu_alloc_resv_region(next, PHYS_ADDR_MAX - next + 1,
> + prot, IOMMU_RESV_RESERVED, GFP_KERNEL);
[Severity: High]
Similarly, can passing `PHYS_ADDR_MAX - next + 1` here truncate the length
to its lower 32 bits on 32-bit systems?
If the remaining address space exceeds 4GB, this truncation could leave high
IOVA addresses unprotected, allowing the IOMMU allocator to hand out reserved
IOVAs.
[ ... ]
> @@ -214,10 +319,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
[ ... ]
> - * The "reg" property is optional and can be omitted by reserved-memory regions
> - * that represent reservations in the IOVA space, which are regions that should
> - * not be mapped.
> + * "iommu-addresses" must be used in combination with a "reg" that provides
> + * the physical address and size of this memory region, for an identity 1:1
> + * IOVA mapping to that physical memory.
> */
> if (of_property_present(it.node, "reg")) {
> err = of_address_to_resource(it.node, 0, &phys);
[ ... ]
> - }
> -
> - maps = of_get_property(it.node, "iommu-addresses", &size);
> - if (!maps)
> + } else {
> + dev_err(dev, "%pOF: iommu-addresses requires a reg property\n",
> + it.node);
> continue;
> + }
[Severity: Medium]
Will this break existing device trees?
This explicitly rejects the previously valid 'no reg' device tree
configurations. Existing device trees that validly relied on
"iommu-addresses" without a "reg" property to create IOVA reservations will
now have their reservations silently ignored.
Could this lead to the IOMMU allocating IOVAs in reserved spaces, causing
DMA faults?
[ ... ]
> @@ -258,6 +367,9 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
> }
> type = iommu_resv_region_get_type(dev, &phys, iova, length);
>
> + if (type != IOMMU_RESV_DIRECT)
> + continue;
> +
> region = iommu_alloc_resv_region(iova, length, prot, type,
> GFP_KERNEL);
[Severity: Medium]
Does this newly added check actively block pure reservations?
By enforcing that only identity mappings are honored, does this violate
backward compatibility for device trees that used pure reservations?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260926-vpu_iommu_iova_handling-v5-0-0322ca…
Dear Yuanzhe Liu:
Thanks for your patches! Unfortunately the Media CI robot detected some
issues:
# Test bisect:0001-cfc389ca037c83ea3a9ce91de8400a4b4df7e7ce bisect build
drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
346 | err_msg = "Failed to register clock\n";
| ^~~~~~~
drivers/platform/x86/intel/int3472/discrete.c:346:33: note: each undeclared identifier is reported only once for each function it appears in
make[7]: *** [scripts/Makefile.build:289: drivers/platform/x86/intel/int3472/discrete.o] Error 1
make[6]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel/int3472] Error 2
make[5]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel] Error 2
make[4]: *** [scripts/Makefile.build:546: drivers/platform/x86] Error 2
make[3]: *** [scripts/Makefile.build:546: drivers/platform] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:546: drivers] Error 2
make[1]: *** [/builds/linux-media/users/patchwork/Makefile:2101: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
# Test bisect:0002-0d7cfa923cff320c58f6bb6a84ddde02ec5ddf21 bisect build
drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
346 | err_msg = "Failed to register clock\n";
| ^~~~~~~
drivers/platform/x86/intel/int3472/discrete.c:346:33: note: each undeclared identifier is reported only once for each function it appears in
make[7]: *** [scripts/Makefile.build:289: drivers/platform/x86/intel/int3472/discrete.o] Error 1
make[7]: *** Waiting for unfinished jobs....
make[6]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel/int3472] Error 2
make[5]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel] Error 2
make[4]: *** [scripts/Makefile.build:546: drivers/platform/x86] Error 2
make[3]: *** [scripts/Makefile.build:546: drivers/platform] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:546: drivers] Error 2
make[1]: *** [/builds/linux-media/users/patchwork/Makefile:2101: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
# Test build-basic:x86_64
drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
346 | err_msg = "Failed to register clock\n";
| ^~~~~~~
drivers/platform/x86/intel/int3472/discrete.c:346:33: note: each undeclared identifier is reported only once for each function it appears in
make[7]: *** [scripts/Makefile.build:289: drivers/platform/x86/intel/int3472/discrete.o] Error 1
make[6]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel/int3472] Error 2
make[5]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel] Error 2
make[4]: *** [scripts/Makefile.build:546: drivers/platform/x86] Error 2
make[3]: *** [scripts/Makefile.build:546: drivers/platform] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:546: drivers] Error 2
make[1]: *** [/builds/linux-media/users/patchwork/Makefile:2101: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
# Test build-basic:x86
drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
346 | err_msg = "Failed to register clock\n";
| ^~~~~~~
drivers/platform/x86/intel/int3472/discrete.c:346:33: note: each undeclared identifier is reported only once for each function it appears in
make[7]: *** [scripts/Makefile.build:289: drivers/platform/x86/intel/int3472/discrete.o] Error 1
make[6]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel/int3472] Error 2
make[5]: *** [scripts/Makefile.build:546: drivers/platform/x86/intel] Error 2
make[4]: *** [scripts/Makefile.build:546: drivers/platform/x86] Error 2
make[3]: *** [scripts/Makefile.build:546: drivers/platform] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [scripts/Makefile.build:546: drivers] Error 2
make[1]: *** [/builds/linux-media/users/patchwork/Makefile:2101: .] Error 2
make: *** [Makefile:248: __sub-make] Error 2
# Test cocci:test-coccinelle
./platform/arm/mali-c55/mali-c55-core.c:871:2-9: line 871 is redundant because platform_get_irq() already prints an error
./dvb-frontends/helene.c:1049:2-7: WARNING: invalid free of devm_ allocated data
./dvb-frontends/helene.c:1013:2-7: WARNING: invalid free of devm_ allocated data
./dvb-core/dvb_frontend.c:2899:2-8: preceding lock on line 2776
./dvb-core/dvb_frontend.c:2899:2-8: preceding lock on line 2786
./dvb-core/dvb_frontend.c:2899:2-8: preceding lock on line 2809
./dvb-core/dvb_frontend.c:2906:1-7: preceding lock on line 2776
./dvb-core/dvb_frontend.c:2906:1-7: preceding lock on line 2786
./dvb-core/dvb_frontend.c:2906:1-7: preceding lock on line 2809
./platform/qcom/iris/iris_vpu_buffer.c:703:13-15: WARNING opportunity for max()
./platform/qcom/iris/iris_vpu_buffer.c:583:23-25: WARNING opportunity for max()
./platform/arm/mali-c55/mali-c55-core.c:461:2-3: Unneeded semicolon
# Test static:test-smatch
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
make[7]: [scripts/Makefile.build:289: drivers/platform/x86/intel/int3472/discrete.o] Error 1 (ignored)
make[7]: [scripts/Makefile.build:475: drivers/platform/x86/intel/int3472/built-in.a] Error 123 (ignored)
drivers/media/v4l2-core/v4l2-dev.c:1036 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
drivers/media/v4l2-core/v4l2-dev.c:1043 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
drivers/media/v4l2-core/v4l2-dev.c:1101 __video_register_device() error: buffer overflow 'video_devices' 256 <= 288
drivers/media/i2c/adv7604.c:3672 adv76xx_probe() error: buffer overflow 'state->pads' 7 <= 4294967294
drivers/media/i2c/adv7604.c:3673 adv76xx_probe() error: buffer overflow 'state->pads' 7 <= u32max
drivers/media/platform/amlogic/c3/isp/c3-isp-params.c:111 c3_isp_params_awb_wt() error: buffer overflow 'cfg->zone_weight' 768 <= u32max
drivers/media/platform/amlogic/c3/isp/c3-isp-params.c:111 c3_isp_params_awb_wt() error: buffer overflow 'cfg->zone_weight' 768 <= u32max
drivers/media/platform/amlogic/c3/isp/c3-isp-params.c:227 c3_isp_params_ae_wt() error: buffer overflow 'cfg->zone_weight' 255 <= u32max
drivers/media/platform/amlogic/c3/isp/c3-isp-params.c:227 c3_isp_params_ae_wt() error: buffer overflow 'cfg->zone_weight' 255 <= u32max
drivers/media/platform/chips-media/wave5/wave5-vpuapi.c:588 wave5_vpu_dec_get_output_info() error: buffer overflow 'inst->frame_buf' 64 <= 127
drivers/staging/media/ipu3/ipu3-css-params.c:1792 imgu_css_cfg_acc_stripe() warn: 'acc->stripe.bds_out_stripes[0]->width - 2 * f' 4294967168 can't fit into 65535 'acc->stripe.bds_out_stripes[1]->offset'
# Test static:test-sparse
drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: ‘err_msg’ undeclared (first use in this function)
346 | err_msg = "Failed to register clock\n";
| ^~~~~~~
drivers/platform/x86/intel/int3472/discrete.c:346:33: note: each undeclared identifier is reported only once for each function it appears in
drivers/platform/x86/intel/int3472/discrete.c:346:33: error: undefined identifier 'err_msg'
drivers/platform/x86/intel/int3472/discrete.c:352:33: error: undefined identifier 'err_msg'
drivers/input/touchscreen/atmel_mxt_ts.c:1485:44: warning: unsigned value that used to be signed checked against zero?
drivers/input/touchscreen/atmel_mxt_ts.c:1483:49: signed value source
x86_64-linux-gnu-ar: drivers/platform/x86/intel/int3472/discrete.o: No such file or directory
make[7]: [scripts/Makefile.build:475: drivers/platform/x86/intel/int3472/built-in.a] Error 123 (ignored)
# Test media-patchstyle:test-valid-ancestor
ERROR: This code is not based on any of the branches: next fixes
from https://gitlab.freedesktop.org/linux-media/media-committers.git.
The output of media-ci will not be reliable, and the code will not
land upstream as-is. Please rebase your code.
# Test media-patchstyle:rc core
/builds/linux-media/users/patchwork/include/media/rc-map.h:265: duplicate value for rc-hauppauge
rc-videomate-m1f.c: name #define RC_MAP_VIDEOMATE_K100 does not match rc-videomate-k100
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:125: expecting rc-rc6-mce found rc-rc5-tv
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:126: expecting rc-real-audio-220-32-keys found rc-rc6-mce
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:127: expecting rc-reddo found rc-real-audio-220-32-keys
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:128: expecting rc-siemens-gigaset-rc20 found rc-reddo
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:150: expecting rc-vega-s9x found rc-videomate-k100
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:151: expecting rc-videomate-m1f found rc-videomate-s350
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:152: expecting rc-videomate-s350 found rc-videomate-tv-pvr
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:153: expecting rc-videomate-tv-pvr found rc-videostrong-kii-pro
/builds/linux-media/users/patchwork/Documentation/devicetree/bindings/media/rc.yaml:154: expecting rc-videostrong-kii-pro found rc-vega-s9x
/builds/linux-media/users/patchwork/include/media/rc-map.h:312: rc-rc5-tv does not exist
/builds/linux-media/users/patchwork/include/media/rc-map.h:339: rc-videomate-k100 does not exist
/builds/linux-media/users/patchwork/include/media/rc-map.h: missing entry for rc-videomate-m1f
errors: 14
Please fix your series, and upload a new version. If you have a patchwork
account, do not forget to mark the current series as Superseded.
For more details, check the full report at:
https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/11119892… .
Best regards, and Happy Hacking!
Media CI robot on behalf of the linux-media community.
---
Check the latest rules for contributing your patches at:
https://docs.kernel.org/driver-api/media/maintainer-entry-profile.html
If you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all
to this message.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mm: alloc_cc_shared_pages_node fails to strip __GFP_MOVABLE
- [Medium] mm: alloc_cc_shared_pages_node fails to strip __GFP_HIGHMEM in fallback path
- [Medium] mm: cc_make_shared and cc_make_private are not exported for modular callers
--
commit 3978c8ce72bbc2aa23e57a460b585808665262a4
Author: Aneesh Kumar K.V (Arm) <aneesh.kumar(a)kernel.org>
mm: Add an allocator for CoCo shared memory
This commit introduces a common allocator for confidential-computing guests
to allocate shared memory. It provides helpers to allocate properly aligned
contiguous pages and transition them to shared state. It also adds helpers
for transitioning memory states when callers manage their own backing memory.
> diff --git a/mm/cc_shared.c b/mm/cc_shared.c
> new file mode 100644
> index 0000000000000..85e16f4504b8f
> --- /dev/null
> +++ b/mm/cc_shared.c
[ ... ]
> +int cc_make_shared(void *addr, size_t size)
> +{
> + int ret = cc_validate_transition(addr, size);
> +
> + if (ret)
> + return ret;
> +
> + return set_memory_decrypted((unsigned long)addr, size >> PAGE_SHIFT);
> +}
[Severity: Medium]
Will this function be unavailable to dynamically loadable modules since it
is missing an EXPORT_SYMBOL_GPL() macro?
The commit message states it should be usable by callers managing their own
backing memory, but virtio or guest drivers won't be able to link to it
without an export.
> +
> +int cc_make_private(void *addr, size_t size)
> +{
> + int ret = cc_validate_transition(addr, size);
> +
> + if (ret)
> + return ret;
> +
> + return set_memory_encrypted((unsigned long)addr, size >> PAGE_SHIFT);
> +}
[Severity: Medium]
Does this function also need an EXPORT_SYMBOL_GPL() macro so that modules
can successfully link and call it?
[ ... ]
> +static int __alloc_cc_shared_pages_node(int nid, gfp_t gfp,
> + size_t requested,
> + struct cc_shared_pages *mem)
> +{
[ ... ]
> + /*
> + * State transitions require a linear-map address and may modify memory.
> + * Allocate from low memory and defer requested zeroing until afterwards.
> + */
> + gfp &= ~(__GFP_HIGHMEM | __GFP_ZERO);
[Severity: High]
Does this code inadvertently leave __GFP_MOVABLE intact if passed by the
caller?
Pages are returned as shared memory, but they lack migration hooks
(movable_operations) to handle encryption state transitions during page
migration.
If a caller passes __GFP_MOVABLE, the page might be placed in ZONE_MOVABLE.
Since the kernel migration code does not know how to handle encryption state
transitions, the page cannot be safely migrated. Could this permanently pin
the movable zone, thereby breaking memory hot-unplug and compaction?
> + if (nid == NUMA_NO_NODE)
> + page = alloc_pages(gfp, order);
[ ... ]
> +int alloc_cc_shared_pages_node(int nid, gfp_t gfp,
> + size_t requested,
> + struct cc_shared_pages *mem)
> +{
[ ... ]
> + if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
> + return __alloc_cc_shared_pages_node(nid, gfp, requested, mem);
> +
> + order = get_order(requested);
> + if (order > MAX_PAGE_ORDER)
> + return -EINVAL;
> +
> + if (nid == NUMA_NO_NODE)
> + page = alloc_pages(gfp, order);
> + else
> + page = alloc_pages_node(nid, gfp, order);
[Severity: Medium]
Can this fallback path inadvertently allocate a highmem page?
The function's kernel-doc explicitly guarantees: "A memory-state transition
requires a valid linear-map address, so such allocations never come from
high memory".
In the non-encrypted fallback path, the caller's unmodified gfp flags
(potentially containing __GFP_HIGHMEM) are passed directly to alloc_pages()
or alloc_pages_node() without any masking.
If a caller passes a flag mask containing __GFP_HIGHMEM (e.g., GFP_HIGHUSER)
on a system without memory encryption, the fallback path will allocate a
highmem page. Any subsequent attempt by the caller to access the memory via
page_address() could return NULL and cause a crash, breaking the API
contract. Should the gfp flags be sanitized in this path as well?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924100529.1398790-1-aneesh.kumar@kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: infinite loop in swiotlb_init_late() when remap fails
--
commit 9e7f1b72520615870ee21508117e4c5c7e0eb684
Author: Aneesh Kumar K.V (Arm) <aneesh.kumar(a)kernel.org>
swiotlb: Align shared IO TLB pools to the shared granule size
This commit aligns and sizes the early memblock pool to the common CoCo
shared granule, leaving the slot count unchanged. It replaces the default
and dynamic pool set_memory calls with helpers to keep alignment validation
and architecture dispatch centralized. Pages are intentionally leaked if
their private state cannot be restored safely.
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index ded7016a46a71..394db93b7eb96 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
[ ... ]
> @@ -578,7 +578,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
> swiotlb_adjust_nareas(num_possible_cpus());
>
> retry:
> - order = get_order(nslabs << IO_TLB_SHIFT);
> + order = get_order(ALIGN(nslabs << IO_TLB_SHIFT, cc_shared_granule_size()));
> nslabs = SLABS_PER_PAGE << order;
[Severity: Medium]
If remap() fails later in this function, nslabs is halved and the code jumps
back to the retry label to try a smaller allocation:
kernel/dma/swiotlb.c:swiotlb_init_late() {
...
if (remap)
rc = remap(vstart, nslabs);
if (rc) {
free_pages((unsigned long)vstart, order);
nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
if (nslabs < IO_TLB_MIN_SLABS)
return rc;
retried = true;
goto retry;
}
...
}
Does the new ALIGN macro at the retry label risk inflating the halved size
back to its original value if cc_shared_granule_size() is >= 2MB?
If so, this would restore nslabs to its original failing value, overriding
the shrinking mechanism and creating an infinite loop.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924100529.1398790-1-aneesh.kumar@kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dma-pool: atomic_pool_expand() falsely returns success on failure
--
commit 7de8bc3a8ea9e2bbef83e09d72fa88999ce898b9
Author: Aneesh Kumar K.V (Arm) <aneesh.kumar(a)kernel.org>
dma-pool: Allocate CoCo atomic pools using CoCo shared memory allocator
This commit modifies atomic DMA pools to use the CoCo shared memory allocator.
It prevents allocation fallback below the required shared granule size, and
uses the cc_make_shared() helper to transition the backing allocations in a
sleepable context.
> diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c
> index 70b7f64b17ab5..f059312c15aa5 100644
> --- a/kernel/dma/pool.c
> +++ b/kernel/dma/pool.c
[ ... ]
> @@ -85,6 +85,9 @@ static bool cma_in_zone(gfp_t gfp)
> static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
> gfp_t gfp)
> {
> + struct cc_shared_layout layout;
> + unsigned long attrs = 0;
> + unsigned int min_order = 0;
> unsigned int order;
> struct page *page = NULL;
> bool leak_pages = false;
> @@ -92,6 +95,17 @@ static int atomic_pool_expand(struct dma_gen_pool *dma_pool, size_t pool_size,
> int ret = -ENOMEM;
> pgprot_t prot __maybe_unused;
>
> + if (dma_pool->cc_shared) {
> + ret = cc_shared_calc_layout(pool_size, &layout);
> + if (ret)
> + goto out;
[Severity: High]
If cc_shared_calc_layout() succeeds, it returns 0 and overwrites the initial
ret = -ENOMEM. Could this cause the function to falsely return 0 (success) on
subsequent failures?
For instance, if page allocation fails below, the function jumps to out and
returns the current value of ret:
if (!page)
goto out;
Similarly, if remapping fails later in the function:
addr = dma_common_contiguous_remap(...)
if (!addr)
goto free_page;
In both cases, ret will be 0 instead of -ENOMEM. Would it be better to reset
ret back to -ENOMEM when these failures occur, or use a separate variable
for the cc_shared_calc_layout() return value?
> + pool_size = layout.shared_size;
> + min_order = get_order(layout.alignment);
> + if (min_order > MAX_PAGE_ORDER)
> + return -E2BIG;
> + attrs = __DMA_ATTR_ALLOC_CC_SHARED;
> + }
> +
> /* Cannot allocate larger than MAX_PAGE_ORDER */
> order = min(get_order(pool_size), MAX_PAGE_ORDER);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924100529.1398790-1-aneesh.kumar@kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] irqchip/gic-v3-its: buddy allocator corruption due to discarded shared_size
--
commit d897529703a71c914b0334abcb563ffb37979469
Author: Aneesh Kumar K.V (Arm) <aneesh.kumar(a)kernel.org>
irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator
This commit updates the ITS allocator to route page allocations through
alloc_cc_shared_pages_node(). It reconstructs common allocation metadata
from the original ITS order and the architecture granule size on release.
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> index ac5507acb1a0c..4814161df02ed 100644
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
[ ... ]
> @@ -214,25 +213,13 @@ static gfp_t gfp_flags_quirk;
> static struct page *its_alloc_pages_node(int node, gfp_t gfp,
> unsigned int order)
> {
> - struct page *page;
> - int ret = 0;
> -
> - page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
> -
> - if (!page)
> - return NULL;
> + struct cc_shared_pages mem;
>
> - ret = set_memory_decrypted((unsigned long)page_address(page),
> - 1 << order);
> - /*
> - * If set_memory_decrypted() fails then we don't know what state the
> - * page is in, so we can't free it. Instead we leak it.
> - * set_memory_decrypted() will already have WARNed.
> - */
> - if (ret)
> + if (alloc_cc_shared_pages_node(node, gfp | gfp_flags_quirk,
> + PAGE_SIZE << order, &mem))
> return NULL;
>
> - return page;
> + return mem.page;
> }
[Severity: High]
Is it safe to discard mem.shared_size here? The API contract seems to require
callers to retain the true allocated size so it can be passed back when
freeing the pages.
> static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
> @@ -242,13 +229,15 @@ static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
>
> static void its_free_pages(void *addr, unsigned int order)
> {
> - /*
> - * If the memory cannot be encrypted again then we must leak the pages.
> - * set_memory_encrypted() will already have WARNed.
> - */
> - if (set_memory_encrypted((unsigned long)addr, 1 << order))
> + struct cc_shared_layout layout;
> + struct cc_shared_pages mem;
> +
> + if (WARN_ON(cc_shared_calc_layout(PAGE_SIZE << order, &layout)))
> return;
> - free_pages((unsigned long)addr, order);
> +
> + mem.page = virt_to_page(addr);
> + mem.shared_size = layout.shared_size;
> + free_cc_shared_pages(&mem);
> }
[Severity: High]
Does recalculating the size here cause a mismatch on non-CC platforms?
When memory encryption is disabled, alloc_cc_shared_pages_node() does not
round up the allocation to the granule size; it simply allocates the
requested order.
However, cc_shared_calc_layout() unconditionally rounds up to the
architectural granule size. If the granule size exceeds the requested
allocation size, free_cc_shared_pages() will call __free_pages() with a
higher order than was actually allocated. Can this corrupt the buddy
allocator by freeing unallocated pages?
> static struct gen_pool *itt_pool;
> @@ -273,7 +262,8 @@ static void *itt_alloc_pool(int node, int size)
> if (!page)
> break;
>
> - gen_pool_add(itt_pool, (unsigned long)page_address(page), PAGE_SIZE, node);
> + gen_pool_add(itt_pool, (unsigned long)page_address(page),
> + cc_shared_granule_size(), node);
> } while (!addr);
>
> return (void *)addr;
[Severity: High]
Will adding a hardcoded granule size to the generic pool advertise unallocated
out-of-bounds memory to consumers?
On non-CC platforms, the underlying allocation size is just a single page,
but this adds the full cc_shared_granule_size() bytes to the pool. Could
this lead to pool consumers accessing memory beyond what was actually
allocated?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924100529.1398790-1-aneesh.kumar@kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] irqchip/gic-v3-its: incomplete NUMA_NO_NODE resolution exposes allocations to task mempolicy
--
commit 6d762ab83972132164ae57c1422f1916decb2fe3
Author: Aneesh Kumar K.V (Arm) <aneesh.kumar(a)kernel.org>
irqchip/gic-v3-its: Resolve the default NUMA node explicitly
alloc_pages_node() resolves NUMA_NO_NODE to numa_mem_id() internally. In
preparation for switching ITS allocations to the CoCo shared memory
allocator, resolve the default node explicitly in its_alloc_pages().
The CoCo shared memory allocator interprets NUMA_NO_NODE as a request to
apply the current task's memory policy. Passing numa_mem_id() instead
preserves the existing nearest-memory-node placement across the
allocator switch. This patch does not change the current allocation
behavior.
> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c
> --- a/drivers/irqchip/irq-gic-v3-its.c
> +++ b/drivers/irqchip/irq-gic-v3-its.c
> @@ -236,7 +237,7 @@ static struct page *its_alloc_pages_node(int node, gfp_t gfp,
>
> static struct page *its_alloc_pages(gfp_t gfp, unsigned int order)
> {
> - return its_alloc_pages_node(NUMA_NO_NODE, gfp, order);
> + return its_alloc_pages_node(numa_mem_id(), gfp, order);
> }
[Severity: Medium]
Will this leave other callers of its_alloc_pages_node() exposed to the
task memory policy change?
When a device probe or ITT allocation occurs with its->numa_node ==
NUMA_NO_NODE (which is common when firmware lacks NUMA info), callers pass
NUMA_NO_NODE directly to its_alloc_pages_node():
drivers/irqchip/irq-gic-v3-its.c:its_alloc_pages_node() {
...
page = alloc_pages_node(node, gfp | gfp_flags_quirk, order);
...
}
If node is NUMA_NO_NODE, it passes it directly to the underlying allocator.
When the underlying allocator interprets NUMA_NO_NODE as a request to apply
task mempolicy, these direct callers will be subjected to the current task's
memory policy instead of bypassing it and using the local node.
If a user binds the driver via sysfs under a restrictive task mempolicy,
the allocations could land on suboptimal distant nodes or fail entirely.
Should the NUMA_NO_NODE resolution logic be moved inside its_alloc_pages_node()
to ensure all callers are protected?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260924100529.1398790-1-aneesh.kumar@kernel…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] media: use-after-free of context bank devices during deferred V4L2 cleanup
--
commit 720de65140e46882c5d0651161ef771fcb1189a2
Author: Vikash Garodia <vikash.garodia(a)oss.qualcomm.com>
media: iris: Route buffers to the matching context bank device
The VPU issues DMA through several SMMU streams, and the hardware does
not give every stream the same addressable range. The non-pixel stream
cannot address the low 600MB of IOVA space, while the pixel stream can
address the full range.
Add iris_get_cb_dev(), which maps a buffer type to the owning context
bank device. Bitstream and internal buffers (BIN, ARP, COMV, LINE,
NON_COMV, PERSIST) belong to the non-pixel device, and uncompressed
buffers (DPB, PARTIAL, SCRATCH_1, SCRATCH_2, VPSS) to the pixel device.
BUF_INPUT and BUF_OUTPUT depend on direction and are resolved from
inst->domain: for a decoder the input is non-pixel and the output pixel,
and the other way round for an encoder.
Fall back to core->dev whenever the relevant context bank device is
absent, so platforms still describing "iommus" on the parent iris node
behave exactly as before to maintain backward compatibility.
> diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
> index eb8de60c1177f..6e03d13ac1a79 100644
> --- a/drivers/media/platform/qcom/iris/iris_buffer.c
> +++ b/drivers/media/platform/qcom/iris/iris_buffer.c
> @@ -531,7 +531,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
> enum iris_buffer_type buffer_type, u32 index)
> {
> struct iris_buffers *buffers = &inst->buffers[buffer_type];
> - struct iris_core *core = inst->core;
> + struct device *dev = iris_get_cb_dev(inst, buffer_type);
[Severity: High]
Does this acquire the context bank device for DMA mapping without taking a
reference to guarantee its lifetime matches the buffer?
If iris_remove() explicitly calls platform_device_unregister() on these
devices upon sysfs driver unbind, and no standard buffers are active, their
refcount can drop to 0 and they will be freed.
> struct iris_buffer *buffer;
>
> if (!buffers->size)
[ ... ]
> @@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
>
> void iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
> {
> - struct iris_core *core = inst->core;
> + struct device *dev = iris_get_cb_dev(inst, buffer->type);
>
> list_del(&buffer->list);
> - dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
> + dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,
[Severity: High]
Can this result in a use-after-free of the context bank device during
deferred V4L2 cleanup?
If standard buffers are active, videobuf2 holds a reference. However, during
deferred cleanup in iris_close(), v4l2_m2m_ctx_release() frees standard
buffers before iris_destroy_all_internal_buffers() runs. This drops the
final refcount, freeing the devices.
Will this fetch and dereference the freed device pointer, passing it to
dma_free_attrs()? Additionally, does the devm-allocated core also get freed
on unbind, making inst->core a dangling pointer here?
[ ... ]
> diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
> index fcbc60016beec..064cf0a80748d 100644
> --- a/drivers/media/platform/qcom/iris/iris_vidc.c
> +++ b/drivers/media/platform/qcom/iris/iris_vidc.c
> @@ -108,7 +108,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
> src_vq->drv_priv = inst;
> src_vq->buf_struct_size = sizeof(struct iris_buffer);
> src_vq->min_reqbufs_allocation = MIN_BUFFERS;
> - src_vq->dev = inst->core->dev;
> + src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);
[Severity: High]
Does this assign a manually lifetime-managed, short-lived device to the
long-lived vb2_queue context?
> src_vq->lock = &inst->ctx_q_lock;
> ret = vb2_queue_init(src_vq);
> if (ret)
> @@ -122,7 +122,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
> dst_vq->drv_priv = inst;
> dst_vq->buf_struct_size = sizeof(struct iris_buffer);
> dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
> - dst_vq->dev = inst->core->dev;
> + dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);
[Severity: High]
Does this also assign a manually lifetime-managed, short-lived device to the
long-lived vb2_queue context?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260926-vpu_iommu_iova_handling-v5-0-0322ca…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Sleeping in atomic context
- [High] Deferred teardown TOCTOU race via flink name re-opening causing IOVA Use-After-Free
--
--- Patch [2]: [PATCH 2/2] drm/msm: don't tear down shared VM mappings on handle close ---
commit c4a550033efcf938dc9587175385266d18df3979
Author: Dmitry Baryshkov <dmitry.baryshkov(a)oss.qualcomm.com>
drm/msm: don't tear down shared VM mappings on handle close
This patch defers the teardown of shared GPU VM mappings until the vma_ref
count drops to zero. This aims to prevent pulling the buffer out from under
other files that still have it open when sharing a global VM address space
on targets without per-process pgtables.
Fixes: 111fdd2198e6 ("drm/msm: drm_gpuvm conversion")
> diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
> index 8b979d84bb958..f17ecd97b72a3 100644
> --- a/drivers/gpu/drm/msm/msm_gem.c
> +++ b/drivers/gpu/drm/msm/msm_gem.c
[ ... ]
> @@ -109,6 +114,12 @@ void msm_gem_vma_put(struct drm_gem_object *obj)
> if (atomic_dec_return(&to_msm_bo(obj)->vma_ref))
> return;
>
> + if (priv->gpu && priv->gpu->vm_shared) {
> + dma_resv_wait_timeout(obj->resv, DMA_RESV_USAGE_BOOKKEEP, false,
> + MAX_SCHEDULE_TIMEOUT);
> + put_iova_spaces(obj, priv->gpu->vm, true, "vma_put");
> + }
> +
[Severity: High]
This is a pre-existing issue, but can this lockless vma_ref check lead to an
IOVA use-after-free if a GEM handle is concurrently closed and re-opened via
flink?
If Thread A closes the last handle, atomic_dec_return() drops vma_ref to 0
and it proceeds to unmap the buffer. However, the flink name remains valid
until drm_gem_object_handle_put_unlocked() runs. If Thread B calls
DRM_IOCTL_GEM_OPEN concurrently, msm_gem_open() can increment vma_ref back to
1 and submit a job using the IOVA. Thread A then acquires locks in
put_iova_spaces() and unconditionally unmaps the buffer via
put_iova_spaces_locked() without re-verifying vma_ref:
drivers/gpu/drm/msm/msm_gem.c:put_iova_spaces_locked() {
...
drm_gpuvm_bo_for_each_va_safe (vma, vmatmp, vm_bo) {
msm_gem_vma_unmap(vma, reason);
if (close)
msm_gem_vma_close(vma);
}
}
Will this destroy Thread B's mapping while its job is running, freeing the
IOVA for immediate reuse?
[Severity: High]
This isn't a bug introduced by this patch, but does adding these blocking
calls cause a scheduling while atomic panic when tearing down a writeback
connector?
The drm core function drm_writeback_connector_cleanup() holds a spinlock with
IRQs disabled when tearing down pending jobs:
drivers/gpu/drm/drm_writeback.c:drm_writeback_connector_cleanup() {
spin_lock_irqsave(&wb_connector->job_lock, flags);
list_for_each_entry_safe(pos, n, &wb_connector->job_queue, list_entry) {
list_del(&pos->list_entry);
drm_writeback_cleanup_job(pos);
}
}
This calls into msm_gem_vma_put() through the teardown path
(dpu_wb_conn_cleanup_job -> dpu_encoder_cleanup_wb_job ->
dpu_encoder_phys_wb_cleanup_wb_job -> msm_framebuffer_cleanup ->
msm_gem_vma_put).
Since dma_resv_wait_timeout() can wait indefinitely and put_iova_spaces()
acquires ww_mutexes via drm_exec, could this result in sleeping while holding
a spinlock with IRQs disabled?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260822-msm-fix-export-v1-0-917b3cbedd43@os…