[PATCH 4/9] x86/mm/pat: don't BUG() on inconsistent page count
From: Mike Rapoport (Microsoft)
Date: Thu Nov 12 2026 - 12:25:00 EST
If a step of __change_page_attr_set_clr() covers more pages than remain
in the range, or no pages at all, that's a bug in CPA, but it does not
justify crashing the kernel.
Warn and fail the request instead.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
arch/x86/mm/pat/set_memory.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index aa7052d247e60..a1bea16a3c3bb 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2101,7 +2101,10 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int primary)
* CPA operation. Either a large page has been
* preserved or a single page update happened.
*/
- BUG_ON(cpa->numpages > rempages || !cpa->numpages);
+ if (WARN_ON_ONCE(cpa->numpages > rempages || !cpa->numpages)) {
+ ret = -EINVAL;
+ goto out;
+ }
rempages -= cpa->numpages;
cpa->curpage += cpa->numpages;
}
--
2.53.0