Message ID | 20250402201841.3245371-2-dwmw2@infradead.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [RFC,1/3] mm: Introduce for_each_valid_pfn() and use it from reserve_bootmem_region() | expand |
On Wed, Apr 02, 2025 at 09:18:40PM +0100, David Woodhouse wrote: > From: David Woodhouse <dwmw@amazon.co.uk> > > In the FLATMEM case, the default pfn_valid() just checks that the PFN is > within the range [ ARCH_PFN_OFFSET .. ARCH_PFN_OFFSET + max_mapnr ). > > The for_each_valid_pfn() function can therefore be a simple for() loop > using those as min/max respectively. > > Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> > --- > include/asm-generic/memory_model.h | 26 +++++++++++++++++++++++++- > 1 file changed, 25 insertions(+), 1 deletion(-) > > diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h > index a3b5029aebbd..4fe7dd3bc09c 100644 > --- a/include/asm-generic/memory_model.h > +++ b/include/asm-generic/memory_model.h > @@ -30,7 +30,31 @@ static inline int pfn_valid(unsigned long pfn) > return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr; > } > #define pfn_valid pfn_valid > -#endif > + > +static inline bool first_valid_pfn(unsigned long *pfn) > +{ > + /* avoid <linux/mm.h> include hell */ > + extern unsigned long max_mapnr; > + unsigned long pfn_offset = ARCH_PFN_OFFSET; > + > + if (*pfn < pfn_offset) { > + *pfn = pfn_offset; > + return true; > + } > + > + if ((*pfn - pfn_offset) < max_mapnr) > + return true; > + > + return false; > +} > + > +#ifndef for_each_valid_pfn > +#define for_each_valid_pfn(pfn, start_pfn, end_pfn) \ > + for (pfn = max_t(unsigned long start_pfn, ARCH_PFN_OFFSET); \ > + pfn < min_t(unsigned long, end_pfn, ARCH_PFN_OFFSET + max_mapnr); \ > + pfn++) > +#endif /* for_each_valid_pfn */ > +#endif /* valid_pfn */ > > #elif defined(CONFIG_SPARSEMEM_VMEMMAP) > > -- > 2.49.0 >
diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h index a3b5029aebbd..4fe7dd3bc09c 100644 --- a/include/asm-generic/memory_model.h +++ b/include/asm-generic/memory_model.h @@ -30,7 +30,31 @@ static inline int pfn_valid(unsigned long pfn) return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr; } #define pfn_valid pfn_valid -#endif + +static inline bool first_valid_pfn(unsigned long *pfn) +{ + /* avoid <linux/mm.h> include hell */ + extern unsigned long max_mapnr; + unsigned long pfn_offset = ARCH_PFN_OFFSET; + + if (*pfn < pfn_offset) { + *pfn = pfn_offset; + return true; + } + + if ((*pfn - pfn_offset) < max_mapnr) + return true; + + return false; +} + +#ifndef for_each_valid_pfn +#define for_each_valid_pfn(pfn, start_pfn, end_pfn) \ + for (pfn = max_t(unsigned long start_pfn, ARCH_PFN_OFFSET); \ + pfn < min_t(unsigned long, end_pfn, ARCH_PFN_OFFSET + max_mapnr); \ + pfn++) +#endif /* for_each_valid_pfn */ +#endif /* valid_pfn */ #elif defined(CONFIG_SPARSEMEM_VMEMMAP)