linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems
@ 2024-01-19 13:14 Nico Pache
  2024-01-21  4:39 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Nico Pache @ 2024-01-19 13:14 UTC (permalink / raw)
  To: linux-kernel, linux-kselftest, linux-mm; +Cc: akpm, shuah, donettom

On systems with 64k page size and 512M huge page sizes, the allocation
and test succeeds but errors out at the munmap. As the comment states,
munmap will failure if its not HUGEPAGE aligned. This is due to the
length of the mapping being 1/2 the size of the hugepage causing the
munmap to not be hugepage aligned. Fix this by making the mapping length
the full hugepage if the hugepage is larger than the length of the
mapping.

Signed-off-by: Nico Pache <npache@redhat.com>
---
 tools/testing/selftests/mm/map_hugetlb.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/mm/map_hugetlb.c b/tools/testing/selftests/mm/map_hugetlb.c
index 193281560b61..86e8f2048a40 100644
--- a/tools/testing/selftests/mm/map_hugetlb.c
+++ b/tools/testing/selftests/mm/map_hugetlb.c
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <fcntl.h>
+#include "vm_util.h"
 
 #define LENGTH (256UL*1024*1024)
 #define PROTECTION (PROT_READ | PROT_WRITE)
@@ -58,10 +59,16 @@ int main(int argc, char **argv)
 {
 	void *addr;
 	int ret;
+	size_t hugepage_size;
 	size_t length = LENGTH;
 	int flags = FLAGS;
 	int shift = 0;
 
+	hugepage_size = default_huge_page_size();
+	/* munmap with fail if the length is not page aligned */
+	if (hugepage_size > length)
+		length = hugepage_size;
+
 	if (argc > 1)
 		length = atol(argv[1]) << 20;
 	if (argc > 2) {
-- 
2.43.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems
  2024-01-19 13:14 [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems Nico Pache
@ 2024-01-21  4:39 ` Andrew Morton
  2024-01-22 14:08   ` Nico Pache
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2024-01-21  4:39 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-kernel, linux-kselftest, linux-mm, shuah, donettom,
	Christophe Leroy, Michael Ellerman

On Fri, 19 Jan 2024 06:14:29 -0700 Nico Pache <npache@redhat.com> wrote:

> On systems with 64k page size and 512M huge page sizes, the allocation
> and test succeeds but errors out at the munmap. As the comment states,
> munmap will failure if its not HUGEPAGE aligned. This is due to the
> length of the mapping being 1/2 the size of the hugepage causing the
> munmap to not be hugepage aligned. Fix this by making the mapping length
> the full hugepage if the hugepage is larger than the length of the
> mapping.

Is

Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")

a suitable Fixes: target for this?

> --- a/tools/testing/selftests/mm/map_hugetlb.c
> +++ b/tools/testing/selftests/mm/map_hugetlb.c
> @@ -15,6 +15,7 @@
>  #include <unistd.h>
>  #include <sys/mman.h>
>  #include <fcntl.h>
> +#include "vm_util.h"
>  
>  #define LENGTH (256UL*1024*1024)
>  #define PROTECTION (PROT_READ | PROT_WRITE)
> @@ -58,10 +59,16 @@ int main(int argc, char **argv)
>  {
>  	void *addr;
>  	int ret;
> +	size_t hugepage_size;
>  	size_t length = LENGTH;
>  	int flags = FLAGS;
>  	int shift = 0;
>  
> +	hugepage_size = default_huge_page_size();
> +	/* munmap with fail if the length is not page aligned */
> +	if (hugepage_size > length)
> +		length = hugepage_size;
> +
>  	if (argc > 1)
>  		length = atol(argv[1]) << 20;
>  	if (argc > 2) {
> -- 
> 2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems
  2024-01-21  4:39 ` Andrew Morton
@ 2024-01-22 14:08   ` Nico Pache
  0 siblings, 0 replies; 3+ messages in thread
From: Nico Pache @ 2024-01-22 14:08 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, linux-kselftest, linux-mm, shuah, donettom,
	Christophe Leroy, Michael Ellerman

Hi Andrew,

No, I think it's always been broken-- I don't think the test was
written with 512M huge page sizes in mind.

-- Nico

On Sat, Jan 20, 2024 at 9:39 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 19 Jan 2024 06:14:29 -0700 Nico Pache <npache@redhat.com> wrote:
>
> > On systems with 64k page size and 512M huge page sizes, the allocation
> > and test succeeds but errors out at the munmap. As the comment states,
> > munmap will failure if its not HUGEPAGE aligned. This is due to the
> > length of the mapping being 1/2 the size of the hugepage causing the
> > munmap to not be hugepage aligned. Fix this by making the mapping length
> > the full hugepage if the hugepage is larger than the length of the
> > mapping.
>
> Is
>
> Fixes: fa7b9a805c79 ("tools/selftest/vm: allow choosing mem size and page size in map_hugetlb")
>
> a suitable Fixes: target for this?
>
> > --- a/tools/testing/selftests/mm/map_hugetlb.c
> > +++ b/tools/testing/selftests/mm/map_hugetlb.c
> > @@ -15,6 +15,7 @@
> >  #include <unistd.h>
> >  #include <sys/mman.h>
> >  #include <fcntl.h>
> > +#include "vm_util.h"
> >
> >  #define LENGTH (256UL*1024*1024)
> >  #define PROTECTION (PROT_READ | PROT_WRITE)
> > @@ -58,10 +59,16 @@ int main(int argc, char **argv)
> >  {
> >       void *addr;
> >       int ret;
> > +     size_t hugepage_size;
> >       size_t length = LENGTH;
> >       int flags = FLAGS;
> >       int shift = 0;
> >
> > +     hugepage_size = default_huge_page_size();
> > +     /* munmap with fail if the length is not page aligned */
> > +     if (hugepage_size > length)
> > +             length = hugepage_size;
> > +
> >       if (argc > 1)
> >               length = atol(argv[1]) << 20;
> >       if (argc > 2) {
> > --
> > 2.43.0
>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-22 14:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-19 13:14 [PATCH v2] selftests: mm: fix map_hugetlb failure on 64K page size systems Nico Pache
2024-01-21  4:39 ` Andrew Morton
2024-01-22 14:08   ` Nico Pache

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox