From: Guenter Roeck <linux@roeck-us.net>
To: Oded Gabbay <ogabbay@kernel.org>
Cc: linux-kernel@vger.kernel.org, Ohad Sharabi <osharabi@habana.ai>
Subject: Re: [PATCH 1/2] habanalabs: make sure device mem alloc is page aligned
Date: Sat, 26 Mar 2022 06:16:29 -0700 [thread overview]
Message-ID: <20220326131629.GA198653@roeck-us.net> (raw)
In-Reply-To: <20220221084914.493784-1-ogabbay@kernel.org>
On Mon, Feb 21, 2022 at 10:49:13AM +0200, Oded Gabbay wrote:
> From: Ohad Sharabi <osharabi@habana.ai>
>
> Working with MMU that supports multiple page sizes requires that mapping
> of a page of a certain size will be aligned to the same size (e.g. the
> physical address of 32MB page shall be aligned to 32MB).
>
> To achieve this the gen_poll allocation is now using the "align" variant
> to comply with the alignment requirements.
>
> Signed-off-by: Ohad Sharabi <osharabi@habana.ai>
> Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
> Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
> ---
> drivers/misc/habanalabs/common/memory.c | 19 ++++++++++++++-----
> 1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/common/memory.c b/drivers/misc/habanalabs/common/memory.c
> index 385bf3448c73..0b76f40e9930 100644
> --- a/drivers/misc/habanalabs/common/memory.c
> +++ b/drivers/misc/habanalabs/common/memory.c
> @@ -90,8 +90,8 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
> struct hl_vm_phys_pg_pack *phys_pg_pack;
> u64 paddr = 0, total_size, num_pgs, i;
> u32 num_curr_pgs, page_size;
> - int handle, rc;
> bool contiguous;
> + int handle, rc;
>
> num_curr_pgs = 0;
>
> @@ -110,7 +110,11 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
> contiguous = args->flags & HL_MEM_CONTIGUOUS;
>
> if (contiguous) {
> - paddr = (u64) gen_pool_alloc(vm->dram_pg_pool, total_size);
> + if (is_power_of_2(page_size))
> + paddr = (u64) gen_pool_dma_alloc_align(vm->dram_pg_pool, total_size, NULL,
> + page_size);
I see that this is fixed in -next, but ...
> + else
> + paddr = (u64) gen_pool_alloc(vm->dram_pg_pool, total_size);
... this has an unnecessary typecast in -next (gen_pool_alloc() returns
unsigned long, not a pointer), and ...
> if (!paddr) {
> dev_err(hdev->dev,
> "failed to allocate %llu contiguous pages with total size of %llu\n",
> @@ -144,9 +148,14 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
> phys_pg_pack->pages[i] = paddr + i * page_size;
> } else {
> for (i = 0 ; i < num_pgs ; i++) {
> - phys_pg_pack->pages[i] = (u64) gen_pool_alloc(
> - vm->dram_pg_pool,
> - page_size);
> + if (is_power_of_2(page_size))
> + phys_pg_pack->pages[i] =
> + (u64) gen_pool_dma_alloc_align(vm->dram_pg_pool,
> + page_size, NULL,
> + page_size);
... this still causes a compile error when building 32-bit test images.
Building mips:allmodconfig ... failed
--------------
Error log:
drivers/misc/habanalabs/common/memory.c: In function 'alloc_device_memory':
drivers/misc/habanalabs/common/memory.c:153:49: error: cast from pointer to integer of different size
Guenter
> + else
> + phys_pg_pack->pages[i] = (u64) gen_pool_alloc(vm->dram_pg_pool,
> + page_size);
> if (!phys_pg_pack->pages[i]) {
> dev_err(hdev->dev,
> "Failed to allocate device memory (out of memory)\n");
> --
> 2.25.1
>
prev parent reply other threads:[~2022-03-26 13:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-21 8:49 [PATCH 1/2] habanalabs: make sure device mem alloc is page aligned Oded Gabbay
2022-02-21 8:49 ` [PATCH 2/2] habanalabs: Fix reset upon device release bug Oded Gabbay
2022-03-26 13:16 ` Guenter Roeck [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=20220326131629.GA198653@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ogabbay@kernel.org \
--cc=osharabi@habana.ai \
/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