tee: optee: interrupt an RPC depend on shutdown flag

Change-Id: I33f33af02afb75bda5d68c9731fe636bb97132fe
Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
This commit is contained in:
Hisping Lin
2024-01-11 17:33:30 +08:00
parent 06dab2ccf7
commit b0b2892b93
3 changed files with 12 additions and 8 deletions

View File

@@ -92,6 +92,7 @@ struct optee_supp {
struct list_head reqs;
struct idr idr;
struct completion reqs_c;
bool shutdown;
};
struct optee_smc {

View File

@@ -7,6 +7,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/arm-smccc.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -1352,6 +1353,11 @@ static void optee_shutdown(struct platform_device *pdev)
{
struct optee *optee = platform_get_drvdata(pdev);
/* Tell requesting thread to interrupt an RPC */
smp_store_mb(optee->supp.shutdown, true);
/* Wait requesting thread to release resources */
mdelay(200);
if (!optee->rpc_param_count)
optee_disable_shm_cache(optee);
}

View File

@@ -82,7 +82,6 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
struct optee_supp_req *req;
bool interruptable;
u32 ret;
unsigned long timeleft;
int id;
struct optee_supp_req *get_req;
@@ -117,14 +116,12 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
* exclusive access again.
*/
while (wait_for_completion_interruptible(&req->c)) {
pr_err("Warning, Interrupting an RPC to supplicant!\n");
timeleft = wait_for_completion_timeout(&req->c, msecs_to_jiffies(2000));
if (timeleft) {
/* get completion, it means tee-supplicant is alive. */
break;
} else {
/* timeout, it means tee-supplicant is dead, interrupting an RPC. */
if (supp->shutdown) {
/* Reboot happen, tee-supplicant is dead, interrupt an RPC */
interruptable = true;
} else {
/* Deep sleep, tee-supplicant is freeze, wait tee-supplicant */
continue;
}
mutex_lock(&supp->mutex);