Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1974226rdb; Mon, 9 Oct 2023 08:36:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHujEkgQcLxb6ujBYAdEOoJaPm00R40R7IojDavyiUfMluw2bc1ogstg/xjWG9kNgBfhMU9 X-Received: by 2002:a05:6a21:33a8:b0:16b:8bcf:9e27 with SMTP id yy40-20020a056a2133a800b0016b8bcf9e27mr9085058pzb.20.1696865819377; Mon, 09 Oct 2023 08:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696865819; cv=none; d=google.com; s=arc-20160816; b=SKzZbCBsqcCjzRRM6qqpXdk2DFZN3dDOVE8JQcLTV05/m81gb5nD7WoFJnqat+Rjqs T1UhmIjpe2wvMGW4VIr2d7IAyAmosGSmtocI3PNsVYjNr1w4jr2KYSF1hOKO9QUKFR93 V/7/JK4xCXoD+3JL7B22UkfstBKluz0jg5PvEZNoMkEdOvESlbSvBl9Nu7lLncqEog7j cD/K/pkJhSpm+DstAFDlmiv0D7/kEIlui5Mu2WeYWZJmZCQffnAajshkDM32dhImbved eLu4bCvQ8grrrGJeFsD55Y8W20egCnhP8QpQeVlOXexh6leSLaZ6NrjngOG6NhEc6nsq hK/w== 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=UnwTp4Lw3p1rKX5DDWLu+LDu8u+Ycx0lOsGSllntXJo=; fh=lirm1ccAeXZZB1cIo+N1DqklpgcFmD/vJ7PCWNIL0HU=; b=ud1moXL14E8KiSDV8cENygmcADTbgNvmIwvT2DFVFcFNQy7HAvKsqqs2LPE6M6RImA SXJjYLIfjnUrca+MraGR1xxbHxYtbEKRYeOKEwi3jGnTn6509FlyUbQvd3Lj3jJ6Ljqr MPB3mnndNXasW+yi7WQyUmQ6BSf/tOM/TnHtiOFk6c7zRg8W5OR2yJJPzCB86XymUqgJ nzobbVGvPsQTi3m5od+lgYkvzGFBwcKYDHIz/iBKe4iEQBFBlH+IrjWfExbnay/Tmiyd zvb9TSY8pjWw4kOY5so6qnkTnbFg3l3J5JFL7+nlfCshQLya//XCv0ria+Dbk3Renbwi SSkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=l3zlqMcC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id bt9-20020a056a00438900b006934390d0casi7514970pfb.36.2023.10.09.08.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=l3zlqMcC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id CDFAA810836C; Mon, 9 Oct 2023 08:36:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377681AbjJIPfJ (ORCPT + 99 others); Mon, 9 Oct 2023 11:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377044AbjJIPey (ORCPT ); Mon, 9 Oct 2023 11:34:54 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94BC2D6 for ; Mon, 9 Oct 2023 08:34:48 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3231d67aff2so4680564f8f.0 for ; Mon, 09 Oct 2023 08:34:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1696865687; x=1697470487; 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=UnwTp4Lw3p1rKX5DDWLu+LDu8u+Ycx0lOsGSllntXJo=; b=l3zlqMcCBQGt9fTe36WjB/AfJTjo3wM4HYMIaG9x2GFKMXxBK0dsSWbDk6x/dm6zxF ervLPreUI0a3HgZWWiJZJ3wW4h2i9hopap3FdNr2TlwHU/tY/AiT5uXKtmO4qrQU7RSb h66J43wMZtvTSe8khKuB6kRMkk/yHKOABhAy5EhSkwGau2EwZyrSDo2Zoizvh6vzRGh7 v8UciTn2byfRHJbZvU9jDvVSfaYkHehohMSDWC0GZBJ/FCAV/0Sfr+5mDrhjg54j6VKv wFJ8pvA2BRuGzIoTIC8pdn5oVLAi0tlx/pZoJPlh+COls8vNaff/ekzRVEHaqGdtYwTX k6Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696865687; x=1697470487; 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=UnwTp4Lw3p1rKX5DDWLu+LDu8u+Ycx0lOsGSllntXJo=; b=VkVm9mvmeEyJFtg9FO3n+MfMym6EWQcML0XvaI9Wzci/Ln63wP45af9tkGVL7tUjDW uuMi41+V/K3EH1U8sh8gsptdcce+QiAUkkpOlQh2WfmX2fYV/tW656wXbAHf2BwZ0DHF rYnhR6r1wRsaXAM2Lve4ppbgYM7SQCCybTjrhPDkqfuFHa4tDytx3qoAq0IdI+JD1OTr XBJc3SvjkpOApUtaqSI7ipzDaPE9DTDqEDDHOxaNPdknRxrcsMdE9mxPMuXYb958FfnV BeTvY1V9QKPCNrlsEwxf1ONKGBxETYusqoZLHYn4r4E7dQ+s3YULV8fEz4By+MnslVa4 dHPQ== X-Gm-Message-State: AOJu0YwNVZGJWyf1vjmKpyYxcsTENOeWGHqgKtGef3gjIcaTyugv/Hd1 /k3PVHy8PJPguFoNkLQWtuocSA== X-Received: by 2002:adf:f452:0:b0:31f:fed4:d79d with SMTP id f18-20020adff452000000b0031ffed4d79dmr14359230wrp.30.1696865686884; Mon, 09 Oct 2023 08:34:46 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:f20d:2959:7545:e99f]) by smtp.gmail.com with ESMTPSA id b3-20020adff243000000b0031431fb40fasm10016521wrp.89.2023.10.09.08.34.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 08:34:46 -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 v3 06/15] firmware: qcom: scm: smc: switch to using the SCM allocator Date: Mon, 9 Oct 2023 17:34:18 +0200 Message-Id: <20231009153427.20951-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231009153427.20951-1-brgl@bgdev.pl> References: <20231009153427.20951-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 09 Oct 2023 08:36:51 -0700 (PDT) X-Spam-Level: ** 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 --- 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