Phil-Engljaehringer opened a new pull request, #21086:
URL: https://github.com/apache/nuttx/pull/21086

   ## Summary
   
     * **Why:** `imx9_rptun_get_resource()` cached the table pointer and 
returned it unchanged on every rptun start after the first one. When rptun is 
restarted while the core keeps running (for example after the Linux host 
reboots or crashes), the old vdev status with `DRIVER_OK` still set was reused. 
The core then did not wait for the new host and used vrings the host had not 
set up yet.
     * **What:** `arch/arm/src/imx9/imx9_rptun.c` (`imx9_rptun_get_resource()`) 
and `arch/arm/src/imx9/Kconfig`.
     * **How:**
       * The `priv->shmem != NULL` early return is removed. The rptun core 
calls `get_resource` once per start, so the cache only took effect on a 
restart, where it returned the stale table.
       * New option `CONFIG_IMX9_RPTUN_ALWAYS_COPY_RSC_TABLE` (default `n`, 
depends on `RPTUN`). When enabled, the built-in resource table is copied to 
`RESOURCE_TABLE_BASE` on every start, which resets the vdev status to 0.
       * When disabled, the existing check is kept: the table is only copied if 
`RESOURCE_TABLE_BASE` does not already hold one (offset compare).
     * **Why a build option and not an unconditional copy:** when Linux 
remoteproc loads the firmware ELF itself, Linux writes the resource table to 
the shared region *before* starting the core and sets the guest features and 
`DRIVER_OK` *after* the core runs. A copy by the core at that point would erase 
that state (the core waits forever for `DRIVER_OK`, and the name service 
feature is lost). There is no reliable way to tell at runtime whether the core 
was started by Linux or by the System Manager / bootloader, so the choice is 
made at build time.
     * **Limitation of the default:** the offset compare also passes for a 
stale table left over from before a warm reboot of the core. Boards where the 
core is started by the System Manager (attach mode) and the host can restart 
independently should enable the option.
     * A similar caching pattern exists in `mx8mp_rptun.c`; it is not touched 
here and could be a follow-up.
     * cc @AndreHeinemans-NXP  (original author of `imx9_rptun.c`), who agreed 
with the Kconfig approach and with dropping the cache.
   
   ## Impact
   
     * Is new feature added? Is existing feature changed? YES: new Kconfig 
option `IMX9_RPTUN_ALWAYS_COPY_RSC_TABLE`. With the option disabled, the only 
change is that a second rptun start re-evaluates the table instead of reusing 
the cached pointer.
     * Impact on user (will user need to adapt to change)? NO. The option 
defaults to `n`.
     * Impact on build (will build process change)? NO.
     * Impact on hardware (will arch(s) / board(s) / driver(s) change)? YES: 
i.MX9 rptun (i.MX95 M7 and i.MX93 share `imx9_rptun.c`). No defconfig is 
changed.
     * Impact on documentation (is update required / provided)? NO. The Kconfig 
help text describes the option.
     * Impact on security (any sort of implications)? NO.
     * Impact on compatibility (backward/forward/interoperability)? NO. Default 
behaviour is unchanged except for the removed cache.
   
   ## Testing
   
     I confirm that changes are verified on local setup and works as intended:
     * Build Host(s): Linux 6.17 x86_64, AMD Ryzen AI 9 HX 370, 
arm-none-eabi-gcc 14.2.1 20241119.
     * Target(s): ARM, mr-navq95b:rpmsg (i.MX95 Cortex-M7), with and without 
`CONFIG_IMX9_RPTUN_ALWAYS_COPY_RSC_TABLE=y` set locally.
     * Steps: M7 started by the System Manager, Linux attaches; reboot Linux 
while the M7 keeps running and check that rpmsg comes back.
     * The path where Linux remoteproc loads the ELF was not tested (no setup 
for it); with the option off that path keeps the existing behaviour.
   
     
   ## AI assistance and sign-off
   
     Parts of the change and of this description were prepared with Claude Code 
(noted in the commit with `Assisted-by`). I reviewed, tested and signed off the 
change myself.
   
   ## PR verification Self-Check
   
     * [x] This PR introduces only one functional change.
     * [x] I have updated all required description fields above.
     * [x] My PR adheres to Contributing 
[Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md) and 
[Documentation](https://nuttx.apache.org/docs/latest/contributing/index.html) 
(git commit title and message, coding standard, etc).
     * [x] My PR is still work in progress (not ready for review).
     * [ ] My PR is ready for review and can be safely merged into a codebase.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to