Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4280579imu; Mon, 28 Jan 2019 21:51:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN7Cj9eaolIZsygs3JTH2Rz7bbPx/aqH9LyDC2BSu8C4eSlQS8coB49PVo1b0/6G3Y3mlFwJ X-Received: by 2002:a62:109b:: with SMTP id 27mr24388966pfq.227.1548741063319; Mon, 28 Jan 2019 21:51:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548741063; cv=none; d=google.com; s=arc-20160816; b=vHydhRqp+7M6nQybTLS4V2FjciJshgfYJbJ5icQWmK9hIo+T3k4gmPBxTcpu3Wd60E BZnd+ejunf48o6BObbHwkUtNXDDBxbkmCjN9oWwh1sUws5sv9mgStQtYAVQTNz47RzLK SzxWg9a5hQqpQgMmL7Ehoxw88zTgw+sSa1sPNfXfRFZPGkJfzqWsRNMkbjkbDmdA7iBn RfjZjVdc7pKy677a5pDe0Fm8o/Qu5Vy4eWyosRL434zkXYTxAriU/KoUURVZczf9CTDB IFdEEzdq6tj20eODDRvxVodJyj8WbNbF5buKEvn8qnl2vhbEZWDlVNbCHbYj4cJBCiF3 VUjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=4tsUCYoQCIITudwXX50zEbDS6TS2iz02PTI9NIhLDSg=; b=PMnqZ8frPnE8VCrxgnmcrE5uqRbrqicWd5wM/RCIJuXr1EwmRUk38k+EHUb+Y6WaKK 5oFmi9ZhTnuDJaTrZhKurMWOytvg89zXEfxmUlOP48t8prZ5JkDjmpzW3R7AgWNdsktB fz/VK6fvc29vXfYs/3M551JrIkXv2NAaBCiB65/iDeA1pteVAJkOaIAIIEoAGKIgl4E+ +AMwOjEuOkUd9h9E+NleFJW4OgyAA0e/zizp3Eu4QXs9i5y6vCvfqBqXW5NZMuVntWX/ qWIIk6wkTkvn1g28z9X8cOKelD/FPAYcG833rdDZfSTcW/8SpGhUhEMNY1hsg0YOwFSE 5x7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2yTK49o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r77si3610283pfa.186.2019.01.28.21.50.48; Mon, 28 Jan 2019 21:51:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2yTK49o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727364AbfA2FuV (ORCPT + 99 others); Tue, 29 Jan 2019 00:50:21 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37281 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725767AbfA2FuU (ORCPT ); Tue, 29 Jan 2019 00:50:20 -0500 Received: by mail-pl1-f196.google.com with SMTP id b5so8877655plr.4 for ; Mon, 28 Jan 2019 21:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4tsUCYoQCIITudwXX50zEbDS6TS2iz02PTI9NIhLDSg=; b=M2yTK49o123n+gyCleT//uhWceNdbgf1/lcglQPUIKwSvTk2G2sC4WVNBtfig0q3s3 bJttwPzQCKii3dz0SYLBeAXTjNhfZcLC4aceMXniAxmlE9zHQpbo+29QEc6gHt+jo3MW UIig8KmF3EVsUT6IU+JYb5EihUwmQxesv7afs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4tsUCYoQCIITudwXX50zEbDS6TS2iz02PTI9NIhLDSg=; b=BWwSSvcryykrl131+n7nqBjeazBjGLanpVHLp3fIpxKOKyZAUdHSkJ76T9jKWPz7mS y6XEF3QzqGWOgpqCq/zOfan+hPQP9DVrSjrHWTWleP/EUfsL+DldNDbyoamdWDSuobx+ iZDJ9H7dwplo/asJipcsWzyiF10gsL7iPDUaI696jMckYParg1T2DefloK/ApDbqZi0F M4JqBA10s3nnvvuaMdXM//bFCwZEvRCeVt1t5EC3WQrZJ/+WasOnFj3yWHB63jQVfA2X N5Xy3Ewus9gqr/MrFQlNyBpgtovvUKAgEU9ko59VKYL0fErov30gn80X854e56b99FZj D3yA== X-Gm-Message-State: AJcUukerT44siCEy4EgbeBNhxrRwyXfWucx7DXFymYa9Ej8xSPw9L5nR 8x/OcSNcv2UCCCvrxWPu8Oe/Zw== X-Received: by 2002:a17:902:bf03:: with SMTP id bi3mr24741865plb.83.1548741020115; Mon, 28 Jan 2019 21:50:20 -0800 (PST) Received: from localhost.localdomain ([117.252.69.38]) by smtp.gmail.com with ESMTPSA id y12sm57379437pfk.70.2019.01.28.21.50.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 21:50:19 -0800 (PST) From: Sumit Garg To: jens.wiklander@linaro.org, herbert@gondor.apana.org.au Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, michal.lkml@markovi.net, mpm@selenic.com, robh+dt@kernel.org, mark.rutland@arm.com, arnd@arndb.de, gregkh@linuxfoundation.org, daniel.thompson@linaro.org, ard.biesheuvel@linaro.org, bhsharma@redhat.com, tee-dev@lists.linaro.org, Sumit Garg Subject: [PATCH v6 2/4] tee: add supp_nowait flag in tee_context struct Date: Tue, 29 Jan 2019 11:19:36 +0530 Message-Id: <1548740978-28495-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548740978-28495-1-git-send-email-sumit.garg@linaro.org> References: <1548740978-28495-1-git-send-email-sumit.garg@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Sumit Garg Reviewed-by: Daniel Thompson --- drivers/tee/optee/supp.c | 10 +++++++++- drivers/tee/tee_core.c | 13 +++++++++++++ include/linux/tee_drv.h | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/tee/optee/supp.c b/drivers/tee/optee/supp.c index 43626e1..92f56b8 100644 --- a/drivers/tee/optee/supp.c +++ b/drivers/tee/optee/supp.c @@ -88,10 +88,18 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params, { struct optee *optee = tee_get_drvdata(ctx->teedev); struct optee_supp *supp = &optee->supp; - struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL); + struct optee_supp_req *req; bool interruptable; u32 ret; + /* + * Return in case there is no supplicant available and + * non-blocking request. + */ + if (!supp->ctx && ctx->supp_nowait) + return TEEC_ERROR_COMMUNICATION; + + req = kzalloc(sizeof(*req), GFP_KERNEL); if (!req) return TEEC_ERROR_OUT_OF_MEMORY; diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 1e14897..25f3b9c 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -105,6 +105,11 @@ static int tee_open(struct inode *inode, struct file *filp) if (IS_ERR(ctx)) return PTR_ERR(ctx); + /* + * Default user-space behaviour is to wait for tee-supplicant + * if not present for any requests in this context. + */ + ctx->supp_nowait = false; filp->private_data = ctx; return 0; } @@ -981,6 +986,14 @@ tee_client_open_context(struct tee_context *start, } while (IS_ERR(ctx) && PTR_ERR(ctx) != -ENOMEM); put_device(put_dev); + /* + * Default behaviour for in kernel client is to not wait for + * tee-supplicant if not present for any requests in this context. + * Also this flag could be configured again before call to + * tee_client_open_session() if any in kernel client requires + * different behaviour. + */ + ctx->supp_nowait = true; return ctx; } EXPORT_SYMBOL_GPL(tee_client_open_context); diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index ce957ce..56d7f1b 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -50,6 +50,11 @@ struct tee_shm_pool; * @releasing: flag that indicates if context is being released right now. * It is needed to break circular dependency on context during * shared memory release. + * @supp_nowait: flag that 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 + * that arises from TEE based kernel drivers that should be + * non-blocking in nature. */ struct tee_context { struct tee_device *teedev; @@ -57,6 +62,7 @@ struct tee_context { void *data; struct kref refcount; bool releasing; + bool supp_nowait; }; struct tee_param_memref { -- 2.7.4