Repository navigation
Mailbox framework - #8285
Mailbox framework#8285jamike wants to merge 7 commits into
Conversation
The framework enables OPTEE exchange with a remote processor based on mailbox channel notification. The framework provide mailbox device registering services and user service for channel exchange with remote processor. A channel is granted to a single consumer at a time: requesting a channel already granted returns TEE_ERROR_BUSY until it is released. Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Add DT_DRIVER_MAILBOX to the device tree driver types so that mailbox controllers can register as device providers and mailbox consumers can resolve their channels from the "mboxes" device tree property. The number of cells of a mailbox specifier is described by the "#mbox-cells" property of the provider node. Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Add the mailbox device tree services, built when CFG_DT is enabled (stubs returning TEE_ERROR_NOT_SUPPORTED otherwise): - mbox_dt_register_controller() registers a controller as a DT_DRIVER_MAILBOX provider; the cells of the consumer "mboxes" specifier are given to the controller request_channel operation. - mbox_dt_request_channel_by_index() gets a channel from the "mboxes" property. - mbox_dt_request_channel_by_name() gets a channel from its name in the "mbox-names" property. Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Register the TI SCI transport as a mailbox controller and drop the dedicated transport initialization from main.c. Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
Implement the Versal IPI as a mailbox controller and route versal_mbox calls through the mailbox framework. Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
A virtual driver mailbox is used to test mailbox framework. The test are launched by PTA commands. A virtual mailbox flavor whose recv_sync() waits for a message using an asynchronous notification is also provided, with two PTA commands to be invoked concurrently: one blocks in mbox_recv_sync() while the other sends the message. The commands return TEE_ERROR_NOT_SUPPORTED when CFG_CORE_ASYNC_NOTIF is disabled. Change-Id: I38015bf7686c46137db3e2d4f9b8d1a849d34fe5 Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
The device tree interface of the mailbox framework was not covered by any test. mbox_dt_register_controller() on the provider side, and both mbox_dt_request_channel_by_index() and mbox_dt_request_channel_by_name() on the consumer side, could only be exercised on a platform embedding a real mailbox controller. Add an emulated mailbox provider to the device tree test device. It is declared on the "linaro,dt-test-provider" compatible, hence it is also covered by the existing probe deferral test. Its channels can send but cannot receive. Add probe_test_mbox() to the test consumer probe. It resolves the two channels by index, checks that a channel already granted cannot be requested again by name, then that once released it is granted again with the same reference. It sends a message on a channel and checks that reception is reported as not supported. It also checks that an out of range index and an unknown name are both rejected. The outcome is reported by the existing DT driver test command, so no new test identifier is needed. Enable CFG_DRIVERS_MAILBOX together with CFG_DT_DRIVER_EMBEDDED_TEST so that these tests are embedded along with the other DT driver tests. Assisted-by: GitHub-Copilot:Claude Opus 5.5 Signed-off-by: Michel JAOUEN <michel.jaouen@st.com>
ee097ce to
df18a4d
Compare
|
FYI @glneo |
df18a4d to
61453f4
Compare
|
@jamike We've reviewed #8285 against our Qualcomm TME-Lite mailbox stack (QMP-Lite transport and its client) (#7956) and we are looking to pick your generic mailbox changes instead of having QCOM specific mbox changes What is the planned timeline for merging #8285? Once your changes are accomodated, our PRs (#7956, #8282, #8274) will depend on #8285 |
|
On my side , the planning is as soon as possible till all the "possible" mailbox framework users provide their feedback. Especially for the review / test for plat-k3 and versal and also the usage in #8120 . @qc-azarrabi and @ldts can you help on this review / test ? |
|
|
||
| ops = chan->controller->desc->ops; | ||
| if (ops->free_channel) | ||
| ops->free_channel(chan); |
There was a problem hiding this comment.
mbox_free_channel() clears requested and drops the lock before it calls free_channel(). A concurrent mbox_request_channel() on a static channel can be granted inside that window. The previous owner's teardown then runs on the channel the new owner just received. Is concurrent request/free meant to be supported? If it is, the channel should stay granted until the op returns. The Versal driver frees the channel inside the op, so that case needs some thought. If it isn't, the spinlock and this ordering could be documented as single-consumer.
| * @retval: TEE_ERROR_BAD_PARAMETERS If there was a bad parameter. | ||
| * @retval: TEE_ERROR_ITEM_NOT_FOUND If @index does not exist. | ||
| * @retval: TEE_ERROR_DEFER_DRIVER_INIT If the controller is not yet probed. | ||
| * @retval: TEE_ERROR_BUSY If the channel is already granted. |
There was a problem hiding this comment.
The channel stays granted until mbox_free_channel(), but a DT consumer probe is re-run when it returns TEE_ERROR_DEFER_DRIVER_INIT. A probe that gets a channel and then defers (on a clock, a regulator, a second channel...) without freeing it gets TEE_ERROR_BUSY on the retry. That puts the driver on the failed list, and probe_dt_drivers() panics. This is easy to get wrong in a real driver. Could the DT getters be idempotent for the same consumer node? At minimum, could the doc say that a probe must mbox_free_channel() every channel it holds before returning an error or DEFER?
There was a problem hiding this comment.
It's the driver's responsibility to handle the resources it got if it takes a TEE_ERROR_DEFER_DRIVER_INIT path.
The thing is the channel isn't really "requested", it's rather "acquired". So I'd rather rename the field in the channel structure and the function names at minimum
There was a problem hiding this comment.
I think we can drop the Assisted-by tag as its no more a valid tag supported by latest checkpatch/CI?
There was a problem hiding this comment.
Change-Id from this commit can be dropped
|
@jamike Are you still collecting feedback on this RFC, or are you planning to open the PR soon? |
Actually , it 's a draft PR, I planned to set as release PR. I collect all the feedback /review comment on this PR. |
|
from my end and now with a user, happy to move it along - will validate your versal changes |
| remote < VERSAL_IPI_ID_PMC || remote > VERSAL_IPI_ID_5) | ||
| return TEE_ERROR_BAD_PARAMETERS; | ||
|
|
||
| ipi = calloc(1, sizeof(*ipi)); |
There was a problem hiding this comment.
on every call we are allocating a new structure. Since we are now part of a runtime framework, shouldn't we make sure that two requests for the same local/remote ipi can not succeed
| { | ||
| TEE_Result res = TEE_SUCCESS; | ||
|
|
||
| if (!versal_controller) { |
There was a problem hiding this comment.
do we need a lock for future use cases?
| #include <malloc.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <tee/cache.h> |
There was a problem hiding this comment.
I think we can now drop <tee/cache.h from here>
| #define IPI_TRIG_OFFSET 0x00 | ||
| #define IPI_OBR_OFFSET 0x04 | ||
| #define IPI_ISR_OFFSET 0x10 | ||
| #define IPI_IMR_OFFSET 0x14 |
There was a problem hiding this comment.
we can drop the unused macros while we are at it
| } | ||
|
|
||
| static const struct mbox_controller_ops versal_mbox_ops = { | ||
| .request_channel = versal_mbox_request_channel, |
There was a problem hiding this comment.
these functions should be renamed as versal_ipi_request_channel, versal_ipi_free_channel and versal_ipi_send_sync I think
|
@GseoC @ldts @b49020 @zelvam95 @jamike Feel free to add my tested by tag <Tested-by: Harikrishna hart@qti.qualcomm.com (IPQ52xx)> |
This series introduces a mailbox framework in OP-TEE core, allowing the secure world to exchange notifications with a remote processor over mailbox channels, together with its device-tree bindings and self-tests.
The framework mirrors the Linux mailbox model: mailbox controllers register as providers and consumers resolve their channels either from the device tree ( mboxes / #mbox-cells ) or programmatically. It supports synchronous send/receive, per-channel.
For the mailbox test execution takes OP-TEE/optee_test#859