From patchwork Fri Jan 11 11:47:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 10757927 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BDF2E1390 for ; Fri, 11 Jan 2019 11:50:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB26B29263 for ; Fri, 11 Jan 2019 11:50:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F68A2987A; Fri, 11 Jan 2019 11:50:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4374329263 for ; Fri, 11 Jan 2019 11:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VFtUw6R2MY+ma01oZKZa8QEX0eXMhKkEc0nGl1BxnwU=; b=HhkoRtZ/CWuNgML1mMB0uPOdnx h0zs4Y/xVMKH4xEb8sTwCUsS4mFB4fYnwCv/Y5SgdXYKgqphOLQdQdcek2A6uC6mArCEDj1fBmmlH +2LjtgxCZdtd1PoRPnU0cv9GBfMNqid7aPAujAwVh/5/2U8h4KGLLtCN+I+fizNDkd9K+BRp+Ri08 Bg0BhYu9PRYEWu8rZ+Bjmw+kg3XSSghyp00Uc/o9XOIAEEclcuXjMoxGZd0KUNyj60xyUSczrRfXH WAm4KX3XM4JXbpQe58/a9vX98ZMg9KNzzCR7Oa68nBuWAS7FEZ9KS+P63pm/eVWyOvkU04YxUVEVo CnF/JKkw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ghvKg-0002RQ-63; Fri, 11 Jan 2019 11:50:38 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ghvKJ-0001mU-9d for linux-arm-kernel@lists.infradead.org; Fri, 11 Jan 2019 11:50:18 +0000 Received: by mail-pl1-x643.google.com with SMTP id t13so6663319ply.13 for ; Fri, 11 Jan 2019 03:50:13 -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=Zqnv4LLkDg8wPzP1MIvwucQL3XBVPPUY8eZwPtDeR+I=; b=An9XWEfxwBQmgY60VBFH2PgnzUFECLIYcdZATyaB+XWVeq82O4UE+u0WtmzHvjtUBX SB6oboCayi2YZm9mMaCL597MrPCQOht5/suCwwVcqoo0nmtxZf3dAH0FSFPBNycC0uBE Nlc7Sd+8q7bmhlSwWL7d8ia293GvGjM7JPBDE= 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=Zqnv4LLkDg8wPzP1MIvwucQL3XBVPPUY8eZwPtDeR+I=; b=qTCng8vqB/5rb9fxnIRhzrFS4bws4OBaMc5adv0AFGFkntNIEiFnKHMJC/qqcgYVM2 2AWyiMXno3fibnu9oAEbyVkwXyIkcf5pbAEwt8M7NkVyUvLmoZqn/K1iXNE7MhU/SdgO rDsqIJmR84zsBee1Z8IvFfTkEmMBtDthZGIxflkdtw7IpXQu6PoWhT1kYTYU8lfSgHMA isfP8pqMjpJzjw9N2b8cp/MXP0eaS1Z9Qj20q38lVMIWP/CDKt/QiYrdJgKYo7IBDwCW /u8xkYdk/ms+WdticAN4pSUr6KuA0gqlEX/LuhdF7U8CalSBa99pNV1CfvhXwHIZIrUl AywA== X-Gm-Message-State: AJcUukeIfW+qk2nrM79auZ8XpKlOwAuFLC4YJvJwcHeis3bHdq4Mz7tE 222M/pnUeS8Kj6nYm+G3VvojSzOjZu4= X-Google-Smtp-Source: ALg8bN5PbP61zIdl4XkV00TWsScqNY5ZDdMTwpftWQ31TuS0fr0CbHG3Bmso66LgBq2Ku3YubRieFQ== X-Received: by 2002:a17:902:6b49:: with SMTP id g9mr14099084plt.98.1547207412969; Fri, 11 Jan 2019 03:50:12 -0800 (PST) Received: from localhost.localdomain ([117.196.233.251]) by smtp.gmail.com with ESMTPSA id b2sm143199988pfm.3.2019.01.11.03.50.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 03:50:12 -0800 (PST) From: Sumit Garg To: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org Subject: [PATCH v3 2/4] tee: add supp_nowait flag in tee_context struct Date: Fri, 11 Jan 2019 17:17:29 +0530 Message-Id: <1547207251-9372-3-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1547207251-9372-1-git-send-email-sumit.garg@linaro.org> References: <1547207251-9372-1-git-send-email-sumit.garg@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190111_035015_565639_AE379A6D X-CRM114-Status: GOOD ( 16.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, Sumit Garg , daniel.thompson@linaro.org, herbert@gondor.apana.org.au, arnd@arndb.de, ard.biesheuvel@linaro.org, gregkh@linuxfoundation.org, bhsharma@redhat.com, linux-kernel@vger.kernel.org, tee-dev@lists.linaro.org, robh+dt@kernel.org, mpm@selenic.com, jens.wiklander@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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 a685940..eed83bd 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 ed16bf1..fe1a920 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 {