[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z-4of2VHLpZ4Uj4q@kernel.org>
Date: Thu, 3 Apr 2025 09:19:43 +0300
From: Mike Rapoport <rppt@...nel.org>
To: David Woodhouse <dwmw2@...radead.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
"Sauerwein, David" <dssauerw@...zon.de>,
Anshuman Khandual <anshuman.khandual@....com>,
Ard Biesheuvel <ardb@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
David Hildenbrand <david@...hat.com>, Marc Zyngier <maz@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Mike Rapoport <rppt@...ux.ibm.com>, Will Deacon <will@...nel.org>,
kvmarm@...ts.cs.columbia.edu, linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH 2/3] mm: Implement for_each_valid_pfn() for
CONFIG_FLATMEM
On Wed, Apr 02, 2025 at 09:18:40PM +0100, David Woodhouse wrote:
> From: David Woodhouse <dwmw@...zon.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@...zon.co.uk>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@...nel.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
>
--
Sincerely yours,
Mike.
Powered by blists - more mailing lists