Re: [PATCH v2 4/4] mm, arch: add generic implementation of pfn_valid() for FLATMEM

From: Conor Dooley
Date: Tue Jan 31 2023 - 13:55:43 EST


Hi Mike,

On Tue, Jan 31, 2023 at 08:41:49PM +0200, Mike Rapoport wrote:
> On Tue, Jan 31, 2023 at 05:47:24PM +0000, Conor Dooley wrote:
> > On Sun, Jan 29, 2023 at 02:42:35PM +0200, Mike Rapoport wrote:
> > > From: "Mike Rapoport (IBM)" <rppt@xxxxxxxxxx>
> > >
> > > Every architecture that supports FLATMEM memory model defines its own
> > > version of pfn_valid() that essentially compares a pfn to max_mapnr.
> > >
> > > Use mips/powerpc version implemented as static inline as a generic
> > > implementation of pfn_valid() and drop its per-architecture definitions.
> > >
> > > Signed-off-by: Mike Rapoport (IBM) <rppt@xxxxxxxxxx>
> > > Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
> > > Acked-by: Guo Ren <guoren@xxxxxxxxxx> # csky
> > > Acked-by: Huacai Chen <chenhuacai@xxxxxxxxxxx> # LoongArch
> > > Acked-by: Stafford Horne <shorne@xxxxxxxxx> # OpenRISC
> >
> > Hmm, so this landed in linux-next today and I bisected a boot failure in
> > my CI to it. However, I am not really sure if it is a real issue worth
> > worrying about as the platform it triggered on is supposed to be using
> > SPARSEMEM, but isn't.
> > I had thought that my CI was using a config with SPARSEMEM since that
> > became required for riscv defconfig builds to boot in v6.1-rc1, but I
> > must have just forgotten to add it to my $platform_defconfig builds too.
> > However, those $platform_defconfig builds continued booting without
> > SPARSEMEM enabled until today.
>
> The issue seems to be that the generic pfn_valid() does not take into
> account pfn_offset when it compares it with max_mapnr.
> Can you please test with the patch below?
>
> diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h
> index 13d2a844d928..6796abe1900e 100644
> --- a/include/asm-generic/memory_model.h
> +++ b/include/asm-generic/memory_model.h
> @@ -26,7 +26,7 @@ static inline int pfn_valid(unsigned long pfn)
> extern unsigned long max_mapnr;
> unsigned long pfn_offset = ARCH_PFN_OFFSET;
>
> - return pfn >= pfn_offset && pfn < max_mapnr;
> + return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr;
> }
> #define pfn_valid pfn_valid
> #endif

Gave that a go, board is booting properly again! Feel free to add a:
Tested-by: Conor Dooley <conor.dooley@xxxxxxxxxxxxx>

Thanks for the prompt fix!

Attachment: signature.asc
Description: PGP signature