mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 3/4] remoteproc: virtio: Drop rvdevs list and associated functions
Date: Sun, 08 Nov 2026 23:32:39 +0100	[thread overview]
Message-ID: <20261108-remoteproc_pdev_decouple-v1-3-3dc2fad4951d@valla.it> (raw)
In-Reply-To: <20261108-remoteproc_pdev_decouple-v1-0-3dc2fad4951d@valla.it>

The rvdevs linked list is kept at rproc side to track the rproc_vdev
devices registered at runtime and de-register them during cleanup, but
the same information can be obtained from the driver core using
parent-child relationships coupled with driver name.

Drop the list and all associated functions and de-register the virtio
children of a remoteproc using device_for_each_child(), with the
following benefits:

 - increased separation between the core and virtio parts of remoteproc;
 - reduction in code and occupied memory;
 - the platform devices whose probe fail are now de-registered correctly
   during remoteproc cleanup.

A dedicated macro is used to register rproc-virtio platform devices to
avoid duplication (in code, not in memory) of the same string.

Signed-off-by: Francesco Valla <francesco@valla.it>
---
 drivers/remoteproc/remoteproc_core.c     | 34 ++++++++++++++++----------------
 drivers/remoteproc/remoteproc_internal.h |  4 ++--
 drivers/remoteproc/remoteproc_virtio.c   |  5 +----
 include/linux/remoteproc.h               |  6 +-----
 4 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index d5fa9d23bd5c..296b955f415f 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -431,17 +431,6 @@ void rproc_free_vring(struct rproc_vring *rvring)
 	}
 }
 
-void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev)
-{
-	if (rvdev && rproc)
-		list_add_tail(&rvdev->node, &rproc->rvdevs);
-}
-
-void rproc_remove_rvdev(struct rproc_vdev *rvdev)
-{
-	if (rvdev)
-		list_del(&rvdev->node);
-}
 /**
  * rproc_handle_vdev() - handle a vdev fw resource
  * @rproc: the remote processor
@@ -513,7 +502,8 @@ 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,
+	pdev = platform_device_register_data(dev, RPROC_VIRTIO_DRV_NAME,
+					     PLATFORM_DEVID_AUTO, &rvdev_data,
 					     sizeof(rvdev_data));
 	if (IS_ERR(pdev)) {
 		dev_err(dev, "failed to create rproc-virtio device\n");
@@ -1212,6 +1202,19 @@ static int rproc_alloc_registered_carveouts(struct rproc *rproc)
 	return 0;
 }
 
+static int rproc_unregister_vdev_pdev(struct device *dev, void *data)
+{
+	struct platform_device *pdev;
+
+	if (!dev_is_platform(dev))
+		return 0;
+
+	pdev = to_platform_device(dev);
+	if (!strcmp(pdev->name, RPROC_VIRTIO_DRV_NAME))
+		platform_device_unregister(pdev);
+
+	return 0;
+}
 
 /**
  * rproc_resource_cleanup() - clean up and free all acquired resources
@@ -1224,7 +1227,6 @@ void rproc_resource_cleanup(struct rproc *rproc)
 {
 	struct rproc_mem_entry *entry, *tmp;
 	struct rproc_debug_trace *trace, *ttmp;
-	struct rproc_vdev *rvdev, *rvtmp;
 	struct device *dev = &rproc->dev;
 
 	/* clean up debugfs trace entries */
@@ -1258,9 +1260,8 @@ void rproc_resource_cleanup(struct rproc *rproc)
 		kfree(entry);
 	}
 
-	/* clean up remote vdev entries */
-	list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node)
-		platform_device_unregister(rvdev->pdev);
+	/* unregister platform devices */
+	device_for_each_child(&rproc->dev, NULL, rproc_unregister_vdev_pdev);
 
 	rproc_coredump_cleanup(rproc);
 }
@@ -2521,7 +2522,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	INIT_LIST_HEAD(&rproc->carveouts);
 	INIT_LIST_HEAD(&rproc->mappings);
 	INIT_LIST_HEAD(&rproc->traces);
