Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp484619rdb; Sat, 17 Feb 2024 19:42:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWMXL85cYYxSowELr48IoFUy0jdDOEx7t12Ms7VYOnSiTFFqWQuSVewyESkS3gM56bdnQspl2vNDJSDZ2sLHqxJec57TxVyJXOrEUZqiw== X-Google-Smtp-Source: AGHT+IHeoYtLssxDcjJl69rAix3nKYqc/iPIcJ0x7qo1ITBLGguoWCrJNJJSfQsW0S1JwMpNfIk7 X-Received: by 2002:a17:906:b106:b0:a3d:dc7f:6e92 with SMTP id u6-20020a170906b10600b00a3ddc7f6e92mr4165202ejy.73.1708227725859; Sat, 17 Feb 2024 19:42:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708227725; cv=pass; d=google.com; s=arc-20160816; b=ga46Oj6FOJ1eMh2QPL6ZqZIMCWLoOT3WONCt+ZvuDzLqIN4aU2VpzJq26EGEiHcV7n EyxG9rMz9YABoTJ9OlIixwtgY41Smv5p0Ooqz7pnesVoQISBEqV60iK+ppYq1sVx7Y5T l/CAjGm4AK04Z1SJ4iXGrvqVQkUHvmCnrYCW3uNDvUQPeo/qFsbxN7/rZqwuqyuX5eYu 2LBhACMOdbzoEWEiOSukkSvwtCq7fTSFdFbyvRzm2oBjHehj7rCfaGtDfdoVcWLHRFJB oiovXKDLVrO8h8HBZhGnlAWL6hkO8wXkFYp+SILNc663vF4XpZ5VKgepnuCzPSVzpjo7 /hsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iY15xg62rIbDC0XNU+qucILhUzWVmY5L1Iq/nBrS06E=; fh=LNu0c3gNPK1mYjOca90icpQXFsjqhO0esU5jl/im0Do=; b=uG5v30+94kioUSfZHe+0Ty3bwQMrucBZSZ26qNHbPqtbdhSd6C923UViojg0vF2VEw wvZosOb1m/YGKF5r6pDWAPvF/eF3gnOmz69ACRq+AJx1T0R4K6fttWaPv9yKJIPi6sWx IYl4GcucuxmKKbFxJov+JcgfStKJx+ZrVeSGKssDpPD9zyyXeEw0tXn4g3KvLPwy3zRb Qb9eoibeSYopv75nLE/iO8koVY9iLMhY5anTI4BlDtCFogN+7kznjbptzUv5LncIaXmB i2zXq/U7sbb52FSCCc3Bz99Y2tYUKdbLeSDlj5xx13/MhBL/LRGY/Zh9s0heiDRy4DfZ d15Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XOqKwDey; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i24-20020a170906251800b00a3d22af3ce3si1403667ejb.112.2024.02.17.19.42.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 19:42:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XOqKwDey; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-70181-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70181-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5F5AF1F21AB6 for ; Sun, 18 Feb 2024 03:42:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36AE0184F; Sun, 18 Feb 2024 03:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XOqKwDey" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E04315C0; Sun, 18 Feb 2024 03:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708227715; cv=none; b=M9pgisJYPt4z0x4gxsxKKjpOUAg7hCgS+VZiba5vupg5uhjbfoN2fNFOnaes7sS9fNdqU5VqOIRt0GhOwvCKriOii8vWWtWxvEjMo6PlkGV07eM/Y60qCsskVW5X+V8Ztb+ZJJ/jimYAf+afACYQDQ4Gx5hTbeHUGuOR5Qud940= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708227715; c=relaxed/simple; bh=quB6jphYgrvGzUWwxD7Z2Plo/0c4tpW8wYaTIvHRV3k=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ply8EnubC6iRxxLk0JBp5CNVWmZRoOEfBjRIzRVenOwUdbzHw51ULiXawv0zHkN/uDkPdwEe8n+FlNfd5YEuECArLSFJXH3BazKa8rr7UWdJF+wctne/3O90LpdLDSC12hjOoQI4nllnzEPJhFA7mmQ1h5sFt9vbLhSS16sMvGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XOqKwDey; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A4EFC433C7; Sun, 18 Feb 2024 03:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708227714; bh=quB6jphYgrvGzUWwxD7Z2Plo/0c4tpW8wYaTIvHRV3k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XOqKwDeyrhoP0rFR9e8DKe6z4kSrba3S4KT7u4Rfpxq2f+h/9rCAL3LNgw6F2IcfA BOluf0a3Jw8dzXrTjd8S7Qedumohr2tv8heAXiDTRA8rjZm68+crwmj9VXlw5F2Jdi /V1DEiNLsjnhsxPLjOiFpuZC/zpWyN4BfCr7diR8Ur0ICJTtqlTbiplYmyr0Y5LKTY ksH522DAqzQPaX8oRMIy9vSg3GYCgc2ntT4ambW1LRB7eUQNejPX7aEDW78y8plJUb 7kcm0APY8MKpG0M2TtiVpoRRFDIoeVj1McLF7BZ4tqjlu0l13aG2fLkoYGt99EK5Ga 9WIv7uLUltaaQ== Date: Sat, 17 Feb 2024 21:41:51 -0600 From: Bjorn Andersson To: Bartosz Golaszewski Cc: Andy Gross , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski , Deepti Jaggi Subject: Re: [PATCH v7 10/12] firmware: qcom: tzmem: enable SHM Bridge support Message-ID: <7pybw4wxlzxfl65yuqxzks5w7uq52hosyq53etlzas6i6o5l6d@vxd4sykcxora> References: <20240205182810.58382-1-brgl@bgdev.pl> <20240205182810.58382-11-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240205182810.58382-11-brgl@bgdev.pl> On Mon, Feb 05, 2024 at 07:28:08PM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski > > Add a new Kconfig option for selecting the SHM Bridge mode of operation The Kconfig option is the least significant bit of this patch. I guess there isn't really a problem to describe, but let's at least mention that we're switching TZ to shmbridge mode and all. > for the TrustZone memory allocator. > > If enabled at build-time, it will still be checked for availability at > run-time. If the architecture doesn't support SHM Bridge, the allocator > will work just like in the default mode. "default mode"...SHMBRIDGE is the default mode from this point onwards. > > Signed-off-by: Bartosz Golaszewski > Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s > Tested-by: Deepti Jaggi #sa8775p-ride > Reviewed-by: Elliot Berman > --- > drivers/firmware/qcom/Kconfig | 10 +++++ > drivers/firmware/qcom/qcom_tzmem.c | 65 +++++++++++++++++++++++++++++- > 2 files changed, 74 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig > index d24d83223867..af6f895c5adf 100644 > --- a/drivers/firmware/qcom/Kconfig > +++ b/drivers/firmware/qcom/Kconfig > @@ -28,6 +28,16 @@ config QCOM_TZMEM_MODE_DEFAULT > Use the default allocator mode. The memory is page-aligned, non-cachable > and contiguous. > > +config QCOM_TZMEM_MODE_SHMBRIDGE > + bool "SHM Bridge" > + help > + Use Qualcomm Shared Memory Bridge. The memory has the same alignment as > + in the 'Default' allocator but is also explicitly marked as an SHM Bridge > + buffer. > + > + With this selected, all buffers passed to the TrustZone must be allocated > + using the TZMem allocator or else the TrustZone will refuse to use them. It's funny how this is the only place in the whole series I can find this mentioned. One could from this statement guess that the eluding scminvoke requires shmbridge and that this patch series exists solely to facilitate the requirement stated in this paragraph. Either this guess is correct and this should have been made clear in the commit messages, or I'm guessing wrong here, in which case I need some help to figure out why this series exists. Regards, Bjorn > + > endchoice > > config QCOM_SCM_DOWNLOAD_MODE_DEFAULT > diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c > index 44a062f2abd4..1ca3773263e5 100644 > --- a/drivers/firmware/qcom/qcom_tzmem.c > +++ b/drivers/firmware/qcom/qcom_tzmem.c > @@ -55,7 +55,70 @@ static void qcom_tzmem_cleanup_pool(struct qcom_tzmem_pool *pool) > > } > > -#endif /* CONFIG_QCOM_TZMEM_MODE_DEFAULT */ > +#elif IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE) > + > +#include > + > +#define QCOM_SHM_BRIDGE_NUM_VM_SHIFT 9 > + > +static bool qcom_tzmem_using_shm_bridge; > + > +static int qcom_tzmem_init(void) > +{ > + int ret; > + > + ret = qcom_scm_shm_bridge_enable(); > + if (ret == -EOPNOTSUPP) { > + dev_info(qcom_tzmem_dev, "SHM Bridge not supported\n"); > + return 0; > + } > + > + if (!ret) > + qcom_tzmem_using_shm_bridge = true; > + > + return ret; > +} > + > +static int qcom_tzmem_init_pool(struct qcom_tzmem_pool *pool) > +{ > + u64 pfn_and_ns_perm, ipfn_and_s_perm, size_and_flags, ns_perms; > + int ret; > + > + if (!qcom_tzmem_using_shm_bridge) > + return 0; > + > + ns_perms = (QCOM_SCM_PERM_WRITE | QCOM_SCM_PERM_READ); > + pfn_and_ns_perm = (u64)pool->pbase | ns_perms; > + ipfn_and_s_perm = (u64)pool->pbase | ns_perms; > + size_and_flags = pool->size | (1 << QCOM_SHM_BRIDGE_NUM_VM_SHIFT); > + > + u64 *handle __free(kfree) = kzalloc(sizeof(*handle), GFP_KERNEL); > + if (!handle) > + return -ENOMEM; > + > + ret = qcom_scm_shm_bridge_create(qcom_tzmem_dev, pfn_and_ns_perm, > + ipfn_and_s_perm, size_and_flags, > + QCOM_SCM_VMID_HLOS, handle); > + if (ret) > + return ret; > + > + pool->priv = no_free_ptr(handle); > + > + return 0; > +} > + > +static void qcom_tzmem_cleanup_pool(struct qcom_tzmem_pool *pool) > +{ > + u64 *handle = pool->priv; > + > + if (!qcom_tzmem_using_shm_bridge) > + return; > + > + qcom_scm_shm_bridge_delete(qcom_tzmem_dev, *handle); > + kfree(handle); > +} > + > +#endif /* CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE */ > > /** > * qcom_tzmem_pool_new() - Create a new TZ memory pool. > -- > 2.40.1 >