Re: [PATCH 5/5] misc: mlx5ctl: Add umem reg/unreg ioctl

From: Saeed Mahameed
Date: Sun Nov 19 2023 - 04:49:33 EST


On 18 Oct 10:33, Greg Kroah-Hartman wrote:
On Wed, Oct 18, 2023 at 01:19:41AM -0700, Saeed Mahameed wrote:
+#define MLX5CTL_UMEM_MAX_MB 64
+
+static size_t umem_num_pages(u64 addr, size_t len)
+{
+ return (size_t)((ALIGN(addr + len, PAGE_SIZE) -
+ ALIGN_DOWN(addr, PAGE_SIZE))) /
+ PAGE_SIZE;
+}

We don't have a function or macro for this already?


I looked around and saw similar implementations, but nothing generic,
each has different assumptions, for example PAGE_SIZE can be different
or base address is assumed to be PAGE aligned, or len has a specific
alignment, so each use is a bit different.

I managed to reduce this to a one liner in V2.

Thanks,
Saeed.