-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Asynchronous notifications #4601
Conversation
857fa2e
to
e014fc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments already, although I have not looked at everything.
core/arch/arm/tee/entry_fast.c
Outdated
@@ -181,6 +190,22 @@ void __weak tee_entry_fast(struct thread_smc_args *args) | |||
__tee_entry_fast(args); | |||
} | |||
|
|||
#if CFG_CORE_ASYNC_NOTIF_INTID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (CFG_CORE_ASYNC_NOTIF_INTID) { ... }
in the function body instead?
de23615
to
393ab15
Compare
Rebased on master on top the commits merged already. Split up a bit as requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple more things. This looks quite useful to me, especially as a remember past discussions with people requesting that kind of functionality.
Update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only minor comments
core/arch/arm/include/sm/optee_smc.h
Outdated
* Retrieve a value of notifications pended since the last call of this | ||
* function. | ||
* | ||
* OP-TEE keeps a records of all posted values. When an interrupts is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/records/record/
s/interrupts/interrupt/
core/arch/arm/include/sm/optee_smc.h
Outdated
* | ||
* OP-TEE keeps a records of all posted values. When an interrupts is | ||
* received which indicates that there are posted values this function | ||
* should be called until all pended values has been retrieved. When a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/has/have/
core/arch/arm/include/sm/optee_smc.h
Outdated
* should be called until all pended values has been retrieved. When a | ||
* value is retrieved it's cleared from the record in secure world. | ||
* | ||
* It is expected that this function is called from and interrupt handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/and/an/
@@ -240,6 +263,19 @@ void __tee_entry_fast(struct thread_smc_args *args) | |||
break; | |||
#endif | |||
|
|||
case OPTEE_SMC_ENABLE_ASYNC_NOTIF: | |||
if (notif_async_is_enabled()) | |||
notif_deliver_atomic_event(NOTIF_EVENT_STARTED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should set args->a0
.
core/include/kernel/notif.h
Outdated
* NOTIF_VALUE_MAX for mutex and condvar wait/wakeup | ||
* | ||
* Any value can be signalled with notif_send_sync() while only the ones | ||
* <= CFG_CORE_ASYNC_NOTIF_MAX can be signalled with notif_send_async(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/CFG_CORE_ASYNC_NOTIF_MAX/NOTIF_ASYNC_VALUE_MAX/
* has been delivered again. | ||
* | ||
* Note that while a @NOTIF_EVENT_STOPPED is being delivered at the same | ||
* time may a @NOTIF_EVENT_STARTED be delivered again so a driver is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe replace a driver
with non-secure world
?
(or did I misunderstood?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A driver is an OP-TEE driver in this case.
I'll remove "shared" from "shared internal state" since I guess that's what put you on the wrong track.
core/include/kernel/notif.h
Outdated
} | ||
#endif | ||
|
||
TEE_Result notif_alloc_async_value(uint32_t *val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/val
/value
/g ?
|
||
cpu_spin_unlock_xrestore(¬if_lock, old_itr_status); | ||
|
||
if (bit < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a DMSG()
trace here to help identifying the out-of-mem reporter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that helps much. This is likely to happen when the drivers are initializing so there's bound some more interesting print or perhaps even a panic.
core/kernel/notif.c
Outdated
bool notif_async_is_started(void) | ||
{ | ||
uint32_t old_itr_status = 0; | ||
bool ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= false;
if (notif_async_is_enabled()) | ||
notif_deliver_event(NOTIF_EVENT_DO_BOTTOM_HALF); | ||
else | ||
goto err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not rv = OPTEE_SMC_RETURN_EBADCMD;
straight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it nice to get the "Unknown cmd..." print in such a case.
Update |
|
a2faf92
to
7f3de17
Compare
Squashed and tags applied |
@etienne-lms do you want to provide a review or ack tag? |
Sorry. Yes, |
I'm sorry, which comment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! this one.
core/kernel/notif.c
Outdated
|
||
COMPILE_TIME_ASSERT(NOTIF_VALUE_DO_BOTTOM_HALF == | ||
OPTEE_SMC_ASYNC_NOTIF_VALUE_DO_BOTTOM_HALF); | ||
COMPILE_TIME_ASSERT(!CFG_CORE_ASYNC_NOTIF_INTID || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: this function mandates CFG_CORE_ASYNC_NOTIF_INTID!=0
note it is already embedded only upon CFG_CORE_ASYNC_NOTIF_INTID!=0 (line 16)
ca25df6
to
14cf2f9
Compare
Addressed comment, applied tag and rebased on master. We should wait with the merging this until we have made some more progress with upstreaming the kernel patches. |
Sure. |
I know and understand this is not high up the priority list, but any idea when this functionality would become available? I would like to test it, to see if it provides the functionality I seek (i.e. periodic tasks, largely independent of the REE). |
14cf2f9
to
245bae4
Compare
Rebased, "core: drivers: gic.h: define PPI and SPI bases" moved closer to the top, and added two "review" commits. |
I'm aiming for the v5.17 Linux kernel with the kernel driver counterpart of this (it seems we're going to be too close to the v5.16 merge window). I expect we can merge this earlier than that though. You can help out by testing this and replying on the kernel mailing list where the patches are posted. I expect to post the v7 patchset later this week so if you can do you test based on that it would be great. I can add you in CC if you like, which address should I use in that case? |
For commit "core: drivers: gic.h: define PPI and SPI bases": |
Not sure I fully understand what you mean here, but I'm glad to help where I can. Since this is work-related for me, feel free to use my work-email: jens.vankeirsbilck at kuleuven.be . Will I be able to test this by just updating my QEMUv7 repo (which I'm using now) ? |
Yes, just switch to this branch for optee_os with this and update linux with this branch https://git.linaro.org/people/jens.wiklander/linux-tee.git/log/?h=async_notif_v6 Build as usual and you should get something like:
on the secure uart when pressing space bar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For commit "core: add asynchronous notifications":
Minor comments below, once addressed:
Reviewed-by: Jerome Forissier <jerome@forissier.org>
Squashed in the update and applied Jerome's R-B on "core: add asynchronous notifications" |
245bae4
to
ec188cf
Compare
Update |
@jenswi-linaro Is there any way I can test this before its upstreamed. I'm anyway trying to bring up periodic tasks on OPTEE as mentioned in issues #4910 and #4920. I could test it out and try to merge some changes on an actual HW if possible. |
|
@jenswi-linaro , indeed. Because I didn't want to overwrite my existing QEMU project, I created a new one using a local default.xml manifest for the repo tool, pointing to your repositories. @panda-balarka I've attached my manifest here, maybe it helps you set up a project too. Due to upload restrictions I renamed the file to .txt extension, to use it with repo, just revert it back to .xml I'll know have a look at the code that produces that output to figure out how to connect it to a timer interrupt and take it from there. Thanks for expediting this so I can play around with it. |
@jenswi-linaro I've been going through the code, and as far as I can see, the code for that UART Notif test is located in While I understand that code, I'm struggling seeing how OPTEE / the notification code differentiates between different notifications, especially to launch the bottom half of the driver. |
All drivers which has registered for bottom half processing will be called each time. I don't expect that many callbacks registered that it will be a performance problem. It should be noted that entering secure world is much more expensive than calling a registered callback. I suppose we could have multiple queues for idle and triggered callbacks, but it seems more trouble than it's worth today. A registered callback should be capable of telling if it has any work to do when called. |
Clarifies the responsibilities of the caller when calling with struct optee_msg_arg as argument. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Adds the two defines GIC_PPI_BASE and GIC_SPI_BASE to tell the base of the ranges for PPIs and SPIs respectively. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Adds a new interface for synchronous notifications. The old RPC interface based on OPTEE_RPC_CMD_WAIT_QUEUE is renamed to OPTEE_RPC_CMD_NOTIFICATION in order to match the new interface. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Adds support for asynchronous notifications from secure world to normal world. This allows a design with a top half and bottom half type of driver where the top half runs in secure interrupt context and a notifications tells normal world to schedule a yielding call to do the bottom half processing. The protocol is defined in optee_msg.h optee_rpc_cmd.h and optee_smc.h. A notification consists of a 32-bit value which normal world can retrieve using a fastcall into secure world. OP-TEE is currently only supporting the value 0-63 where 0 has a special meaning. When 0 is sent it means that normal world is supposed to make a yielding call OPTEE_MSG_CMD_DO_BOTTOM_HALF. The notification framework in OP-TEE defines an interface where drivers can register a callback which is called on each yielding bottom half call. Notification capability is negotiated with the normal world while it initializes its driver. If both sides supports these notifications then they are enabled. CFG_CORE_ASYNC_NOTIF_GIC_INTID is added to define the hardware interrupt used to notify normal world. This is added to the DTB in case OP-TEE can is configured with CFG_DT=y. Other cases requires the normal world DTB to be kept in sync with this. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
When asynchronous notifications are enabled the console driver in qemu is configured as a top half and bottom half driver allowing basic testing of the notification framework. Reviewed-by: Jerome Forissier <jerome@forissier.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
a2861b6
to
78bec5e
Compare
Rebased on master. We've now reached a point where we can merge this. |
Absolutely, thanks! |
Could you help clarifying a few points:
|
Yes, and yes. |
OP-TEE community is working on asynchronous notification support ([1] and [2]) and is likely to merge TEE_GEN_CAP_ASYNC_NOTIF as 1 << 4. This change moves OCALL capability bit position bit field to upper half. We shall sync back with Linux once TEE_GEN_CAP_OCALL is officially upstream. Link: [1] OP-TEE/optee_os#4601 Link: [2] linaro-swg/linux#93 Change-Id: I8b2f3ca3d2f288990d420f4d8071c9fca88f561c Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
This is a preview and RFC of the asynchronous notifications feature.
Note this is tested on QEMU virt (v7) together with the kernel patches in PR linaro-swg/linux#93
I'm in particular interested in feedback on this from a SCMI point of view.
Other aspects to keep in mind is how this harmonizes with asynchronous notifications in FF-A 1.1