remoteproc: imx: Fix invalid loaded resource table detection
PATCH v3 1/1 remoteproc: imx: Fix invalid loaded resource table detection
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table() may incorrectly report a loaded resource table even when the current firmware does not provide one.
When the device tree contains a "rsc-table" entry, priv->rsc_table is non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table, rproc->table_ptr is NULL. The function still returns priv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.
Fix this by returning NULL from imx_rproc_elf_find_loaded_rsc_table() when there is no resource table for the current firmware (i.e. when rproc->table_ptr is NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a valid table_ptr exists.
With this change, starting firmware without a resource table no longer triggers a crash.
---
Changes in v3:
- Update patch subject and commit message using this one [1]
[1] https://lore.kernel.org/all/CANLsYkyrz+A1iEabGZ6rFybFo4=mM+TPVDRSckFB2YUS_7aKow@mail.gmail.com/
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Per Mathieu, Check rproc->table_ptr, update commit log
- Include R-b from Frank
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/remoteproc/imx_rproc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/remoteproc/imx_rproc.c +4 -0
@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ; +if (priv->rsc_table)return (struct resource_table *)priv->rsc_table;
---
base-commit: e3b32dcb9f23e3c3927ef3eec6a5842a988fb574
change-id: 20260122-imx-rproc-fix-e206f8e6e477
Best regards,
Signature · 1 line
Peng Fan <[email protected]>
Quoted 19 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table()may incorrectly report a loaded resource table even when the current firmware does not provide one.When the device tree contains a "rsc-table" entry,
priv->rsc_tableis non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table,rproc->table_ptris NULL. The function still returnspriv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.Fix this by returning NULL from
imx_rproc_elf_find_loaded_rsc_table()when there is no resource table for the current firmware (i.e. whenrproc->table_ptris NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a validtable_ptrexists.
Quoted 6 lines
With this change, starting firmware without a resource table no longer triggers a crash.
Fixes e954a1bd1610 ("remoteproc: imx_rproc: Use imx specific hook for find_loaded_rsc_table")Signed-off-by Peng Fan <[email protected]>
Changes looks good to me >
drivers/remoteproc/imx_rproc.c imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * · line 734
Quoted 9 lines
drivers/remoteproc/imx_rproc.c +3
-0@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ;
I wonder if we can make this change generic because it should happen on other platforms also.
Maybe something like this:
remoteproc: core: Only copy loaded table when valid
Copy resource table in memory only when:
* the current loaded firmware provides one
AND
* there is an explicit request to have the rsc table copied in memory via rsc-table
drivers/remoteproc/remoteproc_core.c +0 -0
@@ -1281,7 +1281,7 @@ static int rproc_start(struct rproc *rproc,
const struct firmware *fw)
* that any subsequent changes will be applied to the loaded version.
*/
loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
- if (loaded_table) {
+ if (rproc->cached_table && loaded_table) {
memcpy(loaded_table, rproc->cached_table, rproc->table_sz);
rproc->table_ptr = loaded_table;
}Hi Daniel,
Quoted 63 lines · Daniel Baluta
Quoted 19 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table()may incorrectly report a loaded resource table even when the current firmware does not provide one.When the device tree contains a "rsc-table" entry,
priv->rsc_tableis non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table,rproc->table_ptris NULL. The function still returnspriv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.Fix this by returning NULL from
imx_rproc_elf_find_loaded_rsc_table()when there is no resource table for the current firmware (i.e. whenrproc->table_ptris NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a validtable_ptrexists.Quoted 6 lines
With this change, starting firmware without a resource table no longer triggers a crash.
Fixes e954a1bd1610 ("remoteproc: imx_rproc: Use imx specific hook for find_loaded_rsc_table")Signed-off-by Peng Fan <[email protected]>Changes looks good to me >
drivers/remoteproc/imx_rproc.c imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * · line 734
Quoted 9 lines
drivers/remoteproc/imx_rproc.c +3
-0@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ;I wonder if we can make this change generic because it should happen on other platforms also.
Maybe something like this:
remoteproc: core: Only copy loaded table when valid
Copy resource table in memory only when:
* the current loaded firmware provides one
AND
* there is an explicit request to have the rsc table copied in memory via rsc-tabledrivers/remoteproc/remoteproc_core.c +1
-1@@ -1281,7 +1281,7 @@ static int rproc_start(struct rproc *rproc,const struct firmware *fw) * that any subsequent changes will be applied to the loaded version. */ loaded_table =rproc_find_loaded_rsc_table (rproc, fw); -if (loaded_table) { +if (rproc->cached_table && loaded_table) {memcpy (loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr = loaded_table;
Quoted 1 line
}
This change looks fine to me; however, it should not be treated as a bug fix for imx_rproc. Since we need a proper Fixes tag for backporting, I would still prefer using the changes in my original patch to ensure it can be applied to older releases.
As for the modification you introduced, I think it can serve as a guard to prevent potential issues on other platforms. You could submit it separately as a formal patch to the mailing list.
Thanks,
Peng
Mathieu Poirier
maintainerQuoted 55 lines · Daniel Baluta
Quoted 19 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table()may incorrectly report a loaded resource table even when the current firmware does not provide one.When the device tree contains a "rsc-table" entry,
priv->rsc_tableis non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table,rproc->table_ptris NULL. The function still returnspriv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.Fix this by returning NULL from
imx_rproc_elf_find_loaded_rsc_table()when there is no resource table for the current firmware (i.e. whenrproc->table_ptris NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a validtable_ptrexists.Quoted 6 lines
With this change, starting firmware without a resource table no longer triggers a crash.
Fixes e954a1bd1610 ("remoteproc: imx_rproc: Use imx specific hook for find_loaded_rsc_table")Signed-off-by Peng Fan <[email protected]>Changes looks good to me >
drivers/remoteproc/imx_rproc.c imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * · line 734
Quoted 9 lines
drivers/remoteproc/imx_rproc.c +3
-0@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ;I wonder if we can make this change generic because it should happen on other platforms also.
Maybe something like this:
remoteproc: core: Only copy loaded table when valid
Copy resource table in memory only when:
* the current loaded firmware provides one
AND
* there is an explicit request to have the rsc table copied in memory via rsc-table
drivers/remoteproc/remoteproc_core.c static int rproc_start(struct rproc *rproc, · line 1285
Quoted 6 lines
drivers/remoteproc/remoteproc_core.c +1
-1@@ -1281,7 +1281,7 @@ static int rproc_start(struct rproc *rproc,const struct firmware *fw) * that any subsequent changes will be applied to the loaded version. */ loaded_table =rproc_find_loaded_rsc_table (rproc, fw); -if (loaded_table) { +if (rproc->cached_table && loaded_table) {
But we would be doing the check for rproc->table_ptr twice (->table_ptr and ->cached_table should be the same). The way it is currently writting forces vendor specific implementation of rproc_elf_find_loaded_rsc_table() to do the right thing.
The merge window has been pushed by a week, giving me an opportunity to merge this patch. Should I do that or should we continue discussing the best approach?
Quoted 3 lines
drivers/remoteproc/remoteproc_core.c +0
-0memcpy (loaded_table, rproc->cached_table, rproc->table_sz); rproc->table_ptr = loaded_table;}
Daniel Baluta
Acked-byQuoted 69 lines · Mathieu Poirier
Quoted 55 lines · Daniel Baluta
Quoted 19 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table()may incorrectly report a loaded resource table even when the current firmware does not provide one.When the device tree contains a "rsc-table" entry,
priv->rsc_tableis non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table,rproc->table_ptris NULL. The function still returnspriv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.Fix this by returning NULL from
imx_rproc_elf_find_loaded_rsc_table()when there is no resource table for the current firmware (i.e. whenrproc->table_ptris NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a validtable_ptrexists.Quoted 6 lines
With this change, starting firmware without a resource table no longer triggers a crash.
Fixes e954a1bd1610 ("remoteproc: imx_rproc: Use imx specific hook for find_loaded_rsc_table")Signed-off-by Peng Fan <[email protected]>Changes looks good to me >
drivers/remoteproc/imx_rproc.c imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * · line 734
Quoted 9 lines
drivers/remoteproc/imx_rproc.c +3
-0@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ;I wonder if we can make this change generic because it should happen on other platforms also.
Maybe something like this:
remoteproc: core: Only copy loaded table when valid
Copy resource table in memory only when:
* the current loaded firmware provides one
AND
* there is an explicit request to have the rsc table copied in memory via rsc-tabledrivers/remoteproc/remoteproc_core.c static int rproc_start(struct rproc *rproc, · line 1285
Quoted 6 lines
drivers/remoteproc/remoteproc_core.c +1
-1@@ -1281,7 +1281,7 @@ static int rproc_start(struct rproc *rproc,const struct firmware *fw) * that any subsequent changes will be applied to the loaded version. */ loaded_table =rproc_find_loaded_rsc_table (rproc, fw); -if (loaded_table) { +if (rproc->cached_table && loaded_table) {But we would be doing the check for
rproc->table_ptrtwice (->table_ptr and ->cached_table should be the same). The way it is currently writting forces vendor specific implementation ofrproc_elf_find_loaded_rsc_table()to do the right thing.
Quoted 3 lines
The merge window has been pushed by a week, giving me an opportunity to merge this patch. Should I do that or should we continue discussing the best approach?
Let's go with Peng's approach:
Quoted 43 lines · Peng Fan (OSS)
From: Peng Fan <[email protected]>
imx_rproc_elf_find_loaded_rsc_table()may incorrectly report a loaded resource table even when the current firmware does not provide one.When the device tree contains a "rsc-table" entry,
priv->rsc_tableis non-NULL and denotes where a resource table would be located if one is present in memory. However, when the current firmware has no resource table,rproc->table_ptris NULL. The function still returnspriv->rsc_table, and the remoteproc core interprets this as a valid loaded resource table.Fix this by returning NULL from
imx_rproc_elf_find_loaded_rsc_table()when there is no resource table for the current firmware (i.e. whenrproc->table_ptris NULL). This aligns the function's semantics with the remoteproc core: a loaded resource table is only reported when a validtable_ptrexists.With this change, starting firmware without a resource table no longer triggers a crash.
Fixes e954a1bd1610 ("remoteproc: imx_rproc: Use imx specific hook for find_loaded_rsc_table")Signed-off-by Peng Fan <[email protected]>---
Changes in v3:
- Update patch subject and commit message using this one [1]
[1] https://lore.kernel.org/all/CANLsYkyrz+A1iEabGZ6rFybFo4=mM+TPVDRSckFB2YUS_7aKow@mail.gmail.com/
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Per Mathieu, Checkrproc->table_ptr, update commit log
- Include R-b from Frank
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/remoteproc/imx_rproc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/remoteproc/imx_rproc.c +0
-0
drivers/remoteproc/imx_rproc.c imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * · line 738
Quoted 10 lines
drivers/remoteproc/imx_rproc.c +4
-0@@ -729,6 +729,10 @@ imx_rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware * {struct imx_rproc *priv = rproc->priv; +/* No resource table in the firmware */ +if (!rproc->table_ptr) +return NULL ; +if (priv->rsc_table)return (struct resource_table *)priv->rsc_table;
Applied.
Thanks,
Mathieu
Quoted 9 lines
---
base-commit:e3b32dcb9f23e3c3927ef3eec6a5842a988fb574
change-id: 20260122-imx-rproc-fix-e206f8e6e477Best regards,
Signature · 1 line
Peng Fan <[email protected]>