From: Francesco Valla <francesco@valla.it>
To: Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Frank Li <Frank.Li@nxp.com>,
Peng Fan <peng.fan@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, virtualization@lists.linux.dev,
imx@lists.linux.dev, iommu@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
Francesco Valla <francesco@valla.it>
Subject: [PATCH RFC 03/12] remoteproc: virtio: support dynamic number of vrings
Date: Wed, 16 Sep 2026 23:10:48 +0200 [thread overview]
Message-ID: <20260916-remoteproc_virtio_map-v1-3-dac8c5eb4aa9@valla.it> (raw)
In-Reply-To: <20260916-remoteproc_virtio_map-v1-0-dac8c5eb4aa9@valla.it>
The number of vrings for each vdev has been fixed to 2 since the
introduction of multi-vdev support [1]; this is completely fine for the
rpmsg usecase, but can conflict with other virtio devices (CAN for
example requires 3 virtqueues, entropy only 1, network a variable number
and so on).
Remove the static vring allocation, transforming it to a flex array that
is allocated at vdev probe time; for the existent usecases (i.e.: mainly
rpmsg) this leads to no functional change, except the additional memory
used for the counter associated to the new array.
The maximum number of virtqueues is limited to 256 due to the uint8_t
value used inside the resource table to indicate the number of vring to
allocate; for this reason, no additional plausibility check is performed
on the number of vrings indicated by the resource table.
As a side effect, this also fixes the single virtqueue usecase, which
was apparently supported also before but for which the remove action
caused an error (because the remove action was trying to unmap also the
second vring, which was in fact not mapped).
[1] https://lore.kernel.org/all/1330589497-4139-5-git-send-email-ohad@wizery.com/
Signed-off-by: Francesco Valla <francesco@valla.it>
---
drivers/remoteproc/remoteproc_core.c | 7 -------
drivers/remoteproc/remoteproc_virtio.c | 21 +++++++++++++--------
include/linux/remoteproc.h | 10 ++++------
3 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 1ed406714849..b7d9957534bf 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -473,7 +473,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
{
struct fw_rsc_vdev *rsc = ptr;
struct device *dev = &rproc->dev;
- struct rproc_vdev *rvdev;
size_t rsc_size;
struct rproc_vdev_data rvdev_data;
struct platform_device *pdev;
@@ -494,12 +493,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
dev_dbg(dev, "vdev rsc: id %d, dfeatures 0x%x, cfg len %d, %d vrings\n",
rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings);
- /* we currently support only two vrings per rvdev */
- if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) {
- dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings);
- return -EINVAL;
- }
-
rvdev_data.id = rsc->id;
rvdev_data.index = rproc->nb_vdev++;
rvdev_data.rsc_offset = offset;
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 4dacd93bf238..74e0da970f1d 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -115,8 +115,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev,
void *addr;
int num, size;
- /* we're temporarily limited to two virtqueues per rvdev */
- if (id >= ARRAY_SIZE(rvdev->vring))
+ if (id >= rvdev->num_vrings)
return ERR_PTR(-EINVAL);
if (!name)
@@ -500,17 +499,20 @@ static int rproc_virtio_probe(struct platform_device *pdev)
if (!rvdev_data)
return -EINVAL;
- rvdev = devm_kzalloc(dev, sizeof(*rvdev), GFP_KERNEL);
+ rsc = rvdev_data->rsc;
+
+ rvdev = kzalloc_flex(*rvdev, vring, rsc->num_of_vrings);
if (!rvdev)
return -ENOMEM;
rvdev->id = rvdev_data->id;
rvdev->rproc = rproc;
rvdev->index = rvdev_data->index;
+ rvdev->num_vrings = rsc->num_of_vrings;
ret = copy_dma_range_map(dev, rproc->dev.parent);
if (ret)
- return ret;
+ goto free_rvdev;
/* Make device dma capable by inheriting from parent's capabilities */
set_dma_ops(dev, get_dma_ops(rproc->dev.parent));
@@ -524,13 +526,11 @@ static int rproc_virtio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, rvdev);
rvdev->pdev = pdev;
- rsc = rvdev_data->rsc;
-
/* parse the vrings */
for (i = 0; i < rsc->num_of_vrings; i++) {
ret = rproc_parse_vring(rvdev, rsc, i);
if (ret)
- return ret;
+ goto free_rvdev;
}
/* remember the resource offset*/
@@ -566,6 +566,9 @@ static int rproc_virtio_probe(struct platform_device *pdev)
for (i--; i >= 0; i--)
rproc_free_vring(&rvdev->vring[i]);
+free_rvdev:
+ kfree(rvdev);
+
return ret;
}
@@ -576,7 +579,7 @@ static void rproc_virtio_remove(struct platform_device *pdev)
struct rproc_vring *rvring;
int id;
- for (id = 0; id < ARRAY_SIZE(rvdev->vring); id++) {
+ for (id = 0; id < rvdev->num_vrings; id++) {
rvring = &rvdev->vring[id];
rproc_free_vring(rvring);
}
@@ -585,6 +588,8 @@ static void rproc_virtio_remove(struct platform_device *pdev)
rproc_remove_rvdev(rvdev);
put_device(&rproc->dev);
+
+ kfree(rvdev);
}
/* Platform driver */
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index a44368737b39..c3ba51fe9e54 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -319,10 +319,6 @@ struct rproc_subdev {
void (*unprepare)(struct rproc_subdev *subdev);
};
-/* we currently support only two vrings per rvdev */
-
-#define RVDEV_NUM_VRINGS 2
-
/**
* struct rproc_vring - remoteproc vring state
* @va: virtual address
@@ -350,9 +346,10 @@ struct rproc_vring {
* @id: virtio device id (as in virtio_ids.h)
* @node: list node
* @rproc: the rproc handle
- * @vring: the vrings for this vdev
* @rsc_offset: offset of the vdev's resource entry
* @index: vdev position versus other vdev declared in resource table
+ * @num_vrings: the number of vrings for this vdev
+ * @vring: the vrings for this vdev
*/
struct rproc_vdev {
struct rproc_subdev subdev;
@@ -361,9 +358,10 @@ struct rproc_vdev {
unsigned int id;
struct list_head node;
struct rproc *rproc;
- struct rproc_vring vring[RVDEV_NUM_VRINGS];
u32 rsc_offset;
u32 index;
+ unsigned int num_vrings;
+ struct rproc_vring vring[] __counted_by(num_vrings);
};
struct rproc *rproc_get_by_phandle(phandle phandle);
--
2.55.0
next prev parent reply other threads:[~2026-09-16 21:11 UTC|newest]
Thread overview: 44+ 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:10 ` [PATCH RFC 02/12] remoteproc: virtio: replace commas with semicolons Francesco Valla
2026-09-16 21:10 ` Francesco Valla [this message]
2026-09-16 21:10 ` [PATCH RFC 04/12] dma-coherent: add base and size APIs Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 05/12] remoteproc: always report VIRTIO_F_VERSION_1 feature Francesco Valla
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-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:10 ` [PATCH RFC 08/12] dt-bindings: remoteproc: add remoteproc-virtio Francesco Valla
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-09-16 21:10 ` [PATCH RFC 09/12] remoteproc: search for a fwnode during vdev registration Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 10/12] remoteproc: imx_rproc: always use non-blocking mailboxes Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 11/12] dt-bindings: remoteproc: imx-rproc: support virtio Francesco Valla
2026-09-16 21:10 ` [PATCH RFC 12/12] PoC: arm64: dts: imx93-11x11-frdm: add multiple vdevs Francesco Valla
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=20260916-remoteproc_virtio_map-v1-3-dac8c5eb4aa9@valla.it \
--to=francesco@valla.it \
--cc=Frank.Li@nxp.com \
--cc=andersson@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gustavoars@kernel.org \
--cc=imx@lists.linux.dev \
--cc=iommu@lists.linux.dev \
--cc=kees@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mathieu.poirier@linaro.org \
--cc=peng.fan@nxp.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=s.hauer@pengutronix.de \
--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
all inboxes | Powered by JetHome®