selftests/mm: fix division-by-zero in uffd-unit-tests
Subsystems (5)
PATCH 1/1 selftests/mm: fix division-by-zero in uffd-unit-tests
Commit 4dfd4bba8578 ("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented in uffd_setup_environment() earlier in the main test loop.
The calculation of nr_pages, which involves a division by page_size, now occurs before checking that default_huge_page_size() returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.
Fix this by relocating the non-zero page_size check before the nr_pages calculation, as it was originally implemented.
--- tools/testing/selftests/mm/uffd-unit-tests.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
tools/testing/selftests/mm/uffd-unit-tests.c +7 -8
@@ -1758,10 +1758,15 @@ int main(int argc, char *argv[]) uffd_test_ops = mem_type->mem_ops; uffd_test_case_ops = test->test_case_ops; -if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE |MEM_HUGETLB )) +if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE |MEM_HUGETLB )) { gopts.page_size =default_huge_page_size (); -else +if (gopts.page_size ==0 ) { +uffd_test_skip ("huge page size is 0, feature missing?" ); +continue ; + } + }else { gopts.page_size =psize (); + }/* Ensure we have at least 2 pages */ gopts.nr_pages =MAX (UFFD_TEST_MEM_SIZE , gopts.page_size *2 )
@@ -1776,12 +1781,6 @@ int main(int argc, char *argv[])continue ;uffd_test_start ("%s on %s" , test->name, mem_type->name); -if ((mem_type->mem_flag ==MEM_HUGETLB || - mem_type->mem_flag ==MEM_HUGETLB_PRIVATE ) && - (default_huge_page_size () ==0 )) { -uffd_test_skip ("huge page size is 0, feature missing?" ); -continue ; - }if (!uffd_feature_supported (test)) {uffd_test_skip ("feature missing" );continue ;
Signature · 1 line
2.51.2.1041.gc1ab5b90ca-goog
Quoted 4 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.
Quoted 8 lines
The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.
Do we CC stable on unit tests? From my recollection, no.
Quoted 3 lines
Fixes 4dfd4bba8578 ("selftests/mm/uffd: refactor non-composite global vars into struct")Signed-off-by Carlos Llamas <[email protected]>---
Signature · 3 lines
Cheers David
Lorenzo Stoakes
Reviewed-byQuoted 9 lines · David Hildenbrand (Red Hat)
Quoted 8 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.
Quoted 6 lines
Quoted 4 lines
Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.Do we CC stable on unit tests? From my recollection, no.
Yeah please let's not.
Quoted 6 lines
Quoted 4 lines
Fixes 4dfd4bba8578 ("selftests/mm/uffd: refactor non-composite global vars into struct")Signed-off-by Carlos Llamas <[email protected]>---
LGTM so also:
Quoted 5 lines
--
CheersDavid
Cheers, Lorenzo
Quoted 10 lines · Lorenzo Stoakes
Quoted 9 lines · David Hildenbrand (Red Hat)
Quoted 8 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.Do we CC stable on unit tests? From my recollection, no.
Yeah please let's not.
Oops, I keep getting confused about this Cc stable thing. Please let me know if a v2 dropping the tag is needed.
--
Carlos Llamas
Quoted 14 lines · Carlos Llamas
Quoted 13 lines · Lorenzo Stoakes
Quoted 12 lines · David Hildenbrand (Red Hat)
Quoted 11 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Do we CC stable on unit tests? From my recollection, no.
Yeah please let's not.
Oops, I keep getting confused about this Cc stable thing. Please let me know if a v2 dropping the tag is needed.
No need, Andrew should spot the objection and drop the tag :)
Quoted 3 lines
--
Carlos Llamas
Cheers, Lorenzo
Andrew Morton
maintainerQuoted 17 lines · On Thu, 13 Nov 2025 15:03:06 +0000 Lorenzo Stoakes…
Quoted 16 lines · Carlos Llamas
Quoted 15 lines · Lorenzo Stoakes
Quoted 14 lines · David Hildenbrand (Red Hat)
Quoted 12 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Do we CC stable on unit tests? From my recollection, no.
Yeah please let's not.
Oops, I keep getting confused about this Cc stable thing. Please let me know if a v2 dropping the tag is needed.
No need, Andrew should spot the objection and drop the tag :)
I actually add cc:stable tags to selftests fixes!
Because why not. Why leave people running known-to-be-buggy code when our backporting processes are so well-functioning and lightweight?
I'm not getting the objection?
David Hildenbrand (Red Hat)
maintainerQuoted 26 lines · Andrew Morton
Quoted 24 lines · On Thu, 13 Nov 2025 15:03:06 +0000 Lorenzo Stoakes…
Quoted 22 lines · Carlos Llamas
Quoted 10 lines · Lorenzo Stoakes
Quoted 9 lines · David Hildenbrand (Red Hat)
Quoted 8 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.Do we CC stable on unit tests? From my recollection, no.
Yeah please let's not.
Oops, I keep getting confused about this Cc stable thing. Please let me know if a v2 dropping the tag is needed.
Quoted 8 lines
Quoted 1 line
No need, Andrew should spot the objection and drop the tag :)
I actually add cc:stable tags to selftests fixes!
Because why not. Why leave people running known-to-be-buggy code when our backporting processes are so well-functioning and lightweight?
I'm not getting the objection?
I thought we were so inconsistent on that that it ends up being a wasted effort to even try taking care about stability of selfests in stable trees.
Signature · 3 lines
Cheers David
Andrew Morton
maintainerQuoted 7 lines · On Fri, 14 Nov 2025 09:11:40 +0100 "David Hildenbrand (Red Hat)"…
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Oops, I keep getting confused about this Cc stable thing. Please let me know if a v2 dropping the tag is needed.
No need, Andrew should spot the objection and drop the tag :)
I actually add cc:stable tags to selftests fixes!
Quoted 7 lines
Quoted 4 lines
Because why not. Why leave people running known-to-be-buggy code when our backporting processes are so well-functioning and lightweight?
I'm not getting the objection?
I thought we were so inconsistent on that that it ends up being a wasted effort to even try taking care about stability of selfests in stable trees.
Oh, I try to be vigilant about it.
hp2:/usr/src/mm> git log tools/testing/selftests/mm | grep stable@|wc
44 89 1462
I pass selftests patches through the same brain algorithm as I do everything else, shrug.
Ujwal Kundur
Reviewed-byQuoted 10 lines
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.
Thanks for the fix! I never tested with CONFIG_HUGETLB turned off. We now need tests for tests :)
Quoted 8 lines · Carlos Llamas
Commit
4dfd4bba8578("selftests/mm/uffd: refactor non-composite global vars into struct") moved some of the operations previously implemented inuffd_setup_environment()earlier in the main test loop.The calculation of
nr_pages, which involves a division bypage_size, now occurs before checking thatdefault_huge_page_size()returns a non-zero This leads to a division-by-zero error on systems with !CONFIG_HUGETLB.
Quoted 6 lines
Fix this by relocating the non-zero
page_sizecheck before thenr_pagescalculation, as it was originally implemented.Fixes 4dfd4bba8578 ("selftests/mm/uffd: refactor non-composite global vars into struct")Signed-off-by Carlos Llamas <[email protected]>
Agree with what David and Lorenzo said about cc:stable.
Quoted 42 lines
--- tools/testing/selftests/mm/uffd-unit-tests.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)tools/testing/selftests/mm/uffd-unit-tests.c +7
-8@@ -1758,10 +1758,15 @@ int main(int argc, char *argv[]) uffd_test_ops = mem_type->mem_ops; uffd_test_case_ops = test->test_case_ops; -if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE |MEM_HUGETLB )) +if (mem_type->mem_flag & (MEM_HUGETLB_PRIVATE |MEM_HUGETLB )) { gopts.page_size =default_huge_page_size (); -else +if (gopts.page_size ==0 ) { +uffd_test_skip ("huge page size is 0, feature missing?" ); +continue ; + } + }else { gopts.page_size =psize (); + }/* Ensure we have at least 2 pages */ gopts.nr_pages =MAX (UFFD_TEST_MEM_SIZE , gopts.page_size *2 )@@ -1776,12 +1781,6 @@ int main(int argc, char *argv[])continue ;uffd_test_start ("%s on %s" , test->name, mem_type->name); -if ((mem_type->mem_flag ==MEM_HUGETLB || - mem_type->mem_flag ==MEM_HUGETLB_PRIVATE ) && - (default_huge_page_size () ==0 )) { -uffd_test_skip ("huge page size is 0, feature missing?" ); -continue ; - }if (!uffd_feature_supported (test)) {uffd_test_skip ("feature missing" );continue ;Signature · 1 line
2.51.2.1041.gc1ab5b90ca-goog
Signature · 2 lines
Sincerely yours, Mike.