From: David Hildenbrand <david@redhat.com>
To: Chunyu Hu <chuhu@redhat.com>,
akpm@linux-foundation.org, shuah@kernel.org, linux-mm@kvack.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com,
vbabka@suse.cz, rppt@kernel.org, surenb@google.com,
mhocko@suse.com
Subject: Re: [PATCH v3 3/3] selftests/mm: fix va_high_addr_switch.sh failure on x86_64
Date: Fri, 12 Sep 2025 14:42:38 +0200 [thread overview]
Message-ID: <302d47a7-4f20-4c74-ad3e-b8574970bce5@redhat.com> (raw)
In-Reply-To: <20250912013711.3002969-4-chuhu@redhat.com>
On 12.09.25 03:37, Chunyu Hu wrote:
> The test will fail as below on x86_64 with cpu la57 support (will skip if
> no la57 support). Note, the test requries nr_hugepages to be set first.
>
> # running bash ./va_high_addr_switch.sh
> # -------------------------------------
> # mmap(addr_switch_hint - pagesize, pagesize): 0x7f55b60fa000 - OK
> # mmap(addr_switch_hint - pagesize, (2 * pagesize)): 0x7f55b60f9000 - OK
> # mmap(addr_switch_hint, pagesize): 0x800000000000 - OK
> # mmap(addr_switch_hint, 2 * pagesize, MAP_FIXED): 0x800000000000 - OK
> # mmap(NULL): 0x7f55b60f9000 - OK
> # mmap(low_addr): 0x40000000 - OK
> # mmap(high_addr): 0x1000000000000 - OK
> # mmap(high_addr) again: 0xffff55b6136000 - OK
> # mmap(high_addr, MAP_FIXED): 0x1000000000000 - OK
> # mmap(-1): 0xffff55b6134000 - OK
> # mmap(-1) again: 0xffff55b6132000 - OK
> # mmap(addr_switch_hint - pagesize, pagesize): 0x7f55b60fa000 - OK
> # mmap(addr_switch_hint - pagesize, 2 * pagesize): 0x7f55b60f9000 - OK
> # mmap(addr_switch_hint - pagesize/2 , 2 * pagesize): 0x7f55b60f7000 - OK
> # mmap(addr_switch_hint, pagesize): 0x800000000000 - OK
> # mmap(addr_switch_hint, 2 * pagesize, MAP_FIXED): 0x800000000000 - OK
> # mmap(NULL, MAP_HUGETLB): 0x7f55b5c00000 - OK
> # mmap(low_addr, MAP_HUGETLB): 0x40000000 - OK
> # mmap(high_addr, MAP_HUGETLB): 0x1000000000000 - OK
> # mmap(high_addr, MAP_HUGETLB) again: 0xffff55b5e00000 - OK
> # mmap(high_addr, MAP_FIXED | MAP_HUGETLB): 0x1000000000000 - OK
> # mmap(-1, MAP_HUGETLB): 0x7f55b5c00000 - OK
> # mmap(-1, MAP_HUGETLB) again: 0x7f55b5a00000 - OK
> # mmap(addr_switch_hint - pagesize, 2*hugepagesize, MAP_HUGETLB): 0x800000000000 - FAILED
> # mmap(addr_switch_hint , 2*hugepagesize, MAP_FIXED | MAP_HUGETLB): 0x800000000000 - OK
> # [FAIL]
>
> addr_switch_hint is defined as DFEFAULT_MAP_WINDOW in the failed test (for
> x86_64, DFEFAULT_MAP_WINDOW is defined as (1UL<<47) - pagesize) in 64 bit.
>
> Before commit cc92882ee218 ("mm: drop hugetlb_get_unmapped_area{_*}
> functions"), for x86_64 hugetlb_get_unmapped_area() is handled in arch code
> arch/x86/mm/hugetlbpage.c and addr is checked with map_address_hint_valid()
> after align with 'addr &= huge_page_mask(h)' which is a round down way, and
> it will fail the check because the addr is within the DEFAULT_MAP_WINDOW but
> (addr + len) is above the DFEFAULT_MAP_WINDOW. So it wil go through the
> hugetlb_get_unmmaped_area_top_down() to find an area within the
> DFEFAULT_MAP_WINDOW.
>
> After commit cc92882ee218 ("mm: drop hugetlb_get_unmapped_area{_*}
> functions"). The addr hint for hugetlb_get_unmmaped_area() will be rounded
> up and aligned to hugepage size with ALIGN() for all arches. And after the
> align, the addr will be above the default MAP_DEFAULT_WINDOW, and the
> map_addresshint_valid() check will pass because both aligned addr (addr0)
> and (addr + len) are above the DEFAULT_MAP_WINDOW, and the aligned hint
> address (0x800000000000) is returned as an suitable gap is found there,
> in arch_get_unmapped_area_topdown().
>
> To still cover the case that addr is within the DEFAULT_MAP_WINDOW, and
> addr + len is above the DFEFAULT_MAP_WINDOW, change to choose the last
> hugepage aligned address within the DEFAULT_MAP_WINDOW as the hint addr,
> and the addr + len (2 hugepages) will be one hugepage above the
> DEFAULT_MAP_WINDOW. An aligned address won't be affected by the page
> round up or round down from kernel, so it's determistic.
>
> Fixes: cc92882ee218 ("mm: drop hugetlb_get_unmapped_area{_*} functions")
> Suggested-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Chunyu Hu <chuhu@redhat.com>
> ---
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers
David / dhildenb
prev parent reply other threads:[~2025-09-12 12:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-12 1:37 [PATCH v3 0/3] Fix va_high_addr_switch.sh test failure Chunyu Hu
2025-09-12 1:37 ` [PATCH v3 1/3] selftests/mm: fix hugepages cleanup too early Chunyu Hu
2025-09-12 1:37 ` [PATCH v3 2/3] selftests/mm: alloc hugepages in va_high_addr_switch test Chunyu Hu
2025-09-12 1:37 ` [PATCH v3 3/3] selftests/mm: fix va_high_addr_switch.sh failure on x86_64 Chunyu Hu
2025-09-12 12:42 ` David Hildenbrand [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=302d47a7-4f20-4c74-ad3e-b8574970bce5@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=chuhu@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox