Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1221461rwr; Fri, 5 May 2023 10:44:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NGmqfayabQ0kvfLRMnwbOwoxzT7nnlySd7FWuYAuHd2G+MYyZAMWewwuaSE8iN4swnSdG X-Received: by 2002:a17:90a:8c17:b0:24d:f3cc:7d34 with SMTP id a23-20020a17090a8c1700b0024df3cc7d34mr2194503pjo.32.1683308689496; Fri, 05 May 2023 10:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683308689; cv=none; d=google.com; s=arc-20160816; b=MK9HCq2dC+fCCrFOHcwTPm2+ZLeUsWLkcaiva2O7O6y0yK29E4XOowzPv0yZp5Jor3 fVvqBvKusERBsq2Z1xBKizUFGShPs5Ztj06kMgj+COtQcuVkF8N0+fOTcWAayNaD+dMu +1hdLxGtykE9lT7rLhRk5LY3Zdyd8qVfPK9M4jK2X92CL0HVzGC+/TqLvh8x87I6aPJl e8++adC61uxEQP/4hwVxhhfK+gqjoo3x98M+3eZhnS/U3z/wYmfOOrJTmPOyp4UBXBPQ oab08CxxktEPWqP1m5nHhCiDB7kxow2ml6NHAspiDPxSO3IuLAYesaFgDArExUu3PxLB 77xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ri6iJ92LeYdJs5/THZ1fw9VQsDiZwy6weBjtBqhDElM=; b=j/LecWiBzOc0iTFJOiD98Gm1hht4tMXgiYWZ3+QfYH2kHcgfPBwmDBisGCXWvBM9ju H7EXSJcv+80S6szrL1pLwwhPHTfB2Id+Bhs+0Op+ewRgEif6rmR9buvjSuA5zLQpMn9O 58hFrX5bSc294ZdAgmmWqi+RISSY/dFcIuGw1OI/LVM9LBcACwLa2Bt2YEUbtMlUkZ3k FUyrtqlSoawUM4mVrA4xVAfgOR2qAE/FCE1XFLQdKFKbqoyC51ysqF7jlqVh3dkmUb8t M22Ro+FN633ZrCUWYCE+Y/xAZL1DcFfEMPis81W8Clp3GoK9SWxBSrw+tuwYYlNUFqTl 8WrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="e/Fk8gPM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 26-20020a17090a031a00b002501961f6ccsi3183918pje.114.2023.05.05.10.44.35; Fri, 05 May 2023 10:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="e/Fk8gPM"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S232195AbjEERbY (ORCPT + 99 others); Fri, 5 May 2023 13:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232160AbjEERbP (ORCPT ); Fri, 5 May 2023 13:31:15 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8471A1C3 for ; Fri, 5 May 2023 10:31:13 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f37a36b713so21034345e9.1 for ; Fri, 05 May 2023 10:31:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683307872; x=1685899872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ri6iJ92LeYdJs5/THZ1fw9VQsDiZwy6weBjtBqhDElM=; b=e/Fk8gPMbcB+MxQMeKYVPMRCTUJ/WOxY72GCP84IThARcITx3T1oUCJ6Vf1Q/D5mGi AW+c795Dti3cZDb6qsWk9SzgK5HZWnkEJgh3y3uq9GGaDNw23drxXreJjlD4/20O4KbK QKXVSNWuy1MaC9k47ERw+18ZQ/8fD3BStpSH0Dsxr/MMPDpduFAB8Bp9HsLHhNd/Hkzs VnJbLoMFgA3/lsTVHzc6LmFmtuJKjeYn9K1Tb7M9jloKZ+R8gkES9PUZRC2TAlo3OAIl gXjDmZ0rSvCOF4nH39LYiC5ktlnWCe4jTZrRPe1jkfunsia9ZQ7aqePGiMSDb8WCNgQ2 pYBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683307872; x=1685899872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ri6iJ92LeYdJs5/THZ1fw9VQsDiZwy6weBjtBqhDElM=; b=SOC8Sn8HTu8FUbgenastyZnR6xaHcp82pOhJDnWb9FQDywF2Til9SkBuDedglyrc+2 gPfV/WceDTn8Qm9Guv03v2gF+n49l0ymfI1p9H00hzLPzSdZshIm+sGcZNCFJsUnH/G9 7w+PjPZwcubqetqmlQWYDKWhcAwvYH71/6PXTTOYunwxaUSfcTbz9xJoeR0T3ci2JMmZ vFpFigdTByvpFazXCaLGiRWdjNMv3NZdzRlWcE2LzWivRf+KCee1K2HjIRn+bX6NJieA d5FfHQHBpmtpbf2Y7/T1cZgjobir5rKrVm6bpkBKkHJr5SkYyYKkCV2M8vL/PsownxIg NmBQ== X-Gm-Message-State: AC+VfDxWP3UlNQML0B59qSXcyVKdchu5L5qsIc4KaLzLRkrwfPcCXOGp Y2x6EN6T26HuKkcMU5dmD31y7dHp1IqFE1i4nWQ= X-Received: by 2002:adf:f790:0:b0:2f2:7a0e:5cc9 with SMTP id q16-20020adff790000000b002f27a0e5cc9mr1771748wrp.19.1683307871844; Fri, 05 May 2023 10:31:11 -0700 (PDT) Received: from lmecxl1178.lme.st.com (lfbn-nan-1-1169-52.w86-212.abo.wanadoo.fr. [86.212.112.52]) by smtp.gmail.com with ESMTPSA id a15-20020adff7cf000000b002f6176cc6desm2971170wrq.110.2023.05.05.10.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 10:31:11 -0700 (PDT) From: Etienne Carriere To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org, Sumit Garg , Jens Wiklander , Sudeep Holla , Cristian Marussi , Etienne Carriere Subject: [PATCH v6 2/4] tee: system session Date: Fri, 5 May 2023 19:30:10 +0200 Message-Id: <20230505173012.881083-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230505173012.881083-1-etienne.carriere@linaro.org> References: <20230505173012.881083-1-etienne.carriere@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adds kernel client API function tee_client_system_session() for a client to request a system service entry in TEE context. This feature is needed to prevent a system deadlock when several TEE client applications invoke TEE, consuming all TEE thread contexts available in the secure world. The deadlock can happen in the OP-TEE driver for example if all these TEE threads issue an RPC call from TEE to Linux OS to access an eMMC RPMB partition (TEE secure storage) which device clock or regulator controller is accessed through an OP-TEE SCMI services. In that case, Linux SCMI driver must reach OP-TEE SCMI service without waiting one of the consumed TEE thread is freed. Co-developed-by: Jens Wiklander Signed-off-by: Jens Wiklander Signed-off-by: Etienne Carriere --- No change since v5 Changes since v4: - Changes extracted from "[PATCH v4 1/2] tee: system invocation" and revised with Jens contribution to cover only definition of tee driver new API function tee_client_system_session() for kernel clients to register their session as a system session. - Commit message rephrased, including header line changed from "tee: system invocation" to "tee: system session" has the feature relates to system attributes of tee sessions. Changes since v3: - Fixed new SMC funcIDs to reserved/unreserve OP-TEE thread contexts: minor renaming + define as fastcall funcIDs. - Moved system_ctx_count from generic struct tee_context to optee's private struct optee_context_data. This changes optee smc_abi.c to release reserved thread contexts when the optee device is released. - Fixed inline description comments. No change since v2 Change since v1 - Addressed comment on Linux client to claim reservation on TEE context. This brings 2 new operations from client to TEE to request and release system thread contexts: 2 new tee_drv.h API functions, 2 new ops functions in struct tee_driver_ops. The OP-TEE implement shall implement 2 new fastcall SMC funcIDs. - Fixed typos in commit message. --- drivers/tee/tee_core.c | 8 ++++++++ include/linux/tee_drv.h | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 0eb342de0b00..91932835d0f7 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -1170,6 +1170,14 @@ int tee_client_close_session(struct tee_context *ctx, u32 session) } EXPORT_SYMBOL_GPL(tee_client_close_session); +int tee_client_system_session(struct tee_context *ctx, u32 session) +{ + if (!ctx->teedev->desc->ops->system_session) + return -EINVAL; + return ctx->teedev->desc->ops->system_session(ctx, session); +} +EXPORT_SYMBOL_GPL(tee_client_system_session); + int tee_client_invoke_func(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg, struct tee_param *param) diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 17eb1c5205d3..911ddf92dcee 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -84,6 +84,7 @@ struct tee_param { * @release: release this open file * @open_session: open a new session * @close_session: close a session + * @system_session: declare session as a system session * @invoke_func: invoke a trusted function * @cancel_req: request cancel of an ongoing invoke or open * @supp_recv: called for supplicant to get a command @@ -100,6 +101,7 @@ struct tee_driver_ops { struct tee_ioctl_open_session_arg *arg, struct tee_param *param); int (*close_session)(struct tee_context *ctx, u32 session); + int (*system_session)(struct tee_context *ctx, u32 session); int (*invoke_func)(struct tee_context *ctx, struct tee_ioctl_invoke_arg *arg, struct tee_param *param); @@ -429,6 +431,20 @@ int tee_client_open_session(struct tee_context *ctx, */ int tee_client_close_session(struct tee_context *ctx, u32 session); +/** + * tee_client_system_session() - Declare session as a system session + * @ctx: TEE Context + * @session: Session id + * + * This function requests TEE to provision an entry context ready to use for + * that session only. The provisioned entry context is used for command + * invocation and session closure, not for command cancelling requests. + * TEE releases the provisioned context upon session closure. + * + * Return < 0 on error else 0 if an entry context has been provisioned. + */ +int tee_client_system_session(struct tee_context *ctx, u32 session); + /** * tee_client_invoke_func() - Invoke a function in a Trusted Application * @ctx: TEE Context -- 2.25.1