mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rijo Thomas <Rijo-john.Thomas@amd.com>
To: Devaraj Rangasamy <Devaraj.Rangasamy@amd.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	Sumit Garg <sumit.garg@linaro.org>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Daniel Sneddon <daniel.sneddon@linux.intel.com>,
	SivaSangeetha SK <SivaSangeetha.SK@amd.com>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Juergen Gross <jgross@suse.com>, Ard Biesheuvel <ardb@kernel.org>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	Yuntao Wang <ytcoode@gmail.com>,
	Sean Christopherson <seanjc@google.com>,
	Jarkko Nikula <jarkko.nikula@linux.intel.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Mario Limonciello <mario.limonciello@amd.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	op-tee@lists.trustedfirmware.org
Cc: Mythri PK <Mythri.Pandeshwarakrishna@amd.com>,
	Nimesh Easow <Nimesh.Easow@amd.com>
Subject: Re: [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory allocations
Date: Wed, 4 Oct 2023 16:29:41 +0530	[thread overview]
Message-ID: <0ad21a06-7a64-7d71-16f6-0bded64b6921@amd.com> (raw)
In-Reply-To: <fe6fd7781d77ea32064e5b861f33150b28768278.1693340098.git.Devaraj.Rangasamy@amd.com>



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@amd.com>
> ---
>  v2:
>  * Replaced __get_free_pages() with alloc_pages_exact().
> 

Reviewed-by: Rijo Thomas <Rijo-john.Thomas@amd.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;
>  }
>  

  parent reply	other threads:[~2023-10-04 11:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2023-10-04 10:59 ` Rijo Thomas [this message]
2023-10-04 19:09 ` [PATCH v2 1/2] tee: amdtee: use page_alloc_exact() for memory allocations Jeff Johnson
2023-10-23 14:01   ` Devaraj Rangasamy

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=0ad21a06-7a64-7d71-16f6-0bded64b6921@amd.com \
    --to=rijo-john.thomas@amd.com \
    --cc=Devaraj.Rangasamy@amd.com \
    --cc=Mythri.Pandeshwarakrishna@amd.com \
    --cc=Nimesh.Easow@amd.com \
    --cc=SivaSangeetha.SK@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=daniel.sneddon@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=hpa@zytor.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jens.wiklander@linaro.org \
    --cc=jgross@suse.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mingo@redhat.com \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=ross.lagerwall@citrix.com \
    --cc=rostedt@goodmis.org \
    --cc=seanjc@google.com \
    --cc=sumit.garg@linaro.org \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    --cc=ytcoode@gmail.com \
    /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®