Re: [PATCH 4/9] x86/mm/pat: don't BUG() on inconsistent page count

From: Edgecombe, Rick P

Date: Tue Nov 24 2026 - 17:57:50 EST


On Thu, 2026-11-12 at 18:31 +0200, Mike Rapoport (Microsoft) wrote:
> 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.

Agreed, but does it also justify special handling to try to return an error to
the caller about the bug in CPA? Why not just change the BUG_ON() to WARN?

>
> 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;
>   }
>
> --