diff mbox series

[v2,1/6] mm/migrate: introduce migrate_pfn_to_folio()

Message ID 20240216211320.222431-1-sidhartha.kumar@oracle.com (mailing list archive)
State New
Headers show
Series [v2,1/6] mm/migrate: introduce migrate_pfn_to_folio() | expand

Commit Message

Sidhartha Kumar Feb. 16, 2024, 9:13 p.m. UTC
Add a folio compatible wrapper for migrate_pfn_to_page() so we can
return a folio directly.

Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Suggested-by: Alistair Popple <apopple@nvidia.com>
---
 include/linux/migrate.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Matthew Wilcox Feb. 16, 2024, 9:50 p.m. UTC | #1
On Fri, Feb 16, 2024 at 01:13:15PM -0800, Sidhartha Kumar wrote:
> +static inline struct folio *migrate_pfn_to_folio(unsigned long mpfn)
> +{
> +	return page_folio(migrate_pfn_to_page(mpfn));

umm, no.

	struct page *page = migrate_pfn_to_page(mpfn);
	if (page)
		return page_folio(page);
	return NULL;
Sidhartha Kumar Feb. 16, 2024, 10:03 p.m. UTC | #2
On 2/16/24 1:50 PM, Matthew Wilcox wrote:
> On Fri, Feb 16, 2024 at 01:13:15PM -0800, Sidhartha Kumar wrote:
>> +static inline struct folio *migrate_pfn_to_folio(unsigned long mpfn)
>> +{
>> +	return page_folio(migrate_pfn_to_page(mpfn));
> 
> umm, no.
> 
> 	struct page *page = migrate_pfn_to_page(mpfn);
> 	if (page)
> 		return page_folio(page);
> 	return NULL;

Thanks, I overlooked checking for NULL before converting the page to a folio. 
I'll make this change for v3.
diff mbox series

Patch

diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index 2ce13e8a309bd..21a1a5e415338 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -171,6 +171,11 @@  static inline struct page *migrate_pfn_to_page(unsigned long mpfn)
 	return pfn_to_page(mpfn >> MIGRATE_PFN_SHIFT);
 }
 
+static inline struct folio *migrate_pfn_to_folio(unsigned long mpfn)
+{
+	return page_folio(migrate_pfn_to_page(mpfn));
+}
+
 static inline unsigned long migrate_pfn(unsigned long pfn)
 {
 	return (pfn << MIGRATE_PFN_SHIFT) | MIGRATE_PFN_VALID;