Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Francesco Valla" <francesco@valla.it>
Cc: robh@kernel.org, devicetree@vger.kernel.org, imx@lists.linux.dev,
	"Eugenio Perez" <eperezma@redhat.com>,
	conor+dt@kernel.org, Frank.Li@kernel.org,
	virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [PATCH RFC 11/12] dt-bindings: remoteproc: imx-rproc: support virtio
Date: Wed, 16 Sep 2026 22:04:11 +0000	[thread overview]
Message-ID: <20260916220411.B33731F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260916-remoteproc_virtio_map-v1-11-dac8c5eb4aa9@valla.it>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [High] remoteproc: out-of-bounds access in rproc_virtio_bounce_slot() fallback
- [High] remoteproc: map_records state corruption for sub-page buffers
- [Medium] remoteproc: fwnode reference leak in rproc_handle_vdev()
- [Low] dt-bindings: spi-virtio.yaml has incorrect $id path
- [Low] dt-bindings: remoteproc-virtio uses maxItems on object
--

commit f36ec8f81fd31468ec48cdde83e92aca3916fcb9
Author: Francesco Valla <francesco@valla.it>

dt-bindings: remoteproc: imx-rproc: support virtio

Add support for virtio devices description.

> diff --git a/Documentation/devicetree/bindings/remoteproc/remoteproc-virtio.yaml b/Documentation/devicetree/bindings/remoteproc/remoteproc-virtio.yaml
> new file mode 100644
> index 0000000000000..c4a0d84b14600
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/remoteproc/remoteproc-virtio.yaml

[ ... ]

> +    patternProperties:
> +      "^vdev@[0-9a-f]+$":
> +        type: object
> +
> +        properties:
> +          reg:
> +            description: Virtio device index inside the resource table.
> +            maxItems: 1
> +
> +        additionalProperties:
> +          type: object
> +          $ref: /schemas/virtio/virtio-device.yaml
> +          maxItems: 1

[Severity: Low]
Does this maxItems: 1 have any effect?

maxItems is a JSON schema keyword that strictly applies only to arrays. Since
the child node is declared as type: object, maxItems: 1 is completely ignored
by the schema validator. Should maxProperties be used on the parent node instead
if the goal was to limit the node to a single child?

> diff --git a/Documentation/devicetree/bindings/spi/spi-virtio.yaml b/Documentation/devicetree/bindings/spi/spi-virtio.yaml
> new file mode 100644
> index 0000000000000..1a0a0763bd2fa
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/spi/spi-virtio.yaml
> @@ -0,0 +1,52 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/i2c/i2c-virtio.yaml#

[Severity: Low]
Is the $id path correct?

DT schema subsystem guidelines strictly require the $id property path to exactly
match the file's location relative to Documentation/devicetree/bindings/. This
newly introduced file has its $id incorrectly declared as
http://devicetree.org/schemas/i2c/i2c-virtio.yaml# due to a copy-paste error.
This mismatch breaks the schema cross-referencing system during
dt_binding_check.

> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index 1ed4067148491..e3ecc61cc1def 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c

[ ... ]

> @@ -511,8 +528,16 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
>  	 * as device id, then we get duplication in sysfs, so need to use
>  	 * PLATFORM_DEVID_AUTO to auto select device id.
>  	 */
> -	pdev = platform_device_register_data(dev, "rproc-virtio", PLATFORM_DEVID_AUTO, &rvdev_data,
> -					     sizeof(rvdev_data));
> +	memset(&pdev_info, 0, sizeof(pdev_info));
> +	pdev_info.parent = dev;
> +	pdev_info.fwnode = rproc_get_vdev_fwnode(dev->parent, rvdev_data.index);
> +	pdev_info.of_node_reused = true;
> +	pdev_info.name = "rproc-virtio";
> +	pdev_info.id = PLATFORM_DEVID_AUTO;
> +	pdev_info.data = &rvdev_data;
> +	pdev_info.size_data = sizeof(rvdev_data);
> +
> +	pdev = platform_device_register_full(&pdev_info);

