The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory allocations
@ 2023-08-29 20:19 Devaraj Rangasamy
  2023-08-29 20:19 ` [PATCH v2 2/2] tee: amdtee: add support for CMA buffer allocations Devaraj Rangasamy
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Devaraj Rangasamy @ 2023-08-29 20:19 UTC (permalink / raw)
  To: Jonathan Corbet, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H . Peter Anvin, Jens Wiklander, Sumit Garg,
	Paul E . McKenney, Catalin Marinas, Randy Dunlap, Peter Zijlstra,
	Steven Rostedt, Daniel Sneddon, Rijo Thomas, Devaraj Rangasamy,
	SivaSangeetha SK, Josh Poimboeuf, Juergen Gross, Ard Biesheuvel,
	Ross Lagerwall, Yuntao Wang, Sean Christopherson, Jarkko Nikula,
	Herbert Xu, Tom Lendacky, Mario Limonciello, linux-doc,
	linux-kernel, op-tee
  Cc: Mythri PK, Nimesh Easow

Use page_alloc_exact() to get buffers, instead of
get_free_pages(), so as to avoid wastage of memory.
Currently get_free_pages() is allocating at next order,
while page_alloc_exact() will free the unused pages.

Signed-off-by: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>
---
 v2:
 * Replaced __get_free_pages() with alloc_pages_exact().

 drivers/tee/amdtee/shm_pool.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/tee/amdtee/shm_pool.c b/drivers/tee/amdtee/shm_pool.c
index f0303126f199..156e8a6f631f 100644
--- a/drivers/tee/amdtee/shm_pool.c
+++ b/drivers/tee/amdtee/shm_pool.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/slab.h>
+#include <linux/mm.h>
 #include <linux/tee_drv.h>
 #include <linux/psp.h>
 #include "amdtee_private.h"
@@ -11,26 +12,23 @@
 static int pool_op_alloc(struct tee_shm_pool *pool, struct tee_shm *shm,
 			 size_t size, size_t align)
 {
-	unsigned int order = get_order(size);
-	unsigned long va;
+	void *va;
 	int rc;
 
-	/*
-	 * Ignore alignment since this is already going to be page aligned
-	 * and there's no need for any larger alignment.
-	 */
-	va = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
+	size = PAGE_ALIGN(size);
+
+	va = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
 	if (!va)
 		return -ENOMEM;
 
 	shm->kaddr = (void *)va;
 	shm->paddr = __psp_pa((void *)va);
-	shm->size = PAGE_SIZE << order;
+	shm->size = size;
 
 	/* Map the allocated memory in to TEE */
 	rc = amdtee_map_shmem(shm);
 	if (rc) {
-		free_pages(va, order);
+		free_pages_exact(va, size);
 		shm->kaddr = NULL;
 		return rc;
 	}
@@ -42,7 +40,7 @@ static void pool_op_free(struct tee_shm_pool *pool, struct tee_shm *shm)
 {
 	/* Unmap the shared memory from TEE */
 	amdtee_unmap_shmem(shm);
-	free_pages((unsigned long)shm->kaddr, get_order(shm->size));
+	free_pages_exact(shm->kaddr, shm->size);
 	shm->kaddr = NULL;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-23 14:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-29 20:19 [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory allocations Devaraj Rangasamy
2023-08-29 20:19 ` [PATCH v2 2/2] tee: amdtee: add support for CMA buffer allocations Devaraj Rangasamy
2023-10-04 10:59 ` [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory allocations Rijo Thomas
2023-10-04 19:09 ` Jeff Johnson
2023-10-23 14:01   ` Devaraj Rangasamy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox