From: Francesco Valla <francesco@valla.it>
To: Bjorn Andersson <andersson@kernel.org>,
Mathieu Poirier <mathieu.poirier@linaro.org>,
Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
Joakim Zhang <joakim.zhang@cixtech.com>
Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
Francesco Valla <francesco@valla.it>
Subject: [PATCH 1/4] remoteproc: virtio: Decouple vdev from the parent pdev
Date: Sun, 08 Nov 2026 23:32:37 +0100 [thread overview]
Message-ID: <20261108-remoteproc_pdev_decouple-v1-1-3dc2fad4951d@valla.it> (raw)
In-Reply-To: <20261108-remoteproc_pdev_decouple-v1-0-3dc2fad4951d@valla.it>
The rproc-virtio platform device can have a lifetime different from the
virtio_device it registers. During cleanup (e.g.: when a remoteproc is
stopped) the platform device is de-registered by the remoteproc core,
but the related virtio_device might be released later; if this happens,
rproc_virtio_dev_release() will try to de-reference a NULL pointer as
part of vdev_to_rvdev(). This can easily be reproduced with
CONFIG_DEBUG_KOBJECT_RELEASE.
Remove the access to the platform device structure from the cleanup path
and interact instead with its backing device, whose refcount was
explicitly increased during rproc_add_virtio_dev() and will be
decremented as part of rproc_virtio_dev_release(). The same is done for
the pdev de-reference inside vdev_to_rvdev(), even if no more used
during cleanup, to maintain the same access pattern.
While at it, fix the comments on the specific matter.
Fixes: 1d7b61c06dc3 ("remoteproc: virtio: Create platform device for the remoteproc_virtio")
Signed-off-by: Francesco Valla <francesco@valla.it>
---
drivers/remoteproc/remoteproc_virtio.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 12f55a81cfa0..7979b2570998 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -49,11 +49,7 @@ static int copy_dma_range_map(struct device *to, struct device *from)
static struct rproc_vdev *vdev_to_rvdev(struct virtio_device *vdev)
{
- struct platform_device *pdev;
-
- pdev = container_of(vdev->dev.parent, struct platform_device, dev);
-
- return platform_get_drvdata(pdev);
+ return dev_get_drvdata(vdev->dev.parent);
}
static struct rproc *vdev_to_rproc(struct virtio_device *vdev)
@@ -348,7 +344,7 @@ static const struct virtio_config_ops rproc_virtio_config_ops = {
/*
* This function is called whenever vdev is released, and is responsible
- * to decrement the remote processor's refcount which was taken when vdev was
+ * to decrement the platform device's refcount which was taken when vdev was
* added.
*
* Never call this function directly; it will be called by the driver
@@ -357,14 +353,13 @@ static const struct virtio_config_ops rproc_virtio_config_ops = {
static void rproc_virtio_dev_release(struct device *dev)
{
struct virtio_device *vdev = dev_to_virtio(dev);
- struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
- kfree(vdev);
+ of_reserved_mem_device_release(dev->parent);
+ dma_release_coherent_memory(dev->parent);
- of_reserved_mem_device_release(&rvdev->pdev->dev);
- dma_release_coherent_memory(&rvdev->pdev->dev);
+ put_device(dev->parent);
- put_device(&rvdev->pdev->dev);
+ kfree(vdev);
}
/**
@@ -372,8 +367,7 @@ static void rproc_virtio_dev_release(struct device *dev)
* @rvdev: the remote vdev
* @id: the device type identification (used to match it with a driver).
*
- * This function registers a virtio device. This vdev's partent is
- * the rproc device.
+ * This function registers a virtio device with the platform device as parent.
*
* Return: 0 on success or an appropriate error value otherwise
*/
@@ -450,7 +444,7 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
vdev->dev.parent = dev;
vdev->dev.release = rproc_virtio_dev_release;
- /* Reference the vdev and vring allocations */
+ /* Reference the parent device, which will be used during teardown. */
get_device(dev);
ret = register_virtio_device(vdev);
--
2.56.0
next prev parent reply other threads:[~2026-11-08 22:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 22:32 [PATCH 0/4] remoteproc: virtio: Fixes and cleanups in the vdev<->pdev relationship Francesco Valla
2026-11-08 22:32 ` Francesco Valla [this message]
2026-11-08 22:32 ` [PATCH 2/4] remoteproc: virtio: Rework memory release Francesco Valla
2026-11-08 22:32 ` [PATCH 3/4] remoteproc: virtio: Drop rvdevs list and associated functions Francesco Valla
2026-11-08 22:32 ` [PATCH 4/4] remoteproc: virtio: Stop de-referencing pdev from its children Francesco Valla
2026-11-09 14:19 ` [PATCH 0/4] remoteproc: virtio: Fixes and cleanups in the vdev<->pdev relationship Mathieu Poirier
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=20261108-remoteproc_pdev_decouple-v1-1-3dc2fad4951d@valla.it \
--to=francesco@valla.it \
--cc=andersson@kernel.org \
--cc=arnaud.pouliquen@foss.st.com \
--cc=joakim.zhang@cixtech.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=mathieu.poirier@linaro.org \
/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®