Re: [PATCH] habanalabs: fix build warning

From: Arnd Bergmann
Date: Fri Apr 01 2022 - 03:53:24 EST


On Fri, Apr 1, 2022 at 8:55 AM Oded Gabbay <ogabbay@xxxxxxxxxx> wrote:
> On Fri, Apr 1, 2022 at 9:40 AM Arnd Bergmann <arnd@xxxxxxxx> wrote:
> > On Fri, Apr 1, 2022 at 6:16 AM Max Filippov <jcmvbkbc@xxxxxxxxx> wrote:
>
> We use gen_pool in this function to manage our device memory
> allocations (this is why it is called alloc_device_memory).

Ok, so it's none of the three I listed ;-)

> Basically, we initialize the genpool with the total size of the device memory,
> and each bit represents a page according to a fixed page size, which
> is dependent on asic type.
> The addresses represent the physical address of the device memory, as
> our device sees them.
> As these addresses are not accessible from the host, it is appropriate
> to hold them in u64, imo.
>
> For future asics which will support multiple page sizes, we need to
> use the gen_pool_dma_alloc_align() variant,
> because then we need the allocation to be aligned to the page size as
> requested by the user per allocation.
>
> We ignore the DMA address because this is device memory, not host memory.
> Therefore, our device's dma engine addresses the memory using the
> virtual memory addresses we assign to it in our device's MMU.
>
> Having said that, I'm wondering whether gen_pool_first_fit_align() can
> also work here, which might be less confusing.

Thank you for the explanation. I think the best way to make this less
confusing and to avoid the type casts would be to define your own
typedef for a device-internal address, and then wrap the allocator
functions such as gen_pool_dma_alloc_align() in helper functions that
do the type conversion safely.

Arnd