drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
When attaching to a remote processor, it is implied that the rproc was
booted by an external entity. Thus, it's carveout and devmem resources
would already have been processed by the external entity during boot.
Re-allocating the carveouts in Linux (without proper flags) would zero
out the memory regions used by the firmware and can lead to undefined
behaviour. And there is no need to re-map the memory regions for devmem
resources as well.
Therefore, do not process the carveout and devmem resources in attach
mode by not appending them to the rproc->carveouts and rproc->mappings
lists respectively.
Signed-off-by: Beleswar Padhi <b-padhi@ti.com>
---
Testing:
1. Tested IPC with remoteprocs in attach mode in TI platforms.
[However, TI K3 platforms do not use resource table for carveouts,
all the memory regions are reserved statically in Device Tree.]
drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 825672100528..ef709a5fa73c 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -640,6 +640,20 @@ static int rproc_handle_devmem(struct rproc *rproc, void *ptr,
return -EINVAL;
}
+ /*
+ * When attaching to a remote processor, it is implied that the rproc
+ * was booted by an external entity. Thus, it's devmem resources would
+ * already have been mapped by the external entity during boot. There is
+ * no need to re-map the memory regions here.
+ *
+ * Skip adding the devmem rsc to the mapping list and return without
+ * complaining.
+ */
+ if (rproc->state == RPROC_DETACHED) {
+ dev_info(dev, "skipping devmem rsc in attach mode\n");
+ return 0;
+ }
+
mapping = kzalloc(sizeof(*mapping), GFP_KERNEL);
if (!mapping)
return -ENOMEM;
@@ -839,6 +853,22 @@ static int rproc_handle_carveout(struct rproc *rproc,
return -EINVAL;
}
+ /*
+ * When attaching to a remote processor, it is implied that the rproc
+ * was booted by an external entity. Thus, it's carveout resources would
+ * already have been allocated by the external entity during boot.
+ * Re-allocating the carveouts here (without proper flags) would zero
+ * out the memory regions used by the firmware and can lead to undefined
+ * behaviour.
+ *
+ * Skip adding the carveouts to the alloc list and return without
+ * complaining.
+ */
+ if (rproc->state == RPROC_DETACHED) {
+ dev_info(dev, "skipping carveout allocation in attach mode\n");
+ return 0;
+ }
+
dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n",
rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
--
2.34.1
On 7/24/25 8:31 AM, Beleswar Padhi wrote: > When attaching to a remote processor, it is implied that the rproc was > booted by an external entity. Thus, it's carveout and devmem resources > would already have been processed by the external entity during boot. > > Re-allocating the carveouts in Linux (without proper flags) would zero > out the memory regions used by the firmware and can lead to undefined > behaviour. And there is no need to re-map the memory regions for devmem > resources as well. > So the zeroing of the memory seems to be one of the core issues, and as you know (just re-stating for folks following along) we internally carry some hacks that allows allocating from these carveouts without the core dma_alloc_coherent() zeroing the memory out. Those will not go upstream so skipping the allocations in the first place does seem logical here, but I'd like to better document what this implies. For one, any requests for devmem and carveouts in the resource table will not be handled by Linux and so *must* be already fulfilled by the external entity that originally booted these rprocs. Two, since Linux is not providing these memory regions, it doesn't know they are in use by these rprocs, so we need to be sure to mark them as no-map or similar, reusable carveout regions will not work here. Lastly, I've been working on some plans to allow better passing of buffers to rprocs which currently requires the rproc framework have knowledge of which rprocs own which regions (for sanity checks, IOMMU translations, etc..). I'll have to think on how we can still associate these memories with the rprocs even if they were not allocated using the below path and don't end up in rproc->mappings. Andrew > Therefore, do not process the carveout and devmem resources in attach > mode by not appending them to the rproc->carveouts and rproc->mappings > lists respectively. > > Signed-off-by: Beleswar Padhi <b-padhi@ti.com> > --- > Testing: > 1. Tested IPC with remoteprocs in attach mode in TI platforms. > [However, TI K3 platforms do not use resource table for carveouts, > all the memory regions are reserved statically in Device Tree.] > > drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 825672100528..ef709a5fa73c 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -640,6 +640,20 @@ static int rproc_handle_devmem(struct rproc *rproc, void *ptr, > return -EINVAL; > } > > + /* > + * When attaching to a remote processor, it is implied that the rproc > + * was booted by an external entity. Thus, it's devmem resources would > + * already have been mapped by the external entity during boot. There is > + * no need to re-map the memory regions here. > + * > + * Skip adding the devmem rsc to the mapping list and return without > + * complaining. > + */ > + if (rproc->state == RPROC_DETACHED) { > + dev_info(dev, "skipping devmem rsc in attach mode\n"); > + return 0; > + } > + > mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); > if (!mapping) > return -ENOMEM; > @@ -839,6 +853,22 @@ static int rproc_handle_carveout(struct rproc *rproc, > return -EINVAL; > } > > + /* > + * When attaching to a remote processor, it is implied that the rproc > + * was booted by an external entity. Thus, it's carveout resources would > + * already have been allocated by the external entity during boot. > + * Re-allocating the carveouts here (without proper flags) would zero > + * out the memory regions used by the firmware and can lead to undefined > + * behaviour. > + * > + * Skip adding the carveouts to the alloc list and return without > + * complaining. > + */ > + if (rproc->state == RPROC_DETACHED) { > + dev_info(dev, "skipping carveout allocation in attach mode\n"); > + return 0; > + } > + > dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", > rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); >
Hi Beleswar, On Thu, Jul 24, 2025 at 07:01:44PM +0530, Beleswar Padhi wrote: > When attaching to a remote processor, it is implied that the rproc was > booted by an external entity. Thus, it's carveout and devmem resources > would already have been processed by the external entity during boot. > > Re-allocating the carveouts in Linux (without proper flags) would zero > out the memory regions used by the firmware and can lead to undefined > behaviour. And there is no need to re-map the memory regions for devmem > resources as well. > > Therefore, do not process the carveout and devmem resources in attach > mode by not appending them to the rproc->carveouts and rproc->mappings > lists respectively. > I think what you are proposing is logical. Arnaud, Daniel, Iuliana and Tanmay - please test this on your platforms. I will also need another TB from someone at TI. Regards, Mathieu > Signed-off-by: Beleswar Padhi <b-padhi@ti.com> > --- > Testing: > 1. Tested IPC with remoteprocs in attach mode in TI platforms. > [However, TI K3 platforms do not use resource table for carveouts, > all the memory regions are reserved statically in Device Tree.] > > drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++ > 1 file changed, 30 insertions(+) > > diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c > index 825672100528..ef709a5fa73c 100644 > --- a/drivers/remoteproc/remoteproc_core.c > +++ b/drivers/remoteproc/remoteproc_core.c > @@ -640,6 +640,20 @@ static int rproc_handle_devmem(struct rproc *rproc, void *ptr, > return -EINVAL; > } > > + /* > + * When attaching to a remote processor, it is implied that the rproc > + * was booted by an external entity. Thus, it's devmem resources would > + * already have been mapped by the external entity during boot. There is > + * no need to re-map the memory regions here. > + * > + * Skip adding the devmem rsc to the mapping list and return without > + * complaining. > + */ > + if (rproc->state == RPROC_DETACHED) { > + dev_info(dev, "skipping devmem rsc in attach mode\n"); > + return 0; > + } > + > mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); > if (!mapping) > return -ENOMEM; > @@ -839,6 +853,22 @@ static int rproc_handle_carveout(struct rproc *rproc, > return -EINVAL; > } > > + /* > + * When attaching to a remote processor, it is implied that the rproc > + * was booted by an external entity. Thus, it's carveout resources would > + * already have been allocated by the external entity during boot. > + * Re-allocating the carveouts here (without proper flags) would zero > + * out the memory regions used by the firmware and can lead to undefined > + * behaviour. > + * > + * Skip adding the carveouts to the alloc list and return without > + * complaining. > + */ > + if (rproc->state == RPROC_DETACHED) { > + dev_info(dev, "skipping carveout allocation in attach mode\n"); > + return 0; > + } > + > dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", > rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); > > -- > 2.34.1 >
Hi Beleswar & Mathieu, Please find my comments below. On 7/29/25 10:34 AM, Mathieu Poirier wrote: > Hi Beleswar, > > On Thu, Jul 24, 2025 at 07:01:44PM +0530, Beleswar Padhi wrote: >> When attaching to a remote processor, it is implied that the rproc was >> booted by an external entity. Thus, it's carveout and devmem resources >> would already have been processed by the external entity during boot. >> >> Re-allocating the carveouts in Linux (without proper flags) would zero >> out the memory regions used by the firmware and can lead to undefined >> behaviour. And there is no need to re-map the memory regions for devmem >> resources as well. >> >> Therefore, do not process the carveout and devmem resources in attach >> mode by not appending them to the rproc->carveouts and rproc->mappings >> lists respectively. >> > > I think what you are proposing is logical. Arnaud, Daniel, Iuliana and Tanmay - > please test this on your platforms. I will also need another TB from someone at > TI. > > Regards, > Mathieu > >> Signed-off-by: Beleswar Padhi <b-padhi@ti.com> >> --- >> Testing: >> 1. Tested IPC with remoteprocs in attach mode in TI platforms. >> [However, TI K3 platforms do not use resource table for carveouts, >> all the memory regions are reserved statically in Device Tree.] >> >> drivers/remoteproc/remoteproc_core.c | 30 ++++++++++++++++++++++++++++ >> 1 file changed, 30 insertions(+) >> >> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c >> index 825672100528..ef709a5fa73c 100644 >> --- a/drivers/remoteproc/remoteproc_core.c >> +++ b/drivers/remoteproc/remoteproc_core.c >> @@ -640,6 +640,20 @@ static int rproc_handle_devmem(struct rproc *rproc, void *ptr, >> return -EINVAL; >> } >> >> + /* >> + * When attaching to a remote processor, it is implied that the rproc >> + * was booted by an external entity. Thus, it's devmem resources would >> + * already have been mapped by the external entity during boot. There is >> + * no need to re-map the memory regions here. >> + * >> + * Skip adding the devmem rsc to the mapping list and return without >> + * complaining. >> + */ >> + if (rproc->state == RPROC_DETACHED) { >> + dev_info(dev, "skipping devmem rsc in attach mode\n"); >> + return 0; >> + } >> + On AMD-Xilinx platforms we don't use RSC_DEVMEM resources so this isn't affected. And I haven't deep dived into how this works. I would let Mathieu take decision here. >> mapping = kzalloc(sizeof(*mapping), GFP_KERNEL); >> if (!mapping) >> return -ENOMEM; >> @@ -839,6 +853,22 @@ static int rproc_handle_carveout(struct rproc *rproc, >> return -EINVAL; >> } >> >> + /* >> + * When attaching to a remote processor, it is implied that the rproc >> + * was booted by an external entity. Thus, it's carveout resources would >> + * already have been allocated by the external entity during boot. >> + * Re-allocating the carveouts here (without proper flags) would zero >> + * out the memory regions used by the firmware and can lead to undefined >> + * behaviour. >> + * >> + * Skip adding the carveouts to the alloc list and return without >> + * complaining. >> + */ >> + if (rproc->state == RPROC_DETACHED) { >> + dev_info(dev, "skipping carveout allocation in attach mode\n"); >> + return 0; >> + } >> + RSC_CARVEOUT type of resources are used on AMD-Xilinx platform firmwares and this path I can test. I will let know results once I do that, But before that I have few comments: 1) This check should be moved right before `rproc_mem_entry_init`. That means if carveout is found then we should allow flags allocation from firmware. This can happen if platform driver has already allocated the carveout and during next attach, we are just updating flags and offset. 2) In this patch following assumption is made: ``` * When attaching to a remote processor, it is implied that the rproc * was booted by an external entity. Thus, it's carveout resources would * already have been allocated by the external entity during boot. ``` I think this is really platform/firmware dependent. This was not complained by any other users yet. That could mean they are relying on Linux to initialize these carveouts and remoteproc firmware may not initialize it. To avoid breaking any back compatibility or other's use case (if there is one), can we add new feature in rproc->features like: RPROC_SKIP_ALLOC_CARVEOUT_ON_ATTACH and platform drivers can set that feature in during probe. Then we can check that feature here along with DETACHED state and make decision based on it. https://github.com/torvalds/linux/blob/89748acdf226fd1a8775ff6fa2703f8412b286c8/include/linux/remoteproc.h#L501 Thanks, Tanmay >> dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n", >> rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags); >> >> -- >> 2.34.1 >>
© 2016 - 2025 Red Hat, Inc.