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
out of memory failures in xtest due to tee_shm_free() from Linux not unregistering SHM DMA buffer in kexec path #3637
Comments
In |
We can see only one reference is there that too should go away with dma_buf_put(). The same code path works when rmmod is called. This issue is seen in kexec execution case as shutdown in drivers is called. |
Perhaps we need a way to tell OP-TEE that normal world is starting over? |
This issue has been marked as a stale issue because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 5 days. Note, that you can always re-open a closed issue at any time. |
It's a strange optimism that supposes bugs can fix themselves by being left alone for 35 days. I believe that I have a related scenario where after kexec, use of tee-os either causes a kernel panic (either null de-reference or Unable to handle kernel paging request at virtual address) or a more sane: [ 415.656408] optee: handle_rpc_func_cmd: tee_shm_get_va ffff80013af83e80 failed I'm going to try building optee as a kernel module and unloading before kexec to see if that fixes that problem |
Haha who knows? 😆 Seriously though, the reason for marking issues "stale" and auto-closing is that we want the list of open issues to be somewhat representative of what people are either working on, or concerned about (so that others can possibly pick up meaningful tasks and contribute). By that logic, a closed issue is not necessarily a fixed one. [Edit] Also note that issues are not always bugs: they may be questions or configuration mistakes etc.
Sure, as always, contributions are welcome. Please do not hesitate to re-open this issue if you are actively investigating it. |
I second what @jforissier said, but I have thought about updating the bot to not close things that have a certain label ("bug" for example). The core team of OP-TEE are just a few persons, who are involved in other things too at the companies where they are working. So even if we want too, it's impossible to jump on every single issue being mentioned. Therefore we and the OP-TEE project as such are very grateful when other developers pick up certain issues and try to chime in. This is also one of the reasons starting with the bot, we had too many questions and open issues that never got closed, so it was almost impossible to keep track of what made sense to look into. A common theme is that people ask questions, but don't close the issue when they've got the answer or that we ask for more information and we never hear anything again. A pure bug report happens more seldom. Pure bugs should have the "bug" label I think. |
+1 that's a good idea IMO |
I confirm that unloaded the optee module before kexec means that optee works for me again after kexec. I don't know if there is a kernel -pre-kexec subscription that optee module could register with, which would give it time to say goodbye to tee-os nicely. I would hope tee-os would accept a synchronous "I'm outta here" message from linux kernel. I think that leaving tee-supplicant running during kexec may be what led to the kernel segfault and merely leaving optee module loaded may be what led to non-fatal failure to function, but that needs more testing. But certainly, making optee a loadable module, and stopping tee-supplicant and unloading the modules before kexec appears to have solved the immediate problem for me. |
OK, good.
What about this? diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index 99698b8a3a74..5426b07a80cb 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -710,6 +710,7 @@ MODULE_DEVICE_TABLE(of, optee_dt_match);
static struct platform_driver optee_driver = {
.probe = optee_probe,
.remove = optee_remove,
+ .shutdown = optee_remove,
.driver = {
.name = "optee",
.of_match_table = optee_dt_match, From https://patchwork.kernel.org/patch/9568549/ and http://lkml.iu.edu/hypermail/linux/kernel/1607.2/04442.html I believe it is what we're after here. Perhaps a more optimized version would be to release only secure world resources, something like that: diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index 99698b8a3a74..00b893a51222 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -584,6 +584,15 @@ static int optee_remove(struct platform_device *pdev)
return 0;
}
+static int optee_shutdown(struct platform_device *pdev)
+{
+ struct optee *optee = platform_get_drvdata(pdev);
+
+ optee_disable_shm_cache(optee);
+
+ return 0;
+}
+
static int optee_probe(struct platform_device *pdev)
{
optee_invoke_fn *invoke_fn;
@@ -710,6 +719,7 @@ MODULE_DEVICE_TABLE(of, optee_dt_match);
static struct platform_driver optee_driver = {
.probe = optee_probe,
.remove = optee_remove,
+ .shutdown = optee_shutdown,
.driver = {
.name = "optee",
.of_match_table = optee_dt_match, |
Great comments @jforissier and some good lkml conversation there. Things seem to have moved on considerably since then, and optee module is no longer a platform module with a The init and exit functions are registered with I guess the the rmmod shutdown path naturally requires that all device instances are already closed and so the exit function is sufficient. So after a few hours, I can't find any way or anywhere even to link in No doubt the |
What is your reference? The patches I have proposed are based on upstream master (v5.8-rc2-64-g8be3a53e18e0). |
Thanks for the correction. I'm using a 4.14 marvell branch. elixir.bootlin.com doesn't go beyond 5.7 right now which explains why I couldn't find anything that looked like yours. |
No, you did not look closely enough instead ;-) |
How right you are! Nothing I said appears to have been reliable. I'll slink away in shame. I can't trust myself to safely work out what could have been going through my mind. thanks for being nice about it |
@samliddicott haha don't be too hard on yourself! ;-) Anyway, If something needs to be fixed in the OP-TEE driver for kexec support, it should preferably go to the LKML directly. Thanks. |
@jforissier Would like to know if you have plans to push the optimized optee_shutdown() to LKML? |
This patch does appear to solve our issues. |
@jforissier I am not sure whether you have seen my previous message. |
@bgooty sorry for the late reply :-/ |
|
@bgooty hey - I don't see the patch submission on LKML or the optee list archives so I wanted to give you a poke. Please cc me (Tyler Hicks tyhicks@linux.microsoft.com) on your submission and I'll give it a review. Thanks! |
Sorry, adding optee_shutdown() does not fix the issue. |
@bgooty Is an alternate fix in the works considering optee_shutdown() did not solve the problem. Thanks. |
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Signed-off-by: Allen Pais <apais@linux.microsoft.com>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Signed-off-by: Allen Pais <apais@linux.microsoft.com>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com>
A fix for this and other kexec/kdump related issues with OP-TEE is available here: https://lore.kernel.org/lkml/20210614223317.999867-1-tyhicks@linux.microsoft.com/ |
@tyhicks thanks for the update. I intend to apply the series onto linaro-swg/linux branch optee as soon as it reaches mainline. |
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
I created linaro-swg/linux#94 to get some more automated testing of these patches. |
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
commit f25889f upstream. The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
commit f25889f upstream. The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
BugLink: https://bugs.launchpad.net/bugs/1942123 commit f25889f upstream. The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
stable inclusion from stable-5.10.58 commit 2a879ff9719fdb75bdedfca029a381105aea6d72 bugzilla: 176984 https://gitee.com/openeuler/kernel/issues/I4E2P4 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2a879ff9719fdb75bdedfca029a381105aea6d72 -------------------------------- commit f25889f upstream. The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Chen Jun <chenjun102@huawei.com> Acked-by: Weilong Chen <chenweilong@huawei.com> Signed-off-by: Chen Jun <chenjun102@huawei.com> Signed-off-by: Zheng Zengkai <zhengzengkai@huawei.com>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
The following out of memory errors are seen on kexec reboot from the optee core. [ 0.368428] tee_bnxt_fw optee-clnt0: tee_shm_alloc failed [ 0.368461] tee_bnxt_fw: probe of optee-clnt0 failed with error -22 tee_shm_release() is not invoked on dma shm buffer. Implement .shutdown() method to handle the release of the buffers correctly. More info: OP-TEE/optee_os#3637 Cc: stable@vger.kernel.org Signed-off-by: Allen Pais <apais@linux.microsoft.com> Reviewed-by: Tyler Hicks <tyhicks@linux.microsoft.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Problem Description
Case A
If tee_shm_free() is called in shutdown() of Linux tee_client_driver and kexec kernel is booted, shutdown() & tee_shm_free() are invoked but tee_shm_release() is not invoked on DMA SHM buffer.
Case B
If tee_shm_free() is called on SHM DMA buffer previously allocated from rmmod path[module_exit()]
It unregisters the SHM memory and sends OPTEE_MSG_CMD_UNREGISTER_SHM to optee_os through optee_shm_unregister().
Call Sequence
Case A: kexec path
.shutdown()-->tee_shm_free()-->dma_buf_put()
Case B: rmmod path
.shutdown()-->tee_shm_free()-->dma_buf_put()()-->tee_shm_release()-->optee_shm_unregister()
-->optee_do_call_with_arg() [cmd = OPTEE_MSG_CMD_UNREGISTER_SHM]
Repercussions of the issue: xtest failure due to out of memory
If we register a big buffer of say 8MB in Linux tee client driver, if the same memory is not unregistered, it can cause overhead of 210248 = 16KB memory overhead for shm page book keeping data structures calloc'd in optee_os. After kexec it causes 16 +16=32KB which significant memory on a minimal heap of size, say 64KB. This causes failures with asymmetric crypto operations of xtest due to out of memory error.
Context
In Linux kernel tee_client_driver probe() we 're calling tee_shm_alloc() with flags=TEE_SHM_MAPPED | TEE_SHM_DMA_BUF
In remove() & shutdown() functions of the driver: we 're calling tee_shm_free() on shm reference allocated in probe.
The text was updated successfully, but these errors were encountered: