[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0ad21a06-7a64-7d71-16f6-0bded64b6921@amd.com>
Date: Wed, 4 Oct 2023 16:29:41 +0530
From: Rijo Thomas <Rijo-john.Thomas@....com>
To: Devaraj Rangasamy <Devaraj.Rangasamy@....com>,
Jonathan Corbet <corbet@....net>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H . Peter Anvin" <hpa@...or.com>,
Jens Wiklander <jens.wiklander@...aro.org>,
Sumit Garg <sumit.garg@...aro.org>,
"Paul E . McKenney" <paulmck@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Randy Dunlap <rdunlap@...radead.org>,
Peter Zijlstra <peterz@...radead.org>,
Steven Rostedt <rostedt@...dmis.org>,
Daniel Sneddon <daniel.sneddon@...ux.intel.com>,
SivaSangeetha SK <SivaSangeetha.SK@....com>,
Josh Poimboeuf <jpoimboe@...nel.org>,
Juergen Gross <jgross@...e.com>,
Ard Biesheuvel <ardb@...nel.org>,
Ross Lagerwall <ross.lagerwall@...rix.com>,
Yuntao Wang <ytcoode@...il.com>,
Sean Christopherson <seanjc@...gle.com>,
Jarkko Nikula <jarkko.nikula@...ux.intel.com>,
Herbert Xu <herbert@...dor.apana.org.au>,
Tom Lendacky <thomas.lendacky@....com>,
Mario Limonciello <mario.limonciello@....com>,
linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
op-tee@...ts.trustedfirmware.org
Cc: Mythri PK <Mythri.Pandeshwarakrishna@....com>,
Nimesh Easow <Nimesh.Easow@....com>
Subject: Re: [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory
allocations
On 8/30/2023 1:49 AM, Devaraj Rangasamy wrote:
> 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@....com>
> ---
> v2:
> * Replaced __get_free_pages() with alloc_pages_exact().
>
Reviewed-by: Rijo Thomas <Rijo-john.Thomas@....com>
Thanks,
Rijo
> 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;
> }
>
Powered by blists - more mailing lists