CV-Bowen opened a new pull request, #22075:
URL: https://github.com/apache/nuttx/pull/22075
## Summary
`rpmsg_alloc_buf()` on rpmsg_virtio only works on the driver side, which
owns the shared memory; on the device side it returns NULL.
Add `CONFIG_RPMSG_HEAP`. With it, each rpmsg device creates an
`rpmsg-heap` endpoint. The device side forwards `rpmsg_alloc_buf()` and
`rpmsg_free_buf()` over this endpoint to the driver side, which
allocates from or frees to the shared memory and returns the physical
address, converted with `up_addrenv_pa_to_va()`/`up_addrenv_va_to_pa()`.
## Impact
- New Kconfig `RPMSG_HEAP` (default n). Both sides of a link must enable
it.
- No change when the option is off.
- The `rpmsg-heap` endpoint is created on every rpmsg device, including
transports without `alloc_buf` (rpmsg_port); requests over those fail
as before.
## Testing
Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
`rpmsg_alloc_buf()` has no in-tree caller, so a test-only patch (not in
this PR) runs it after `rpmsg ping`, for every rpmsg device:
```c
b = rpmsg_alloc_buf(rdev, 256, 8);
syslog(LOG_EMERG, "buftest: support=%d buf=%p aligned=%d\n",
rpmsg_support_alloc_buf(rdev), b,
b != NULL && ((uintptr_t)b & 7) == 0);
if (b != NULL)
{
memset(b, 0x5a, 256);
rpmsg_free_buf(rdev, b);
syslog(LOG_EMERG, "buftest: freed\n");
}
```
Configs: sim:rpserver + sim:rpproxy, and qemu-armv8a:rpserver +
qemu-armv8a:rpproxy (connected over rpmsg_virtio/ivshmem and
rpmsg_port_uart), both sides with `CONFIG_RPMSG_HEAP=y` and
`CONFIG_RPMSG_POOL_COUNT=4`. nsh: `rpmsg ping all 1 64 1 0` on the
server, then twice on the proxy; `rpmsg dump all` on the proxy.
| rpmsg_virtio link | master | this PR |
|---|---|---|
| server (driver side) | 8-byte aligned buffer, freed | same |
| proxy (device side), sim | `buf=0` | buffer, freed; the second run gets
the same address |
| proxy (device side), qemu-armv8a | `buf=0` | buffer, freed; the second run
gets the same address |
<details><summary>qemu-armv8a, this PR</summary>
```
[server] buftest: support=1 buf=0x8000416350 aligned=1
[server] buftest: freed
[proxy] buftest: support=1 buf=0x8000416350 aligned=1
[proxy] buftest: freed
[proxy] buftest: support=1 buf=0x8000416350 aligned=1
[proxy] buftest: freed
[proxy] ept rpmsg-heap 0x4069d1e8: addr=1028 dest=1027 refcnt=1
priority=127 priv=0x406af8b0
```
</details>
<details><summary>sim, this PR</summary>
```
[server] buftest: support=1 buf=0xeea793a8 aligned=1
[server] buftest: freed
[proxy] buftest: support=1 buf=0xe854f3a8 aligned=1
[proxy] buftest: freed
[proxy] buftest: support=1 buf=0xe854f3a8 aligned=1
[proxy] buftest: freed
[proxy] ept rpmsg-heap 0xe857f0d8: addr=1040 dest=1038 refcnt=1
priority=127 priv=0xe857f940
```
</details>
<details><summary>master</summary>
```
[server] buftest: support=1 buf=0xe91be3a8 aligned=1
[server] buftest: freed
[proxy] buftest: support=1 buf=0 aligned=0
```
</details>
All four images build with 0 warnings with `RPMSG_HEAP` on and off.
Not tested: a device side whose shared memory is mapped at a different
physical address than the driver side's (both setups here translate
addresses identically or through the same mapping); failure of the
driver-side allocation (the request then returns NULL).
No regression in rpmsg: sim:rpserver/rpproxy and
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping,
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC
disabled, which current master needs for nxinit to start nsh there; unrelated
to this change.
--
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]