From patchwork Fri May 5 17:30:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 13232881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18B42C7EE22 for ; Fri, 5 May 2023 17:32:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6TlLdJsy2H7wlT22WGqvqEc5POYp+O+gHMVuO/jEdmw=; b=zXjGph/VT8DXuc 8pWYk0Yna0GnzCTOxN80eUN9+6AARUc/l+iuOrGnmbIlW3v6ZW01FYF29HjiXETPChW86aHRCEuIG HuhvgFtxiXx3QXipoq18F+nVTokUBcB5oqh2q0C7o9uyT7xFqizv+N2VlknXOEM9oy/Ab04wbCIfU K0zPTlyhQrIzpXeJUOEBOABepHS2/gIJ1ZMW3iaosK/1pge52rCPEvd33c5SPcbJAI0HzrMfGoc+L 0OQDlxH78Cl8fTOWMiaqSRY96Zl7pRa69NHpPQp9tRMtgk0vfC0LBWnSBwyKR01kaTul0nHIF5c3f eJoxsCk+2/udSNQjV1vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1puzH7-00BPdB-0f; Fri, 05 May 2023 17:31:21 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1puzH1-00BPbW-1r for linux-arm-kernel@lists.infradead.org; Fri, 05 May 2023 17:31:17 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-2fa47de5b04so1979342f8f.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=HcorjZhjfK5CutUAmDnrrj8M8W8y+H9rqUA7PR9LBM/RFGlJoGFrJ8ZebJbfKfuCb8 PbwXHa+o+lHUyc/prENbK3zmTt86La889jO0ii9W0iGs2TvdP7SzvV+RjrMcWFqXL3uZ RW/SzNwH/sCclQPGw2KwiRaztaOIk+G+e43TxYYNP3avr9PF5bFVwzVIkfNqw1N8XYQE 1seCyAebkkF5+nBedjiTyYtSe7oSeKpoGW/YfTpQWiojSMh1BxfFl+KIjuUqLR+PRuds iOFG4POTbtSY5jPqYR6Ua1TdbLyBX+9U5aNY7KfxNP/gpxTr57Wo9oL5sua+A14HCw3M v3dw== X-Gm-Message-State: AC+VfDyt5lrIALfXvEqY5IaadT1nVUbMx6MLf7arKH7aIT12XuvnABfT DjyVZSB1c+e3W9TNaOHXwr04eA== X-Google-Smtp-Source: ACHHUZ4AiHynWcr90fj9G0LaDmdLYO1Z3uLLHCDAx+ThHFWaLWEwf7yyEyzShXwuH8XYiG3Ot+iU3w== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230505_103115_611088_992A39EE X-CRM114-Status: GOOD ( 17.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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