From patchwork Mon Jan 30 09:41:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 13120817 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 815F3C54EED for ; Mon, 30 Jan 2023 09:46: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: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:In-Reply-To:References: List-Owner; bh=fqnRMQRATH30/kRwoMv8tHeGERcc7nMcydsIfQXP+Uk=; b=LP4upcALzWu/BX zPkPSE3eM7cCsNjOPY/hab1Bahvv04jbQg1L5eT1o/7G1e5aT6eNak2PjFDQPxTDyuam2fOMno3I6 VMQ1DG5AZ4067cKUdCMG85cdti+rRf7uBd8DBqhCxQcUn0ML6MuarwrJKtFX9udXqzNIbCKPlYaqp nh6J1fT7D8h/pq1OJbEozA9uoJQlLNehSVaIGLhkaI10Uivk+Zqz0FZ6fhHE6WKCWxs201dK38NT5 mFmuFsFD5SMyjPDZ2uMeyU32LU16k+3KZisxGfXj4FwUbLCGVC+hvoZHx+bUdWtxJKIlS7FMNG4V3 N8vX7B3jQ/v7P87gXrrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMQhp-002wvH-Tu; Mon, 30 Jan 2023 09:44:06 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMQg2-002wZM-JU for linux-arm-kernel@lists.infradead.org; Mon, 30 Jan 2023 09:42:16 +0000 Received: by mail-wm1-x32e.google.com with SMTP id k16so7533461wms.2 for ; Mon, 30 Jan 2023 01:42:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=A/fX6lK4kyxqMY7Pp3GDtdcgmqukLTrE8ke8XBHGOTA=; b=ju53VfroPlDppWOtB93M8K7Bqn1MGhyRPaPLLDed3/0mTJGYkaXIGQhCi4OW1Aiu+n aUbvQgFJJPHorz6OJMqr6SQWxAp/BsKQFAIDwBNgcxRpJMV8gS5uceWOS9/y3nXAPidd Mjq99Er6rI67wnQvnFXercYS0fBeYVoIVO7MWtDt/6U0oyOVfQeSSg9OfVQaGqDUW8S+ hU/qtPT+St+FS9nyrHax/BnCpMKqA/oRZ9D65oIiC8dhRvvynUtUvPQ1Jx9di1ANWZTK tKnoqwL7j/T9kWZUjqeG6DA1sOYU/ZO3BuRPozQjm0KOMkyJ+hCVvqKk0wFTZBcK1ejY DY8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A/fX6lK4kyxqMY7Pp3GDtdcgmqukLTrE8ke8XBHGOTA=; b=lShdwX96bx/j/K+c+T9WLNKi6Ky9kndtsKGyxk5P6JVT0CIcL9ov9s5IbNoXZzlpSj 6t5vLL0Ko2NjjFMqh0CMgoORTFvjcRtFYEsMDE/CkRPHo4k8o3C0ETTVHrochlkldEBt /iLBvF2wUcQuqKH6dZ5WFu/ro1EoP1lD8k+vhLYmU8Sjg6BRwnKzF/lzzQiDgBSFFXX0 EBBM9dxVVZJLfY5hjqk0EpYib7m9qDMTqvf/DyN5D5esOXzZ8kRhIZip6OM9R8Vzi2mY LCNp5zFC+e6qWG7CAxpTsutVi3K62QMxac57o6aOxZRzmgixmZzD7Cf20G9ImLBa+pOH TTUw== X-Gm-Message-State: AFqh2kqXAmG5Df8rZ3cM1hFUo3LAmS5tD1hLIVREuA9D2GGKH9nccV6o rzzwYeCAiGBrMofQkqxOsIqjQA== X-Google-Smtp-Source: AMrXdXsoyDXYaQTzXXbRjiz1dXjuc9fryyMN3KlXmOeDuM3N3ggoIMP6q7ypPh6889jmSj3Pl1PXlQ== X-Received: by 2002:a05:600c:3c92:b0:3d5:365b:773e with SMTP id bg18-20020a05600c3c9200b003d5365b773emr50188850wmb.39.1675071728384; Mon, 30 Jan 2023 01:42:08 -0800 (PST) Received: from lmecxl1178.lme.st.com ([80.215.193.251]) by smtp.gmail.com with ESMTPSA id i27-20020a05600c4b1b00b003dc54d9aeeasm3865606wmp.36.2023.01.30.01.42.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 01:42:07 -0800 (PST) From: Etienne Carriere To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Jens Wiklander , Sumit Garg , Sudeep Holla , Cristian Marussi , Etienne Carriere Subject: [PATCH 1/2] tee: system invocation Date: Mon, 30 Jan 2023 10:41:56 +0100 Message-Id: <20230130094157.1082712-1-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230130_014214_674673_4D4519C4 X-CRM114-Status: GOOD ( 18.19 ) 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 TEE context flag sys_service to be enabled for invocation contexts that should used TEE provisioned system resources. OP-TEE SMC ABI entry rely this information to use a dedicated entry function to request allocation of a system thread from a dedicated system context pool. This feature is needed when a TEE invocation cannot afford to wait for a free TEE thread when all TEE threads context are used and suspended as these may be suspended waiting for a system service, as an SCMI clock or voltage regulator, to be enabled. An example is when OP-TEE invokes a Linux OS remove service (RPC) to access an eMMC RPMB partition and the eMMC device is supplied by an OP-TEE SCMI regulator. Signed-off-by: Etienne Carriere --- drivers/tee/optee/optee_smc.h | 14 +++++++++++--- drivers/tee/optee/smc_abi.c | 6 +++++- include/linux/tee_drv.h | 4 ++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/tee/optee/optee_smc.h b/drivers/tee/optee/optee_smc.h index 73b5e7760d10..7c7eedf183c5 100644 --- a/drivers/tee/optee/optee_smc.h +++ b/drivers/tee/optee/optee_smc.h @@ -108,7 +108,8 @@ struct optee_smc_call_get_os_revision_result { * Call with struct optee_msg_arg as argument * * When called with OPTEE_SMC_CALL_WITH_RPC_ARG or - * OPTEE_SMC_CALL_WITH_REGD_ARG in a0 there is one RPC struct optee_msg_arg + * OPTEE_SMC_CALL_WITH_REGD_ARG or OPTEE_SMC_FUNCID_CALL_SYSTEM_WITH_REGD_ARG + * in a0 there is one RPC struct optee_msg_arg * following after the first struct optee_msg_arg. The RPC struct * optee_msg_arg has reserved space for the number of RPC parameters as * returned by OPTEE_SMC_EXCHANGE_CAPABILITIES. @@ -130,8 +131,8 @@ struct optee_smc_call_get_os_revision_result { * a4-6 Not used * a7 Hypervisor Client ID register * - * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG: - * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG + * Call register usage, OPTEE_SMC_CALL_WITH_REGD_ARG and OPTEE_SMC_FUNCID_CALL_SYSTEM_WITH_REGD_ARG: + * a0 SMC Function ID, OPTEE_SMC_CALL_WITH_REGD_ARG or OPTEE_SMC_FUNCID_CALL_SYSTEM_WITH_REGD_ARG * a1 Upper 32 bits of a 64-bit shared memory cookie * a2 Lower 32 bits of a 64-bit shared memory cookie * a3 Offset of the struct optee_msg_arg in the shared memory with the @@ -175,6 +176,8 @@ struct optee_smc_call_get_os_revision_result { OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_RPC_ARG) #define OPTEE_SMC_CALL_WITH_REGD_ARG \ OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG) +#define OPTEE_SMC_CALL_SYSTEM_WITH_REGD_ARG \ + OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_SYSTEM_WITH_REGD_ARG) /* * Get Shared Memory Config @@ -254,6 +257,8 @@ struct optee_smc_get_shm_config_result { #define OPTEE_SMC_SEC_CAP_ASYNC_NOTIF BIT(5) /* Secure world supports pre-allocating RPC arg struct */ #define OPTEE_SMC_SEC_CAP_RPC_ARG BIT(6) +/* Secure world provisions thread for system service invocation */ +#define OPTEE_SMC_SEC_CAP_SYSTEM_THREAD BIT(7) #define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9 #define OPTEE_SMC_EXCHANGE_CAPABILITIES \ @@ -426,6 +431,9 @@ struct optee_smc_disable_shm_cache_result { /* See OPTEE_SMC_CALL_WITH_REGD_ARG above */ #define OPTEE_SMC_FUNCID_CALL_WITH_REGD_ARG 19 +/* See OPTEE_SMC_CALL_SYSTEM_WITH_REGD_ARG above */ +#define OPTEE_SMC_FUNCID_CALL_SYSTEM_WITH_REGD_ARG 20 + /* * Resume from RPC (for example after processing a foreign interrupt) * diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c index a1c1fa1a9c28..513038a138f6 100644 --- a/drivers/tee/optee/smc_abi.c +++ b/drivers/tee/optee/smc_abi.c @@ -889,7 +889,11 @@ static int optee_smc_do_call_with_arg(struct tee_context *ctx, } if (rpc_arg && tee_shm_is_dynamic(shm)) { - param.a0 = OPTEE_SMC_CALL_WITH_REGD_ARG; + if (ctx->sys_service && + (optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_SYSTEM_THREAD)) + param.a0 = OPTEE_SMC_CALL_SYSTEM_WITH_REGD_ARG; + else + param.a0 = OPTEE_SMC_CALL_WITH_REGD_ARG; reg_pair_from_64(¶m.a1, ¶m.a2, (u_long)shm); param.a3 = offs; } else { diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index 17eb1c5205d3..1ff292ba7679 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -47,6 +47,9 @@ struct tee_shm_pool; * non-blocking in nature. * @cap_memref_null: flag indicating if the TEE Client support shared * memory buffer with a NULL pointer. + * @sys_service: flag set by the TEE Client to indicate that it is part of + * a system service and that the TEE may use resources reserved + * for this. */ struct tee_context { struct tee_device *teedev; @@ -55,6 +58,7 @@ struct tee_context { bool releasing; bool supp_nowait; bool cap_memref_null; + bool sys_service; }; struct tee_param_memref { From patchwork Mon Jan 30 09:41:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Etienne Carriere X-Patchwork-Id: 13120816 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 7F6E1C54EAA for ; Mon, 30 Jan 2023 09:45:41 +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=i5iF0rIIc4X7IFQ4vFVvRCbYUBZ5P/YzLnrxpFjk6jw=; b=uw++D/rFJRSP1h YKpbHNhSeNj5pq/4D3aNGwlZueI1A8+sdNUxvAyT9X5f8owjkKeZgDagdcwMiaha/a89VExuZsesN aXkdP/BBjYGim4Eh3+njnzCR7FxKy+a67ro4tMGF5W8L8ZGj5MiYKdhEl+5rqBmMqLChPuQvwCHhK sJzYGyd2soCwaIbsKjatQP2+AEXQ2fdPxPJaojp9VBXya150QfINnFYZuMop38HAxVASQhE7Bs7s0 8reMkCRV+CKOC6nYtGhf19UUVd+BgItRiHNmGaIU7X9VOIRZE9Yo/2c37xtiuhz1kLy03Fge8f9ui JAbuzuN6REswwaBR9ROw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMQhE-002wmK-5Y; Mon, 30 Jan 2023 09:43:28 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pMQg2-002wZg-T7 for linux-arm-kernel@lists.infradead.org; Mon, 30 Jan 2023 09:42:16 +0000 Received: by mail-wm1-x32a.google.com with SMTP id m5-20020a05600c4f4500b003db03b2559eso7673781wmq.5 for ; Mon, 30 Jan 2023 01:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; 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=0t96y3FkXLiiInAiF7GMyUM6Gu9zpGQXe2nbijo00u8=; b=ybsShXm5tTFAPukgpSLb+cbxoAvhAgJCNnyXmTkKCJ37DAqqHf/XjSI0FbLgeK12w6 HZPRA/1JQiCBoKbAuXfluzsutzTcA/vkCzQC1w/ru5ZQ2WRPdornAJ2a+UNJ/mdgwHER rwu1hbj403wQ+qTpY8TNhv0KyZk5fQPmGRhwwESfxwkrcsRkAJtjJpyqRtm9ZpQ68H3I jADislAuT59q4au3Tclzf3OCxWclBO6hAAJ4Acsw1i4icQVLemj2+AjvPQxj6WMJOn3c nrZt86VmC2toRWTFJtTRKoY2E+E1faQu2UMGQTOG41OnJmYBxg00pzYLnPaf2HLrR4Ri P3JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=0t96y3FkXLiiInAiF7GMyUM6Gu9zpGQXe2nbijo00u8=; b=EQto/kyn5J2oDXKnVJrQWZ8Ibk3208jw2Tt0tUsMFg52kanUkyCxT/fzU0K5tRY91g j1XGMoDIOWpUjZt6IV8dF0SQ5GXE1oX9EfYZtI1Lw5++5IrRqkzi1Eg9/IZNeJi/NFmP UDi8fpvDS1EwGsrMX7PpnCU5r4OSzPpGb7WL2iaBy1/HzkoggSKdZKirvrDouongu7qV v9ExRcqUzQchGOG5YyRbfVxuWWJzbd2CPK3/uiUvBaNHO+Gwm0LssUfyCIbTdOB0V/hX YLo1Y7hCWC5yPQuKtdLHN2JD6yhS6g54qgymUh7zvlvQQMEUXdASOr9TMy4awMixXiwj z10g== X-Gm-Message-State: AFqh2krWBr8Yf5t37Otbn7VwyW2kqpQda52+yX53e+xwwOEBji54gNEU U9GYf8MNuH1h4HfCxtt104/eog== X-Google-Smtp-Source: AMrXdXuC+dEKXJlmfv5Nn2MwvVWClowQHDNX7f6bEFuAizBj3VRG2y8pN35Le3YmF/KEKjYh0vUvIw== X-Received: by 2002:a05:600c:444b:b0:3da:fd06:a6f1 with SMTP id v11-20020a05600c444b00b003dafd06a6f1mr47372661wmn.31.1675071729531; Mon, 30 Jan 2023 01:42:09 -0800 (PST) Received: from lmecxl1178.lme.st.com ([80.215.193.251]) by smtp.gmail.com with ESMTPSA id i27-20020a05600c4b1b00b003dc54d9aeeasm3865606wmp.36.2023.01.30.01.42.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jan 2023 01:42:09 -0800 (PST) From: Etienne Carriere To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Jens Wiklander , Sumit Garg , Sudeep Holla , Cristian Marussi , Etienne Carriere Subject: [PATCH 2/2] firmware: arm_scmi: optee: use optee system invocation Date: Mon, 30 Jan 2023 10:41:57 +0100 Message-Id: <20230130094157.1082712-2-etienne.carriere@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230130094157.1082712-1-etienne.carriere@linaro.org> References: <20230130094157.1082712-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-20230130_014214_975634_394765F7 X-CRM114-Status: GOOD ( 10.80 ) 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 Changes SCMI optee transport to enable sys_service capability of its tee context to leverage provisioned system resources in OP-TEE preventing possible deadlock. Such deadlock could happen when many Linux clients invoke OP-TEE are are all suspended waiting for an OP-TEE RPC request access an SCMI resource through the SCMI OP-TEE PTA service. Signed-off-by: Etienne Carriere Acked-by: Sudeep Holla --- drivers/firmware/arm_scmi/optee.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/firmware/arm_scmi/optee.c b/drivers/firmware/arm_scmi/optee.c index 2a7aeab40e54..91840345e946 100644 --- a/drivers/firmware/arm_scmi/optee.c +++ b/drivers/firmware/arm_scmi/optee.c @@ -559,6 +559,9 @@ static int scmi_optee_service_probe(struct device *dev) if (IS_ERR(tee_ctx)) return -ENODEV; + /* SCMI agent can used TEE system service resources */ + tee_ctx->sys_service = true; + agent = devm_kzalloc(dev, sizeof(*agent), GFP_KERNEL); if (!agent) { ret = -ENOMEM;