This flag indicates that requests in this context should not wait for tee-supplicant daemon to be started if not present and just return with an error code. It is needed for requests which should be non-blocking in nature like ones arising from TEE based kernel drivers or any in kernel api that uses TEE internal client interface.
Unified · Split
| @@ -88,10 +88,18 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, · 87 unmodified lines | ||
| 88 | 88 | { |
| 89 | 89 | struct optee *optee = tee_get_drvdata(ctx->teedev); |
| 90 | 90 | struct optee_supp *supp = &optee->supp; |
| 91 | − struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL); | |
| 91 | + struct optee_supp_req *req; | |
| 92 | 92 | bool interruptable; |
| 93 | 93 | u32 ret; |
| 94 | 94 | |
| 95 | + /* | |
| 96 | + * Return in case there is no supplicant available and | |
| 97 | + * non-blocking request. | |
| 98 | + */ | |
| 99 | + if (!supp->ctx && ctx->supp_nowait) | |
| 100 | + return TEEC_ERROR_COMMUNICATION; | |
| 101 | + | |
| 102 | + req = kzalloc(sizeof(*req), GFP_KERNEL); | |
| 95 | 103 | if (!req) |
| 96 | 104 | return TEEC_ERROR_OUT_OF_MEMORY; |
| 97 | 105 | |
| @@ -106,6 +106,11 @@ static int tee_open(struct inode *inode, struct file *filp) · 105 unmodified lines | ||
| 106 | 106 | if (IS_ERR(ctx)) |
| 107 | 107 | return PTR_ERR(ctx); |
| 108 | 108 | |
| 109 | + /* | |
| 110 | + * Default user-space behaviour is to wait for tee-supplicant | |
| 111 | + * if not present for any requests in this context. | |
| 112 | + */ | |
| 113 | + ctx->supp_nowait = false; | |
| 109 | 114 | filp->private_data = ctx; |
| 110 | 115 | return 0; |
| 111 | 116 | } |
| @@ -982,6 +987,14 @@ tee_client_open_context(struct tee_context *start, · 870 unmodified lines | ||
| 982 | 987 | } while (IS_ERR(ctx) && PTR_ERR(ctx) != -ENOMEM); |
| 983 | 988 | |
| 984 | 989 | put_device(put_dev); |
| 990 | + /* | |
| 991 | + * Default behaviour for in kernel client is to not wait for | |
| 992 | + * tee-supplicant if not present for any requests in this context. | |
| 993 | + * Also this flag could be configured again before call to | |
| 994 | + * tee_client_open_session() if any in kernel client requires | |
| 995 | + * different behaviour. | |
| 996 | + */ | |
| 997 | + ctx->supp_nowait = true; | |
| 985 | 998 | return ctx; |
| 986 | 999 | } |
| 987 | 1000 | EXPORT_SYMBOL_GPL(tee_client_open_context); |
| @@ -47,6 +47,11 @@ struct tee_shm_pool; · 46 unmodified lines | ||
| 47 | 47 | * @releasing: flag that indicates if context is being released right now. |
| 48 | 48 | * It is needed to break circular dependency on context during |
| 49 | 49 | * shared memory release. |
| 50 | + * @supp_nowait: flag that indicates that requests in this context should not | |
| 51 | + * wait for tee-supplicant daemon to be started if not present | |
| 52 | + * and just return with an error code. It is needed for requests | |
| 53 | + * that arises from TEE based kernel drivers that should be | |
| 54 | + * non-blocking in nature. | |
| 50 | 55 | */ |
| 51 | 56 | struct tee_context { |
| 52 | 57 | struct tee_device *teedev; |
| @@ -54,6 +59,7 @@ struct tee_context { · 1 unmodified line | ||
| 54 | 59 | void *data; |
| 55 | 60 | struct kref refcount; |
| 56 | 61 | bool releasing; |
| 62 | + bool supp_nowait; | |
| 57 | 63 | }; |
| 58 | 64 | |
| 59 | 65 | struct tee_param_memref { |