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

From: Edgecombe, Rick P

Date: Wed Nov 25 2026 - 15:46:59 EST


On Wed, 2026-11-25 at 11:11 +0200, Mike Rapoport wrote:
> On Tue, Nov 24, 2026 at 10:57:39PM +0000, Edgecombe, Rick P wrote:
> > 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?
>
> If we only replace BUG_ON() with WARN_ON(), either rempages wraps around
> and we keep changing pages past the end, or we loop forever.

I think the preference for WARN_ON() is not to make a large effort to survive
bugs, but allow for the possibility of keeping the kernel running in the case of
one.

If we try to handle every warning condition we will be doing defensive
programming against the kernels bugs. So if sometimes we loop forever
(essentially a BUG_ON()) things are no worse then the BUG_ON(). If we run past
the end, then maybe the kernel stays running long enough for the user to take
some protective action. We are just not jumping in the middle with a BUG_ON() to
say, "no you don't even get a chance".

AI probably will try to get us to handle all possible bugs if we let it. It
would be a big change to try to do this.

>
> In any case we must break the loop and returning -EINVAL seems the most
> appropriate action there.
>