Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp898136rdg; Fri, 13 Oct 2023 04:50:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0qncW7rf+/vAfpFwSQc3KmbI/wAyHd7v3LFpKE95Y1ybwFIEEGarUGoI80pBjeB+JEPrK X-Received: by 2002:a17:90b:1b4c:b0:267:fc61:5a37 with SMTP id nv12-20020a17090b1b4c00b00267fc615a37mr23168082pjb.39.1697197800915; Fri, 13 Oct 2023 04:50:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697197800; cv=none; d=google.com; s=arc-20160816; b=wi2myYNw5j+S2P+irk3Sbqd/+3cOWXrMyOs/fKg9Vj8fkDOGnWywkde9H9H/zV7FXt xcJWGv+Q66lkX/RKbJaAJKEfqkrKJvQXlh2OSBn8IEBaF1yl/2uVOj0yqwNbBpe9jGS9 SzR3FUgamkhWV1JmJhL9cF2O5K5G2STzJLfzjYYPn98SSkwVw9N2IcewDdMSd8jCmWoK PfNzniV7sRN7fRkntlEHUGOAfJ0cIX+YxUFA5SDPpMLzBE6LiY5KxV+8ocQC4rUxs9Ev OjoGGJLIkDQFW8bZkWC9m8bbYeUv7NwAQX9daXKSaca8uViHBNj17f0kjVOyR/wL7hwv FLfg== 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=j3Nse7R/os6r+uhJloTkZlstOK0kfuV+AzH9d866bbs=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=Cd2zAXKgEE1Eo4VG8e50j8HjTDIKNao/yc2clTGQUE4SC5+8GwsY+CFxGL7Gy5Lf+L jjO4eld9fBo9mx5Ob/i4V4sasdftYjKFAc7iBmUJZyfCfxny0SqFqhG6w9WCkjy8gG9C fq6SRizX7ezH2BvS+RXhsQx933qAcRTvSuT6ilmrp7WYodSqWF4wJM1FzpIlWgYWZOGM VFIXRmCaYvy915ryN1a73xl22VQ3SniKCyz6LR5oAlm5vxHtN/bF3Vn3AOGqsrk2+IgE i4WxnhKrkXmVUr+2fDCzoe09/LOVa+a4Nt68eDAERleHhv6f3n3QKuosCrBoEaaeVxmn umSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=pj34b21b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id n7-20020a17090a73c700b0026b74f6aaa8si4224946pjk.63.2023.10.13.04.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:50:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=pj34b21b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3E7C582DC606; Fri, 13 Oct 2023 04:49:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231608AbjJMLtU (ORCPT + 99 others); Fri, 13 Oct 2023 07:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbjJMLtC (ORCPT ); Fri, 13 Oct 2023 07:49:02 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D09CCA for ; Fri, 13 Oct 2023 04:49:00 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-99bdeae1d0aso326780366b.1 for ; Fri, 13 Oct 2023 04:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697197739; x=1697802539; darn=vger.kernel.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=j3Nse7R/os6r+uhJloTkZlstOK0kfuV+AzH9d866bbs=; b=pj34b21bv4GH2bcOYcXUT3zitoZXw9urJG7IblVI/G/7tvygjKzFbc8uyl765zKgAR N6bL72fq5ot3bUMpcjxIfW9NRiHhiKRgFppXCsx9z52L4+LhI8iE+tIVCECq73ZJ37hj jc6cYjKyVUX56fI33IkqHJf23tglhe6vNXnvrUFxTMeJ7L9tAKxTvOwit5cEJosjwdTy jHcb7TGqQEKps408ZMKVBhCiH+gvn3g9rWk3BGinD51NljxVKQoxANlzCb3zDRs28xlO l4hAo1Y6eBh1Gx4NFTddYLw6ZF1CJM9PbRMmQq+vELSwgS8zaxjSDwc2K0IPrrf5S3x4 tRng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697197739; x=1697802539; 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=j3Nse7R/os6r+uhJloTkZlstOK0kfuV+AzH9d866bbs=; b=nb5PzKmbEOytMQAD4KTqOS271VcQoDCiNP7+rX/yHwtbLgppw2ht1SGUKYwvTI3m4M Sbh311xFHbbJDvYorqQAW2xjLdtJfBaHzJsf4lq/DrCUN2heAXW+M0gugbk13BRiHV93 YfZ6oLvmX+EiwClhIIgr3QjmoBHVycWC3laQ16svmc1Qf50MSHQ1YOHyjSdOQ3Vv8r+T TNETMdkdnfWy79Uii9YseWLU9U0neM+2Cutja2+y/yD4SBDMtQ0oJS835yRqovFwrFSe vAcjYjwVlVrtNow6Dp9cO6igLJ773PszBljmLIfXw2rU/P1j2acnPv65W+p8wOVSXCUH SrFg== X-Gm-Message-State: AOJu0Yw1QB7TKng2RMFlzH5RZ2BzW9CbZZWL/DDSMkVK+cgp2ZarnTns yaZa3FCMvkqFyeF0mvgxczdQ4w== X-Received: by 2002:a17:906:31d6:b0:99b:ed44:1a79 with SMTP id f22-20020a17090631d600b0099bed441a79mr22961296ejf.3.1697197738752; Fri, 13 Oct 2023 04:48:58 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:4209:13a:988d:80be]) by smtp.gmail.com with ESMTPSA id j23-20020a05600c1c1700b00407754b998dsm974509wms.27.2023.10.13.04.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 04:48:58 -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 v4 06/15] firmware: qcom: scm: smc: switch to using the SCM allocator Date: Fri, 13 Oct 2023 13:48:34 +0200 Message-Id: <20231013114843.63205-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231013114843.63205-1-brgl@bgdev.pl> References: <20231013114843.63205-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 13 Oct 2023 04:49:49 -0700 (PDT) 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 --- drivers/firmware/qcom/qcom_scm-smc.c | 28 ++++++++-------------------- drivers/firmware/qcom/qcom_scm.c | 5 +++++ drivers/firmware/qcom/qcom_scm.h | 3 +++ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 16cf88acfa8e..1a423d1cba6c 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,12 @@ 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 -- 2.39.2