Skip to content

Commit 1bdc8f2

Browse files
etienne-lmsjforissier
authored andcommitted
tee: optee: system thread call property
Adds an argument to do_call_with_arg() handler to tell whether the call is a system thread call or nor. This change always sets this info to false hence no functional change. This change prepares management of system invocation proposed in a later change. Reviewed-by: Sumit Garg <[email protected]> Co-developed-by: Jens Wiklander <[email protected]> Signed-off-by: Etienne Carriere <[email protected]> [jw: clarified that it's system thread calls] Signed-off-by: Jens Wiklander <[email protected]>
1 parent 31efef6 commit 1bdc8f2

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

drivers/tee/optee/call.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct optee_shm_arg_entry {
4040
};
4141

4242
void optee_cq_wait_init(struct optee_call_queue *cq,
43-
struct optee_call_waiter *w)
43+
struct optee_call_waiter *w, bool sys_thread)
4444
{
4545
/*
4646
* We're preparing to make a call to secure world. In case we can't
@@ -328,7 +328,8 @@ int optee_open_session(struct tee_context *ctx,
328328
goto out;
329329
}
330330

331-
if (optee->ops->do_call_with_arg(ctx, shm, offs)) {
331+
if (optee->ops->do_call_with_arg(ctx, shm, offs,
332+
sess->use_sys_thread)) {
332333
msg_arg->ret = TEEC_ERROR_COMMUNICATION;
333334
msg_arg->ret_origin = TEEC_ORIGIN_COMMS;
334335
}
@@ -360,7 +361,8 @@ int optee_open_session(struct tee_context *ctx,
360361
return rc;
361362
}
362363

363-
int optee_close_session_helper(struct tee_context *ctx, u32 session)
364+
int optee_close_session_helper(struct tee_context *ctx, u32 session,
365+
bool system_thread)
364366
{
365367
struct optee *optee = tee_get_drvdata(ctx->teedev);
366368
struct optee_shm_arg_entry *entry;
@@ -374,7 +376,7 @@ int optee_close_session_helper(struct tee_context *ctx, u32 session)
374376

375377
msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION;
376378
msg_arg->session = session;
377-
optee->ops->do_call_with_arg(ctx, shm, offs);
379+
optee->ops->do_call_with_arg(ctx, shm, offs, system_thread);
378380

379381
optee_free_msg_arg(ctx, entry, offs);
380382

@@ -385,6 +387,7 @@ int optee_close_session(struct tee_context *ctx, u32 session)
385387
{
386388
struct optee_context_data *ctxdata = ctx->data;
387389
struct optee_session *sess;
390+
bool system_thread;
388391

389392
/* Check that the session is valid and remove it from the list */
390393
mutex_lock(&ctxdata->mutex);
@@ -394,9 +397,10 @@ int optee_close_session(struct tee_context *ctx, u32 session)
394397
mutex_unlock(&ctxdata->mutex);
395398
if (!sess)
396399
return -EINVAL;
400+
system_thread = sess->use_sys_thread;
397401
kfree(sess);
398402

399-
return optee_close_session_helper(ctx, session);
403+
return optee_close_session_helper(ctx, session, system_thread);
400404
}
401405

402406
int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
@@ -408,12 +412,15 @@ int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
408412
struct optee_msg_arg *msg_arg;
409413
struct optee_session *sess;
410414
struct tee_shm *shm;
415+
bool system_thread;
411416
u_int offs;
412417
int rc;
413418

414419
/* Check that the session is valid */
415420
mutex_lock(&ctxdata->mutex);
416421
sess = find_session(ctxdata, arg->session);
422+
if (sess)
423+
system_thread = sess->use_sys_thread;
417424
mutex_unlock(&ctxdata->mutex);
418425
if (!sess)
419426
return -EINVAL;
@@ -432,7 +439,7 @@ int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
432439
if (rc)
433440
goto out;
434441

435-
if (optee->ops->do_call_with_arg(ctx, shm, offs)) {
442+
if (optee->ops->do_call_with_arg(ctx, shm, offs, system_thread)) {
436443
msg_arg->ret = TEEC_ERROR_COMMUNICATION;
437444
msg_arg->ret_origin = TEEC_ORIGIN_COMMS;
438445
}
@@ -457,12 +464,15 @@ int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session)
457464
struct optee_shm_arg_entry *entry;
458465
struct optee_msg_arg *msg_arg;
459466
struct optee_session *sess;
467+
bool system_thread;
460468
struct tee_shm *shm;
461469
u_int offs;
462470

