[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aRXEDLQQtwVPz7va@kernel.org>
Date: Thu, 13 Nov 2025 13:42:04 +0200
From: Mike Rapoport <rppt@...nel.org>
To: Carlos Llamas <cmllamas@...gle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, Peter Xu <peterx@...hat.com>,
David Hildenbrand <david@...hat.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>,
Suren Baghdasaryan <surenb@...gle.com>,
Michal Hocko <mhocko@...e.com>, Shuah Khan <shuah@...nel.org>,
Ujwal Kundur <ujwal.kundur@...il.com>,
Brendan Jackman <jackmanb@...gle.com>, kernel-team@...roid.com,
linux-kernel@...r.kernel.org, stable@...r.kernel.org,
"open list:MEMORY MANAGEMENT - USERFAULTFD" <linux-mm@...ck.org>,
"open list:KERNEL SELFTEST FRAMEWORK" <linux-kselftest@...r.kernel.org>
Subject: Re: [PATCH] selftests/mm: fix division-by-zero in uffd-unit-tests
On Thu, Nov 13, 2025 at 03:46:22AM +0000, Carlos Llamas wrote:
> 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.
>
> Cc: stable@...r.kernel.org
> Fixes: 4dfd4bba8578 ("selftests/mm/uffd: refactor non-composite global vars into struct")
> Signed-off-by: Carlos Llamas <cmllamas@...gle.com>
Agree with what David and Lorenzo said about cc:stable.
Reviewed-by: Mike Rapoport (Microsoft) <rppt@...nel.org>
> ---
> tools/testing/selftests/mm/uffd-unit-tests.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/mm/uffd-unit-tests.c b/tools/testing/selftests/mm/uffd-unit-tests.c
> index 9e3be2ee7f1b..f917b4c4c943 100644
> --- a/tools/testing/selftests/mm/uffd-unit-tests.c
> +++ b/tools/testing/selftests/mm/uffd-unit-tests.c
> @@ -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;
> --
> 2.51.2.1041.gc1ab5b90ca-goog
>
--
Sincerely yours,
Mike.
Powered by blists - more mailing lists