Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp84303rdb; Fri, 29 Sep 2023 18:01:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlI6m+wGj07/q86xP3bHigGuc7aat+u2DyZzi7Yfo4oaq9MXzACn3ijsNMx3YSm5OGV8YF X-Received: by 2002:a17:902:e74a:b0:1c3:9f2b:4d08 with SMTP id p10-20020a170902e74a00b001c39f2b4d08mr6857676plf.20.1696035715116; Fri, 29 Sep 2023 18:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696035715; cv=none; d=google.com; s=arc-20160816; b=IHd34m2iImL5KgG4gRkFBdMeomw79wMoxG7tmpyGroPiClOfv83CDcHR1Nx0OnrZmu 6Unav5+0RTRUewd5N+lE9d6DXSFIx7irxk8laVBWUTKyrJofaOtB2NUwSXuGMvyPn1Zc qRD3qIVf2QkDx8uXlpcAzOhOtU8SFrZUCNWRg55m1gnMNPoElB8WjckT+UOFDzsZZ/Ii bKA4IS2t2rUEyQMpCUQ9mPwZpfou5Z3TygqnJ8EUNg3gMpGL+c7Enrz7s7txqNo0dhJx Wj3BTe79PpudTN7rmwNlmk8AvexP5Kni+P5BwGBMebeFYmYkzxfyVxlxf95K6wIryv9V ay8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:references :mime-version:in-reply-to:from:dkim-signature; bh=bKHr/R9x/1NqeTBuXlIluFo+yXauTlrOF4zuHxZuxHw=; fh=APGO2QiZNx+AVEM7oqevjyuJbfiXyP6fMAMqhTzS6ts=; b=DLtHHC3X598frz4Q999V4GazintNEQt9i0Ct0NamY42D9G6hkE5WCMU/8+WMvM+wJ9 NNlDDwv7z3mHt0zLK29I+H/DwBXP2doPiuON/OidVTBCdtJ/pT3X6ED+icrURYqXkO6f EuKK6SBkNORdr0pGcSV9m74/2SNnVIOMQnRo5Juj+ZL2lKTGKXvJr7uMyHBTnEwNH41S zCaa3GMjB4cgAL3IX0Vlpevsp92hOuEXggM4g2TFmqrlu5cGr8pIlnqn8owEtH+in8c8 KlIRYbRMzaLxsnV/1R2PmM060ZJCT2buuh3oE3jGCcxYS1whnWwU0yzVgLFTjuXIhPdM q9IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=zEDWHsNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f1-20020a170902f38100b001c752a540cdsi639678ple.145.2023.09.29.18.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 18:01:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=zEDWHsNK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id EAEDF804A738; Fri, 29 Sep 2023 12:22:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233559AbjI2TWX (ORCPT + 99 others); Fri, 29 Sep 2023 15:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233577AbjI2TWV (ORCPT ); Fri, 29 Sep 2023 15:22:21 -0400 Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [IPv6:2607:f8b0:4864:20::a2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D3ABE7 for ; Fri, 29 Sep 2023 12:22:18 -0700 (PDT) Received: by mail-vk1-xa2b.google.com with SMTP id 71dfb90a1353d-4908d8f7263so5862825e0c.2 for ; Fri, 29 Sep 2023 12:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1696015337; x=1696620137; darn=vger.kernel.org; h=cc:to:subject:message-id:date:references:mime-version:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=bKHr/R9x/1NqeTBuXlIluFo+yXauTlrOF4zuHxZuxHw=; b=zEDWHsNKNVPaDP/vTysjiJNmi41GZNg7aPBuBj/r+iZRwSKmASWlGybRzEUqsyIhde u7KnUpej0iluIaEI6hqMdcvdtKjFo8rMz4xZoDx/ZmWI+HQEN8tJO2/iMzaS3nyQb4dg BxLQ9ANnw9wa3DTCYJjnCG072TXQCEN30TzcKGE3oFOrdgV1EJDPYhx3WmY6hiHhqnoY mrmS2l8C2wSBqLbqkvBjkZorQC7V5mmUh6COuDJRpZ/dl339neHhz3tcpSI5Lx+SxYTd eoM2y37AdwvThz9s//f0VQH5Hr8LuuIMQaEerRBAm6vh7wGnEQAgYvlvmZVP4cZmD7Fs eKKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696015337; x=1696620137; h=cc:to:subject:message-id:date:references:mime-version:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bKHr/R9x/1NqeTBuXlIluFo+yXauTlrOF4zuHxZuxHw=; b=HFGDSCMqhDn/4kzqgwQ0qNRjmjTeBuwwNmyuNZXREJMXyC3yt1b6QAhhQtFXfTK4oZ YOeko2FGFZqKvgXOS+mSKL5zvoK7DUsi57AHxVHUWhiBUKgtmCx1sA14V8+/30P7YRMD b1zHevFgoQXuHzR7GiRHc5DjONwvb0i/gVRo2fqTSaTOH+HQ6mKCoEI/L7hZSRVnlb1e 3tFlJ3R+wxVvMRl+Zdwkglb5UYPvYTm1uEcSQ0sbdDsQWA3qpJSoSirXabd3vECqf7u8 Ct4+uhWC68ZUB7D0AfynXfcNLk3/7qMG44csBGNIutY9WjschEYFWV4UoIssMIv1hTw8 FrNg== X-Gm-Message-State: AOJu0Yx+VnBcCIPjg1AMF8gWD+j1b25CvJSIVPMWfakL0FbyY+5f3JFm 5CRnKmQeSPFZRbNjVVjNOrYqO28blExJQSTQFClSjQ== X-Received: by 2002:a1f:d6c4:0:b0:48f:8e3a:5b83 with SMTP id n187-20020a1fd6c4000000b0048f8e3a5b83mr5546267vkg.14.1696015337610; Fri, 29 Sep 2023 12:22:17 -0700 (PDT) Received: from 969154062570 named unknown by gmailapi.google.com with HTTPREST; Fri, 29 Sep 2023 12:22:16 -0700 From: Bartosz Golaszewski In-Reply-To: MIME-Version: 1.0 References: <20230928092040.9420-1-brgl@bgdev.pl> <20230928092040.9420-7-brgl@bgdev.pl> Date: Fri, 29 Sep 2023 12:22:16 -0700 Message-ID: Subject: Re: [PATCH v2 06/11] firmware: qcom: scm: make qcom_scm_pas_init_image() use the SCM allocator To: Andrew Halaney Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Maximilian Luz , Krzysztof Kozlowski , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, kernel@quicinc.com, Bartosz Golaszewski , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" 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 agentk.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 (agentk.vger.email [0.0.0.0]); Fri, 29 Sep 2023 12:22:44 -0700 (PDT) On Fri, 29 Sep 2023 21:16:51 +0200, Andrew Halaney said: > On Thu, Sep 28, 2023 at 11:20:35AM +0200, Bartosz Golaszewski wrote: >> From: Bartosz Golaszewski >> >> Let's use the new SCM memory allocator to obtain a buffer for this call >> instead of using dma_alloc_coherent(). >> >> Signed-off-by: Bartosz Golaszewski >> --- >> drivers/firmware/qcom/qcom_scm.c | 16 +++++----------- >> 1 file changed, 5 insertions(+), 11 deletions(-) >> >> diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c >> index 02a773ba1383..c0eb81069847 100644 >> --- a/drivers/firmware/qcom/qcom_scm.c >> +++ b/drivers/firmware/qcom/qcom_scm.c >> @@ -532,7 +532,7 @@ static void qcom_scm_set_download_mode(bool enable) >> int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, >> struct qcom_scm_pas_metadata *ctx) >> { >> - dma_addr_t mdata_phys; >> + phys_addr_t mdata_phys; > >> void *mdata_buf; >> int ret; >> struct qcom_scm_desc desc = { >> @@ -544,13 +544,7 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, >> }; >> struct qcom_scm_res res; >> >> - /* >> - * During the scm call memory protection will be enabled for the meta >> - * data blob, so make sure it's physically contiguous, 4K aligned and >> - * non-cachable to avoid XPU violations. >> - */ >> - mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, >> - GFP_KERNEL); >> + mdata_buf = qcom_scm_mem_alloc(size, GFP_KERNEL); > > mdata_phys is never initialized now, and its what's being shoved into > desc.args[1] later, which I believe is what triggered the -EINVAL > with qcom_scm_call() that I reported in my cover letter reply this > morning. > > Prior with the DMA API that would have been the device view of the buffer. > Gah! Thanks for finding this. Can you try the following diff? diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 794388c3212f..b0d4ea237034 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -556,6 +556,7 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); return -ENOMEM; } + mdata_phys = qcom_scm_mem_to_phys(mdata_buf); memcpy(mdata_buf, metadata, size); ret = qcom_scm_clk_enable(); @@ -578,7 +579,7 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, qcom_scm_mem_free(mdata_buf); } else if (ctx) { ctx->ptr = mdata_buf; - ctx->phys = qcom_scm_mem_to_phys(mdata_buf); + ctx->phys = mdata_phys; ctx->size = size; } Bart >> if (!mdata_buf) { >> dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); >> return -ENOMEM; >> @@ -574,10 +568,10 @@ int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, >> >> out: >> if (ret < 0 || !ctx) { >> - dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys); >> + qcom_scm_mem_free(mdata_buf); >> } else if (ctx) { >> ctx->ptr = mdata_buf; >> - ctx->phys = mdata_phys; >> + ctx->phys = qcom_scm_mem_to_phys(mdata_buf); >> ctx->size = size; >> } >> >> @@ -594,7 +588,7 @@ void qcom_scm_pas_metadata_release(struct qcom_scm_pas_metadata *ctx) >> if (!ctx->ptr) >> return; >> >> - dma_free_coherent(__scm->dev, ctx->size, ctx->ptr, ctx->phys); >> + qcom_scm_mem_free(ctx->ptr); >> >> ctx->ptr = NULL; >> ctx->phys = 0; >> -- >> 2.39.2 >> > >