-	INIT_LIST_HEAD(&rproc->rvdevs);
 	INIT_LIST_HEAD(&rproc->subdevs);
 	INIT_LIST_HEAD(&rproc->dump_segments);
 
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
index 3a742ef6ef60..d587a3301811 100644
--- a/drivers/remoteproc/remoteproc_internal.h
+++ b/drivers/remoteproc/remoteproc_internal.h
@@ -18,6 +18,8 @@
 #include <linux/io.h>
 #endif
 
+#define RPROC_VIRTIO_DRV_NAME	"rproc-virtio"
+
 struct rproc;
 
 struct rproc_debug_trace {
@@ -122,8 +124,6 @@ struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
 						       const struct firmware *fw);
 struct rproc_mem_entry *
 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...);
-void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev);
-void rproc_remove_rvdev(struct rproc_vdev *rvdev);
 
 #ifdef CONFIG_HAS_IOMEM
 static inline int rproc_mem_entry_ioremap_wc(struct rproc *rproc,
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index bd4edc89e696..ac0103a5c261 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -548,8 +548,6 @@ static int rproc_virtio_probe(struct platform_device *pdev)
 			goto unwind_vring_allocations;
 	}
 
-	rproc_add_rvdev(rproc, rvdev);
-
 	rvdev->subdev.start = rproc_vdev_do_start;
 	rvdev->subdev.stop = rproc_vdev_do_stop;
 
@@ -587,7 +585,6 @@ static void rproc_virtio_remove(struct platform_device *pdev)
 	}
 
 	rproc_remove_subdev(rproc, &rvdev->subdev);
-	rproc_remove_rvdev(rvdev);
 
 	put_device(&rproc->dev);
 }
@@ -597,7 +594,7 @@ static struct platform_driver rproc_virtio_driver = {
 	.probe		= rproc_virtio_probe,
 	.remove		= rproc_virtio_remove,
 	.driver		= {
-		.name	= "rproc-virtio",
+		.name	= RPROC_VIRTIO_DRV_NAME,
 	},
 };
 builtin_platform_driver(rproc_virtio_driver);
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 00019b1895e6..77ea0e1067e0 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -228,8 +228,7 @@ enum rproc_features {
  * @carveouts: list of physically contiguous memory allocations
  * @mappings: list of iommu mappings we initiated, needed on shutdown
  * @bootaddr: address of first instruction to boot rproc with (optional)
- * @rvdevs: list of remote virtio devices
- * @vq_srcu: SRCU domain for the virtqueue callbacks of @rvdevs
+ * @vq_srcu: SRCU domain for the virtqueue callbacks of the virtio devices
  * @subdevs: list of subdevices, to following the running state
  * @notifyids: idr for dynamically assigning rproc-wide unique notify ids
  * @index: index of this rproc device
@@ -275,7 +274,6 @@ struct rproc {
 	struct list_head carveouts;
 	struct list_head mappings;
 	u64 bootaddr;
-	struct list_head rvdevs;
 	struct srcu_struct vq_srcu;
 	struct list_head subdevs;
 	struct idr notifyids;
@@ -351,7 +349,6 @@ struct rproc_vring {
  * @subdev: handle for registering the vdev as a rproc subdevice
  * @pdev: remoteproc virtio platform device
  * @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
@@ -362,7 +359,6 @@ struct rproc_vdev {
 	struct platform_device *pdev;
 
 	unsigned int id;
-	struct list_head node;
 	struct rproc *rproc;
 	struct rproc_vring vring[RVDEV_NUM_VRINGS];
 	u32 rsc_offset;

-- 
2.56.0


  parent reply	other threads:[~2026-11-08 22:33 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 ` [PATCH 1/4] remoteproc: virtio: Decouple vdev from the parent pdev Francesco Valla
2026-11-08 22:32 ` [PATCH 2/4] remoteproc: virtio: Rework memory release Francesco Valla
2026-11-08 22:32 ` Francesco Valla [this message]
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-3-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®