On Wed, Feb 05, 2025 at 04:17:21PM -0700, Alex Williamson wrote: > + if (is_invalid_reserved_pfn(*pfn)) { > + unsigned long epfn; > + > + epfn = (((*pfn << PAGE_SHIFT) + ~pgmask + 1) > + & pgmask) >> PAGE_SHIFT; > + ret = min_t(int, npages, epfn - *pfn); You've really made life hard for yourself by passing around a page mask instead of an order (ie 0/PMD_ORDER/PUD_ORDER). Why not: epfn = round_up(*pfn + 1, 1 << order); Although if you insist on passing around a mask, this could be: unsigned long sz = (~pgmask >> PAGE_SHIFT) + 1; unsigned long epfn = round_up(*pfn + 1, sz)