This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 84de5d87cb431a686e172d5edada23491368e0b9
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Sep 29 21:58:27 2026 +0800

    rptun: give each side a pool carveout of its own
    
    Only the master could publish a pool, so a slave driving a device of its
    own had nowhere to allocate from and needed a placed carveout for every
    one of them instead.
    
    Name the pool after the side that owns it: the master takes "vdevbuffer"
    and the slave "hdevbuffer".  Both sides read the same table, so one name
    cannot serve both -- two heaps over one region would hand out the same
    memory twice.
    
    The pool no longer depends on which device is being created, so build it
    once before the loop rather than on every pass through
    rptun_create_carveout().
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/rptun.c | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index 2a80b27272a..8b577e891d7 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -642,10 +642,6 @@ rptun_create_heap(FAR struct rptun_priv_s *priv, FAR char 
*name,
  *   manage.  Where the table leaves every device on the vhost side, none of
  *   this runs and the memory stays the peer's.
  *
- *   The pool is published once, by the master: both sides read the same
- *   table, so a slave building its own heap over it would alias the
- *   master's allocations.  A slave device needs a carveout of its own.
- *
  ****************************************************************************/
 
 static FAR struct rptun_carveout_s *
@@ -655,16 +651,6 @@ rptun_create_carveout(FAR struct rptun_priv_s *priv, 
unsigned int index)
   FAR struct fw_rsc_carveout *rsc;
   char name[RPROC_MAX_NAME_LEN];
 
-  if (priv->heap == NULL && RPTUN_IS_MASTER(priv->dev))
-    {
-      rsc = rptun_find_carveout(priv->rproc.rsc_table, "vdevbuffer");
-      if (rsc != NULL)
-        {
-          priv->heap = rptun_create_heap(priv, priv->poolname, rsc->name,
-                                         rsc->da, NULL, rsc->len);
-        }
-    }
-
   carv = kmm_zalloc(sizeof(struct rptun_carveout_s));
   if (carv != NULL)
     {
@@ -1081,12 +1067,6 @@ static void rptun_remove_devices(FAR struct rptun_priv_s 
*priv)
     }
 
   metal_mutex_release(&rproc->lock);
-
-  if (priv->heap != NULL)
-    {
-      mm_uninitialize(priv->heap);
-      priv->heap = NULL;
-    }
 }
 
 /****************************************************************************
@@ -1465,6 +1445,27 @@ static int rptun_start_thread(int argc, FAR char *argv[])
   ret = rptun_do_start(&priv->rproc);
   if (ret >= 0)
     {
+      FAR struct fw_rsc_carveout *rsc;
+      FAR const char *name;
+
+      /* Build the pool the devices without a region of their own allocate
+       * from.  Each side gets its own carveout, because both read the same
+       * table: two heaps over one region would hand out the same memory
+       * twice.  The master takes "vdevbuffer" and the slave "hdevbuffer".
+       */
+
+      if (priv->heap == NULL)
+        {
+          name = RPTUN_IS_MASTER(priv->dev) ? "vdevbuffer" : "hdevbuffer";
+          rsc = rptun_find_carveout(priv->rproc.rsc_table, name);
+          if (rsc != NULL)
+            {
+              priv->heap = rptun_create_heap(priv, priv->poolname,
+                                             rsc->name, rsc->da, NULL,
+                                             rsc->len);
+            }
+        }
+
       while (!priv->stop)
         {
           ret = rptun_create_devices(priv);
@@ -1546,6 +1547,13 @@ static int rptun_dev_stop(FAR struct remoteproc *rproc)
 
       RPTUN_UNREGISTER_CALLBACK(priv->dev);
       rptun_remove_devices(priv);
+
+      if (priv->heap != NULL)
+        {
+          mm_uninitialize(priv->heap);
+          priv->heap = NULL;
+        }
+
 #ifdef CONFIG_COREDUMP
       rptun_update_coredump_regions(priv, false);
 #endif

Reply via email to