Re: [PATCH v2 3/4] mm: Factor __pfn_valid() out of pfn_valid()

From: Mike Rapoport

Date: Sun Nov 01 2026 - 15:04:25 EST


On Sun, Nov 01, 2026 at 07:04:38PM +0200, Viorel Cernateanu via B4 Relay wrote:
> From: Viorel Cernateanu <vrilutza@xxxxxxxxx>
>
> KMSAN needs to validate a PFN during metadata lookup without entering
> instrumented code. Calling pfn_valid() also calls
> rcu_read_lock_sched(), which can enter instrumented code and recurse
> into the metadata lookup.
>
> Extract the PFN checks into __pfn_valid(), whose caller must already
> be in an RCU-sched read-side critical section. Keep pfn_valid() as
> the wrapper that acquires and releases that protection.
>
> This lets KMSAN reuse the existing PFN validation while providing
> the required protection without instrumented helpers.
>
> The wrapper now also holds the RCU-sched read lock during the
> initial range checks, which previously ran before acquiring it.
>
> Suggested-by: Alexander Potapenko <glider@xxxxxxxxxx>
> Signed-off-by: Viorel Cernateanu <vrilutza@xxxxxxxxx>

Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>

> ---
> include/linux/mmzone.h | 42 +++++++++++++++++++++++++-----------------
> 1 file changed, 25 insertions(+), 17 deletions(-)

--
Sincerely yours,
Mike.