From 11d07e1a508bb011cbcd88312e0deeb2467ead72 Mon Sep 17 00:00:00 2001 From: Amirreza Zarrabi Date: Tue, 11 Apr 2023 20:43:16 -0700 Subject: [PATCH] securemsm-kernel: smcinvoke: Add argument to choose to retry the EBUSY The synchronous release may happen in the path of callback response. The retry may unnecessarily be resulted in callback response timeout. Run concurrently to evaluate the test: smcinvoke_vendor_client -i /data/smplap64.mbn 5 1 smcinvoke_vendor_client -c /data 1 Change-Id: Idefca46a34fd72c867e3cba616d30985af40ffe4 Signed-off-by: Amirreza Zarrabi --- smcinvoke/smcinvoke.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/smcinvoke/smcinvoke.c b/smcinvoke/smcinvoke.c index 403371a2b6..44477f6357 100644 --- a/smcinvoke/smcinvoke.c +++ b/smcinvoke/smcinvoke.c @@ -398,7 +398,7 @@ static int prepare_send_scm_msg(const uint8_t *in_buf, phys_addr_t in_paddr, struct smcinvoke_cmd_req *req, union smcinvoke_arg *args_buf, bool *tz_acked, uint32_t context_type, - struct qtee_shm *in_shm, struct qtee_shm *out_shm); + struct qtee_shm *in_shm, struct qtee_shm *out_shm, bool retry); static void process_piggyback_data(void *buf, size_t buf_size); static void add_mem_obj_info_to_async_side_channel_locked(void *buf, size_t buf_size, struct list_head *l_pending_mem_obj); @@ -572,7 +572,7 @@ static int smcinvoke_release_tz_object(struct qtee_shm *in_shm, struct qtee_shm ret = prepare_send_scm_msg(in_buf, in_shm->paddr, SMCINVOKE_TZ_MIN_BUF_SIZE, out_buf, out_shm->paddr, SMCINVOKE_TZ_MIN_BUF_SIZE, &req, NULL, - &release_handles, context_type, in_shm, out_shm); + &release_handles, context_type, in_shm, out_shm, false); process_piggyback_data(out_buf, SMCINVOKE_TZ_MIN_BUF_SIZE); if (ret) { pr_err_ratelimited("Failed to release object(0x%x), ret:%d\n", @@ -1887,7 +1887,8 @@ static int prepare_send_scm_msg(const uint8_t *in_buf, phys_addr_t in_paddr, struct smcinvoke_cmd_req *req, union smcinvoke_arg *args_buf, bool *tz_acked, uint32_t context_type, - struct qtee_shm *in_shm, struct qtee_shm *out_shm) + struct qtee_shm *in_shm, struct qtee_shm *out_shm, + bool retry) { int ret = 0, cmd, retry_count = 0; u64 response_type; @@ -1912,7 +1913,7 @@ static int prepare_send_scm_msg(const uint8_t *in_buf, phys_addr_t in_paddr, msleep(SMCINVOKE_SCM_EBUSY_WAIT_MS); } - } while ((ret == -EBUSY) && + } while (retry && (ret == -EBUSY) && (retry_count++ < SMCINVOKE_SCM_EBUSY_MAX_RETRY)); if (!ret && !is_inbound_req(response_type)) { @@ -2798,7 +2799,7 @@ static long process_invoke_req(struct file *filp, unsigned int cmd, ret = prepare_send_scm_msg(in_msg, in_shm.paddr, inmsg_size, out_msg, out_shm.paddr, outmsg_size, &req, args_buf, &tz_acked, context_type, - &in_shm, &out_shm); + &in_shm, &out_shm, true); /* * If scm_call is success, TZ owns responsibility to release