From nobody Sat Apr 4 04:48:19 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 533E83E3145 for ; Fri, 20 Mar 2026 18:08:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774030084; cv=none; b=DRu4aoRQ/j1YuvNiF9AtebAFdRUu/kzAEJPq/JwR3HEI7qhKNaZI/RKG3ZZAA/Wcnfh9yMhkTlBMXPnLpc+I2GiskYBOMroxr2obrEBvq6wPleBjOQqfuVeVabZwcs0w/y8IUj20JPiSkkrBKyF04JIDgtsMZfQxXHGcgcIkXMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774030084; c=relaxed/simple; bh=0+GlSeGdSvEbk7Xvpg9UTnriV57myN66M3z+ejCspIw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sr3avbKfLwwUudhjFLsGV+L3y79cOQILHxDv0PsZTxZPLCXGSRbsbxgRn3zZEAmOWeR78erGhvhfNjlv2pgbqp1tRvhwIaiPszXPOrG3fxWVlGjeNue+IzckrtCG7EA8lVQZBodt1I0Gjrg5NGimh5hQ3yPNcqD/XY6G6buc+Tg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vp8rY01q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Vp8rY01q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A39CC4CEF7; Fri, 20 Mar 2026 18:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774030083; bh=0+GlSeGdSvEbk7Xvpg9UTnriV57myN66M3z+ejCspIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vp8rY01q/ADSly9S0oZzHX9BeisKfH4/tXjVnxU6oSlnyETElhWI4MAIn2oFAxBtK 3n/01WJKOMzJLND+lCSDid55KjRqtwUuWL44FDJMzY4X+gPle1iMnbzxgnKlnBosG+ zBMYyALSVtEn89licpz9JV0B9CWXMb4EpH9BrcP9MQmOoC2t2R6XbnKDn/+gE+7xXI iPTeMSGmptRwIkHk84I40eP33uNagvXsq9keqkUJjNnuTnXDbXkg0fFVBRNsryz6ln Vgv79ct3xAvnqRtINcB/p1GDstXhoTwAm2Ts9nu2m4d+Y+oTgwxuk7fqs6N7Guqp6J +hlAN3cI9s/zw== From: "Lorenzo Stoakes (Oracle)" To: Andrew Morton Cc: David Hildenbrand , Zi Yan , Baolin Wang , "Liam R . Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kiryl Shutsemau , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 11/13] mm: add softleaf_is_valid_pmd_entry(), pmd_to_softleaf_folio() Date: Fri, 20 Mar 2026 18:07:28 +0000 Message-ID: X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Separate pmd_is_valid_softleaf() into separate components, then use the pmd_is_valid_softleaf() predicate to implement pmd_to_softleaf_folio(). This returns the folio associated with a softleaf entry at PMD level. It expects this to be valid for a PMD entry. If CONFIG_DEBUG_VM is set, then assert on this being an invalid entry, and either way return NULL in this case. This lays the ground for further refactorings. Signed-off-by: Lorenzo Stoakes (Oracle) Reviewed-by: Suren Baghdasaryan --- include/linux/leafops.h | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/include/linux/leafops.h b/include/linux/leafops.h index dd4130b7cb7f..65957283fa9f 100644 --- a/include/linux/leafops.h +++ b/include/linux/leafops.h @@ -603,7 +603,20 @@ static inline bool pmd_is_migration_entry(pmd_t pmd) } =20 /** - * pmd_is_valid_softleaf() - Is this PMD entry a valid leaf entry? + * softleaf_is_valid_pmd_entry() - Is the specified softleaf entry obtaine= d from + * a PMD one that we support at PMD level? + * @entry: Entry to check. + * Returns: true if the softleaf entry is valid at PMD, otherwise false. + */ +static inline bool softleaf_is_valid_pmd_entry(softleaf_t entry) +{ + /* Only device private, migration entries valid for PMD. */ + return softleaf_is_device_private(entry) || + softleaf_is_migration(entry); +} + +/** + * pmd_is_valid_softleaf() - Is this PMD entry a valid softleaf entry? * @pmd: PMD entry. * * PMD leaf entries are valid only if they are device private or migration @@ -616,9 +629,27 @@ static inline bool pmd_is_valid_softleaf(pmd_t pmd) { const softleaf_t entry =3D softleaf_from_pmd(pmd); =20 - /* Only device private, migration entries valid for PMD. */ - return softleaf_is_device_private(entry) || - softleaf_is_migration(entry); + return softleaf_is_valid_pmd_entry(entry); +} + +/** + * pmd_to_softleaf_folio() - Convert the PMD entry to a folio. + * @pmd: PMD entry. + * + * The PMD entry is expected to be a valid PMD softleaf entry. + * + * Returns: the folio the softleaf entry references if this is a valid sof= tleaf + * entry, otherwise NULL. + */ +static inline struct folio *pmd_to_softleaf_folio(pmd_t pmd) +{ + const softleaf_t entry =3D softleaf_from_pmd(pmd); + + if (!softleaf_is_valid_pmd_entry(entry)) { + VM_WARN_ON_ONCE(true); + return NULL; + } + return softleaf_to_folio(entry); } =20 #endif /* CONFIG_MMU */ --=20 2.53.0