Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: add softleaf_is_valid_pmd_entry(), pmd_to_softleaf_folio()

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.

Link: https://lkml.kernel.org/r/b677592596274fa3fd701890497948e4b0e07cec.1774029655.git.ljs@kernel.org
Signed-off-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nico Pache <npache@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes (Oracle) and committed by
Andrew Morton
64b7d889 f87854c9

+35 -4
+35 -4
include/linux/leafops.h
··· 607 607 } 608 608 609 609 /** 610 - * pmd_is_valid_softleaf() - Is this PMD entry a valid leaf entry? 610 + * softleaf_is_valid_pmd_entry() - Is the specified softleaf entry obtained from 611 + * a PMD one that we support at PMD level? 612 + * @entry: Entry to check. 613 + * Returns: true if the softleaf entry is valid at PMD, otherwise false. 614 + */ 615 + static inline bool softleaf_is_valid_pmd_entry(softleaf_t entry) 616 + { 617 + /* Only device private, migration entries valid for PMD. */ 618 + return softleaf_is_device_private(entry) || 619 + softleaf_is_migration(entry); 620 + } 621 + 622 + /** 623 + * pmd_is_valid_softleaf() - Is this PMD entry a valid softleaf entry? 611 624 * @pmd: PMD entry. 612 625 * 613 626 * PMD leaf entries are valid only if they are device private or migration ··· 633 620 { 634 621 const softleaf_t entry = softleaf_from_pmd(pmd); 635 622 636 - /* Only device private, migration entries valid for PMD. */ 637 - return softleaf_is_device_private(entry) || 638 - softleaf_is_migration(entry); 623 + return softleaf_is_valid_pmd_entry(entry); 624 + } 625 + 626 + /** 627 + * pmd_to_softleaf_folio() - Convert the PMD entry to a folio. 628 + * @pmd: PMD entry. 629 + * 630 + * The PMD entry is expected to be a valid PMD softleaf entry. 631 + * 632 + * Returns: the folio the softleaf entry references if this is a valid softleaf 633 + * entry, otherwise NULL. 634 + */ 635 + static inline struct folio *pmd_to_softleaf_folio(pmd_t pmd) 636 + { 637 + const softleaf_t entry = softleaf_from_pmd(pmd); 638 + 639 + if (!softleaf_is_valid_pmd_entry(entry)) { 640 + VM_WARN_ON_ONCE(true); 641 + return NULL; 642 + } 643 + return softleaf_to_folio(entry); 639 644 } 640 645 641 646 #endif /* CONFIG_MMU */