From: "Oscar Salvador (SUSE)" <osalvador@kernel.org>
To: Dave Hansen <dave.hansen@intel.com>
Cc: Karsten Desler <kdesler@soohrt.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [REGRESSION] x86/hugetlb: AMD F15h VA alignment offset breaks MAP_HUGETLB alignment
Date: Thu, 28 May 2026 14:45:01 +0200 [thread overview]
Message-ID: <ahg4zTSRK6THd2yP@localhost.localdomain> (raw)
In-Reply-To: <ahfWdMdxX68ni4ZM@localhost.localdomain>
On Thu, May 28, 2026 at 07:45:24AM +0200, Oscar Salvador (SUSE) wrote:
> On Wed, May 27, 2026 at 02:04:10PM -0700, Dave Hansen wrote:
> > On 5/27/26 11:28, Oscar Salvador (SUSE) wrote:
> > > if (filp) {
> > > info.align_mask = get_align_mask(filp);
> > > - info.align_offset += get_align_bits();
> > > + /*
> > > + * Hugepages must remain hugepage-aligned, so skip adding an offset
> > > + * in case we enabled 'align_va_addr'.
> > > + */
> > > + if (!is_file_hugepages(filp))
> > > + info.align_offset += get_align_bits();
> > > }
> >
> > That's a good hack to show the scope of the problem.
>
> Haha, do not worry, I myself have 0 interestin spreading hugetlb-specific
> code around (on the contrary), but I wanted to proof the point.
>
> >
> > But I'd really rather this be dealt with in the arch-independent code,
> > not by adding hugetlb hacks to arch code. It isn't even clear to me what
> > exactly goes wrong when you set a tiny ->align_offset and have a larger
> > ->align_mask. Shouldn't the tiny offset just get masked off?
> >
> > gap += (info->align_offset - gap) & info->align_mask;
Ok, I finally got to it.
So, let us assume we ask for a 2MB hugetlb page.
~huge_page_mask = 0x1fffff
huge_page_mask_align = PAGE_MASK & ~huge_page_mask(hstate_file(file)) = 0x1ff000
unmapped_area_topdown()
info->length = 0x200000 (2MB)
info->align_mask = 0x1ff000
/* Adjust search length to account for worst case alignment overhead */
total_gap_lenght_requested = info->length + info->align_mask = 0x3ff000
We find a gap: 0x7f28cfb10000 - 0x7f28cfd10000 (2MB) and assuming align_offset is = 0:
gap -= (gap - info->align_offset) & info->align_mask
0x7f28cfb10000 -= 0x7f28cfb10000 & 0x1ff000 = 7f28cfa00000 (2MB aligned)
IIUC, we mask what we got with align_mask to know how much we need to substract in
order to be properly aligned (and since we already accounted for extra length before,
we are sure we do not overstep anything below).
Now, I have to acknowledge that I had to look at the code several times, because
it was not clear to me why we were not just masking off 2MB, but I guess if we do we
lose whatever align_offset gives us (if smaller than align_mask).
I mean, code was already like that before my refactoring, just that back
then we did "align_offset = 0" unilaterally for hugetlb mappings.
The only thing bugging is, should not the same happen for THP-file-backed mappings?
--
Oscar Salvador
SUSE Labs
next prev parent reply other threads:[~2026-05-28 12:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 14:36 [REGRESSION] x86/hugetlb: AMD F15h VA alignment offset breaks MAP_HUGETLB alignment Karsten Desler
2026-05-27 15:53 ` Oscar Salvador (SUSE)
2026-05-27 18:28 ` Oscar Salvador (SUSE)
2026-05-27 20:39 ` Karsten Desler
2026-05-27 21:04 ` Dave Hansen
2026-05-28 5:45 ` Oscar Salvador (SUSE)
2026-05-28 12:45 ` Oscar Salvador (SUSE) [this message]
2026-05-28 14:03 ` Oscar Salvador (SUSE)
2026-05-28 15:31 ` Borislav Petkov
2026-05-28 18:29 ` Oscar Salvador (SUSE)
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=ahg4zTSRK6THd2yP@localhost.localdomain \
--to=osalvador@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kdesler@soohrt.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
/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