[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMRc=MfBoekf_5gjF13Acj+zS9H81pA=7=MVYys3E70qvEzUQw@mail.gmail.com>
Date: Fri, 29 Sep 2023 10:15:00 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andy Gross <agross@...nel.org>,
Bjorn Andersson <andersson@...nel.org>,
Konrad Dybcio <konrad.dybcio@...aro.org>,
Maximilian Luz <luzmaximilian@...il.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@...aro.org>
Cc: linux-kernel@...r.kernel.org, linux-arm-msm@...r.kernel.org,
kernel@...cinc.com,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH v2 03/11] firmware: qcom: scm: switch to using the SCM allocator
On Thu, Sep 28, 2023 at 11:21 AM Bartosz Golaszewski <brgl@...ev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
>
> 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 SCM
> allocator for that memory and shrink the code in process.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> ---
> drivers/firmware/qcom/qcom_scm-smc.c | 21 ++++-----------------
> 1 file changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c
> index 16cf88acfa8e..0d5554df1321 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 <linux/cleanup.h>
> #include <linux/io.h>
> #include <linux/errno.h>
> #include <linux/delay.h>
> @@ -152,8 +153,7 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
> {
> int arglen = desc->arginfo & 0xf;
> int i, ret;
> - dma_addr_t args_phys = 0;
> - void *args_virt = NULL;
> + void *args_virt __free(qcom_scm_mem) = NULL;
> size_t alloc_len;
> gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL;
> u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL;
> @@ -173,7 +173,7 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc,
>
> 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_scm_mem_alloc(PAGE_ALIGN(alloc_len), flag);
Ah, I realized the PAGE_ALIGN() here can be dropped when switching to
the new allocator.
There'll be a v3 anyway so I'll drop it then.
Bart
>
> if (!args_virt)
> return -ENOMEM;
> @@ -192,25 +192,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_scm_mem_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;
>
> --
> 2.39.2
>
Powered by blists - more mailing lists