From: Jens Wiklander <jens.wiklander@linaro.org>
To: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org
Cc: Sumit Garg <sumit.garg@linaro.org>,
Jerome Forissier <jerome.forissier@linaro.org>,
Shyam Saini <shyamsaini@linux.microsoft.com>,
Jens Wiklander <jens.wiklander@linaro.org>
Subject: [PATCH v2 2/2] optee: allocate shared memory with alloc_pages_exact()
Date: Wed, 8 Nov 2023 11:27:55 +0100 [thread overview]
Message-ID: <20231108102755.93079-3-jens.wiklander@linaro.org> (raw)
In-Reply-To: <20231108102755.93079-1-jens.wiklander@linaro.org>
Allocate memory to share with the secure using alloc_pages_exact()
instead of alloc_pages() for more efficient memory usage.
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
---
drivers/tee/optee/core.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index a425eca0173d..6303085a1b49 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -26,21 +26,19 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
size_t num_pages,
unsigned long start))
{
- unsigned int order = get_order(size);
- unsigned int nr_pages = 1 << order;
- struct page *page;
+ size_t nr_pages = roundup(size, PAGE_SIZE) / PAGE_SIZE;
int rc = 0;
/*
* Ignore alignment since this is already going to be page aligned
* and there's no need for any larger alignment.
*/
- page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
- if (!page)
+ shm->kaddr = alloc_pages_exact(nr_pages * PAGE_SIZE,
+ GFP_KERNEL | __GFP_ZERO);
+ if (!shm->kaddr)
return -ENOMEM;
- shm->kaddr = page_address(page);
- shm->size = PAGE_SIZE << order;
+ shm->size = nr_pages * PAGE_SIZE;
/*
* If memory is registered immediately use a temporary page list
@@ -66,7 +64,8 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
}
for (i = 0; i < nr_pages; i++)
- pages[i] = page + i;
+ pages[i] = virt_to_page((u8 *)shm->kaddr +
+ i * PAGE_SIZE);
if (shm_register) {
rc = shm_register(shm->ctx, shm, pages, nr_pages,
@@ -79,12 +78,12 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
shm->num_pages = nr_pages;
}
} else {
- shm->paddr = page_to_phys(page);
+ shm->paddr = virt_to_phys(shm->kaddr);
}
return 0;
err:
- free_pages((unsigned long)shm->kaddr, order);
+ free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
return rc;
}
@@ -95,7 +94,7 @@ void optee_pool_op_free_helper(struct tee_shm_pool *pool, struct tee_shm *shm,
{
if (shm_unregister)
shm_unregister(shm->ctx, shm);
- free_pages((unsigned long)shm->kaddr, get_order(shm->size));
+ free_pages_exact(shm->kaddr, shm->size);
shm->kaddr = NULL;
kfree(shm->pages);
shm->pages = NULL;
--
2.34.1
prev parent reply other threads:[~2023-11-08 10:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-08 10:27 [PATCH v2 0/2] OP-TEE kernel private shared memory optimizations Jens Wiklander
2023-11-08 10:27 ` [PATCH v2 1/2] optee: add page list to kernel private shared memory Jens Wiklander
2023-11-10 14:36 ` Sumit Garg
2023-11-13 17:13 ` Jens Wiklander
2023-11-08 10:27 ` Jens Wiklander [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231108102755.93079-3-jens.wiklander@linaro.org \
--to=jens.wiklander@linaro.org \
--cc=jerome.forissier@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=op-tee@lists.trustedfirmware.org \
--cc=shyamsaini@linux.microsoft.com \
--cc=sumit.garg@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®