Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp637769rdg; Wed, 11 Oct 2023 00:39:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9MYBaVcmJx3fBF168BtJ9vms5HSojywkokrAn0wotO2enjoE/chOB0eNw7ednPhF39MvI X-Received: by 2002:a05:6870:3b0f:b0:1e9:845c:933f with SMTP id gh15-20020a0568703b0f00b001e9845c933fmr2480533oab.6.1697009992608; Wed, 11 Oct 2023 00:39:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697009992; cv=none; d=google.com; s=arc-20160816; b=iylCp9SVwCMkfgPtgfd+1wB5xDJLIfLiPhBe8ldEQDi1x/z+qTFt2PrZ6sl6qnW49C pMsNQA0iLiqDI9P58VQ3hrlgUhhRve14l3TBsDIBlXJNtuXVhGLK1fdIf2Q2a3/+S0r2 30PsnDBgL42uj1YAsVfKbiEGDNKCHQdADqPR2Al67Xf4fcQPU2EU1SOimR452OsH0b0Y +O9xSEn2fSDCqHlpwlASvj49XOeRog6dEufP3Mbks2qjUZQ18trxbc4Qdr8XLrJhmugn 5O0nwPZoMWeiD6BYMJmMDmen5j9rwEXtUUkIQ1JCLYxfzHIAczzl7Nh7xpZ/+BksAIVB mNpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OWrbWu0Oap0wNNOVGtrSvCx+2kjgQ+v9eimTvsjr3Uc=; fh=89S32swxLyeX0nV1QKEbzPKxVMotD+YOi0T3gfQ3XuI=; b=szXnn6vJOB1zdpON/pOwBpi7EdkCyPozSn5C7R3TJ+Ww0ttU8JRcSqWC9LXG4aYHZD OBsYDtE7c69Hva1jYX8Y298hNYPGNLmUi9yUMwZj046Q0qtjpkfI50gUTpO6SNOjsvDz OCk6nTKBZ8N9Z6tZ9qm6P3O+m3kq0WL3s5PLap5YmuCohFMKS20zot86PB8plsAGc3DH IuDPlvAasz5echF5RGW5lAPvn0GppxOrWa9ajp8pyiKgclrtodoXMHKmTJrxiz8b2OtP CklenQEp2xU3nWPzqvaFaVz8FWYCF8ty5o36N1QM0bW4xI87XV75pfXmjS+cvEoex1mI O4Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=UbzsGaAv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u70-20020a638549000000b005a0018ec786si38927pgd.854.2023.10.11.00.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 00:39:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=UbzsGaAv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 B49218025CC7; Wed, 11 Oct 2023 00:39: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 S1344747AbjJKHjd (ORCPT + 99 others); Wed, 11 Oct 2023 03:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjJKHjc (ORCPT ); Wed, 11 Oct 2023 03:39:32 -0400 Received: from mail-ua1-x934.google.com (mail-ua1-x934.google.com [IPv6:2607:f8b0:4864:20::934]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2667792 for ; Wed, 11 Oct 2023 00:39:30 -0700 (PDT) Received: by mail-ua1-x934.google.com with SMTP id a1e0cc1a2514c-7b5f0bbe137so788125241.2 for ; Wed, 11 Oct 2023 00:39:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697009969; x=1697614769; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OWrbWu0Oap0wNNOVGtrSvCx+2kjgQ+v9eimTvsjr3Uc=; b=UbzsGaAvjJDDjAtrxt+DGTCOaCO5LOui8STj4oM+YBVj56kHK7hyLZHZAskHjMOUJD uTnsH07u4d6kXZI0GBcA6moJbihWf7FfkLFqr5tcYgZ+sWIyiVX3p9NXVg2mDitU8nqL TykxsDWeF1+RhnwtdWj5kT6z8pL/M2r9SVT8L+F7sELKxlWtMRPBdIDQH6uw1m6JJn68 zE9xbn9If3mWCzMW8Pxhzh8wVza72sudkeOBxqkFsxUOtsR2EmrZ14JzsdGXtVclHN6b 3qN0dYqAvIF9rsQM3t/nH2N8DFj6+m6D7kzbqaN4I83NNflAq3FSNQv37c0FMLnschfr dPkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697009969; x=1697614769; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OWrbWu0Oap0wNNOVGtrSvCx+2kjgQ+v9eimTvsjr3Uc=; b=PXzKz8+MpUcEzc5hXrgw942r3o2RIFmYRqQ4VLWB5V1qMb/4iSnkSnNsRwAxDoaj5y xS6Hzr6muOUHUSR41HMJ6OZ72swGPC3vmmAL5AIBY8y0cFQZmaF/vrOhoYJPF9j4f93J Wg7QUDssomE/PNCd9MQNvYTfB5DawAn6yp7yaP+fWy1C/VHjrU7/X0HSalfVwEMVZwM7 ZVZzIqaiWwADDpL+iq3IyNWe9f04p+gRD9Waiy6zQBhkG42SzmVr7uCUqbyuDFd6QYjd 4MjB6YS/g0QsIIWgliNhyRjeUWjsEJChv3WYmfD2f0R6jWPk2iHKf98sKnrUHdmSl27Q nRsw== X-Gm-Message-State: AOJu0YzPPan78yesbYG4UDQjTcurMR7Y6On0urwxm+KkpeKdDKD5uBAh VvDqz4ejVI3j5oJvkoGsqUIsBQk0l6X/UEUo1msK7w== X-Received: by 2002:a67:e2da:0:b0:452:5e2e:a4e1 with SMTP id i26-20020a67e2da000000b004525e2ea4e1mr19185104vsm.14.1697009969146; Wed, 11 Oct 2023 00:39:29 -0700 (PDT) MIME-Version: 1.0 References: <20231009153427.20951-1-brgl@bgdev.pl> <20231009153427.20951-5-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Wed, 11 Oct 2023 09:39:18 +0200 Message-ID: Subject: Re: [PATCH v3 04/15] firmware: qcom: add a dedicated TrustZone buffer allocator To: Andrew Halaney 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 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]); Wed, 11 Oct 2023 00:39:49 -0700 (PDT) X-Spam-Level: ** On Tue, Oct 10, 2023 at 10:48=E2=80=AFPM Andrew Halaney wrote: > > On Tue, Oct 10, 2023 at 10:26:34AM +0200, Bartosz Golaszewski wrote: > > On Mon, Oct 9, 2023 at 11:28=E2=80=AFPM Andrew Halaney wrote: > > > > > > On Mon, Oct 09, 2023 at 05:34:16PM +0200, Bartosz Golaszewski wrote: > > > > From: Bartosz Golaszewski > > > > > > > > We have several SCM calls that require passing buffers to the Trust= Zone > > > > on top of the SMC core which allocates memory for calls that requir= e > > > > more than 4 arguments. > > > > > > > > Currently every user does their own thing which leads to code > > > > duplication. Many users call dma_alloc_coherent() for every call wh= ich > > > > is terribly unperformant (speed- and size-wise). > > > > > > > > Provide a set of library functions for creating and managing pool o= f > > > > memory which is suitable for sharing with the TrustZone, that is: > > > > page-aligned, contiguous and non-cachable as well as provides a way= of > > > > mapping of kernel virtual addresses to physical space. > > > > > > > > Signed-off-by: Bartosz Golaszewski > > > > --- > > > > [snip] > > > > > > > > I got these warnings with this series: > > > > > > ahalaney@fedora ~/git/linux-next (git)-[7204cc6c3d73] % ARCH=3Dar= m64 CROSS_COMPILE=3Daarch64-linux-gnu- make W=3D1 C=3D2 drivers/firmware/qc= om/ > > > drivers/firmware/qcom/qcom_tzmem.c:137: warning: Function paramet= er or member 'size' not described in 'qcom_tzmem_pool_new' > > > CHECK drivers/firmware/qcom/qcom_tzmem.c > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: warning: incorrect typ= e in assignment (different address spaces) > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: expected void **slo= t > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: got void [noderef] = __rcu ** > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: warning: incorrect typ= e in assignment (different address spaces) > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: expected void **slo= t > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: got void [noderef] = __rcu ** > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: warning: incorrect typ= e in argument 1 (different address spaces) > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: expected void [node= ref] __rcu **slot > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: got void **slot > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: warning: incorrect typ= e in assignment (different address spaces) > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: expected void **slo= t > > > drivers/firmware/qcom/qcom_tzmem.c:204:17: got void [noderef] = __rcu ** > > > drivers/firmware/qcom/qcom_tzmem.c:339:13: warning: context imbal= ance in 'qcom_tzmem_to_phys' - wrong count at exit > > > > I fixed the other ones but this one I think comes from CHECK not > > dealing correctly with the spinlock guard. > > > > > > > > > > > All are confusing me, size seems described, I don't know much about > > > radix tree usage / rcu, and the locking in qcom_tzmem_to_phys seems s= ane > > > to me but I'm still grappling with the new syntax. > > > > > > For the one address space one, I _think_ maybe a diff like this is in > > > order? > > > > > > diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmwar= e/qcom/qcom_tzmem.c > > > index b3137844fe43..5b409615198d 100644 > > > --- a/drivers/firmware/qcom/qcom_tzmem.c > > > +++ b/drivers/firmware/qcom/qcom_tzmem.c > > > @@ -193,7 +193,7 @@ void qcom_tzmem_pool_free(struct qcom_tzmem_p= ool *pool) > > > struct qcom_tzmem_chunk *chunk; > > > struct radix_tree_iter iter; > > > bool non_empty =3D false; > > > - void **slot; > > > + void __rcu **slot; > > > > > > if (!pool) > > > return; > > > @@ -202,7 +202,7 @@ void qcom_tzmem_pool_free(struct qcom_tzmem_p= ool *pool) > > > > > > scoped_guard(spinlock_irqsave, &qcom_tzmem_chunks_lock) { > > > radix_tree_for_each_slot(slot, &qcom_tzmem_chunks= , &iter, 0) { > > > - chunk =3D *slot; > > > + chunk =3D radix_tree_deref_slot_protected= (slot, &qcom_tzmem_chunks_lock); > > > > We need to keep the lock taken for the duration of the looping so we > > can use the regular radix_tree_deref_slot(). > > IIUC, using the protected version is preferable since you already > have the lock in hand: https://www.kernel.org/doc/html/latest/RCU/whatisR= CU.html#id2 > > Quote: > The variant rcu_dereference_protected() can be used outside of an RCU > read-side critical section as long as the usage is protected by locks > acquired by the update-side code. This variant avoids the lockdep war= ning > that would happen when using (for example) rcu_dereference() without > rcu_read_lock() protection. Using rcu_dereference_protected() also ha= s > the advantage of permitting compiler optimizations that rcu_dereferen= ce() > must prohibit. The rcu_dereference_protected() variant takes a lockde= p > expression to indicate which locks must be acquired by the caller. > If the indicated protection is not provided, a lockdep splat is emitt= ed. > > Thanks, > Andrew I should have RTFM I guess. I assumed that the _protected() variant just takes the indicated lock. Thanks Bart > > > > > > Bart > > > > > > > > if (chunk->owner =3D=3D pool) > > > non_empty =3D true; > > > > > > > > > Still planning on reviewing/testing the rest, but got tripped up ther= e > > > so thought I'd highlight it before doing the rest. > > > > > > Thanks, > > > Andrew > > > > > >