From patchwork Mon Jan 21 09:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 156186 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp6167894jaa; Mon, 21 Jan 2019 01:30:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN4ALUsF917fXLT4L0BqnhpwZsEkYSNYahD+h7MGZxqRyG2lTs8Eouylv/HTyrUsf6qqy5N8 X-Received: by 2002:a17:902:6b49:: with SMTP id g9mr28909533plt.98.1548063010995; Mon, 21 Jan 2019 01:30:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548063010; cv=none; d=google.com; s=arc-20160816; b=f07sxzqduCAMsvTdnUHqHF6kk693Y0SthmjMQDxNTiXZEAnjaWSbW/6FaTYoW/p9uA +MnvYZ07/K5cJUy25tMAH89t0rhYbAfGmUAmV+vsrka9fmEKxkDdzvTBooDykdcZ5ggp tklUozNFCbtvDzk2TFxHJn5QaIKHqCqO37SZ0ijv3q/+Ha98ExFsPItX8WExo2gIahoV ji+XKrPrB/4a1OL3HqU8d2h/o+z8VcMEtTerRXFpOsdb24vWCyh7dxmvr2Pg0eWUOFon Dv4dsrAsG53H/3YKnGMAxakwrYGUiUFeTBJuHuSPuYm5unAP9zocpGJxZmAwQwGIJGuc TFLw== 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=KVZe+JdIXEOq53OVAEyR9i83a9gBMP1LhsWNd9YK638=; b=we9s3AAO+DEbwJeUrH/Y1+M9q8equul05PDLfImhSFoNODbZyPumegkcSLoizjZ/ho +E6g7iJZiZPOkGmDI5UXthwePPFyunJjfHKbMyk7JujNsjAWnfUEOAX76k1+B3EU+rdF KBq4o+1emqT0kBLizcRKVekIAcoNRwmwK93AeK0TI9JsQGInp+Mqb7L/Piv2fDVCocjU II4pE2kAFkvbZ10NW0GE2tTs2Fidxbd1oG61xz56H3w83I7xOTH1rVAsj7LtX8F94R+v 0UEraVTV02ctMmz+A9Szo4x2pY19kBOP3zp4xdZKbY6DzPucwFrjt5oDnF4L0mD2KBVk WWew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Bt8zc/t0"; 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 u24si12637340pgj.489.2019.01.21.01.30.10; Mon, 21 Jan 2019 01:30:10 -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="Bt8zc/t0"; 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 S1727740AbfAUJaJ (ORCPT + 24 others); Mon, 21 Jan 2019 04:30:09 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39843 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726418AbfAUJaI (ORCPT ); Mon, 21 Jan 2019 04:30:08 -0500 Received: by mail-pg1-f194.google.com with SMTP id w6so9219788pgl.6 for ; Mon, 21 Jan 2019 01:30:08 -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=KVZe+JdIXEOq53OVAEyR9i83a9gBMP1LhsWNd9YK638=; b=Bt8zc/t0rEncfMEdzopClS60wNL6dg/68jiLQWvQvSVyqXf/yTbCxvq6JBHox1FYXx enWK7NNO+z4KeO6tGAh70/MMonVYsKehNreJak/U1sDsSw2/XY37qsCHch/zAjeP6LEV CGy1ui8bHhEqFZUFW9x8ukL+eYxR0GfQGYXHk= 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=KVZe+JdIXEOq53OVAEyR9i83a9gBMP1LhsWNd9YK638=; b=dy37xW3vob+ZMnOoNOcT/IJ/tDGxwF/60yMaY3QV4dCVCcsaQmLjXlu0m1rWxsyZqL Rxu3GattIXheL4+lMeaiYU57uctEUa2NbweXOZ5KY6gIpryhtICXQE0o0kSzQjbLoJXj fsoZuWTJfoX2S8RjG3VvH6KQ4eFQiwoBsa1W9wD8EM8oYkz9AK/xUvViSX9NmnlYyEj/ hy/lqUMPdxZRzIgqP2jNCZEcvLPxXF6DigegClDVf8kLZnnN9L7DeQ3wlYScWx6Pt0iv 3d3aH++B5smxVKYvIp5MuXVrWzfpgMFpV1ynJUJJlO1NE5TNjRrtg+Rxv/Gys5MNPd1M 9fKg== X-Gm-Message-State: AJcUukes7hSPK4AksRQMA8jzrysSfMlW/zHJJY0eCGqnQThv9lgn1k4G +UrVPnxyFzV95Hd+/EkeuIYh8A== X-Received: by 2002:a62:8949:: with SMTP id v70mr28459427pfd.85.1548063007852; Mon, 21 Jan 2019 01:30:07 -0800 (PST) Received: from localhost.localdomain ([117.252.65.115]) by smtp.gmail.com with ESMTPSA id h9sm16182777pgd.53.2019.01.21.01.30.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jan 2019 01:30:07 -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, 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 v4 2/4] tee: add supp_nowait flag in tee_context struct Date: Mon, 21 Jan 2019 14:59:17 +0530 Message-Id: <1548062959-31860-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548062959-31860-1-git-send-email-sumit.garg@linaro.org> References: <1548062959-31860-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 --- 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(-) -- 2.7.4 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 55370d5..56222ea 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 ba985d8..a44374a 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -49,6 +49,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; @@ -56,6 +61,7 @@ struct tee_context { void *data; struct kref refcount; bool releasing; + bool supp_nowait; }; struct tee_param_memref {