[Severity: Medium]
Does this code leak the fwnode reference in rproc_handle_vdev()?

rproc_get_vdev_fwnode() iterates over child nodes and returns a fwnode handle
with an incremented reference count via fwnode_get_next_child_node(). This
returned fwnode is assigned to pdev_info.fwnode.

platform_device_register_full() internally passes this to device_set_node(),
which explicitly takes its own reference to the fwnode by calling
fwnode_handle_get(). After platform_device_register_full() returns,
rproc_handle_vdev() exits without ever dropping its original reference acquired
by rproc_get_vdev_fwnode(), causing a permanent fwnode resource reference leak.

> diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
> index d5e9ff045a28a..d21b3b8044df9 100644
> --- a/drivers/remoteproc/remoteproc_virtio.c
> +++ b/drivers/remoteproc/remoteproc_virtio.c

[ ... ]

> +static inline unsigned int rproc_virtio_bounce_slot(struct device *dma_dev,
> +						    dma_addr_t dma_handle)
> +{
> +	const dma_addr_t dma_base = dma_dev_coherent_base(dma_dev);
> +
> +	return (dma_handle - dma_base) >> PAGE_SHIFT;
> +}
> +
> +static dma_addr_t rproc_virtio_map_page(union virtio_map map, struct page *page,
> +					unsigned long offset, size_t size,
> +					enum dma_data_direction dir,
> +					unsigned long attrs)
> +{

[ ... ]

> +	if (paddr >= dma_base && paddr < (dma_base + dma_size)) {
> +		// The allocation details will be recorded also in this case,
> +		// indicating that no bounce buffer was allocated.
> +		map_handle = (dma_addr_t)paddr;
> +		bounce = NULL;
> +	} else {
> +		// Allocate bounce buffer from device coherent memory
> +		bounce = dma_alloc_coherent(dev, size, &map_handle, GFP_KERNEL | __GFP_ZERO);
> +		if (!bounce)
> +			return DMA_MAPPING_ERROR;
> +
> +		// Copy data to bounce buffer
> +		memcpy(bounce, vaddr, size);
> +	}
> +
> +	// Save bounce details
> +	record = &rvdev->map_records[rproc_virtio_bounce_slot(dev, map_handle)];
> +
> +	record->original = vaddr;
> +	record->size = size;
> +	record->bounce = bounce;

[Severity: High]
Can this write out-of-bounds in rproc_virtio_map_page() if the device lacks a
dedicated coherent memory pool, or if the pool is exhausted?

When a bounce buffer is needed, it calls dma_alloc_coherent(). If the device
pool is exhausted or non-existent, it transparently falls back to generic system
memory. The returned map_handle will not be based at dma_base.

rproc_virtio_bounce_slot() will then compute a completely uncontrolled slot
index using (map_handle - dma_base) >> PAGE_SHIFT. The function then writes to
rvdev->map_records[slot], causing an immediate out-of-bounds array write and
corrupting adjacent kernel memory.

[Severity: High]
Can this corrupt the map_records state for sub-page buffers?

If virtio drivers map multiple sub-page buffers (e.g., headers or small
requests) that happen to fall within the same physical page in the coherent
pool, they will compute the exact same slot index because the shift operation
in rproc_virtio_bounce_slot() discards the offset.

The second mapping will overwrite the map_records entry of the first mapping
(record->original and record->size). During rproc_virtio_unmap_page(), this
leads to a WARN_ON(size != record->size) trigger and incorrectly clears the
shared state, corrupting subsequent unmaps for that page.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916-remoteproc_virtio_map-v1-0-dac8c5eb4aa9@valla.it?part=11

  reply	other threads:[~2026-09-16 22:04 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 21:10 [PATCH RFC 00/12] remoteproc: add support for any virtio device Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 01/12] remoteproc: virtio: cleanup rproc_add_virtio_dev error path Francesco Valla
2026-09-16 21:56   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 02/12] remoteproc: virtio: replace commas with semicolons Francesco Valla
2026-09-16 21:58   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 03/12] remoteproc: virtio: support dynamic number of vrings Francesco Valla
2026-09-16 22:00   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 04/12] dma-coherent: add base and size APIs Francesco Valla
2026-09-16 21:55   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 05/12] remoteproc: always report VIRTIO_F_VERSION_1 feature Francesco Valla
2026-09-16 22:00   ` sashiko-bot
2026-09-21 15:47   ` Mathieu Poirier
2026-09-22  6:32     ` Francesco Valla
2026-09-22 15:10       ` Mathieu Poirier
2026-09-16 21:10 ` [PATCH RFC 06/12] remoteproc: virtio: add bounce buffering for data buffers Francesco Valla
2026-09-16 22:03   ` sashiko-bot
2026-09-22 15:58   ` Mathieu Poirier
2026-09-22 19:39     ` Francesco Valla
2026-09-23 14:44       ` Mathieu Poirier
2026-09-23 16:05         ` Francesco Valla
2026-09-25 15:07           ` Mathieu Poirier
2026-09-25 16:48             ` Robin Murphy
2026-09-25 19:05               ` Francesco Valla
2026-09-27 22:12                 ` Francesco Valla
2026-09-25 17:03   ` Robin Murphy
2026-09-16 21:10 ` [PATCH RFC 07/12] dt-bindings: spi: add bindings for spi-virtio Francesco Valla
2026-09-16 21:52   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 08/12] dt-bindings: remoteproc: add remoteproc-virtio Francesco Valla
2026-09-16 21:56   ` sashiko-bot
2026-09-22 15:40   ` Mathieu Poirier
2026-09-22 19:44     ` Francesco Valla
2026-09-23 14:56       ` Mathieu Poirier
2026-10-06 18:39       ` Rob Herring
2026-10-07  0:51         ` Mathieu Poirier
2026-10-07 13:42           ` Rob Herring
2026-10-07 16:34             ` Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 09/12] remoteproc: search for a fwnode during vdev registration Francesco Valla
2026-09-16 21:58   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 10/12] remoteproc: imx_rproc: always use non-blocking mailboxes Francesco Valla
2026-09-16 22:05   ` sashiko-bot
2026-09-16 21:10 ` [PATCH RFC 11/12] dt-bindings: remoteproc: imx-rproc: support virtio Francesco Valla
2026-09-16 22:04   ` sashiko-bot [this message]
2026-09-16 21:10 ` [PATCH RFC 12/12] PoC: arm64: dts: imx93-11x11-frdm: add multiple vdevs Francesco Valla
2026-09-16 22:07   ` sashiko-bot
2026-09-22 15:43   ` Mathieu Poirier
2026-09-22 20:19     ` Francesco Valla
2026-09-23 15:48       ` Mathieu Poirier
2026-09-23 18:42         ` Francesco Valla
2026-09-24 15:49           ` Mathieu Poirier
2026-09-25 19:13             ` Francesco Valla
2026-09-25  8:39   ` Alexander Stein
2026-09-25 19:26     ` Francesco Valla
2026-09-18 16:53 ` [PATCH RFC 00/12] remoteproc: add support for any virtio device Mathieu Poirier
2026-09-19  7:33   ` Francesco Valla
2026-09-21  3:31     ` Mathieu Poirier
2026-09-22  6:28       ` Francesco Valla
2026-09-22 13:53         ` Mathieu Poirier
2026-09-23 15:13 ` Robin Murphy

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=20260916220411.B33731F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=eperezma@redhat.com \
    --cc=francesco@valla.it \
    --cc=imx@lists.linux.dev \
    --cc=mst@redhat.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@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