From patchwork Mon Feb 5 18:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5956CC48292 for ; Mon, 5 Feb 2024 18:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VY+rEBTVmWhIYBs8CjgYGPuR8LT7qD/YpsmvztpvHc0=; b=aFyDxo6EME0004 ij1dRzq++ReViUr9Z5UoVeh26SpHrNN7H6744XuBP7cp5hfaRSKjczyn51WAlnNJ9yeKmK7lJfJm9 Lb3hmwVMDiHAiAXQrNI69a4DvJtVZoNgPqnBH7Ex/DLYMjOnS89RtRVLmn7t1b/t1qm50TvUBGrBf CIpgQDVqwozZrHqfZB5txdORekNbYGnhA1dBNVPM9JTZSYnsokwEKGL0SCLSXn0F+nosvnhGARDTd 0vLKQXcCvsYo/vbQCTRHJc5thLXla5vMqNuy+6nEXKD30MY3CFdmnf3/BnZN8+W/tILdP1vVWy/cu 8yIK6bmOjqxndoBotJKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hk-00000004Mrd-1EXf; Mon, 05 Feb 2024 18:28:28 +0000 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3he-00000004MoK-1UUf for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:23 +0000 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so3535533f8f.1 for ; Mon, 05 Feb 2024 10:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157701; x=1707762501; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iXLMoacnXZApMvDAtKdNFyHpWYhZ3+I4GQHq7nHbfbw=; b=J18cMN5KfjIvZ39pMtno0/6i5KopDb5qAwZRwilzz27pxX7WuHYZzNpDKJQOuAPk74 aLW86mZBmeR/c+iMd8rdTp4UYTP6mQJutei5tkWG4FDiYjgua9HsQeliztOxdg7dwq1e zwoacG9Wc17Y8cUmVUQTn9SXKFQljEpw6tj31Qxq2slXxsJxZTowDn1ZBEQgojiErt7Y FsXKwpYTLuLPPH5oEZXCFxun+BUxqofkNc21vP8MnOZsddS88l60OO7WxF6ZdZpx/mq2 g7ZXN61aLk2wc6fG7e197U4rHabVc2qVJGscNgsg2fCXS2Aq8nqobBtSHjx06PnE4a6J Xc6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157701; x=1707762501; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iXLMoacnXZApMvDAtKdNFyHpWYhZ3+I4GQHq7nHbfbw=; b=TjMdXE5dM17Vh/Rw3TpQoT0cyDH7C8BjFBQQ/io9BA/mcBsyZEHTGRXaT7viNKrAMz +jWIvxhsGFHg9zUfEoIcRkdeix1lx/9gGIKix3Ljt0LBzQSfpr7+glUEIU8IghpMWZF6 /HzEKfTDGRtwmvppSV8j/XIbEhE2o+/3Gyhrj6VPXd+68RvWrahZwWBTiBQvgtQh81+l nBLX8hgxCYS+9egMhjemrczaHZR5npBJpB8k8Xvi2cs8nbUG7wt8AOrw5Rkm9QQtMR+5 ocF8kcxXFTTP/jLyD2gCBLldvEOePYSgryc9V5dXSDjJ4LnhudSOwGFuX4Rs6Y5V21nu OgOw== X-Gm-Message-State: AOJu0YxQ/TocpkpIZd0qaQKUz16v9SuwTEgbFxP2Q2hRId6CNDWxVjz0 y511cC8zT4w1Qp73AJgfT2UeZBhBLHWbSv/kMZgZPgnAjRV5VQB/1FJsOQITu5k= X-Google-Smtp-Source: AGHT+IFt2xWb248CMzd0tVsYdO1z3HpkWrhZu4JbOOb+GE29aqJN5LB2OQLOqwcQCVxiCFNyrXf/WA== X-Received: by 2002:a5d:5143:0:b0:33a:e6dc:2e98 with SMTP id u3-20020a5d5143000000b0033ae6dc2e98mr261820wrt.5.1707157700856; Mon, 05 Feb 2024 10:28:20 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWle0SsMQhI3023C9IJ2oTQxhymUUr/4GmLVDp8wYsTs9MQ/1WfNrJKlz38Sdt3Y5iMXZ/4zq01maxkAUfZr+Db5sDk1JHIfJXQof8jGWxqmbC9b2e4WMW/zlXMms6oKyQv5XqK1c82IFQGxRN0x6FidE/K5YCmDhu7Kgl5JQR/y/jGhIbXcuESxymosAAWVdlupmCMdOQKAFtyY7vWT1uRHHb4uBNNY1i+eTTJPaA7IKGCvtkt0F/ky2IXT9fIU/6PxpAeyuiV6qdqZSnVCztq6D2OHm8gVWpWWzZi0x89v2S6JtRz7UrWBp5cUZKbGI9AERL3aIxRGJlbGEYRlI1/bFGMLo+0C6uGXp8UEt0EpFJQu/nKQ1GnflDQfaNSksBwUJpiuZKBD1W9llit2vkieh0rKFkn2ihbkeRNdK61kmcptvSsmFlvB8eBXZVDFw0Apio4gD5x66OdWlh2S+wYCBNbvh5TlGlZbP5abuy1oEWO0u7Fx/SEBKPxdHEDpU5zMzsv8xRzLv7PNXIOgk1Z5Ej6UgRA51tllutDnJb0Fl8TwwB32AoonscMXVcLstU= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:20 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 01/12] firmware: qcom: add a dedicated TrustZone buffer allocator Date: Mon, 5 Feb 2024 19:27:59 +0100 Message-Id: <20240205182810.58382-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102822_567565_9056B974 X-CRM114-Status: GOOD ( 26.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski We have several SCM calls that require passing buffers to the TrustZone on top of the SMC core which allocates memory for calls that require 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 which is terribly unperformant (speed- and size-wise). Provide a set of library functions for creating and managing pool of 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 Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- MAINTAINERS | 8 + drivers/firmware/qcom/Kconfig | 20 ++ drivers/firmware/qcom/Makefile | 1 + drivers/firmware/qcom/qcom_tzmem.c | 302 +++++++++++++++++++++++ drivers/firmware/qcom/qcom_tzmem.h | 13 + include/linux/firmware/qcom/qcom_tzmem.h | 28 +++ 6 files changed, 372 insertions(+) create mode 100644 drivers/firmware/qcom/qcom_tzmem.c create mode 100644 drivers/firmware/qcom/qcom_tzmem.h create mode 100644 include/linux/firmware/qcom/qcom_tzmem.h diff --git a/MAINTAINERS b/MAINTAINERS index ff059e870a44..0c82625de50d 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18231,6 +18231,14 @@ L: linux-arm-msm@vger.kernel.org S: Maintained F: drivers/firmware/qcom/qcom_qseecom.c +QUALCOMM TRUST ZONE MEMORY ALLOCATOR +M: Bartosz Golaszewski +L: linux-arm-msm@vger.kernel.org +S: Maintained +F: drivers/firmware/qcom/qcom_tzmem.c +F: drivers/firmware/qcom/qcom_tzmem.h +F: include/linux/firmware/qcom/qcom_tzmem.h + QUALCOMM QSEECOM UEFISECAPP DRIVER M: Maximilian Luz L: linux-arm-msm@vger.kernel.org diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index 3f05d9854ddf..f18686edf415 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -9,6 +9,26 @@ menu "Qualcomm firmware drivers" config QCOM_SCM tristate +config QCOM_TZMEM + tristate + select GENERIC_ALLOCATOR + +choice + prompt "TrustZone interface memory allocator mode" + default QCOM_TZMEM_MODE_DEFAULT + help + Selects the mode of the memory allocator providing memory buffers of + suitable format for sharing with the TrustZone. If in doubt, select + 'Default'. + +config QCOM_TZMEM_MODE_DEFAULT + bool "Default" + help + Use the default allocator mode. The memory is page-aligned, non-cachable + and contiguous. + +endchoice + config QCOM_SCM_DOWNLOAD_MODE_DEFAULT bool "Qualcomm download mode enabled by default" depends on QCOM_SCM diff --git a/drivers/firmware/qcom/Makefile b/drivers/firmware/qcom/Makefile index c9f12ee8224a..0be40a1abc13 100644 --- a/drivers/firmware/qcom/Makefile +++ b/drivers/firmware/qcom/Makefile @@ -5,5 +5,6 @@ obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o +obj-$(CONFIG_QCOM_TZMEM) += qcom_tzmem.o obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c new file mode 100644 index 000000000000..44a062f2abd4 --- /dev/null +++ b/drivers/firmware/qcom/qcom_tzmem.c @@ -0,0 +1,302 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Memory allocator for buffers shared with the TrustZone. + * + * Copyright (C) 2023 Linaro Ltd. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qcom_tzmem.h" + +struct qcom_tzmem_pool { + void *vbase; + dma_addr_t pbase; + size_t size; + struct gen_pool *pool; + void *priv; +}; + +struct qcom_tzmem_chunk { + phys_addr_t paddr; + size_t size; + struct qcom_tzmem_pool *owner; +}; + +static struct device *qcom_tzmem_dev; +static RADIX_TREE(qcom_tzmem_chunks, GFP_ATOMIC); +static DEFINE_SPINLOCK(qcom_tzmem_chunks_lock); + +#if IS_ENABLED(CONFIG_QCOM_TZMEM_MODE_DEFAULT) + +static int qcom_tzmem_init(void) +{ + return 0; +} + +static int qcom_tzmem_init_pool(struct qcom_tzmem_pool *pool) +{ + return 0; +} + +static void qcom_tzmem_cleanup_pool(struct qcom_tzmem_pool *pool) +{ + +} + +#endif /* CONFIG_QCOM_TZMEM_MODE_DEFAULT */ + +/** + * qcom_tzmem_pool_new() - Create a new TZ memory pool. + * @size: Size of the new pool in bytes. + * + * Create a new pool of memory suitable for sharing with the TrustZone. + * + * Must not be used in atomic context. + * + * Returns: + * New memory pool address or ERR_PTR() on error. + */ +struct qcom_tzmem_pool *qcom_tzmem_pool_new(size_t size) +{ + struct qcom_tzmem_pool *pool; + int ret = -ENOMEM; + + if (!size) + return ERR_PTR(-EINVAL); + + size = PAGE_ALIGN(size); + + pool = kzalloc(sizeof(*pool), GFP_KERNEL); + if (!pool) + return ERR_PTR(-ENOMEM); + + pool->size = size; + + pool->vbase = dma_alloc_coherent(qcom_tzmem_dev, size, &pool->pbase, + GFP_KERNEL); + if (!pool->vbase) + goto err_kfree_pool; + + pool->pool = gen_pool_create(PAGE_SHIFT, -1); + if (!pool) + goto err_dma_free; + + gen_pool_set_algo(pool->pool, gen_pool_best_fit, NULL); + + ret = gen_pool_add_virt(pool->pool, (unsigned long)pool->vbase, + (phys_addr_t)pool->pbase, size, -1); + if (ret) + goto err_destroy_genpool; + + ret = qcom_tzmem_init_pool(pool); + if (ret) + goto err_destroy_genpool; + + return pool; + +err_destroy_genpool: + gen_pool_destroy(pool->pool); +err_dma_free: + dma_free_coherent(qcom_tzmem_dev, size, pool->vbase, pool->pbase); +err_kfree_pool: + kfree(pool); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(qcom_tzmem_pool_new); + +/** + * qcom_tzmem_pool_free() - Destroy a TZ memory pool and free all resources. + * @pool: Memory pool to free. + * + * Must not be called if any of the allocated chunks has not been freed. + * Must not be used in atomic context. + */ +void qcom_tzmem_pool_free(struct qcom_tzmem_pool *pool) +{ + struct qcom_tzmem_chunk *chunk; + struct radix_tree_iter iter; + bool non_empty = false; + void __rcu **slot; + + if (!pool) + return; + + qcom_tzmem_cleanup_pool(pool); + + scoped_guard(spinlock_irqsave, &qcom_tzmem_chunks_lock) { + radix_tree_for_each_slot(slot, &qcom_tzmem_chunks, &iter, 0) { + chunk = radix_tree_deref_slot_protected(slot, + &qcom_tzmem_chunks_lock); + + if (chunk->owner == pool) + non_empty = true; + } + } + + WARN(non_empty, "Freeing TZ memory pool with memory still allocated"); + + gen_pool_destroy(pool->pool); + dma_free_coherent(qcom_tzmem_dev, pool->size, pool->vbase, pool->pbase); + kfree(pool); +} +EXPORT_SYMBOL_GPL(qcom_tzmem_pool_free); + +static void devm_qcom_tzmem_pool_free(void *data) +{ + struct qcom_tzmem_pool *pool = data; + + qcom_tzmem_pool_free(pool); +} + +/** + * devm_qcom_tzmem_pool_new() - Managed variant of qcom_tzmem_pool_new(). + * @dev: Device managing this resource. + * @size: Size of the pool in bytes. + * + * Must not be used in atomic context. + * + * Returns: + * Address of the managed pool or ERR_PTR() on failure. + */ +struct qcom_tzmem_pool * +devm_qcom_tzmem_pool_new(struct device *dev, size_t size) +{ + struct qcom_tzmem_pool *pool; + int ret; + + pool = qcom_tzmem_pool_new(size); + if (IS_ERR(pool)) + return pool; + + ret = devm_add_action_or_reset(dev, devm_qcom_tzmem_pool_free, pool); + if (ret) + return ERR_PTR(ret); + + return pool; +} + +/** + * qcom_tzmem_alloc() - Allocate a memory chunk suitable for sharing with TZ. + * @pool: TZ memory pool from which to allocate memory. + * @size: Number of bytes to allocate. + * @gfp: GFP flags. + * + * Can be used in any context. + * + * Returns: + * Address of the allocated buffer or NULL if no more memory can be allocated. + * The buffer must be released using qcom_tzmem_free(). + */ +void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp) +{ + struct qcom_tzmem_chunk *chunk; + unsigned long vaddr; + int ret; + + if (!size) + return NULL; + + size = PAGE_ALIGN(size); + + chunk = kzalloc(sizeof(*chunk), gfp); + if (!chunk) + return NULL; + + vaddr = gen_pool_alloc(pool->pool, size); + if (!vaddr) { + kfree(chunk); + return NULL; + } + + chunk->paddr = gen_pool_virt_to_phys(pool->pool, vaddr); + chunk->size = size; + chunk->owner = pool; + + scoped_guard(spinlock_irqsave, &qcom_tzmem_chunks_lock) { + ret = radix_tree_insert(&qcom_tzmem_chunks, vaddr, chunk); + if (ret) { + gen_pool_free(pool->pool, vaddr, size); + kfree(chunk); + return NULL; + } + } + + return (void *)vaddr; +} +EXPORT_SYMBOL_GPL(qcom_tzmem_alloc); + +/** + * qcom_tzmem_free() - Release a buffer allocated from a TZ memory pool. + * @vaddr: Virtual address of the buffer. + * + * Can be used in any context. + */ +void qcom_tzmem_free(void *vaddr) +{ + struct qcom_tzmem_chunk *chunk; + + scoped_guard(spinlock_irqsave, &qcom_tzmem_chunks_lock) + chunk = radix_tree_delete_item(&qcom_tzmem_chunks, + (unsigned long)vaddr, NULL); + + if (!chunk) { + WARN(1, "Virtual address %p not owned by TZ memory allocator", + vaddr); + return; + } + + gen_pool_free(chunk->owner->pool, (unsigned long)vaddr, chunk->size); + kfree(chunk); +} +EXPORT_SYMBOL_GPL(qcom_tzmem_free); + +/** + * qcom_tzmem_to_phys() - Map the virtual address of a TZ buffer to physical. + * @vaddr: Virtual address of the buffer allocated from a TZ memory pool. + * + * Can be used in any context. The address must have been returned by a call + * to qcom_tzmem_alloc(). + * + * Returns: + * Physical address of the buffer. + */ +phys_addr_t qcom_tzmem_to_phys(void *vaddr) +{ + struct qcom_tzmem_chunk *chunk; + + guard(spinlock_irqsave)(&qcom_tzmem_chunks_lock); + + chunk = radix_tree_lookup(&qcom_tzmem_chunks, (unsigned long)vaddr); + if (!chunk) + return 0; + + return chunk->paddr; +} +EXPORT_SYMBOL_GPL(qcom_tzmem_to_phys); + +int qcom_tzmem_enable(struct device *dev) +{ + if (qcom_tzmem_dev) + return -EBUSY; + + qcom_tzmem_dev = dev; + + return qcom_tzmem_init(); +} +EXPORT_SYMBOL_GPL(qcom_tzmem_enable); + +MODULE_DESCRIPTION("TrustZone memory allocator for Qualcomm firmware drivers"); +MODULE_AUTHOR("Bartosz Golaszewski "); +MODULE_LICENSE("GPL"); diff --git a/drivers/firmware/qcom/qcom_tzmem.h b/drivers/firmware/qcom/qcom_tzmem.h new file mode 100644 index 000000000000..f82f5dc5b7b1 --- /dev/null +++ b/drivers/firmware/qcom/qcom_tzmem.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023 Linaro Ltd. + */ + +#ifndef __QCOM_TZMEM_PRIV_H +#define __QCOM_TZMEM_PRIV_H + +struct device; + +int qcom_tzmem_enable(struct device *dev); + +#endif /* __QCOM_TZMEM_PRIV_H */ diff --git a/include/linux/firmware/qcom/qcom_tzmem.h b/include/linux/firmware/qcom/qcom_tzmem.h new file mode 100644 index 000000000000..8e7fddab8cb4 --- /dev/null +++ b/include/linux/firmware/qcom/qcom_tzmem.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023 Linaro Ltd. + */ + +#ifndef __QCOM_TZMEM_H +#define __QCOM_TZMEM_H + +#include +#include +#include + +struct device; +struct qcom_tzmem_pool; + +struct qcom_tzmem_pool *qcom_tzmem_pool_new(size_t size); +void qcom_tzmem_pool_free(struct qcom_tzmem_pool *pool); +struct qcom_tzmem_pool * +devm_qcom_tzmem_pool_new(struct device *dev, size_t size); + +void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp); +void qcom_tzmem_free(void *ptr); + +DEFINE_FREE(qcom_tzmem, void *, if (_T) qcom_tzmem_free(_T)); + +phys_addr_t qcom_tzmem_to_phys(void *ptr); + +#endif /* __QCOM_TZMEM */ From patchwork Mon Feb 5 18:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9FF4CC48297 for ; Mon, 5 Feb 2024 18:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lcXKlH/doeZ0uTcg7HzemPOTjdVbVDm2LuO8s2YSRgA=; b=OqO7YFcLTGNyvE iQ1esrajXcrYSkMBn42NjXSSFSqnnnVcosJ6cqoQPUcFX2vwidagLgQbeOej6L2Y+VNfg7NgeHe/g PGn2GdDbar5s2TDSpuc7c/ihER0Z3mKrvoXRRvhosKPeGoQCipC1hBa4uPOVAIVT9nmC1DEFxfauS 0Lv2u9noToakZSnwvZauBHCF1fvLCxKcNUQ2tx+DKH60OBgCJ//EQkb8MaUCrxSTWxFEUBmluuv0G hSclPPGX8TmtX7oRDKDRILXNmloBgqKrlpJVglkRmFKqZyvpQwByxd7Gqjy8z0c+0SAQSohlQhdh2 GPYoTStV0o3xquKfBqtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hl-00000004MsT-15tA; Mon, 05 Feb 2024 18:28:29 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hf-00000004Mof-2i08 for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:25 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33b0f36b808so3076911f8f.3 for ; Mon, 05 Feb 2024 10:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157702; x=1707762502; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yEj/dNYHLTAVVx1z4vuCfUrAofiAmwzp/9dgycGoE2E=; b=pOc89+0618PpnWigh9N08mWYsZsVs5VAS1w2uDVUqLJrg2WVRlbjveZ00Lz/zourSm taj7oOxxoYGfp+Fl3jMLMGXx5xZtyQrAZxVuPAeQEElOBCGtfILhsCJMlu7tfqgFFNfJ YLXLuz/S4YQfr9eMbA1cbvrU9SHCYhGV+JGCH9Vka3CxNdkBxdh40+YJ3oH2Zh7dfATn GjaDFBryMc7D2ydctpvdf5PHT3KZmvJ3ZEEDhr3EOSqXkVssNEdT3jmCa4ObJV+V36bk abdLVbPhMQkquo08yWvkW9w0hol1v3agk5xHQCNLCYBvfz65x3SJHuqxslx7Ys2XfqzI FPpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157702; x=1707762502; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yEj/dNYHLTAVVx1z4vuCfUrAofiAmwzp/9dgycGoE2E=; b=MM9ckoEi88jloY7Gc0t2Yvei/lvRsnbL12PUhfxwwJIIAkIkzo3Jy28q0pfujyvmsu nloyyDX8WjvvdCpxJdufD6bz9afTRBRKF/LDjYMcawLeNILsTLQAPDh1g0OcgmLG4PhJ jezdC2gjgYLxm/UNIO6bly5d5U5Qjdhq7RM9p5aywZ9ncTv3/aBjKrF0ynpiLdstW4W+ 7FndAkN8FQ3aas+g9vDsuHgN63Upe1E5jFzNQtv3Fg7Mek56sK8uL4jASsz5MXv35pjf aBDJVamDTw9QRgzKYkSxznqRn/yz08Sf4X2rqjMUp0GAHNy+hBD6zOP6jcGxCtqnJp+A OHRA== X-Gm-Message-State: AOJu0YxxFCTVIjd7JwzXcxyXiALWSq2c+yyu8aIf57hwApFlJuuG5/9+ f4PwzW1nu3NZ18KO3+ksNmOe7jC/6jwMgVz8LDSvrTVNuJTljyDdGNPxVRJ7NMg= X-Google-Smtp-Source: AGHT+IEhRf/Nq70YfOTrEL0Ga/uegesRWr0w2slR5DVCq7BJ+6JlbySRSoBMwByr+5DcIPQnXJ4VeA== X-Received: by 2002:adf:a112:0:b0:33b:15fc:22c1 with SMTP id o18-20020adfa112000000b0033b15fc22c1mr271098wro.52.1707157701997; Mon, 05 Feb 2024 10:28:21 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW/9WEP5RMyqyIoyiK3EYuSmo/OO7XiMrIADASEM48FGfWG76Ej9QS0/h/WB9eKfaUo4LTV04U38ij7kayZPtYlYdJStuPF9xrxBpPbRKNhOuRiNZ31hX/hvVA8qvBxmGmJWcXbAsFpICmLQgpV/QUccyZ2ObTQZcRIhhDgnRUfLVr5MtblFMmkInHMmXLpm65WgCwFBAB4BxoxQWE58HWTL9gZy4r0phfFgIL4pzF02ntmJdlzClUNpmhhb1/CdugDGekPY6B3ihBZQO+ToMxR5/73R30tQCr4zGEZ7kju6gY6nCTTBGZ3oZTVaKGQib4n9LffW33GOeE6GHDLxuTI5sIdamxWYfhEe3He7dK7mgsdfRPvvViBySp8l3c+nKhksfSShfUxLeTGy+dXcT/7rbC/dnYWv9BzQ8RfvHSdhLxwwRZT7JdFHFHUOxyAY8QFYs/iGedj6UAXerG8OFKad5cAXC5ikYPiDObMzJFnkgB18n41nZKXVd/0lufl/VfCOcmeIjIALR/Hg69nFa4wirfjL+S9VtsL6X0sBiv3jCUEtAoGuUpVxVOQBlwNrxY= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:21 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 02/12] firmware: qcom: scm: enable the TZ mem allocator Date: Mon, 5 Feb 2024 19:28:00 +0100 Message-Id: <20240205182810.58382-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102823_718298_812050B8 X-CRM114-Status: GOOD ( 14.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Select the TrustZone memory allocator in Kconfig and create a pool of memory shareable with the TrustZone when probing the SCM driver. This will allow a gradual conversion of all relevant SCM calls to using the dedicated allocator. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/Kconfig | 1 + drivers/firmware/qcom/qcom_scm.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/firmware/qcom/Kconfig b/drivers/firmware/qcom/Kconfig index f18686edf415..d24d83223867 100644 --- a/drivers/firmware/qcom/Kconfig +++ b/drivers/firmware/qcom/Kconfig @@ -7,6 +7,7 @@ menu "Qualcomm firmware drivers" config QCOM_SCM + select QCOM_TZMEM tristate config QCOM_TZMEM diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 520de9b5633a..0d4c028be0c1 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -8,8 +8,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -20,9 +22,11 @@ #include #include #include +#include #include #include "qcom_scm.h" +#include "qcom_tzmem.h" static bool download_mode = IS_ENABLED(CONFIG_QCOM_SCM_DOWNLOAD_MODE_DEFAULT); module_param(download_mode, bool, 0); @@ -41,6 +45,8 @@ struct qcom_scm { int scm_vote_count; u64 dload_mode_addr; + + struct qcom_tzmem_pool *mempool; }; struct qcom_scm_current_perm_info { @@ -1887,6 +1893,16 @@ static int qcom_scm_probe(struct platform_device *pdev) if (of_property_read_bool(pdev->dev.of_node, "qcom,sdi-enabled")) qcom_scm_disable_sdi(); + ret = qcom_tzmem_enable(__scm->dev); + if (ret) + return dev_err_probe(__scm->dev, ret, + "Failed to enable the TrustZone memory allocator\n"); + + __scm->mempool = devm_qcom_tzmem_pool_new(__scm->dev, SZ_256K); + if (IS_ERR(__scm->mempool)) + return dev_err_probe(__scm->dev, PTR_ERR(__scm->mempool), + "Failed to create the SCM memory pool\n"); + /* * Initialize the QSEECOM interface. * From patchwork Mon Feb 5 18:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2ED9DC48297 for ; Mon, 5 Feb 2024 18:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MKJETG0WuaJ0wEyoGOdF9nfnW8yyZ2gUvPWQSuzyCwg=; b=0h35PSFuUTT/tc bAfU2QBpL3vC2fGnO3baosx+dEh0tzS99ttvhSdWQCM1zCrR2ZkmCTDkuOJRFwVsEPSL081gP74/c V3Tuuj915hzDP9ssxdfk5tsyaTJ3grPKg/u7OP4jnbyjnKlc+i7MsAzB8QvnhJtJA4C/nvubKNf/o zWlrzPnF5afNsi0uqOn7P0LZ9KqLuxgYXRV/O7BxgFgHMo95TFUkdNEHijG8eTAAgF+3HV9KlRU5j 7LwrBj8MUzD6/ie4ag+szemjY2eGPBw1mwH3axfvCsvBtwsBl1+m/5AiQVYSOsa8rieDs7Hy2EOv3 tV+BOcdvAGz/3jFrwF3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hm-00000004MtD-0uJf; Mon, 05 Feb 2024 18:28:30 +0000 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hg-00000004Mp3-0oN4 for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:25 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3392b12dd21so2651990f8f.0 for ; Mon, 05 Feb 2024 10:28:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157703; x=1707762503; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4erhe8goMZDE7TLr/dsCJoHJXktIjwgA8fkMwhmJPgI=; b=ZMMdpYe5Gfz6mZ6fFRnDg+E+kRJiROGivxdhcLQ0lgvB1oVWKIS1LRrTSQGj1yHLdR lWoEj6BZhSGUPcvrsA3RaqmwtnDD7FalaatJhg+URx8wbTbYyEsDBgEUObahLQl0n8Do tuwh739AtwmwQ/r6MMxjzckvyeio/ivxAfgOVZ7csIj8DatloLJYG91Jop2C3NgTxuh3 X5UqSv+8T1BL50HF0U/vPsqO+qDfxEJ1L0cpzXHLoFoYS3+wq8DiizRmUsQvL4tksoP2 TfWob3dMX2oJgS5+GAgneenSkB2jfrpW6yCHc8Zf9aeQAl9P9tDLVVDQQGweARsN1MUt TP3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157703; x=1707762503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4erhe8goMZDE7TLr/dsCJoHJXktIjwgA8fkMwhmJPgI=; b=uDvx8T+lAvU7ZR9/p65hW4NV3UcQUekVl74HzaZHZvqtNGo2xXrhRZCQjW9p3/5mW9 n6+fLuP311zOJytqjRI8lp3L+kKAhxHFnC/JkCxjv6DaOFHG/mDMXSBxxSUu6iVoTlk5 /9JHOKHesGcMtIFZUtxlPsTAs947K2CSKP/a13a7X7sJjgWiLuNaYou85IHC9WshokpA TjnhtBhDZuYbcQx+Q48gT0lZxiZmV3uKMvwB2Dx7xhWfvylTqk4gKoG+1VC/6XZ2nRns NAjIx1AlQqaveamW++DjuhOalO60I2CbxEVtUKIGG6s0IdHNXlaZixmlVPOdjfKjMb/7 UbHA== X-Gm-Message-State: AOJu0YygIgz3t50HH/JUs397joxNyW14IuAbBUOuOdaOACLy+JxalU/e zMnGbmIWh1x3ghfN7O9OKBr69Iri5nvclkaoUKwi8rpgFMlxuPMsirIkwHKM3z4= X-Google-Smtp-Source: AGHT+IGKP5WP3LJxKwWq8VqGtQqQKQUIgUbNeqbbetBbxeSkGGTeDvm/kta8S7D9mdz8FJyEy4JUKw== X-Received: by 2002:a5d:64c5:0:b0:33a:ef2c:7a4e with SMTP id f5-20020a5d64c5000000b0033aef2c7a4emr309426wri.49.1707157702951; Mon, 05 Feb 2024 10:28:22 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCU5Hkb2S7GtTbqOeCv8VPamd8tigkjXeJLcSVnraO2i6DUO3BkAxNh5YYC4cLU3LB7hW+DYQeg44+UnkN7OyISbJo4tImjcnkcMmPfon1Gi/gBmb6sYt+QQ7Vc8PLWFVO39pgcfAUu5kRjAXL4J5wn2vgn3OPSq9h78DqcUqZ2RNdjNxfNBOMV7AJU0rmel2hwrnAOw0peESkcb2IRieTc1+sof7qvYavDVGH7QRzjLJcFaFGdFLbDRR3/oAtTGUFm+eXK1EVG6dIOVJAAlncaF5wtrj37idXzBBd7IK3ZIsJPfw2UgxM9tsBdurZq7pnAgpTtIw/aVD7QeI4vvq9BPriDsyXAzKriDSMklveN9tlNG7UP5qivbfRHfvCjFYzBvfyLq6pdghmWEGDLzbjyL1k5DxT6pKXoM6hBDEjOE6RXO6iUSSJu+rGnLFfQuuIKF3ZGf0JMCwijiI8w3Ubqz7VKKm0xARYEQs4Sw72/+k2I+taF8ZCmv9glhg5ji1T7+futsqwTLLfHPFwul3+lR9bMzn/KzbOeM++n+NaqIyN2bbVJQ3Ts5eWIo/ucq7FI= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:22 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 03/12] firmware: qcom: scm: smc: switch to using the SCM allocator Date: Mon, 5 Feb 2024 19:28:01 +0100 Message-Id: <20240205182810.58382-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102824_262603_7D7121F2 X-CRM114-Status: GOOD ( 17.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski 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 TrustZone allocator for that memory and shrink the code in process. As this code lives in a different compilation unit than the rest of the SCM code, we need to provide a helper in the form of qcom_scm_get_tzmem_pool() that allows the SMC low-level routines to access the SCM memory pool. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm-smc.c | 30 ++++++++-------------------- drivers/firmware/qcom/qcom_scm.c | 5 +++++ drivers/firmware/qcom/qcom_scm.h | 3 +++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm-smc.c b/drivers/firmware/qcom/qcom_scm-smc.c index 16cf88acfa8e..dca5f3f1883b 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 #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include @@ -150,11 +152,10 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, enum qcom_scm_convention qcom_convention, struct qcom_scm_res *res, bool atomic) { + struct qcom_tzmem_pool *mempool = qcom_scm_get_tzmem_pool(); int arglen = desc->arginfo & 0xf; int i, ret; - dma_addr_t args_phys = 0; - void *args_virt = NULL; - size_t alloc_len; + void *args_virt __free(qcom_tzmem) = NULL; gfp_t flag = atomic ? GFP_ATOMIC : GFP_KERNEL; u32 smccc_call_type = atomic ? ARM_SMCCC_FAST_CALL : ARM_SMCCC_STD_CALL; u32 qcom_smccc_convention = (qcom_convention == SMC_CONVENTION_ARM_32) ? @@ -172,9 +173,9 @@ int __scm_smc_call(struct device *dev, const struct qcom_scm_desc *desc, smc.args[i + SCM_SMC_FIRST_REG_IDX] = desc->args[i]; 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_tzmem_alloc(mempool, + SCM_SMC_N_EXT_ARGS * sizeof(u64), + flag); if (!args_virt) return -ENOMEM; @@ -192,25 +193,10 @@ 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_tzmem_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; diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 0d4c028be0c1..71e98b666391 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -201,6 +201,11 @@ static void qcom_scm_bw_disable(void) enum qcom_scm_convention qcom_scm_convention = SMC_CONVENTION_UNKNOWN; static DEFINE_SPINLOCK(scm_query_lock); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void) +{ + return __scm->mempool; +} + static enum qcom_scm_convention __get_convention(void) { unsigned long flags; diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index 4532907e8489..aa7d06939f8e 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -5,6 +5,7 @@ #define __QCOM_SCM_INT_H struct device; +struct qcom_tzmem_pool; enum qcom_scm_convention { SMC_CONVENTION_UNKNOWN, @@ -78,6 +79,8 @@ int scm_legacy_call_atomic(struct device *dev, const struct qcom_scm_desc *desc, int scm_legacy_call(struct device *dev, const struct qcom_scm_desc *desc, struct qcom_scm_res *res); +struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void); + #define QCOM_SCM_SVC_BOOT 0x01 #define QCOM_SCM_BOOT_SET_ADDR 0x01 #define QCOM_SCM_BOOT_TERMINATE_PC 0x02 From patchwork Mon Feb 5 18:28:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1264EC48298 for ; Mon, 5 Feb 2024 18:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=A9m2JS4zTRtDOerOiwXZS2aigxYEpYanrDOxJdyJ8gQ=; b=niVwvOEgz37HRK 80K8ozV3wEuF2Oj+PEhffBlSA3RSwkSI4VG0OW5J9upiBpXgKR7D/Fvtgu5OdG+JWAY9+mKkLmeTn 3fNHrOeLzQT1acQUt3w/kedZKsadHGDfxSxC258huFLOGQwgseshkWPaqJM2SQPG4ycKQSJ/9UXin YuctukW1PPEHZUV6RR/ca6EPq8jskAJY86TuFaaFaSfxLqU+gO1v2gKFw0C7lJ3X/Hpj4rwZJMonA SeJnBSoJzI5h0p/mRT5F9+z+ESRQ4T49YVQSORDDJK0MGJstZh/R8eV6NypH7IQ8jY0wvE6yOQUbR +qmwKuIEWgsoRyz18Kbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hn-00000004Mtn-0SmU; Mon, 05 Feb 2024 18:28:31 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hh-00000004Mq1-3lHJ for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:27 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40fdd65a9bdso7740155e9.2 for ; Mon, 05 Feb 2024 10:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157704; x=1707762504; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ky7A6Q6k7ixaopUQaNLMQkcUAky1WorEIskukk+Y5Zs=; b=SXNaj68VcTYoUTew9N7hymgjqZRV5gTVHFjbWqMyyvpfnOhZ9t/L26giqbs317Rzkf qMgZvg+f3OitGzUtq9CBXRkpi/d44Ab0YoowX1T+me1VFctl4SneneIzfWhvrWSCX2dR NkK+p5Shw5nntfoOIVG9Al1FNl1MToUZo/RBzVI0Ie3Yc07n1q3zH8EkthEx35MJWVf+ zqXB0y+ItQ6qrULphzuOUbArUb07vqzSgXxE3XjShToyTXdbD8PlhN5IGZs3kJ2rTBTR fsTgnfW4llNenGwkJKnZo1T7NV/E+v9vDWTi3Ym0tJVrxkscL3eAxHZ0J1UcKaUdNNga V5Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157704; x=1707762504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ky7A6Q6k7ixaopUQaNLMQkcUAky1WorEIskukk+Y5Zs=; b=UORoUoO+01CGcY8ipL/oslAAQ1k06ll8EGkMo16NK1L8hXOuvnoR7etZGdY3bR0d79 r3txITnEkfyIfZeiu/MT+4eQe39RJ2BA2vN0rASy9Oq+cStElFNU/rEQSIsUpIom3/0w JEH6JCbNBHFDv2glLDD7aNp9JiIp2K6SavZx0WTDiZHbHGeXQ8v+NggD1Jp9nPOQBiBm jdAtOAJ5/kt79SSyHHtmpyqo400BDhskC5PNmSmSYdS8v9GlGqrJ6xctMNE8R2MCDkwi suKlp69UFt8gIwlKDhMEmfbGWBZZSYWqTQKwjTourK8KFrsPQ+YpSbBtXl+vyu6aLH9M ttow== X-Forwarded-Encrypted: i=1; AJvYcCWE+JdG7lR1Y7zibbmD1+smaR/ZcMuHvTJIBA0SQSZi91g8kjHElZIY/n4o7x/bDB/PufYya3GYd/eKx+S+ZrxOGFRTWTvDkDltm7t5FlrvN4vCF30= X-Gm-Message-State: AOJu0YyGG4UlhYwO3t+ETjqyTVfrYCL+7tAO3FcM08byK6gx1xjSJ/hd vCHRFEELSginc1txnkPsL43W7FnCREBHq1Rw+l5MXCXI1yGFS2R9bdUeTI+Sauw= X-Google-Smtp-Source: AGHT+IHD765uexuf9D1x8wbid5+wPG/IxGvcXWflosUmyncm2IQaH5q+GGQQo9+ALGv8/8VJY9iD7Q== X-Received: by 2002:adf:b35a:0:b0:33b:28ee:645d with SMTP id k26-20020adfb35a000000b0033b28ee645dmr226903wrd.68.1707157703922; Mon, 05 Feb 2024 10:28:23 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUdIiXSS/gpH931MfkdO0Sc5wlorS96kz6Tl+QjssTR3Qn14dYYj0MZDMg7QnloL0AiYaif6ZjjXPYRinmZ0GzAeXTEHKRNySKsblDiF+cPy2n+h6HoymfrcbFzXb1mPsiIlP+0kDmbqPbV3UYXpNKEmqqxLjoTrn2zN0a5go0tfPysE/vdgz0NZXqa6oMS9Bk96BpSPT37LC6FEB+zNmD9H0dxC5SaoODhdTZaeOXyT3o5ReqJGGbe3KVd78R1sfzt3aW7jOR3wlRWtOr89ttoWMe5M/4Y4g3zuj5C94rPv5ba1MccmdpGME5vGh0p2oy5LgcPNcVh9S/VAAsQFc753V1KWNEt51YvoqABivktphkj8v9I4RJq0X6qA6tHvCcDJKFnYQGCupXTBXfLYLZzMULI9zXIZ/0Mbbvf2KYStDUYTn4Sn7sPeNV3mDxHNE23ecKYflh/JHcS0W5OReZkwxtlXIo9XSzcs+5sL9+Ea7RH6XoPeO/+t4Yia6Hr5XCnKndftiFvABgBK50wUiYJjvoMf75DyHIdGIw5NrKskt0nT2K6KjuFYJcFYMXSUZU= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:23 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 04/12] firmware: qcom: scm: make qcom_scm_assign_mem() use the TZ allocator Date: Mon, 5 Feb 2024 19:28:02 +0100 Message-Id: <20240205182810.58382-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102825_968623_793CE86A X-CRM114-Status: GOOD ( 12.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- 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; 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); From patchwork Mon Feb 5 18:28:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3310AC48292 for ; Mon, 5 Feb 2024 18:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=AhkFoHTLj2EE74eIijXhMz2kPukwc7xpEnG6QeddNTE=; b=oiseskMMTbvMc3 IT0GIous0RkpWGHGPh8dRa8TIpKC22ksZINOITSHKgVqGFb6r74YcZoesC75AkUV8F9GWB4tBc5VY iyY99X2rB4CD5edORQjHTPn5OgLUHmjOUAZFYUlVdWVsYYufEU0EMpdnWhnH+2NCKICVex//qcYfB 4Tzl3eyB8/NH5jrefPNKCGLgGziLGugHlJWqMvnOb9b2bJNaeEcypGgshH+QcCPSmdn6mIxnjqyCN 61fjl927ZTFWq3FHjIhXtEmRDDHh+LCudRG5lFEaomYuEOFWndytcqSJ9cyZmKMUzZJl0tWuQDoaH HH2igEwNkgNURtkKa7kg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hu-00000004Myr-24w3; Mon, 05 Feb 2024 18:28:38 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hj-00000004Mqo-2jIP for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:28 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33b0e5d1e89so3767829f8f.0 for ; Mon, 05 Feb 2024 10:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157706; x=1707762506; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/tupJ2FnxBizYD8gOKKXQjNXDQsDvYn5mQ/R4h0dASo=; b=kusw506Pqxu0cJkOlsxq6tkPCGfp4j5LbahqSl0NSoJppVGeDKjlkpGXTgSnLSNSP4 btCmLmi+lz6ISjG7csGhah2HUvxUnR8Y41e8V25FDIgVrfP82FHR7dG7hK9KgGOy6wNc 7aLA5NCZX247M3tVkMg8s1IyVyWyHimhEdpCKAEIDPSFuCJAHdZHywyIi7iMe3KdfiT7 xFeJ+W/pT/q/l+bR0c678Z4wQgFTxbLC0FcERqlCT/pkwrPTtCtuBGNYELGDtMhNhZco QuBK1wwfXqq+ZpbKkCLdmJeMfJ7/+XD2HV+FBVeBXhO1FsjHwE4vTC+OI1wbFGt/LXIQ jLDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157706; x=1707762506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/tupJ2FnxBizYD8gOKKXQjNXDQsDvYn5mQ/R4h0dASo=; b=aALXnbqWrSx1HDIN7VVFOuIsaP/eAUUfVd/exweF+DZN2G1cCfiM9ziR3JD+NyWELc +MP2/qmG+O3qk+fPZ29tn06FCwlGghIUAkGg+Y4Pd0N7LVofTgo30gQaEmywg4a4dfyP EhWOjgJOEjB49mO3aiovAYSq56l2zoQtbVhTzhKiJRQRdgia2X8joXqftthlhdPulp97 V1DeMqIZ/wXYDv/qMuYaGD75zW3125RY/NHpbi5dI28mTv83pwW2ifyksSAx4p5UtHrn dp9kq+HOqCq//5fXgEHW5M108Mdl2HoLheGbsqYDX6Kz/iLJVp59RM5yeaNkyZOb0PpC OCzA== X-Gm-Message-State: AOJu0YxmefQU5TV+uBBnOzynQA9NbaFYmVbMfjI6x55Z/KyZCK3Tjst3 S4TwefbLtKezqLf3sgDlQAeI58i3MMWSgwYa7LP7pqRADGKMkyTuQk731S/nGkw= X-Google-Smtp-Source: AGHT+IG+sbdjO6Ne8XmtkOxg440O385CsG10rcZ7aD0fSOEF5DCvQP0k+e5WPvC4oyOL/1iaE06kWw== X-Received: by 2002:a5d:494e:0:b0:33a:df1f:c18d with SMTP id r14-20020a5d494e000000b0033adf1fc18dmr255069wrs.50.1707157705890; Mon, 05 Feb 2024 10:28:25 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXT4ZnvEnP4r10+RPvCVOQEo/78xjrvuNkUXKNr++627Pk5BHgAMo+Rf0L/87RTJA+svf85xNKmwk6kmz1uPt2PkGDVRD2gnMPKtsJwWgLUZyGmpD1E0uhk4e1CZObeYh6dabINSzekps/tw9VN9MY5EQgzJzUem0h87D4uH7M7mX7vRI6+dlFYxfvdozs2Lm+53hPSmrvuvl8S/AONFl/aHEbigym1Lih9+1BaOE9+Itd0diqOSE6bvzlmhmZGrtPHMgyRteHjV1fgRVNm13JMscAALB38tXEbAi0VTrtcUDT6I0E5ZR4VwAMVT1CMmSxQiNm3fPWhG0CVeZB6o6rr2DJtowzN8/KpJzGDrMzABZZoVCxlUc02q6IW7fM91L3839j7Zfn497dsZj86Jyr901En4lqTvLZ1jFsxvmrSTHMTXU0henmvHiXvgvOFRpN2PbFszLxiZDZA6aPA0YOZNtbcuqdW+yVzIcpbVMp5SfbDS/NE/r0ac3Ztb/qbKD0vVtrIw+dtjRJh48zQk5y+58svR/mty7n4a/gumYUcukQq9R9+zjeHcXWYgusCqUQ= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:24 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 05/12] firmware: qcom: scm: make qcom_scm_ice_set_key() use the TZ allocator Date: Mon, 5 Feb 2024 19:28:03 +0100 Message-Id: <20240205182810.58382-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102827_718740_6D37E49E X-CRM114-Status: GOOD ( 12.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 754f6056b99f..31071a714cf1 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1197,32 +1197,21 @@ int qcom_scm_ice_set_key(u32 index, const u8 *key, u32 key_size, .args[4] = data_unit_size, .owner = ARM_SMCCC_OWNER_SIP, }; - void *keybuf; - dma_addr_t key_phys; + int ret; - /* - * 'key' may point to vmalloc()'ed memory, but we need to pass a - * physical address that's been properly flushed. The sanctioned way to - * do this is by using the DMA API. But as is best practice for crypto - * keys, we also must wipe the key after use. This makes kmemdup() + - * dma_map_single() not clearly correct, since the DMA API can use - * bounce buffers. Instead, just use dma_alloc_coherent(). Programming - * keys is normally rare and thus not performance-critical. - */ - - keybuf = dma_alloc_coherent(__scm->dev, key_size, &key_phys, - GFP_KERNEL); + void *keybuf __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, + key_size, + GFP_KERNEL); if (!keybuf) return -ENOMEM; memcpy(keybuf, key, key_size); - desc.args[1] = key_phys; + desc.args[1] = qcom_tzmem_to_phys(keybuf); ret = qcom_scm_call(__scm->dev, &desc, NULL); memzero_explicit(keybuf, key_size); - dma_free_coherent(__scm->dev, key_size, keybuf, key_phys); return ret; } EXPORT_SYMBOL_GPL(qcom_scm_ice_set_key); From patchwork Mon Feb 5 18:28:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546020 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A226C48292 for ; Mon, 5 Feb 2024 18:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OB52cnLDzEPy0Aq6yuaiYddN2R6x6aXx+xQlkRx+Nik=; b=eTgnK4oLbWlQCN /IcTpjhuoeYFV3YIAVzFDjSH2zeWoDaInYqk9D95IyFIo3lFK6tVyC3b3BP1SugOY7uYAizTDbUU9 vz4DBcwgnHZQPCT2aFW12MGMNiSkIlYD8noynygGRDE+4oT1HJv4gyb7zugwOesld7CZrH0KS7fnV u9f3+1VfgM1hUV4CJRxnek/VLzSeDGkQygSNJm7j2n1pnXRaqgfXabWG5YZuC/oIB4OGOoWCP/KZM gnV9VY1r0dGM35JSyyfT4+M9y6o2bDeAX7+NMRmih22C/PPQy5u1fVmjLoOq6XbRHL+YBoNpMEHdJ OB/vjMMDKU6UxS9kYfIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hv-00000004Mze-1tLI; Mon, 05 Feb 2024 18:28:39 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hk-00000004MrC-2y6T for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:30 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33adec41b55so3023829f8f.0 for ; Mon, 05 Feb 2024 10:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157707; x=1707762507; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y0tdf3eyAnzGsNLeuGvazlCndWizgRVXM7rJoHxIMZA=; b=KH4UK8i0gdYpJTkMbPZlVzRgZy+4bcyRTZDo+4+/NY9rI9Vq7tK7+DBdv6MVoV0Mca f26AtxAKKCZ5jnfNmhFx7tmxK1eNMkPX6B6y6gjTS+k3xT7Zj8I48VCHo8Nx0JQdR0t1 fJWJ2arlOP3lq76YxdoD3UaODfRhObIImtC1uC2raRw9wNjV8JCMBt6bM7eTqleSPDzv wtVi7rHoY1EDgfEywbDz+9oQizJHy6+dARWrjYK1pqJ02zVQVSuP6az7D+ZFLmmoY0XI hXaTBDMBxAmMI6gHnpfwgxrA7kUIvNeQlLsKQbxPEzMdKchiSE6A4rG1taZQgtJRTawd tlXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157707; x=1707762507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y0tdf3eyAnzGsNLeuGvazlCndWizgRVXM7rJoHxIMZA=; b=VPBtEGs3//jhksZAc4+GLREaahbN4shE58dX+DD+onrAlQVZ20ru67uZVUjkN/CGbk FG5Zk3RRU/ZMnMhk0J/f7nKFuLspXB9iJZpH3sQ2rtX7KS8iS5oWcy8agZ3MutBDLRe6 /VxnhUr0m/557siFiDQ4JUfIt9Bw/j1VwF+c7N/SupDQhXb4GJ/rhyM/YH/bJ5iJMMI0 9VKIjQcNkRnwxTUoK71HE13CZ+kyhJtjHhwwn3tluH20RD2+wcfeCCH8lAt/8dJXb+8o 10i0cuMcoQZYSCBo3tJhDr4ayn0jaVw7cwA9NeNrKG9JjjbEEoItg4D1Fyhv/9JB4bzJ T/hg== X-Gm-Message-State: AOJu0Yy02SJWkEsrqYBkN2P+Z/SXw5oQBy/Vj3yjPQM5P0G/Lz+ePUl/ K6qVh8z60iTbZf30T7vpwC68rkC2KArQ/AXkN8cFIPhY2+6jY7k1FkactfygprI= X-Google-Smtp-Source: AGHT+IHu5p1ceHFoAUa++kZkcnC3iCS/21606cNviCdPf+6pX55U9pu4oXhyXtJF6JmtMSV/S4UbKg== X-Received: by 2002:a05:6000:1a50:b0:33b:3ced:a5e1 with SMTP id t16-20020a0560001a5000b0033b3ceda5e1mr243568wry.20.1707157706813; Mon, 05 Feb 2024 10:28:26 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXGRBLc/LqneVab/oV9PBWtd0RCAUMnY+sHtiXRGVsKANmqAxba5G6tcECdeTHHpnPjSiRcWsn0zChBXJhXgszshnBOd8Fo4Cj+AKcG/InSph0+OfBODs8GtnACDq1QZFrPjNoT/9TaP99NGEVERvaiMDUv5T1RwzKhLusUZaT7VkuMDHmKJA8JCP0fuYkdxXLFPnEkF08NP15WVLhbjbX6p+XLug6x+NnFcqpz0ur3KAkGug5hR8GYEQdWRXUtrDEBqhfHKFnXInLjJsL8Wm3GMtfMPXDjAHID1PyLgJ0Czo+jFBDbVcuRpbiFveU8BhIBDGSEdLdSFxxIxtCdvYUr3byl33M3nbVLB86JNXQvjGa4WiTITOSM/9coD9i5fuAZcundTalQx1ubNGKPncUEK6I7RJIQaaPond8W0bfcnx1yhQMtaLx9flVGFEMgwBAcQonQWGxFapvtuHMNq+xGPMZ8xgCi8+D0PXmcSfQYy1i4PBjxo1l5+XHbXdzcBtJkqOQ8sKPN6vHawF5djxi6Iszoc+WcxzBwECWeruU5VBw0asO37OMCk1HX8Vbq0BM= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:26 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 06/12] firmware: qcom: scm: make qcom_scm_lmh_dcvsh() use the TZ allocator Date: Mon, 5 Feb 2024 19:28:04 +0100 Message-Id: <20240205182810.58382-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102828_804755_CC2754AD X-CRM114-Status: GOOD ( 11.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 31071a714cf1..11638daa2fe5 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1340,8 +1340,6 @@ EXPORT_SYMBOL_GPL(qcom_scm_lmh_profile_change); int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, u64 limit_node, u32 node_id, u64 version) { - dma_addr_t payload_phys; - u32 *payload_buf; int ret, payload_size = 5 * sizeof(u32); struct qcom_scm_desc desc = { @@ -1356,7 +1354,9 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, .owner = ARM_SMCCC_OWNER_SIP, }; - payload_buf = dma_alloc_coherent(__scm->dev, payload_size, &payload_phys, GFP_KERNEL); + u32 *payload_buf __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, + payload_size, + GFP_KERNEL); if (!payload_buf) return -ENOMEM; @@ -1366,11 +1366,10 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, payload_buf[3] = 1; payload_buf[4] = payload_val; - desc.args[0] = payload_phys; + desc.args[0] = qcom_tzmem_to_phys(payload_buf); ret = qcom_scm_call(__scm->dev, &desc, NULL); - dma_free_coherent(__scm->dev, payload_size, payload_buf, payload_phys); return ret; } EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh); From patchwork Mon Feb 5 18:28:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546022 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 519D8C48297 for ; Mon, 5 Feb 2024 18:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OusOVeQSXsHBGUaRlQzGnXL15/k4J1ixlciKkMOR7rc=; b=EIkiYfHB+0vnX9 CI8izThhIf+WeD70SbPW2Rf8U+t0YiPzydBC/mZ/pbFq8X5tOkPLtbArIkp3p8ZpwkXdPlb4eEalg zZWNkpBMiFYe0mUuuEtibTqLes3Yj4EEsaWG1Lo4GbOtHNqwqpo57Z/VVXdVwJvteb7VOfyLcRIA8 ubVnVFXCC6E1kNCdqDgptZY8/B4gsf9pgkykkV+hBuSPmeU4uEFrPWtTNsDnVfwxdvwG/YI0my9ba DNJorO66d2UiXme7/chY+u4SjxTHwYCWle+bMhISNFN/kBFqB0qzsPq6A6uyla5W5xEcJTOuM9Av4 zoMel3HwCLRxWPRetNLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hw-00000004N0X-1qgR; Mon, 05 Feb 2024 18:28:40 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hl-00000004Mrj-2hE9 for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:31 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so3535612f8f.1 for ; Mon, 05 Feb 2024 10:28:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157708; x=1707762508; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s0oEOKGcE5RDVKHJLOO6pZt7g+TRP+w7zOsv5ctScyA=; b=oLL3d40y/XZEhN7GkZcoZCS1DrrlmdkkmiRN0Q/bja3KX6b1DFaZEYYFNjgJ8dEaOS 1xj1RcYjXzNCbz+sigy5H/HohC8YRdYMp95Ukg+I9OxYm0MXh68iZWXyvIXoelXwJQZR InoEXYGT9CzzVTDZDYEWYZVYk5AMml/hdhg8kupjX7eZ7SX9PoWjoU6124fEup7KHQcb 7TysZE4UGSAUcq4JTmKuCutUCs8PUg407/tNo7Nn7QdWetmN56iTFtI1eJzyOLftFNN7 VnJfvPqU0cnzKVIXgmjulYxSYP3oCdjbeAGKIW5Rbc3iEoC74Gx51jKhSwPZdCAvpKFV Vaag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157708; x=1707762508; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s0oEOKGcE5RDVKHJLOO6pZt7g+TRP+w7zOsv5ctScyA=; b=izJ/wlBoxwk9RTw2hGkaNy+gp0MWEAzOVlV0DOjZGhcM9TFF70k/sNJvzVK6tZ0sNz mi3ynhdLtb6BOxoyWWTVeYnYAFrSne73qelsyTub/dARy9MeaQDmW/e6JPDJXQVLvM1O bQWtZFnersKB14wK6wKANwIYqeJxRLM6/Pzn9OgR9Z97Muu90y/+XQcM+iJ6rNe+pKjO sORgpD6HFDbs7yOwSqHKg2TKdiJrYLuXph8iTk39TVrKQ4q52Sog4lCMVH0T0CIpRCTu Jno6b+puOjRDQKugJQZDd38rQtfF2bJ8dnJEGvUKg0SWmzOUbwbumoUAaxgAf4+xbn4c sdvg== X-Gm-Message-State: AOJu0YwA3dMCrqw46rqNAFE8+IDQHBdRniI0L2s28ZYJznulEmCOyFBf Sg1QNTXbeVY3nDKdmMZNXi806bUeZvuFRCAvrAQsbTGNgLzg34YsBLGJuCjt/uw= X-Google-Smtp-Source: AGHT+IEbZ91ZP8juBJlYfzHEEEkyJuuPPIxG2nnGFJhu1M+wrdILW9y7zEKqJcg/Y/9qH7CgyyKmsg== X-Received: by 2002:a5d:698d:0:b0:33b:150e:627a with SMTP id g13-20020a5d698d000000b0033b150e627amr188208wru.70.1707157707812; Mon, 05 Feb 2024 10:28:27 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCVnHR7MaTmuXNXpSFb/KHk62IruZCfaJyE2NhFVgsQ8v4ZKzkCNgdg8im2IA9UO//5RtflXbuaSbXfQjUOQ5Nc7rhtR/h92SOavahh3Oy/2YUvp5I3STFKS4SciONT37cPKIEXbTV3GqNEeGm/gClTT70BbN/vQ1U0oLciPqqHlTlIPFZCnz6MUZgLC/B2RPTDI+vT7/7Q1qv5JYnxA2xGUfxstrITYjexPK0F6f47jNM5OTJW9lnV/4xO3mrfvTzs4gp/+vJOP4oqThc3gNmtcoszoV9vmnBGpXpFq84LE/W9r5YAzN549zbgJnzSpiLrpVfDib/0xyE/peP37WuCPLwD8yOGBNWDt8hoRRim78eKJSAeqDGnXqmpZTBjLI6ue3aOv1OxqLxpYIYBAT6vFVYqCbfHd3LXPLdyWCY5GS3BzDyCNEQNDKA7RRiCFz22idtO4s8FUOF8eYFQrIQCJGxif2gcfpO/wJMLW98yLnsm17vSDQ9diQsWP7Sll7S2WHuLREMkK641IQLD3IlEPtVJORaEPazIyTTSA/WAwY3p/BmwmZcAvqKTsA2gL7y4= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:27 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 07/12] firmware: qcom: scm: make qcom_scm_qseecom_app_get_id() use the TZ allocator Date: Mon, 5 Feb 2024 19:28:05 +0100 Message-Id: <20240205182810.58382-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102829_750217_BBC848B2 X-CRM114-Status: GOOD ( 11.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Let's use the new TZ memory allocator to obtain a buffer for this call instead of manually kmalloc()ing it and then mapping to physical space. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Maximilian Luz Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 11638daa2fe5..3a6cefb4eb2e 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1525,37 +1525,27 @@ int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id) unsigned long app_name_len = strlen(app_name); struct qcom_scm_desc desc = {}; struct qcom_scm_qseecom_resp res = {}; - dma_addr_t name_buf_phys; - char *name_buf; int status; if (app_name_len >= name_buf_size) return -EINVAL; - name_buf = kzalloc(name_buf_size, GFP_KERNEL); + char *name_buf __free(qcom_tzmem) = qcom_tzmem_alloc(__scm->mempool, + name_buf_size, + GFP_KERNEL); if (!name_buf) return -ENOMEM; memcpy(name_buf, app_name, app_name_len); - name_buf_phys = dma_map_single(__scm->dev, name_buf, name_buf_size, DMA_TO_DEVICE); - status = dma_mapping_error(__scm->dev, name_buf_phys); - if (status) { - kfree(name_buf); - dev_err(__scm->dev, "qseecom: failed to map dma address\n"); - return status; - } - desc.owner = QSEECOM_TZ_OWNER_QSEE_OS; desc.svc = QSEECOM_TZ_SVC_APP_MGR; desc.cmd = QSEECOM_TZ_CMD_APP_LOOKUP; desc.arginfo = QCOM_SCM_ARGS(2, QCOM_SCM_RW, QCOM_SCM_VAL); - desc.args[0] = name_buf_phys; + desc.args[0] = qcom_tzmem_to_phys(name_buf); desc.args[1] = app_name_len; status = qcom_scm_qseecom_call(&desc, &res); - dma_unmap_single(__scm->dev, name_buf_phys, name_buf_size, DMA_TO_DEVICE); - kfree(name_buf); if (status) return status; From patchwork Mon Feb 5 18:28:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED4B2C48292 for ; Mon, 5 Feb 2024 18:28:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VqTEmoXUyMI44G16y/f5WB2k+VoFN5EWqE8aXybDi7A=; b=P4fLQsuAaxdoAI AyDmlYxLiI9b4M5JsS01Pt/wtlWB89Iz1njc44SdE/jhpl1AbVwXxmPJtlgn4Hf01I/VU4ibVPgKB t3fb5ZmWZhUR5ANLxOhpRHt7rx0pBskubjs6ong0ZpEbSJW4WkUji569V3yrU8SgI83y6iHhwiILl ydB7/Q/hMjId4LEnZJMV2tCeVavlhFo/Nq+A4J10oNQBRkJww3mmOydOY9Ccq1LKppRTtOIsuojs8 RNRe9FKHzbVua+eFfY+ITMT0T4cesE0SLWtKFN+Lpes6+QSqsQ8EGFUXjAbVLli8DT3ZbbL91rbSV 5cBCddVw4REeUoRLpwVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hy-00000004N1y-32cP; Mon, 05 Feb 2024 18:28:42 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hm-00000004Mst-3pNJ for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:33 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40fb63c40c0so42297955e9.2 for ; Mon, 05 Feb 2024 10:28:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157709; x=1707762509; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TWiBsxQWnXiJtHV/JtQJWRsA3qzVyYhEwyyTPGYnYe4=; b=yRfIdBnmlz76ifK60KP6npHxTBfaWP7UyV2aLO2ALavvIIx+4GBuSqyosFWF/V5DoT g3NiCogBapVMSwVEJJXFBARkZ4G/Ad8kOlVfpxSc8dp5FAy+H1asddx2qH4BguohwGnY K3Hsl52bu99qBkTwIneEDzZJu3sTV/mrPslKY5d2zLy0E2s7bFzEoDLINvMAi6+xgGfB 33mKLt6mOHLBKihloHoiRtUVRhodA++ndvwccYN1NYazz3pvhwFMCR4pyCdcx/ps3ce8 s9CYUATYebYt+b9475kjlKa4adZS0vveoSK8rSWUsBwdyTWgjR5YL+4FQLaz4xzyTQMM QLPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157709; x=1707762509; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TWiBsxQWnXiJtHV/JtQJWRsA3qzVyYhEwyyTPGYnYe4=; b=ernVqFinWXYURGd2ibJh+p9RiQ9nZnzo/5pay4YZuGE9nETUXdqAJagoIeD3K80XOI ftO4O9gZ83E4epaudcMuXbe35ySMgNBng4Kp9ChgYa7Qsl6Ri2y2FLayLiudbYYGlYNG GA45AS//L6GFeQprOwMJYJe1X7NrVyw9KJ3f+DTn5YE0zJbvlzPI3IO4PE0d2ZX9sRit PB+MvwdaxLDXF+peca267Cxo9RrAQgnpRsfD5T+ZxB2VYjAQDNJP7T0t6kuJL27g21Q3 3MMtQbBfDiWssj6tecGLDMhF7FYfpkSop9o5CYv8r/0jm0fefIDzkk4C840OW58B+5j7 ICvQ== X-Gm-Message-State: AOJu0Yy+ZkKd3ENg+Wr/aH9CdF2i+bJReRYWYbyX7+oDoImMMjxbFYO5 uxrurDiIu++sTamkXRGqNMIjY5XWCunK+t8ddw1NTXi89uXyxGSBN6aYIqmavqk= X-Google-Smtp-Source: AGHT+IHtp1AzWSqi26YOoZr/ui6DHQzj/kUxDAoAc3QdKuqtEyguHL/+LT4Bq5or5mKeJdoXR7Yyhw== X-Received: by 2002:a5d:46c6:0:b0:33b:2281:ef32 with SMTP id g6-20020a5d46c6000000b0033b2281ef32mr181745wrs.69.1707157708955; Mon, 05 Feb 2024 10:28:28 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXMw+ruDxCTOkcnQeBS8yQYRyNNVMMgtBNzmO3uNYo+uQuahdaDkk+1KBEGjrDMvng4OeEeu4lJVOYi6xAeuuhUlrJSo8saDSnFRN5aVpNMS0lJpEOh7WNnbakBSM0vECXy8M9x5jdh5UUiiFR84ddXQVfoc2HQFM9JEj7VHz0IZS6vRO7niQsbID4AhB31N8i3qFiIbNAL/PzPCoCnneBqXgTV0CL5FLQUk8pT8sxkZUeukkDCNzpYAxcA3DxuyBjdKd8GvmvjFZU/oHV3R2oaTZ4jpzA5vAgQo9VICQ6E/dvkan8c7Q0r6iBnIp6x0q28bE9pnhI7L6zNi4H/CeQWCo/lam7rY0M28UVn8r+Ie4j+dOS0lXdy+cXepU61rWrRkuAZOMRF4YGOz9tW+OsDny9SiNIEDx5+3qBsgu8KfF+UM0opSgpfsy3KJNZYocjXY7YMo9vSjg0fT/rYmecoECFvWmCpLGHrTBeTn1xcqsW+juZcAGBmXYd+w8WrJHV93+NKphFScF4NDNsZmpEMK7OPqNltoymOdPu2Vy5qiddlKLMdWy5j0nJ8aW3/rRU= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:28 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 08/12] firmware: qcom: qseecom: convert to using the TZ allocator Date: Mon, 5 Feb 2024 19:28:06 +0100 Message-Id: <20240205182810.58382-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102831_068383_1C07729D X-CRM114-Status: GOOD ( 20.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Drop the DMA mapping operations from qcom_scm_qseecom_app_send() and convert all users of it in the qseecom module to using the TZ allocator for creating SCM call buffers. Together with using the cleanup macros, it has the added benefit of a significant code shrink. As this is largely a module separate from the SCM driver, let's use a separate memory pool. Signed-off-by: Bartosz Golaszewski Reviewed-by: Andrew Halaney Tested-by: Maximilian Luz Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- .../firmware/qcom/qcom_qseecom_uefisecapp.c | 281 +++++++----------- drivers/firmware/qcom/qcom_scm.c | 30 +- include/linux/firmware/qcom/qcom_qseecom.h | 4 +- 3 files changed, 111 insertions(+), 204 deletions(-) diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c index 32188f098ef3..3a068f8b6990 100644 --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c @@ -7,17 +7,21 @@ * Copyright (C) 2023 Maximilian Luz */ +#include #include #include #include #include #include #include +#include #include #include #include #include +#include +#include /* -- Qualcomm "uefisecapp" interface definitions. -------------------------- */ @@ -253,6 +257,7 @@ struct qsee_rsp_uefi_query_variable_info { struct qcuefi_client { struct qseecom_client *client; struct efivars efivars; + struct qcom_tzmem_pool *mempool; }; static struct device *qcuefi_dev(struct qcuefi_client *qcuefi) @@ -272,11 +277,11 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e const efi_guid_t *guid, u32 *attributes, unsigned long *data_size, void *data) { - struct qsee_req_uefi_get_variable *req_data; - struct qsee_rsp_uefi_get_variable *rsp_data; + struct qsee_req_uefi_get_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_get_variable *rsp_data __free(qcom_tzmem) = NULL; unsigned long buffer_size = *data_size; - efi_status_t efi_status = EFI_SUCCESS; unsigned long name_length; + efi_status_t efi_status; size_t guid_offs; size_t name_offs; size_t req_size; @@ -304,17 +309,13 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e __array(u8, buffer_size) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, rsp_size, GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_GET_VARIABLE; req_data->data_size = buffer_size; @@ -325,28 +326,20 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e req_data->length = req_size; status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, name_length); - if (status < 0) { - efi_status = EFI_INVALID_PARAMETER; - goto out_free; - } + if (status < 0) + return EFI_INVALID_PARAMETER; memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, rsp_size); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_GET_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_GET_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length < sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length < sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", @@ -360,18 +353,14 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e *attributes = rsp_data->attributes; } - goto out_free; + return efi_status; } - if (rsp_data->length > rsp_size) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length > rsp_size) + return EFI_DEVICE_ERROR; - if (rsp_data->data_offset + rsp_data->data_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->data_offset + rsp_data->data_size > rsp_data->length) + return EFI_DEVICE_ERROR; /* * Note: We need to set attributes and data size even if the buffer is @@ -394,33 +383,23 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e if (attributes) *attributes = rsp_data->attributes; - if (buffer_size == 0 && !data) { - efi_status = EFI_SUCCESS; - goto out_free; - } + if (buffer_size == 0 && !data) + return EFI_SUCCESS; - if (buffer_size < rsp_data->data_size) { - efi_status = EFI_BUFFER_TOO_SMALL; - goto out_free; - } + if (buffer_size < rsp_data->data_size) + return EFI_BUFFER_TOO_SMALL; memcpy(data, ((void *)rsp_data) + rsp_data->data_offset, rsp_data->data_size); -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const efi_char16_t *name, const efi_guid_t *guid, u32 attributes, unsigned long data_size, const void *data) { - struct qsee_req_uefi_set_variable *req_data; - struct qsee_rsp_uefi_set_variable *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_set_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_set_variable *rsp_data __free(qcom_tzmem) = NULL; unsigned long name_length; size_t name_offs; size_t guid_offs; @@ -450,17 +429,14 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e __array_offs(u8, data_size, &data_offs) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*rsp_data), + GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_SET_VARIABLE; req_data->attributes = attributes; @@ -473,10 +449,8 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e req_data->length = req_size; status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, name_length); - if (status < 0) { - efi_status = EFI_INVALID_PARAMETER; - goto out_free; - } + if (status < 0) + return EFI_INVALID_PARAMETER; memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); @@ -485,42 +459,31 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, sizeof(*rsp_data)); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_SET_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_SET_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length != sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length != sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", __func__, rsp_data->status); - efi_status = qsee_uefi_status_to_efi(rsp_data->status); + return qsee_uefi_status_to_efi(rsp_data->status); } -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, unsigned long *name_size, efi_char16_t *name, efi_guid_t *guid) { - struct qsee_req_uefi_get_next_variable *req_data; - struct qsee_rsp_uefi_get_next_variable *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_get_next_variable *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_get_next_variable *rsp_data __free(qcom_tzmem) = NULL; + efi_status_t efi_status; size_t guid_offs; size_t name_offs; size_t req_size; @@ -545,17 +508,13 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, __array(*name, *name_size / sizeof(*name)) ); - req_data = kzalloc(req_size, GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_tzmem_alloc(qcuefi->mempool, req_size, GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(rsp_size, GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, rsp_size, GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_GET_NEXT_VARIABLE; req_data->guid_offset = guid_offs; @@ -567,26 +526,18 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, *name_size / sizeof(*name)); - if (status < 0) { - efi_status = EFI_INVALID_PARAMETER; - goto out_free; - } + if (status < 0) + return EFI_INVALID_PARAMETER; status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, rsp_size); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_GET_NEXT_VARIABLE) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_GET_NEXT_VARIABLE) + return EFI_DEVICE_ERROR; - if (rsp_data->length < sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length < sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", @@ -601,77 +552,59 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, if (efi_status == EFI_BUFFER_TOO_SMALL) *name_size = rsp_data->name_size; - goto out_free; + return efi_status; } - if (rsp_data->length > rsp_size) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length > rsp_size) + return EFI_DEVICE_ERROR; - if (rsp_data->name_offset + rsp_data->name_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->name_offset + rsp_data->name_size > rsp_data->length) + return EFI_DEVICE_ERROR; - if (rsp_data->guid_offset + rsp_data->guid_size > rsp_data->length) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->guid_offset + rsp_data->guid_size > rsp_data->length) + return EFI_DEVICE_ERROR; if (rsp_data->name_size > *name_size) { *name_size = rsp_data->name_size; - efi_status = EFI_BUFFER_TOO_SMALL; - goto out_free; + return EFI_BUFFER_TOO_SMALL; } - if (rsp_data->guid_size != sizeof(*guid)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->guid_size != sizeof(*guid)) + return EFI_DEVICE_ERROR; memcpy(guid, ((void *)rsp_data) + rsp_data->guid_offset, rsp_data->guid_size); status = ucs2_strscpy(name, ((void *)rsp_data) + rsp_data->name_offset, rsp_data->name_size / sizeof(*name)); *name_size = rsp_data->name_size; - if (status < 0) { + if (status < 0) /* * Return EFI_DEVICE_ERROR here because the buffer size should * have already been validated above, causing this function to * bail with EFI_BUFFER_TOO_SMALL. */ - efi_status = EFI_DEVICE_ERROR; - } + return EFI_DEVICE_ERROR; -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, u32 attr, u64 *storage_space, u64 *remaining_space, u64 *max_variable_size) { - struct qsee_req_uefi_query_variable_info *req_data; - struct qsee_rsp_uefi_query_variable_info *rsp_data; - efi_status_t efi_status = EFI_SUCCESS; + struct qsee_req_uefi_query_variable_info *req_data __free(qcom_tzmem) = NULL; + struct qsee_rsp_uefi_query_variable_info *rsp_data __free(qcom_tzmem) = NULL; int status; - req_data = kzalloc(sizeof(*req_data), GFP_KERNEL); - if (!req_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out; - } + req_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*req_data), + GFP_KERNEL); + if (!req_data) + return EFI_OUT_OF_RESOURCES; - rsp_data = kzalloc(sizeof(*rsp_data), GFP_KERNEL); - if (!rsp_data) { - efi_status = EFI_OUT_OF_RESOURCES; - goto out_free_req; - } + rsp_data = qcom_tzmem_alloc(qcuefi->mempool, sizeof(*rsp_data), + GFP_KERNEL); + if (!rsp_data) + return EFI_OUT_OF_RESOURCES; req_data->command_id = QSEE_CMD_UEFI_QUERY_VARIABLE_INFO; req_data->attributes = attr; @@ -679,26 +612,19 @@ static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, status = qcom_qseecom_app_send(qcuefi->client, req_data, sizeof(*req_data), rsp_data, sizeof(*rsp_data)); - if (status) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (status) + return EFI_DEVICE_ERROR; - if (rsp_data->command_id != QSEE_CMD_UEFI_QUERY_VARIABLE_INFO) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->command_id != QSEE_CMD_UEFI_QUERY_VARIABLE_INFO) + return EFI_DEVICE_ERROR; - if (rsp_data->length != sizeof(*rsp_data)) { - efi_status = EFI_DEVICE_ERROR; - goto out_free; - } + if (rsp_data->length != sizeof(*rsp_data)) + return EFI_DEVICE_ERROR; if (rsp_data->status) { dev_dbg(qcuefi_dev(qcuefi), "%s: uefisecapp error: 0x%x\n", __func__, rsp_data->status); - efi_status = qsee_uefi_status_to_efi(rsp_data->status); - goto out_free; + return qsee_uefi_status_to_efi(rsp_data->status); } if (storage_space) @@ -710,12 +636,7 @@ static efi_status_t qsee_uefi_query_variable_info(struct qcuefi_client *qcuefi, if (max_variable_size) *max_variable_size = rsp_data->max_variable_size; -out_free: - kfree(rsp_data); -out_free_req: - kfree(req_data); -out: - return efi_status; + return EFI_SUCCESS; } /* -- Global efivar interface. ---------------------------------------------- */ @@ -844,6 +765,10 @@ static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev, if (status) qcuefi_set_reference(NULL); + qcuefi->mempool = devm_qcom_tzmem_pool_new(&aux_dev->dev, SZ_256K); + if (IS_ERR(qcuefi->mempool)) + return PTR_ERR(qcuefi->mempool); + return status; } diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 3a6cefb4eb2e..318d7d398e5f 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1567,9 +1567,9 @@ EXPORT_SYMBOL_GPL(qcom_scm_qseecom_app_get_id); /** * qcom_scm_qseecom_app_send() - Send to and receive data from a given QSEE app. * @app_id: The ID of the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be TZ memory) * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be TZ memory) * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given ID and read back @@ -1585,26 +1585,12 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, { struct qcom_scm_qseecom_resp res = {}; struct qcom_scm_desc desc = {}; - dma_addr_t req_phys; - dma_addr_t rsp_phys; + phys_addr_t req_phys; + phys_addr_t rsp_phys; int status; - /* Map request buffer */ - req_phys = dma_map_single(__scm->dev, req, req_size, DMA_TO_DEVICE); - status = dma_mapping_error(__scm->dev, req_phys); - if (status) { - dev_err(__scm->dev, "qseecom: failed to map request buffer\n"); - return status; - } - - /* Map response buffer */ - rsp_phys = dma_map_single(__scm->dev, rsp, rsp_size, DMA_FROM_DEVICE); - status = dma_mapping_error(__scm->dev, rsp_phys); - if (status) { - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - dev_err(__scm->dev, "qseecom: failed to map response buffer\n"); - return status; - } + req_phys = qcom_tzmem_to_phys(req); + rsp_phys = qcom_tzmem_to_phys(rsp); /* Set up SCM call data */ desc.owner = QSEECOM_TZ_OWNER_TZ_APPS; @@ -1622,10 +1608,6 @@ int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, /* Perform call */ status = qcom_scm_qseecom_call(&desc, &res); - /* Unmap buffers */ - dma_unmap_single(__scm->dev, rsp_phys, rsp_size, DMA_FROM_DEVICE); - dma_unmap_single(__scm->dev, req_phys, req_size, DMA_TO_DEVICE); - if (status) return status; diff --git a/include/linux/firmware/qcom/qcom_qseecom.h b/include/linux/firmware/qcom/qcom_qseecom.h index 5c28298a98be..e868fac55675 100644 --- a/include/linux/firmware/qcom/qcom_qseecom.h +++ b/include/linux/firmware/qcom/qcom_qseecom.h @@ -27,9 +27,9 @@ struct qseecom_client { /** * qcom_qseecom_app_send() - Send to and receive data from a given QSEE app. * @client: The QSEECOM client associated with the target app. - * @req: Request buffer sent to the app (must be DMA-mappable). + * @req: Request buffer sent to the app (must be TZ memory). * @req_size: Size of the request buffer. - * @rsp: Response buffer, written to by the app (must be DMA-mappable). + * @rsp: Response buffer, written to by the app (must be TZ memory). * @rsp_size: Size of the response buffer. * * Sends a request to the QSEE app associated with the given client and read From patchwork Mon Feb 5 18:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DB645C4828D for ; Mon, 5 Feb 2024 18:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uJIHNMHCXXfKPrXjkxa2ia9R9ukLfl1aGEMirfRTWrs=; b=SXdoLjES2WUWT8 u2CKECfoCm5yqHHXd+gkIrCZbGc0Xj6UifNyc2vZb3+7PhmypF51/w8Z/JUXkjneaAarwkpCUJf0Z XD/JOzWbfmMzYI1Qqm9DiKFuiEaqp8oUfQanyGHOETzd/ppxQjf/YF/MScSUFqflR0Rs+SBVTe5n+ fofQJuKSMv8ga6fJhgOVXl/VKrYYAfByLrRQijld7oPlsfUuqNWu14pPL1P2pIY4tb7kVIlAbqJL1 BIRirMC7NTzZEaLJ6suCYJrCj21YArXloFv7cUnnapT/YT7JFi4wZO8y36YItUSYHOUoMmr++1C+N vsLoqKWLlPuXGfWff0zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hx-00000004N16-1pZi; Mon, 05 Feb 2024 18:28:41 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hn-00000004MtK-2qrR for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:33 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40ef64d8955so43314165e9.3 for ; Mon, 05 Feb 2024 10:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157710; x=1707762510; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2ES7ecXlXJM4Un4rzG7GFObnKvctiGb4CfffnKCJdG4=; b=keaC7yGkJmMwJf/s3Lo3X/ww6Zm0sntdw4hvDCNASEOau1Eg4tnZOKanOLLoy+b9XS +ISq2M7h0JPeGrbMTd+ac2oLUEcYYF/sR8/+JDWJvPPPaN2lktimYezcv9V8aXvZvaX8 Q1xctiwZK64u8RbI9m9+W/prINk5L06mAceWDMOtMnO7gsQh6c5A7A9A8eGKxmhI9ecE 9M1/9jq3RlVSiREIZkZH88fll/NUOcPXGSr4eclKD6j2NvFPjLIW1OqWbratsilDwd1W rzv+LqCcfxwFrflQTfLmiQkZ1VkVawhSL5U124Bd3KJ3W1VyjmkW5pMbk/InhPfUCEQW IP5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157710; x=1707762510; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ES7ecXlXJM4Un4rzG7GFObnKvctiGb4CfffnKCJdG4=; b=hCLt/gALssSfWJlqG39Ws+vo6Cth71TT3Q1r14pZexE6FbTEkEJVRRy6BlHCVjSfT2 bbI++HtCXC3ExKJI870yyiVlteeOQkRt4AJpEu9mCgO+K1imCu0/jbnXyU6gnt3mY3lV nb7/Izu8dCtmz/tJCIuw+RXorwk784Wc42sYhly7LwbtCYYSamE3Mmuk+1erywa+Eu7v XrExCYneNH25cyqn7rbewP+JSQy+jKAy5aYVmskPuZDr78/zlhD3vGHVPnaJ3EPNL4MI 2+UI/dLUu2Li9tUI8vHxbaP4PlNvGCKz/uDze/c3u+uGZLDb+V4Veu03uzAJADW75Qdl 5nsQ== X-Gm-Message-State: AOJu0YxIS2wEsuMjrtppqkJdFMklByYpXBCHPH57zUFLPON/mg+hr7Iq MEHPwW5h3MazbuoJYMJLLcUJlGt7sDWycsLnMLw4EBpu7vZVrVy+ooekerHAWX4= X-Google-Smtp-Source: AGHT+IHRaxer47lLsNPzE1lYerxnHDOmXIYeuKvwusAuZfA0G+ZPa72Q9c/tVaihsJD/QECD4k3d6w== X-Received: by 2002:a05:600c:4ed4:b0:40f:cd96:31b7 with SMTP id g20-20020a05600c4ed400b0040fcd9631b7mr397542wmq.30.1707157709934; Mon, 05 Feb 2024 10:28:29 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCXG4NRUGyz5H1DuEu3Wfk/Kz0AdLGb+zwwdX27Og5B0V7rIfarK16JLITSBQM/V9KeyyGchkFjLnJq7U9cX0GxpZtXosrAMPWWfYMFs2+/fLe50BF/hxsFGhKKOp5F8+jYV4rKyLp0BybdCDhPtJKBwg1kDXd5I7XZn7Ko+ZaZCmi+v09BUiOiXYpBYizzi8cxavpe2SlviXaovcaQ0daNEOl8C2LrqSGm8VmzkN7W6y0LBquZ4jJSFwbd1rJmxp36ubDgFfauUaTaDSLzg7bAd6aIYf/6ntYPSPjJavzU+u5k+8+nbEF4XDQNXTxMHlMT54VwjsqfzelEQ6Q2W8ONCV6f9xuhtNWVCflicS/5XDLAaSa0vZrqlkWncoMrtQIm4jF4DVfq/rRvHGqhOGTI/rrOV6v0IFM3Nhb1jCljYOT9hOBDfaQf43NaWgg4wIAFYdivbD449bwQme8kwM7SK9u5nvaGTmxR9G0oWfTqBt2JmMV5+EyPJZ2snVWBc7BW/BRXExustKITp2ztgqUsNnw5stbn8kNEPc/RBuaCEXpbWIIDpet1nkCZWLxDkMus= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:29 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 09/12] firmware: qcom: scm: add support for SHM bridge operations Date: Mon, 5 Feb 2024 19:28:07 +0100 Message-Id: <20240205182810.58382-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102831_841833_CE771B49 X-CRM114-Status: GOOD ( 12.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Add low-level primitives for enabling SHM bridge support as well as creating and destroying SHM bridge pools to qcom-scm. Signed-off-by: Bartosz Golaszewski Acked-by: Andrew Halaney Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- drivers/firmware/qcom/qcom_scm.c | 60 ++++++++++++++++++++++++++ drivers/firmware/qcom/qcom_scm.h | 3 ++ include/linux/firmware/qcom/qcom_scm.h | 6 +++ 3 files changed, 69 insertions(+) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 318d7d398e5f..839773270a21 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -1323,6 +1323,66 @@ bool qcom_scm_lmh_dcvsh_available(void) } EXPORT_SYMBOL_GPL(qcom_scm_lmh_dcvsh_available); +int qcom_scm_shm_bridge_enable(void) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_ENABLE, + .owner = ARM_SMCCC_OWNER_SIP + }; + + struct qcom_scm_res res; + + if (!__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_MP, + QCOM_SCM_MP_SHM_BRIDGE_ENABLE)) + return -EOPNOTSUPP; + + return qcom_scm_call(__scm->dev, &desc, &res) ?: res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_enable); + +int qcom_scm_shm_bridge_create(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids, u64 *handle) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_CREATE, + .owner = ARM_SMCCC_OWNER_SIP, + .args[0] = pfn_and_ns_perm_flags, + .args[1] = ipfn_and_s_perm_flags, + .args[2] = size_and_flags, + .args[3] = ns_vmids, + .arginfo = QCOM_SCM_ARGS(4, QCOM_SCM_VAL, QCOM_SCM_VAL, + QCOM_SCM_VAL, QCOM_SCM_VAL), + }; + + struct qcom_scm_res res; + int ret; + + ret = qcom_scm_call(__scm->dev, &desc, &res); + + if (handle && !ret) + *handle = res.result[1]; + + return ret ?: res.result[0]; +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_create); + +int qcom_scm_shm_bridge_delete(struct device *dev, u64 handle) +{ + struct qcom_scm_desc desc = { + .svc = QCOM_SCM_SVC_MP, + .cmd = QCOM_SCM_MP_SHM_BRIDGE_DELETE, + .owner = ARM_SMCCC_OWNER_SIP, + .args[0] = handle, + .arginfo = QCOM_SCM_ARGS(1, QCOM_SCM_VAL), + }; + + return qcom_scm_call(__scm->dev, &desc, NULL); +} +EXPORT_SYMBOL_GPL(qcom_scm_shm_bridge_delete); + int qcom_scm_lmh_profile_change(u32 profile_id) { struct qcom_scm_desc desc = { diff --git a/drivers/firmware/qcom/qcom_scm.h b/drivers/firmware/qcom/qcom_scm.h index aa7d06939f8e..cb7273aa0a5e 100644 --- a/drivers/firmware/qcom/qcom_scm.h +++ b/drivers/firmware/qcom/qcom_scm.h @@ -116,6 +116,9 @@ struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void); #define QCOM_SCM_MP_IOMMU_SET_CP_POOL_SIZE 0x05 #define QCOM_SCM_MP_VIDEO_VAR 0x08 #define QCOM_SCM_MP_ASSIGN 0x16 +#define QCOM_SCM_MP_SHM_BRIDGE_ENABLE 0x1c +#define QCOM_SCM_MP_SHM_BRIDGE_DELETE 0x1d +#define QCOM_SCM_MP_SHM_BRIDGE_CREATE 0x1e #define QCOM_SCM_SVC_OCMEM 0x0f #define QCOM_SCM_OCMEM_LOCK_CMD 0x01 diff --git a/include/linux/firmware/qcom/qcom_scm.h b/include/linux/firmware/qcom/qcom_scm.h index ccaf28846054..9b6054813f59 100644 --- a/include/linux/firmware/qcom/qcom_scm.h +++ b/include/linux/firmware/qcom/qcom_scm.h @@ -115,6 +115,12 @@ int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, int qcom_scm_lmh_profile_change(u32 profile_id); bool qcom_scm_lmh_dcvsh_available(void); +int qcom_scm_shm_bridge_enable(void); +int qcom_scm_shm_bridge_create(struct device *dev, u64 pfn_and_ns_perm_flags, + u64 ipfn_and_s_perm_flags, u64 size_and_flags, + u64 ns_vmids, u64 *handle); +int qcom_scm_shm_bridge_delete(struct device *dev, u64 handle); + #ifdef CONFIG_QCOM_QSEECOM int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id); From patchwork Mon Feb 5 18:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A18ECC48297 for ; Mon, 5 Feb 2024 18:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=d6dqrImdIsfmPIBWcIrkSzyKlP2zyYVisCNopJtUzd4=; b=GUvb1ImWOOTINk a8p3NP/v03RofzMY/nm1KYL1HPoAafgGZs7KaRsgCKOdCym27kNCAxKOVNwqA7lZAC+yLETASUBcI l9bFKWlanIjzTlQNDfpvRP9ebQraqXaqIddHIHYnMErYAuB4+CUaXhBrJpZ65WeeOFXohPYLLO05N CrKBzJmTFOlez2TxDbZNej0k3A5lRl/6Dw14cuOQuEnb0Q8u3M3s6JHWIEo4YlMipyTVYTkvYr6jE LkKSZ+j8PFFVuaOR7M8LQSFWGE83kGx0CqlBSpyvQ+iEVTgRftKYMdvQQOkNnKvwGcdvNSErMBYCi ok3SUgE6L1PxOfTpEimQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3i0-00000004N3U-0Wra; Mon, 05 Feb 2024 18:28:44 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3ho-00000004MuQ-1jKD for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:34 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40fc52c2ae4so31531725e9.3 for ; Mon, 05 Feb 2024 10:28:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157711; x=1707762511; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=un7cEtb3KJw1A3qP7llM4B4OwSm9CqRxp4DvgeD9Ir4=; b=kDQUNu46h6uDY7+nulxG3ADrnOQGyar9T/mm/ietA+4zB1MKOjIBVR6IsaSHMt2c9N DnXSkmttCaRk1VAiEqSuUc4OkQDPO/ykH5NtYOg4i1wV3TmRNkp9sAJz2qqJiCEf7ENM 1LoZD7HFb2YnGy99eYopL+oB3VqKrYbmGujnw43v6Ji5HkvOY208Qbaokh+21UXgZfAM wogcVP/WHLVUOlK5L8q+HYBGduFvmlBSgYp8G0YFPr34jDvlB39xoiLOjg4cx+85f5WD lUFtA8r5p1e2/QB589iPc5CClvQ+n8NDe64IUtLTIZqZCQakz5D+fZfcN90vuMJZeTDd eC7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157711; x=1707762511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=un7cEtb3KJw1A3qP7llM4B4OwSm9CqRxp4DvgeD9Ir4=; b=qbnQmPLBEnhfM6EJmAPcvhhnMPboGzckRHsgQe+hEpVQAsdDBZ4p24vjgbxRQVyL8D kvyQE2qvSF4gkusO8gD4hywt4QGKcOe9H2MoGNBrAmh6dLkZi1fQvZ9/KHmKLSJU+eBa rm3KnqV+FWWFUpO2AtlUvxz2uHtDl9Ccxz8pNwaFeIk2zSqoGcoqxRTf6jIbvS8EcWBL +so4ODSW7DUCNld1Yx2V68wYcDZ3z/ze6OyArYptFpFXIY3MIf6HXyA1WFEZ2yk7FyZl wGhqT8jgADCRyrtSr6KBGncTKLueKS3eSa9hpSkFpLEYArTiA977ooyfAfhD4w2bGB+z x/ww== X-Gm-Message-State: AOJu0YxTPLaMwX3exwiMt32ISYk2ImxtzO8mC+yawH6aWaYY4QL4ksHY Z+RDE+SK8U2bGdTsNDgVmXEUNwIyjkHvqOk+ThcbOdSAPDvgYA+P3wWZ+lVrp6Y= X-Google-Smtp-Source: AGHT+IH+YlBI22schHQmMqidb7q3KHo+sRIdEP+Vmn6IUjpvEfBRLsCLSdwDp6ZXMGp2snNBJadkvQ== X-Received: by 2002:a5d:6d0c:0:b0:33b:1390:d952 with SMTP id e12-20020a5d6d0c000000b0033b1390d952mr317743wrq.19.1707157711039; Mon, 05 Feb 2024 10:28:31 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW3Htlt/5bJrrn9O1UdvEw6ixuei44u/CC58MhspOd6vqORlCnuOqqkZRF/NxTIONM6zbOXlvoYSv8sRFYaRSmgezLya4CjuF8V4Fwi2n0I/uwG94mUnku1SWSzhUHZ9noFevkniE46GT4gPJcHOukfnAxIfA9YToOrnaj7oSfmpueTu7Y4nkoLj0y+8rhzpOrKZ3EQkCj7kxdyaNNcwzrZDWd4J4TVv4sfQE6J85/AyBa/SnUjrcZ8nSHzN6sp8fY67PvOMFb4wsCx9g5OlB6yrRLetTGOlLgPTFrXQIAc78SPR+36t00yAIRlHspeFwprkDwhNdDHoAVxFr2EidtezBV1sA8YWz6P1TBm0LJ3MLnQGFOyfWL115nhVpXnjSGQUvcvRK5r4MZAVAuNY9GtHZcLWvqk05Aozm+sgzAf+v5360wJEQJPu/doQA5zik1GDidf32ZJEbBohor3t4B/xo99XPqdH1IxVA3B7iXr/1VCN6He3r3prGNJWmXVLzqyAprt/jeMy3CkHhIeAZp/m6/jTDCkr7iN6EILhf5J9wm8Qen9Q01uMcCbxp/exNs= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:30 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 10/12] firmware: qcom: tzmem: enable SHM Bridge support Date: Mon, 5 Feb 2024 19:28:08 +0100 Message-Id: <20240205182810.58382-11-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102832_563341_10E4928F X-CRM114-Status: GOOD ( 17.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Add a new Kconfig option for selecting the SHM Bridge mode of operation 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. 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. + 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. From patchwork Mon Feb 5 18:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44760C4828D for ; Mon, 5 Feb 2024 18:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1cLLXAcvcFwiPjO/W0jhKaUo7slEnLmo9X4LPaf40G4=; b=nUnJsDyvZaLjm/ ycnPZbiK8ZkPoLT2/VsoFGRIhful7F5MigrbHjRUtFjh++k5BOBjETo20NK5RS225sP3JLlfTo3sj BYmssXG5r0rUy/7qrfzw5J2PmEqjyg50Uz++Zc6KSbvhvQGNBzHx9Xc/mqsDrmjh9Wj7vNvOqgpbR saBzELAvbjjjM3cOKbZDeFXU3J5ysQjqJmcaH/ubhicrjHp49BPY6gSqipNODBCkuftR78L2m5TPu jwBLb6VdOsdTy4SXDEvZ4dtkilcCBJH6QC9trXhvoKM7K/SbhxMjNYWwMU0ILK9vrlgu7Yb00RL+p SEXnblvRgYJ0ewqmDeUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3i2-00000004N5I-26RV; Mon, 05 Feb 2024 18:28:46 +0000 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hp-00000004Mv1-1Ol6 for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:34 +0000 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40fc6343bd2so30060775e9.1 for ; Mon, 05 Feb 2024 10:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157712; x=1707762512; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I7SHOJjWn4ajTNVMkc896KlcCL3KSTkPo3OUGdVQzNA=; b=mFY9tVQVoZcb96pnU3l8f2k5lYSGToxGImtPzM+SgPqOrIP3REpqp84z0PpbUpU0zB APdH45KZe48dr3MWhKfSlKHnkW4aT2KEPRuoRA/DC/CXh7sIbz73sEm2QI7Rn9xi5ww7 RiWTX8dOzO8lZg2tPrtP0Us8Ej4162sJHxbjTerbS/YefQqJnnC8uZvz0mwE26Sds2Us bR0jDRQ6uwXfntf0gYpdJFVXAS77jPIGQL+MUbEYwyLHiuBJCCE7I39M+VG0UmxbxY9u 5rHhSLHLf1rAr1UKJqMT9mtv7hm3dS1HaVYePWiW/BZE3ZMRaqAkAxRWbUvzDNLD0h+2 t4jA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157712; x=1707762512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I7SHOJjWn4ajTNVMkc896KlcCL3KSTkPo3OUGdVQzNA=; b=kVIYZ3CgNbqXF/7SDptv9GNTJvlyu7Od2/qJns1ZRWb22KHpnlF74zNrDI9nGHMreO S8VQ4OocHkh7al+ZPr/zz8caOCzDNQKI8mwhp5ovGgXkOm7ukk2wX4A/3osW22uPv1bg ubi4pII6tqgCPVDuubk3suxXuflanLVp/TZFsbZjEbdwG/XOQI3LkKoEwDcehOzsFeII sKQZFY/okd++LNaGUcMX0eGDXodJXlsX40m/nco4DfMRq/8rrWCiS9AqeeTQ9sNS401f yDwkiAAJCHVdatcHI4tHEOPascXrI38qHCVUEclhUKak+E0UlcMaNGH505O48Dcy/J+0 E8zQ== X-Gm-Message-State: AOJu0YwCkEZp/vbAcJ+yLQdE7LA9T3ic2psh8HUmBAivtyXC6AnnXC5H Za/D2xXB1nDoxG5CHfrEVXf1dPU794CPlPA7kzafTstK0B+GsTbSnctW3tf49jU= X-Google-Smtp-Source: AGHT+IHdz/8C3w++G3TtxRyJjaTTNdLu+sTaVnsD4pE65MfKIdmPxliBIwgVedipoXEPhMJto4XEeg== X-Received: by 2002:a5d:44c4:0:b0:33b:2884:edf2 with SMTP id z4-20020a5d44c4000000b0033b2884edf2mr235515wrr.56.1707157712083; Mon, 05 Feb 2024 10:28:32 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWFmpYMxItrm4bBmJ9+HOBf3GceWMnNDYxReZOmJvsQeVxTV8L8qfCoyq2WW8W0rkQe0S3Tp0SwVLK4x20iaG8v/aH62qitEpg2aHFmtVbe5g2QUX/uGeebRaGuZZ638Ru8/5fb54H+u97BVOzbCAlE/BiLBQCR9lPZBvPUiloZDCo/qmMWF2YUZoO3O/7nfa0vjGlWyHwxNeIDbVK93uSDykWuqFEJm4c1v6iGq6xbyMpyWQv9aOMZ+c/A20g19a13guXOt4kA3I7W2uyTbbkvWR/UrQRIV0DBySUsLA84CZI8qNyNGW5kLr6NxKfEjbXJvqjQCB5bQPL0OBOW16tMRU4r/PAwCZgkc7WrAprZ7BOP18JqTtu+pqsgC5gTuH2KoQr/wmR062h4ZUWYAfNSGfVXXcQHgnRWlS33Sp9ICZrlbGdAHN55r1IhwfKgvVPevsxbvRFxCQ21Fg5OyuHRDzPmJrE5q4Tl08XN05rzmU2Q57aUiJRCFpxK5oHg1WHpmPo9gbDXkpGyWOJz/7wmcBwP9R4YonSZxeaTEpubnKdgXynxBPxL3dBNiag141Y= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:31 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 11/12] firmware: qcom: scm: clarify the comment in qcom_scm_pas_init_image() Date: Mon, 5 Feb 2024 19:28:09 +0100 Message-Id: <20240205182810.58382-12-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102833_595553_A855832F X-CRM114-Status: GOOD ( 13.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski The "memory protection" mechanism mentioned in the comment is the SHM Bridge. This is also the reason why we do not convert this call to using the TZ memory allocator. 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/qcom_scm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/firmware/qcom/qcom_scm.c b/drivers/firmware/qcom/qcom_scm.c index 839773270a21..7ba5cff6e4e7 100644 --- a/drivers/firmware/qcom/qcom_scm.c +++ b/drivers/firmware/qcom/qcom_scm.c @@ -563,9 +563,13 @@ 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. + * During the SCM call the hypervisor will make the buffer containing + * the program data into an SHM Bridge. This is why we exceptionally + * must not use the TrustZone memory allocator here as - depending on + * Kconfig - it may already use the SHM Bridge mechanism internally. + * + * If we pass a buffer that is already part of an SHM Bridge to this + * call, it will fail. */ mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, GFP_KERNEL); From patchwork Mon Feb 5 18:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13546027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 501EBC48297 for ; Mon, 5 Feb 2024 18:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2khbFtzzl07rFHOZy/NaiOPy2ujYm+dQYNoQSHDvp/8=; b=Dwrc0bOWqFOTvG ErPb5m7wVg6wUAWvt25b7OViZH/hQZPMLjvAiy6tAAtwnWFXa6mxsYCHqtuHm87SwMrI07dMSBmUJ nPhGPTjK+XvBIoN8fXNOcusRYnftatdOycqFWcCQYCESc3lajCkUPENhLnyY8E8xRXTvxSO2PKMMP 28VFReuHI5eIvnBzfxu91q4n259iHr82Ptxw6pHhlAC6t+okxtkarQeSx9AM++oXn6jzJ0evyEAff b8SU4o3egzQAFlybkPmSvgogThZu17Lp5g7ATctPt+k6SWzKayj6y39rBYkJHDX4F0Kgs5zTt/mWG b6yXe8jhEFAaSIU4Ns5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3i5-00000004N8M-1XQB; Mon, 05 Feb 2024 18:28:49 +0000 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rX3hr-00000004Mw0-0Vij for linux-arm-kernel@lists.infradead.org; Mon, 05 Feb 2024 18:28:36 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so3535681f8f.1 for ; Mon, 05 Feb 2024 10:28:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1707157713; x=1707762513; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RxZtfpTVf0bCO7EHLm2jgbKpvylHq5U4dLxNmrei5Xc=; b=ywEGFnsBCcW3e/bH27eswMbZSP8ly00XV49u98CSt/6Gtcek1zxb1FacDKgVIhPo1B lwTwyib6bUhNPugY0IZaconFlvkWmcItn7/HmW9vC3dTAJlMwzIDkSTy3s1PQ2cdbX1A +tFStRtw+tIugn4H+zK+Yb4fhf+R7WFxaNQTJIknbsIWv0qPNprc31uE3Hy9pRttLPNZ gfqQ5ap2k+TqS8uCmkih/PmmvN0VBmw4djxwZ/Evw2B0HYkNSxQGpyKPdHyHtQYW3/KG b1ROSOzylLDXekwUOvwuBZIBYu8xcbA7XrTrFbr6OPltAyWDWAX49/72AaeV0bAxAGPL tRxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707157713; x=1707762513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RxZtfpTVf0bCO7EHLm2jgbKpvylHq5U4dLxNmrei5Xc=; b=aCk5Ia/JEb/dX5+PPWHAO9SePm0QEUq3BZCObnXWJ7Ffc0wUXtnT63+/egvXvuigW8 3Y+FzpgyP9DTV9OZUxyBoMEWRVI6aNTX9gABWwuoY2ce9mzYaeKYIBELnW50YpvWF3L0 oxEsdsSivabof6gfXTnQA4tlYfgfeYUVJgly1/kHsC0uSEbnY/u4+kA5+2cGpdaXAMlW otVExkIlHvOkMGbNGzCOPAg1viK9yT3PyPPa18Yay7pBfTW/bpY8ZwRyemUB9rxLPa8F dIPXSAKPvl1YQri5hoJWPXlLYBTtHD2UZPJRpeAFwuYVSYAL//sOrDQzxlIvBjRf8DwS VetQ== X-Gm-Message-State: AOJu0Ywyni1zXHdihR9eYrc6ZkvEfpJ7cZXPCLDTNPM4P7k48zRsT7lw cz9TX0UEuxnDUgk/e8TaYaIwD1ff6ha4zPB7GOAEwDS9e7GGzKinU0HFczC7oac= X-Google-Smtp-Source: AGHT+IFpmEq2moHMRC6KEcwqwdWJnF72beZnSyfAR3Lk3OBN++riqvciA4tBGfw4SSutLs3EC5Mtvw== X-Received: by 2002:a5d:5046:0:b0:33a:fdb6:b1df with SMTP id h6-20020a5d5046000000b0033afdb6b1dfmr221612wrt.19.1707157713337; Mon, 05 Feb 2024 10:28:33 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCX7L90gPRH+fHuzHbeWfH8QHoz87Z1cIzaDeTGyJLMvXregJGx7AldZkKxPdE76W2NmUy+OmNcRQPP+hhdXNHLgRrBNTtcGEPULvIQy9U8HOU7cpvnqVAz7AFiLwr6jsymAeFVKBRZ4bd1BajyXebwk56WRoaYKlje4/UKds5NONGlKTtlBrVroRq0AdK3w/8RVt5yHjkU8jMIKA0vRAgV0zxk2yk+XZ4Bv/k33b2oueE/xa0Ev46IFwfCbnQfTZ8RmTK6ZD45rQ9oUbbvmdv4IhWcwLIcocfxA5uEPhSlpBnukJyD57qK/6Jl5J2VSRhsjeu1PauXdeN2/9eZ7kZvZFnp4zHVKwNoezsgP/5m6zATsefIVtnR2V2eZB8FTd2PNFwf+N684UXz1o1p3SfrnFYZW0mdrl7obk9ZZ0cGkWRl6ZD3pSzC/hJiXahkaeJqrd8ZAFd85j3VFAXG5NZxtMyfx9A/ga2PPxmzSrJ7NF2+NZw23awiS7x2ObjVl0e2atYBBfUpiF6M3UEiRcM4XhPCmjKE1KgVjy6AsZQ7n7jVnm4Azili+HRtGGT51nJ8= Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:d929:10db:5b5c:b49d]) by smtp.gmail.com with ESMTPSA id v15-20020a5d678f000000b0033b17e18df8sm203229wru.12.2024.02.05.10.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 10:28:32 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla , Arnd Bergmann Cc: 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: [PATCH v7 12/12] arm64: defconfig: enable SHM Bridge support for the TZ memory allocator Date: Mon, 5 Feb 2024 19:28:10 +0100 Message-Id: <20240205182810.58382-13-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240205182810.58382-1-brgl@bgdev.pl> References: <20240205182810.58382-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240205_102835_281665_5BDE57E4 X-CRM114-Status: GOOD ( 10.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Enable SHM Bridge support in the Qualcomm TrustZone allocator by default as even on architectures that don't support it, we automatically fall back to the default behavior. Signed-off-by: Bartosz Golaszewski Tested-by: Andrew Halaney # sc8280xp-lenovo-thinkpad-x13s Tested-by: Deepti Jaggi #sa8775p-ride Reviewed-by: Elliot Berman --- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index cfa3e00def09..f17bd3ea4a7f 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -253,6 +253,7 @@ CONFIG_INTEL_STRATIX10_RSU=m CONFIG_MTK_ADSP_IPC=m CONFIG_EFI_CAPSULE_LOADER=y CONFIG_IMX_SCU=y +CONFIG_QCOM_TZMEM_MODE_SHMBRIDGE=y CONFIG_QCOM_QSEECOM=y CONFIG_QCOM_QSEECOM_UEFISECAPP=y CONFIG_GNSS=m