Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1061818rdg; Wed, 11 Oct 2023 13:15:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLYW63jKb5j38OJjNfCC1fyZeS5z8Yg3tq6/KPCD1hQtqsKG68zdvnrPBFPYr4UO378Fgi X-Received: by 2002:a05:6358:2605:b0:12b:e45b:3fac with SMTP id l5-20020a056358260500b0012be45b3facmr22831941rwc.32.1697055299910; Wed, 11 Oct 2023 13:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697055299; cv=none; d=google.com; s=arc-20160816; b=V9SuY/jgMRVWmhxPVrtQLP35uhaPDAyFVBSRBKtL+GeBQxBvKVrm836sYtlTUguMYH jSUp1TwEeWzkmowQ66yv6CTYufBkvVMCO0WyZ8+p05drsr1o/9W0N9wlXNAuCCKOK46N 5SEKrjhEA+gi0aYJ/XKvW7LJ2VZ1o/egArBzm8rgI2fvp8nvBrssltXbSNmtYjbfugY7 TDe6jYyaKz78vo83c0dvv/APuhiUCJi1oEhrmyLa6x6xjSjsBc4tjwmJcFlHqyBZODBB ETjwOAb7iGzLcjhwYUNzyG2F3sI5UUqdyjZcWIHMfRkckElL3/09BqQjLT4ZsMOWtjuK /Rwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bYit+PDu9PL4z4YO7eZa6nfZUOBQU0KXacY8Uj59d+o=; fh=4jyF2ZUBQ/SiJHAfGoV+niA288FYUMeb6Ahk+NIw7Pw=; b=MGIDtCjP/XAMnzDaOP+Tlj3q1B8zlwqXJE2aM2yfP3UIVKPfatHvITEvxC4iJsk9+A 2kGFqLXxUCZF12Z21QbwOmrbVyFaDje2g8o8GnDhhHt/Qq0GjYNckPIKkC3LqasGh1W2 VIDKLX0eOVUHnVLIdDCP/CxarGxhdncWqEc8CKGSrpQuAqal3BK68mcfDe1O8W29vhQY p/ffrDtLW007vr+sJX//odtWApjycPo8iewNnCNEPCVvuQxPrih8Zlg6BsDHARemTI60 XFJ8/FWm3fBa/yr4fTTq2cMcJfxkZyIrD2aFyNS/poPJtlaww7J39yYk/JEF9znzh3W4 5/8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V2niZ/P+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id h20-20020a056a001a5400b00690cc6f7598si13386554pfv.247.2023.10.11.13.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="V2niZ/P+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 3E5CD81349A4; Wed, 11 Oct 2023 13:14:57 -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 S1346999AbjJKUOt (ORCPT + 99 others); Wed, 11 Oct 2023 16:14:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233279AbjJKUOs (ORCPT ); Wed, 11 Oct 2023 16:14:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FC6A90 for ; Wed, 11 Oct 2023 13:13:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697055238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bYit+PDu9PL4z4YO7eZa6nfZUOBQU0KXacY8Uj59d+o=; b=V2niZ/P+BxKNV1zqdo0CcSeb+xh93jDXI+ZWjzUUMk3niN0ylxgkZnvkc2SnzQ985IuXru TO9DZ50MeL13Tc017Yzzparhw7zl0XbhbrvICEDrr6c3KgHJSj4xoQuFJHelRpvHFvN8+/ WuzMwlsGbY9NHZDY9zUvYTkuQ7g2q3s= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-3-RLwmt8a6OhS0w5Zzx9EbCA-1; Wed, 11 Oct 2023 16:13:47 -0400 X-MC-Unique: RLwmt8a6OhS0w5Zzx9EbCA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-7740c0e88ffso24714585a.1 for ; Wed, 11 Oct 2023 13:13:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697055226; x=1697660026; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bYit+PDu9PL4z4YO7eZa6nfZUOBQU0KXacY8Uj59d+o=; b=boWsB+TvLdepncMSvmkCxnUb5uf+VUW1nUKNmyGbYt+Qo80KI6a/YH01fOqJMCwNgF /1WJksF/xR+ozLbDhdErS9CWXwrg+9YQVOp0HceF9JID+Avw5PJdeIMIDRWUd6tKgpwW DzY+a8nRF+ET3QArPtVq0gsBL4wdf+flFwXSCMJp3dUJYaeGg2IZX2ChhmE/nLSZ/lVP CrwU+EvqlmJOaFQU6nlq4zj491oUzsToiQucCTQR6i+lbV5/BTatLH3qap4LjGKndFuz pLYJhyD7YTiy5OLIg71zWa26zm19gRGAx6mQPFEv+0CSOuDdkBDx2WHzuWB+NPZOQd0M NdUg== X-Gm-Message-State: AOJu0YzO6YFypMKQZCRggKbXNVYrj2uyk6iss+cwDae2BDEpvgCFbxKW ED9SdPjgCuQ0iRmOh2lfSBOx/Fe3Psr4p5z4Tc3lwRO3vN6cdvMS4RhfpEnWT4hoUsura9Od0ka Jsgg5hB0//PDvqmrQQ/s+OADzRyfjz1DF X-Received: by 2002:a05:620a:1da4:b0:774:2e8a:ccc6 with SMTP id pj36-20020a05620a1da400b007742e8accc6mr20969916qkn.32.1697055226653; Wed, 11 Oct 2023 13:13:46 -0700 (PDT) X-Received: by 2002:a05:620a:1da4:b0:774:2e8a:ccc6 with SMTP id pj36-20020a05620a1da400b007742e8accc6mr20969892qkn.32.1697055226350; Wed, 11 Oct 2023 13:13:46 -0700 (PDT) Received: from fedora ([2600:1700:1ff0:d0e0::37]) by smtp.gmail.com with ESMTPSA id os22-20020a05620a811600b007757acf488esm5473106qkn.39.2023.10.11.13.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 13:13:46 -0700 (PDT) Date: Wed, 11 Oct 2023 15:13:43 -0500 From: Andrew Halaney To: Bartosz Golaszewski Cc: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Maximilian Luz , Alex Elder , Srini Kandagatla , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski Subject: Re: [PATCH v3 07/15] firmware: qcom: scm: make qcom_scm_assign_mem() use the TZ allocator Message-ID: <3tguyivqgoovzil7mqivkyx5n5n27qnwqh36dvz36s46vgqd7s@qi6zqxj5pswk> References: <20231009153427.20951-1-brgl@bgdev.pl> <20231009153427.20951-8-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 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]); Wed, 11 Oct 2023 13:14:57 -0700 (PDT) X-Spam-Level: ** On Wed, Oct 11, 2023 at 04:33:53PM +0200, Bartosz Golaszewski wrote: > On Wed, Oct 11, 2023 at 3:54 PM Andrew Halaney wrote: > > > > On Wed, Oct 11, 2023 at 09:41:49AM +0200, Bartosz Golaszewski wrote: > > > On Wed, Oct 11, 2023 at 12:19 AM Andrew Halaney wrote: > > > > > > > > On Mon, Oct 09, 2023 at 05:34:19PM +0200, Bartosz Golaszewski wrote: > > > > > From: Bartosz Golaszewski > > > > > > > > > > Let's use the new TZ 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 | 10 ++++++---- > > > > > 1 file changed, 6 insertions(+), 4 deletions(-) > > > > > > > > > > diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c > > > > > index 71e98b666391..754f6056b99f 100644 > > > > > --- a/drivers/firmware/qcom/qcom_scm.c > > > > > +++ b/drivers/firmware/qcom/qcom_scm.c > > > > > @@ -4,6 +4,7 @@ > > > > > */ > > > > > > > > > > #include > > > > > +#include > > > > > #include > > > > > #include > > > > > #include > > > > > @@ -998,14 +999,13 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, > > > > > struct qcom_scm_mem_map_info *mem_to_map; > > > > > phys_addr_t mem_to_map_phys; > > > > > phys_addr_t dest_phys; > > > > > - dma_addr_t ptr_phys; > > > > > + phys_addr_t ptr_phys; > > > > > size_t mem_to_map_sz; > > > > > size_t dest_sz; > > > > > size_t src_sz; > > > > > size_t ptr_sz; > > > > > int next_vm; > > > > > __le32 *src; > > > > > - void *ptr; > > > > > > > > nit: couldn't you keep this up here? > > > > > > > > > > This still needs to make its way into the coding style guide but I got > > > yelled at by Linus Torvalds personally for not declaring the managed > > > variables where they are initialized. So this is the correct approach. > > > > I'm being a stick in the mud, but couldn't you initialize to NULL and > > keep them all up top? That seems more in line with the current "declare > > all variables at the start of function" guideline the kernel follows. > > > > Not a big deal... yours call! but /me shrugs > > > > I agree with you but it's not my call to make. Please see[1]. > Yeah, I see you're following the guidance there (declare + initialize together unless there's a conditional, etc, preventing that) in this series. Thanks for the pointer. > Bartosz > > [1] https://lore.kernel.org/lkml/20230919193516.GA20937@noisy.programming.kicks-ass.net/T/#m7f97e10dbfde777f58493398a77933e6a2f3c15d > > > > > > > Bart > > > > > > > Otherwise, > > > > > > > > Reviewed-by: Andrew Halaney > > > > > > > > > int ret, i, b; > > > > > u64 srcvm_bits = *srcvm; > > > > > > > > > > @@ -1015,10 +1015,13 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, > > > > > ptr_sz = ALIGN(src_sz, SZ_64) + ALIGN(mem_to_map_sz, SZ_64) + > > > > > ALIGN(dest_sz, SZ_64); > > > > > > > > > > - ptr = dma_alloc_coherent(__scm->dev, ptr_sz, &ptr_phys, GFP_KERNEL); > > > > > + void *ptr __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, > > > > > + ptr_sz, GFP_KERNEL); > > > > > if (!ptr) > > > > > return -ENOMEM; > > > > > > > > > > + ptr_phys = qcom_tzmem_to_phys(ptr); > > > > > + > > > > > /* Fill source vmid detail */ > > > > > src = ptr; > > > > > i = 0; > > > > > @@ -1047,7 +1050,6 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz, > > > > > > > > > > ret = __qcom_scm_assign_mem(__scm->dev, mem_to_map_phys, mem_to_map_sz, > > > > > ptr_phys, src_sz, dest_phys, dest_sz); > > > > > - dma_free_coherent(__scm->dev, ptr_sz, ptr, ptr_phys); > > > > > if (ret) { > > > > > dev_err(__scm->dev, > > > > > "Assign memory protection call failed %d\n", ret); > > > > > -- > > > > > 2.39.2 > > > > > > > > > > > > > > >