From patchwork Tue Oct 17 09:27:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13424899 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 57BF9CDB485 for ; Tue, 17 Oct 2023 09:28:42 +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=8rmbMmQym3VlXSIu9JcEwdtErpmOylwZ/9GNSuxD2WQ=; b=AMVHt0rmPgZ1PQ 8r9bPrEgS1onf+VG9ur52DYMIGaFuzTpuXeZmRXmHc5PPBVlcmFpNksVrTdMA/SRPxazRyIPpNsA8 2jndBJumnsMvhGh5NZRogUEelYx40MdCkMx8TloJ7rgJ+zwyPRKNgiJG2UIHWXtK4oZA5aPYicJgr OByeYpCcECXox6eQAYkLbBHvWbWW5YbZVY9OmwPbzVyf8oQUnkesKBDhCd6IgnWG9B5q5xuGDVE5w NRe86+eqmuXDkiOM3vWym9tZHtJ1SDeG4f+HxunEGCpEtWbh95KAFB8kS+esu1BQv9YGz/SyujxTB /M43cGgseyGTpbDXGJZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qsgMz-00BoRt-2h; Tue, 17 Oct 2023 09:28:09 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qsgMe-00BoFD-39 for linux-arm-kernel@lists.infradead.org; Tue, 17 Oct 2023 09:27:50 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40806e4106dso1909165e9.1 for ; Tue, 17 Oct 2023 02:27:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697534864; x=1698139664; darn=lists.infradead.org; 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=G1CbllhVp2OW4IWOAZO20mv5yal3Ji0MpQSHQu6sgzM=; b=mhfED36NXoRXpVhLnbbnb7OZXyTpa7ZYAzoedm0ZAdEAJWC+kNt2Qdnwgog5ODgQ6u HQ3n4mmVhLGt1QdgGpK+QMu5N2ymx4OpAYQ3Jyr2eXi7C6D/Z1js5k1YI4hhtx6YnLVq v7pMC4mf3z5kJexFHCcbUnUF1sT6ycHzWFpgj/eJUH+ZHIbik9e1TnXgQz0XI96B/VgZ CKvpxioUpQJ8jYynUCI7GdGUz+E/ZQgrCl99p8CnTEZi7psji9bA2CWI72QEWDcRGMQQ U/WbK08BYo7Ue3dQqNGS+tXUIekdKz+mkLMkQm52AJTlx9uCMEyeB8Czgo/31DuLyGJl YuHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697534864; x=1698139664; 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=G1CbllhVp2OW4IWOAZO20mv5yal3Ji0MpQSHQu6sgzM=; b=O1OfoGJPtBv5gQzld2WldG2sloL3UJjMy7euISclm7XZQ+Nls6RmwacVckTZs5pscO 7Lp0hBItxlIaOjbsg7MxmHVcA1vTBEG6YYrX6bpk7S5GrmIZb/RwIMii/T5CDfoiKmSo iE9jFce0rDfgcYz8pKSyRPwSt1v0IDyegizMlIyOUzMdoKH7370EJw9aE5ljqU9PwTVW tjTHPtm+Rz5/jKOTwDx7iYABN8YKxjVTM/co/hhYqnYB2VzwfcWatNBPzTZsVQuqpcWj nPnVKklhwR6kBggzuSOdCEs8QaZ9YUx31iP5BRR07/4nq2ubLBegUolx13MOhTRUp+Tq Q5ew== X-Gm-Message-State: AOJu0YxE/CquudcuQj0ViHj5p72hqAd0RKjAEFn52s01ZkYvK3KLFT63 8qbwC4xZbl14tV/aSzM6iLtHkw== X-Google-Smtp-Source: AGHT+IG0saDedMt9qaVolTW9RqgfZdkEhG8Uv+BgnyugI8IQplqRddVmL20mM4432fnzw8E0yAPuyQ== X-Received: by 2002:a05:600c:4e86:b0:402:ea8c:ea57 with SMTP id f6-20020a05600c4e8600b00402ea8cea57mr1120135wmq.7.1697534864321; Tue, 17 Oct 2023 02:27:44 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f1ee:b000:ce90:ed14]) by smtp.gmail.com with ESMTPSA id j5-20020a05600c1c0500b003fe1c332810sm9460787wms.33.2023.10.17.02.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 02:27:43 -0700 (PDT) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski Subject: [PATCH v5 06/15] firmware: qcom: scm: smc: switch to using the SCM allocator Date: Tue, 17 Oct 2023 11:27:23 +0200 Message-Id: <20231017092732.19983-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231017092732.19983-1-brgl@bgdev.pl> References: <20231017092732.19983-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231017_022749_011257_9E182BAF X-CRM114-Status: GOOD ( 16.71 ) 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 From: Bartosz Golaszewski We need to allocate, map and pass a buffer to the trustzone if we have more than 4 arguments for a given SCM calls. Let's use the new TrustZone allocator for that memory and shrink the code in process. As this code lives in a different compilation unit than the rest of the SCM code, we need to provide a helper in the form of qcom_scm_get_tzmem_pool() that allows the SMC low-level routines to access the SCM memory pool. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s --- drivers/firmware/qcom/qcom_scm-smc.c | 30 ++++++++-------------------- drivers/firmware/qcom/qcom_scm.c | 5 +++++ drivers/firmware/qcom/qcom_scm.h | 3 +++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 16cf88acfa8e..dca5f3f1883b 100644 --- a/drivers/firmware/qcom/qcom_scm-smc.c +++ b/drivers/firmware/qcom/qcom_scm-smc.c @@ -2,6 +2,7 @@ /* Copyright (c) 2015,2019 The Linux Foundation. All rights reserved. */ +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include @@ -150,11 +152,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, enum qcom_scm_convention qcom_convention, struct qcom_scm_res *res, bool atomic) { + struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool(); int arglen = desc->arginfo & 0xf; int i, ret; - dma_addr_t args_phys = 0; - void *args_virt = NULL; - size_t alloc_len; + void *args_virt __free(qcom_tzmem) = NULL; gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL; u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL; u32 qcom_smccc_convention = (qcom_convention == SMC_CONVENTION_ARM_32) ? @@ -172,9 +173,9 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i]; if (unlikely(arglen > SCM_SMC_N_REG_ARGS)) { - alloc_len = SCM_SMC_N_EXT_ARGS * sizeof(u64); - args_virt = kzalloc(PAGE_ALIGN(alloc_len), flag); - + args_virt = qcom_tzmem_alloc(mempool, + SCM_SMC_N_EXT_ARGS * sizeof(u64), + flag); if (!args_virt) return -ENOMEM; @@ -192,25 +193,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, SCM_SMC_FIRST_EXT_IDX]); } - args_phys = dma_map_single(dev, args_virt, alloc_len, - DMA_TO_DEVICE); - - if (dma_mapping_error(dev, args_phys)) { - kfree(args_virt); - return -ENOMEM; - } - - smc.args[SCM_SMC_LAST_REG_IDX] = args_phys; + smc.args[SCM_SMC_LAST_REG_IDX] = qcom_tzmem_to_phys(args_virt); } - /* ret error check follows after args_virt cleanup*/ ret = __scm_smc_do(dev, &smc, &smc_res, atomic); - - if (args_virt) { - dma_unmap_single(dev, args_phys, alloc_len, DMA_TO_DEVICE); - kfree(args_virt); - } - if (ret) return ret; diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 0d4c028be0c1..71e98b666391 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -201,6 +201,11 @@ static void qcom_scm_bw_disable(void) enum qcom_scm_convention qcom_scm_convention = SMC_CONVENTION_UNKNOWN; static DEFINE_SPINLOCK(scm_query_lock); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void) +{ + return __scm->mempool; +} + static enum qcom_scm_convention __get_convention(void) { unsigned long flags; diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index 4532907e8489..aa7d06939f8e 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -5,6 +5,7 @@ #define __QCOM_SCM_INT_H struct device; +struct qcom_tzmem_pool; enum qcom_scm_convention { SMC_CONVENTION_UNKNOWN, @@ -78,6 +79,8 @@ int scm_legacy_call_atomic(struct device *dev, const struct qcom_scm_desc *desc, int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc, struct qcom_scm_res *res); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void); + #define QCOM_SCM_SVC_BOOT 0x01 #define QCOM_SCM_BOOT_SET_ADDR 0x01 #define QCOM_SCM_BOOT_TERMINATE_PC 0x02