From: Muchun Song <songmuchun@bytedance.com>
To: Alexander Potapenko <glider@google.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Marco Elver <elver@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Chris Down <chris@chrisdown.name>,
David Hildenbrand <david@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Brendan Jackman <brendan.jackman@linux.dev>,
Zi Yan <ziy@nvidia.com>, Muchun Song <muchun.song@linux.dev>,
Joerg Roedel <joerg.roedel@amd.com>,
Lu Baolu <baolu.lu@linux.intel.com>,
Pranjal Shrivastava <praan@google.com>,
Ketan <ketan.kishore@oss.qualcomm.com>,
Mostafa Saleh <smostafa@google.com>,
Sang-Heon Jeon <ekffu200098@gmail.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Sashiko <sashiko-bot@kernel.org>,
kasan-dev@googlegroups.com, workflows@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Muchun Song <songmuchun@bytedance.com>
Subject: [PATCH v3 2/7] mm/page_ext: fix client data alignment
Date: Thu, 19 Nov 2026 14:58:07 +0800 [thread overview]
Message-ID: <20261119065812.89959-3-songmuchun@bytedance.com> (raw)
In-Reply-To: <20261119065812.89959-1-songmuchun@bytedance.com>
page_ext lays out client payloads consecutively without aligning their
offsets or the final entry size. This happened to work while the active
payload sizes kept the stride naturally aligned, but IOMMU debug page
allocation added a four-byte payload after data requiring eight-byte
alignment.
When page owner and IOMMU debug page allocation are both enabled on
x86-64, struct page_ext, struct page_owner, and the IOMMU payload use
8, 64, and 4 bytes respectively. This produces a 76-byte entry stride,
leaving struct page_ext and page_owner data in every other entry only
four-byte aligned instead of eight-byte aligned.
Align each client offset and round the final entry size to the largest
active alignment so every page_ext entry preserves the alignment
required by all active clients.
Fixes: 466ae6978a5b ("iommu: Add page_ext for IOMMU_DEBUG_PAGEALLOC")
Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Reviewed-by: Chris Down <chris@chrisdown.name>
Tested-by: Chris Down <chris@chrisdown.name>
---
v3:
- Cap client alignment at u64 alignment to preserve 64-bit alignment on
32-bit architectures (reported by Sashiko)
- Open-code the lowest power-of-two factor for readability (suggested by
Andrew Morton)
- Use a local for the u64 alignment (suggested by Mike Rapoport)
- Simplify the commit message to focus on the alignment guarantee
- Collect Reviewed-by and Tested-by from Chris Down
v2:
- New patch to fix the existing page_ext client alignment bug
---
mm/page_ext.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/mm/page_ext.c b/mm/page_ext.c
index b679a8c1f7d7..39a4464fc979 100644
--- a/mm/page_ext.c
+++ b/mm/page_ext.c
@@ -116,8 +116,27 @@ static int __init setup_early_page_ext(char *str)
}
early_param("early_page_ext", setup_early_page_ext);
+static inline size_t page_ext_data_alignment(size_t size)
+{
+ const size_t align = __alignof__(u64);
+
+ if (!size)
+ return 1;
+
+ /* u64 has the strictest alignment required by page_ext clients. */
+ if (IS_ALIGNED(size, align))
+ return align;
+
+ /*
+ * A type's size is a multiple of its natural alignment, so its
+ * lowest set bit is at least that alignment.
+ */
+ return size & -size;
+}
+
static bool __init invoke_need_callbacks(void)
{
+ size_t max_align = 1;
int i;
int entries = ARRAY_SIZE(page_ext_ops);
bool need = false;
@@ -126,6 +145,7 @@ static bool __init invoke_need_callbacks(void)
if (page_ext_ops[i]->need()) {
if (page_ext_ops[i]->need_shared_flags) {
page_ext_size = sizeof(struct page_ext);
+ max_align = __alignof__(struct page_ext);
break;
}
}
@@ -133,11 +153,17 @@ static bool __init invoke_need_callbacks(void)
for (i = 0; i < entries; i++) {
if (page_ext_ops[i]->need()) {
+ size_t align;
+
+ align = page_ext_data_alignment(page_ext_ops[i]->size);
+ page_ext_size = ALIGN(page_ext_size, align);
page_ext_ops[i]->offset = page_ext_size;
page_ext_size += page_ext_ops[i]->size;
+ max_align = max(max_align, align);
need = true;
}
}
+ page_ext_size = ALIGN(page_ext_size, max_align);
return need;
}
--
2.54.0
next prev parent reply other threads:[~2026-11-19 7:00 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 6:58 [PATCH v3 0/7] KMSAN: Move per-page metadata out of struct page Muchun Song
2026-11-19 6:58 ` [PATCH v3 1/7] kmsan: encapsulate per-page metadata access Muchun Song
2026-11-19 6:58 ` Muchun Song [this message]
2026-11-19 8:00 ` [PATCH v3 2/7] mm/page_ext: fix client data alignment Mike Rapoport
2026-11-19 6:58 ` [PATCH v3 3/7] mm/page_ext: always use vmalloc for section page extensions Muchun Song
2026-11-19 6:58 ` [PATCH v3 4/7] mm/page_ext: use common allocation and initialization entry points Muchun Song
2026-11-19 6:58 ` [PATCH v3 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM Muchun Song
2026-11-19 6:58 ` [PATCH v3 6/7] mm/page_ext: inline unchecked page extension lookup Muchun Song
2026-11-19 7:56 ` Mike Rapoport
2026-11-19 6:58 ` [PATCH v3 7/7] kmsan: fix metadata loss during HugeTLB struct page reinitialization Muchun Song
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=20261119065812.89959-3-songmuchun@bytedance.com \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=baolu.lu@linux.intel.com \
--cc=brendan.jackman@linux.dev \
--cc=chris@chrisdown.name \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=dvyukov@google.com \
--cc=ekffu200098@gmail.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=hannes@cmpxchg.org \
--cc=joerg.roedel@amd.com \
--cc=kasan-dev@googlegroups.com \
--cc=ketan.kishore@oss.qualcomm.com \
--cc=liam@infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=praan@google.com \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=smostafa@google.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=workflows@vger.kernel.org \
--cc=ziy@nvidia.com \
/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
all inboxes | Powered by JetHome®