463471
/* Check that the session is valid */
464472
mutex_lock(&ctxdata->mutex);
465473
sess = find_session(ctxdata, session);
474+
if (sess)
475+
system_thread = sess->use_sys_thread;
466476
mutex_unlock(&ctxdata->mutex);
467477
if (!sess)
468478
return -EINVAL;
@@ -474,7 +484,7 @@ int optee_cancel_req(struct tee_context *ctx, u32 cancel_id, u32 session)
474484
msg_arg->cmd = OPTEE_MSG_CMD_CANCEL;
475485
msg_arg->session = session;
476486
msg_arg->cancel_id = cancel_id;
477-
optee->ops->do_call_with_arg(ctx, shm, offs);
487+
optee->ops->do_call_with_arg(ctx, shm, offs, system_thread);
478488

479489
optee_free_msg_arg(ctx, entry, offs);
480490
return 0;

drivers/tee/optee/core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ int optee_open(struct tee_context *ctx, bool cap_memref_null)
129129

130130
static void optee_release_helper(struct tee_context *ctx,
131131
int (*close_session)(struct tee_context *ctx,
132-
u32 session))
132+
u32 session,
133+
bool system_thread))
133134
{
134135
struct optee_context_data *ctxdata = ctx->data;
135136
struct optee_session *sess;
@@ -141,7 +142,7 @@ static void optee_release_helper(struct tee_context *ctx,
141142
list_for_each_entry_safe(sess, sess_tmp, &ctxdata->sess_list,
142143
list_node) {
143144
list_del(&sess->list_node);
144-
close_session(ctx, sess->session_id);
145+
close_session(ctx, sess->session_id, sess->use_sys_thread);
145146
kfree(sess);
146147
}
147148
kfree(ctxdata);

drivers/tee/optee/ffa_abi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ static void optee_handle_ffa_rpc(struct tee_context *ctx, struct optee *optee,
528528

529529
static int optee_ffa_yielding_call(struct tee_context *ctx,
530530
struct ffa_send_direct_data *data,
531-
struct optee_msg_arg *rpc_arg)
531+
struct optee_msg_arg *rpc_arg,
532+
bool system_thread)
532533
{
533534
struct optee *optee = tee_get_drvdata(ctx->teedev);
534535
struct ffa_device *ffa_dev = optee->ffa.ffa_dev;
@@ -541,7 +542,7 @@ static int optee_ffa_yielding_call(struct tee_context *ctx,
541542
int rc;
542543

543544
/* Initialize waiter */
544-
optee_cq_wait_init(&optee->call_queue, &w);
545+
optee_cq_wait_init(&optee->call_queue, &w, system_thread);
545546
while (true) {
546547
rc = msg_ops->sync_send_receive(ffa_dev, data);
547548
if (rc)
@@ -612,7 +613,8 @@ static int optee_ffa_yielding_call(struct tee_context *ctx,
612613
*/
613614

614615
static int optee_ffa_do_call_with_arg(struct tee_context *ctx,
615-
struct tee_shm *shm, u_int offs)
616+
struct tee_shm *shm, u_int offs,
617+
bool system_thread)
616618
{
617619
struct ffa_send_direct_data data = {
618620
.data0 = OPTEE_FFA_YIELDING_CALL_WITH_ARG,
@@ -642,7 +644,7 @@ static int optee_ffa_do_call_with_arg(struct tee_context *ctx,
642644
if (IS_ERR(rpc_arg))
643645
return PTR_ERR(rpc_arg);
644646

645-
return optee_ffa_yielding_call(ctx, &data, rpc_arg);
647+
return optee_ffa_yielding_call(ctx, &data, rpc_arg, system_thread);
646648
}
647649

648650
/*

drivers/tee/optee/optee_private.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ struct optee;
130130
*/
131131
struct optee_ops {
132132
int (*do_call_with_arg)(struct tee_context *ctx,
133-
struct tee_shm *shm_arg, u_int offs);
133+
struct tee_shm *shm_arg, u_int offs,
134+
bool system_thread);
134135
int (*to_msg_param)(struct optee *optee,
135136
struct optee_msg_param *msg_params,
136137
size_t num_params, const struct tee_param *params);
@@ -180,6 +181,7 @@ struct optee {
180181
struct optee_session {
181182
struct list_head list_node;
182183
u32 session_id;
184+
bool use_sys_thread;
183185
};
184186

185187
struct optee_context_data {
@@ -228,7 +230,8 @@ int optee_supp_send(struct tee_context *ctx, u32 ret, u32 num_params,
228230
int optee_open_session(struct tee_context *ctx,
229231
struct tee_ioctl_open_session_arg *arg,
230232
struct tee_param *param);
231-
int optee_close_session_helper(struct tee_context *ctx, u32 session);
233+
int optee_close_session_helper(struct tee_context *ctx, u32 session,
234+
bool system_thread);
232235
int optee_close_session(struct tee_context *ctx, u32 session);
233236
int optee_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg,
234237
struct tee_param *param);
@@ -277,7 +280,7 @@ static inline void optee_to_msg_param_value(struct optee_msg_param *mp,
277280
}
278281

279282
void optee_cq_wait_init(struct optee_call_queue *cq,
280-
struct optee_call_waiter *w);
283+
struct optee_call_waiter *w, bool sys_thread);
281284
void optee_cq_wait_for_completion(struct optee_call_queue *cq,
282285
struct optee_call_waiter *w);
283286
void optee_cq_wait_final(struct optee_call_queue *cq,

drivers/tee/optee/smc_abi.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static void optee_enable_shm_cache(struct optee *optee)
263263
struct optee_call_waiter w;
264264

265265
/* We need to retry until secure world isn't busy. */
266-
optee_cq_wait_init(&optee->call_queue, &w);
266+
optee_cq_wait_init(&optee->call_queue, &w, false);
267267
while (true) {
268268
struct arm_smccc_res res;
269269

@@ -288,7 +288,7 @@ static void __optee_disable_shm_cache(struct optee *optee, bool is_mapped)
288288
struct optee_call_waiter w;
289289

290290
/* We need to retry until secure world isn't busy. */
291-
optee_cq_wait_init(&optee->call_queue, &w);
291+
optee_cq_wait_init(&optee->call_queue, &w, false);
292292
while (true) {
293293
union {
294294
struct arm_smccc_res smccc;
@@ -487,7 +487,7 @@ static int optee_shm_register(struct tee_context *ctx, struct tee_shm *shm,
487487
msg_arg->params->u.tmem.buf_ptr = virt_to_phys(pages_list) |
488488
(tee_shm_get_page_offset(shm) & (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1));
489489

490-
if (optee->ops->do_call_with_arg(ctx, shm_arg, 0) ||
490+
if (optee->ops->do_call_with_arg(ctx, shm_arg, 0, false) ||
491491
msg_arg->ret != TEEC_SUCCESS)
492492
rc = -EINVAL;
493493

@@ -530,7 +530,7 @@ static int optee_shm_unregister(struct tee_context *ctx, struct tee_shm *shm)
530530
msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT;
531531
msg_arg->params[0].u.rmem.shm_ref = (unsigned long)shm;
532532

533-
if (optee->ops->do_call_with_arg(ctx, shm_arg, 0) ||
533+
if (optee->ops->do_call_with_arg(ctx, shm_arg, 0, false) ||
534534
msg_arg->ret != TEEC_SUCCESS)
535535
rc = -EINVAL;
536536
out:
@@ -865,7 +865,8 @@ static void optee_handle_rpc(struct tee_context *ctx,
865865
* Returns return code from secure world, 0 is OK
866866
*/
867867
static int optee_smc_do_call_with_arg(struct tee_context *ctx,
868-
struct tee_shm *shm, u_int offs)
868+
struct tee_shm *shm, u_int offs,
869+
bool system_thread)
869870
{
870871
struct optee *optee = tee_get_drvdata(ctx->teedev);
871872
struct optee_call_waiter w;
@@ -906,7 +907,7 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx,
906907
reg_pair_from_64(&param.a1, &param.a2, parg);
907908
}
908909
/* Initialize waiter */
909-
optee_cq_wait_init(&optee->call_queue, &w);
910+
optee_cq_wait_init(&optee->call_queue, &w, system_thread);
910911
while (true) {
911912
struct arm_smccc_res res;
912913

@@ -957,7 +958,7 @@ static int simple_call_with_arg(struct tee_context *ctx, u32 cmd)
957958
return PTR_ERR(msg_arg);
958959

959960
msg_arg->cmd = cmd;
960-
optee_smc_do_call_with_arg(ctx, shm, offs);
961+
optee_smc_do_call_with_arg(ctx, shm, offs, false);
961962

962963
optee_free_msg_arg(ctx, entry, offs);
963964
return 0;

0 commit comments

Comments
 (0)