diff mbox series

[RFC,v4,2/9] tools headers: Add a macro to get HUGETLB page sizes for mmap

Message ID 20210302125751.19080-3-wangyanan55@huawei.com
State Superseded
Headers show
Series KVM: selftests: some improvement and a new test for kvm page table | expand

Commit Message

Yanan Wang March 2, 2021, 12:57 p.m. UTC
We know that if a system supports multiple hugetlb page sizes,
the desired hugetlb page size can be specified in bits [26:31]
of the flag arguments. The value in these 6 bits will be the
shift of each hugetlb page size.

So add a macro to get the page size shift and then calculate the
corresponding hugetlb page size, using flag x.

Cc: Ben Gardon <bgardon@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Suggested-by: Ben Gardon <bgardon@google.com>
Signed-off-by: Yanan Wang <wangyanan55@huawei.com>
Reviewed-by: Ben Gardon <bgardon@google.com>
---
 include/uapi/linux/mman.h       | 2 ++
 tools/include/uapi/linux/mman.h | 2 ++
 2 files changed, 4 insertions(+)

Comments

Andrew Jones March 12, 2021, 11:14 a.m. UTC | #1
On Tue, Mar 02, 2021 at 08:57:44PM +0800, Yanan Wang wrote:
> We know that if a system supports multiple hugetlb page sizes,

> the desired hugetlb page size can be specified in bits [26:31]

> of the flag arguments. The value in these 6 bits will be the

> shift of each hugetlb page size.

> 

> So add a macro to get the page size shift and then calculate the

> corresponding hugetlb page size, using flag x.

> 

> Cc: Ben Gardon <bgardon@google.com>

> Cc: Ingo Molnar <mingo@kernel.org>

> Cc: Adrian Hunter <adrian.hunter@intel.com>

> Cc: Jiri Olsa <jolsa@redhat.com>

> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>

> Cc: Arnd Bergmann <arnd@arndb.de>

> Cc: Michael Kerrisk <mtk.manpages@gmail.com>

> Cc: Thomas Gleixner <tglx@linutronix.de>

> Suggested-by: Ben Gardon <bgardon@google.com>

> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>

> Reviewed-by: Ben Gardon <bgardon@google.com>

> ---

>  include/uapi/linux/mman.h       | 2 ++

>  tools/include/uapi/linux/mman.h | 2 ++

>  2 files changed, 4 insertions(+)

> 

> diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h

> index f55bc680b5b0..8bd41128a0ee 100644

> --- a/include/uapi/linux/mman.h

> +++ b/include/uapi/linux/mman.h

> @@ -41,4 +41,6 @@

>  #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB

>  #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB

>  

> +#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))


Needs to be '1ULL' to avoid shift overflow when given MAP_HUGE_16GB.

Thanks,
drew

> +

>  #endif /* _UAPI_LINUX_MMAN_H */

> diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h

> index f55bc680b5b0..8bd41128a0ee 100644

> --- a/tools/include/uapi/linux/mman.h

> +++ b/tools/include/uapi/linux/mman.h

> @@ -41,4 +41,6 @@

>  #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB

>  #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB

>  

> +#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))

> +

>  #endif /* _UAPI_LINUX_MMAN_H */

> -- 

> 2.23.0

>
Yanan Wang March 15, 2021, 2:06 a.m. UTC | #2
On 2021/3/12 19:14, Andrew Jones wrote:
> On Tue, Mar 02, 2021 at 08:57:44PM +0800, Yanan Wang wrote:

>> We know that if a system supports multiple hugetlb page sizes,

>> the desired hugetlb page size can be specified in bits [26:31]

>> of the flag arguments. The value in these 6 bits will be the

>> shift of each hugetlb page size.

>>

>> So add a macro to get the page size shift and then calculate the

>> corresponding hugetlb page size, using flag x.

>>

>> Cc: Ben Gardon <bgardon@google.com>

>> Cc: Ingo Molnar <mingo@kernel.org>

>> Cc: Adrian Hunter <adrian.hunter@intel.com>

>> Cc: Jiri Olsa <jolsa@redhat.com>

>> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>

>> Cc: Arnd Bergmann <arnd@arndb.de>

>> Cc: Michael Kerrisk <mtk.manpages@gmail.com>

>> Cc: Thomas Gleixner <tglx@linutronix.de>

>> Suggested-by: Ben Gardon <bgardon@google.com>

>> Signed-off-by: Yanan Wang <wangyanan55@huawei.com>

>> Reviewed-by: Ben Gardon <bgardon@google.com>

>> ---

>>   include/uapi/linux/mman.h       | 2 ++

>>   tools/include/uapi/linux/mman.h | 2 ++

>>   2 files changed, 4 insertions(+)

>>

>> diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h

>> index f55bc680b5b0..8bd41128a0ee 100644

>> --- a/include/uapi/linux/mman.h

>> +++ b/include/uapi/linux/mman.h

>> @@ -41,4 +41,6 @@

>>   #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB

>>   #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB

>>   

>> +#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))

> Needs to be '1ULL' to avoid shift overflow when given MAP_HUGE_16GB.

Thanks, drew. Will fix it.
> Thanks,

> drew

>

>> +

>>   #endif /* _UAPI_LINUX_MMAN_H */

>> diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h

>> index f55bc680b5b0..8bd41128a0ee 100644

>> --- a/tools/include/uapi/linux/mman.h

>> +++ b/tools/include/uapi/linux/mman.h

>> @@ -41,4 +41,6 @@

>>   #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB

>>   #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB

>>   

>> +#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))

>> +

>>   #endif /* _UAPI_LINUX_MMAN_H */

>> -- 

>> 2.23.0

>>

> .
diff mbox series

Patch

diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h
index f55bc680b5b0..8bd41128a0ee 100644
--- a/include/uapi/linux/mman.h
+++ b/include/uapi/linux/mman.h
@@ -41,4 +41,6 @@ 
 #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB
 #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB
 
+#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))
+
 #endif /* _UAPI_LINUX_MMAN_H */
diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h
index f55bc680b5b0..8bd41128a0ee 100644
--- a/tools/include/uapi/linux/mman.h
+++ b/tools/include/uapi/linux/mman.h
@@ -41,4 +41,6 @@ 
 #define MAP_HUGE_2GB	HUGETLB_FLAG_ENCODE_2GB
 #define MAP_HUGE_16GB	HUGETLB_FLAG_ENCODE_16GB
 
+#define MAP_HUGE_PAGE_SIZE(x) (1 << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK))
+
 #endif /* _UAPI_LINUX_MMAN_H */