Commit 8702048b authored by Jocelyn Falempe's avatar Jocelyn Falempe
Browse files

mm/kmap: Add kmap_local_page_try_from_panic()



kmap_local_page() can be unsafe to call from a panic handler, if
CONFIG_HIGHMEM is set, and the page is in the highmem zone.
So add kmap_local_page_try_from_panic() to handle this case.

Suggested-by: default avatarSimona Vetter <simona.vetter@ffwll.ch>
Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarJocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/r/20250407140138.162383-2-jfalempe@redhat.com
parent d74cc229
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -73,6 +73,14 @@ static inline void *kmap_local_page(struct page *page)
	return __kmap_local_page_prot(page, kmap_prot);
}

static inline void *kmap_local_page_try_from_panic(struct page *page)
{
	if (!PageHighMem(page))
		return page_address(page);
	/* If the page is in HighMem, it's not safe to kmap it.*/
	return NULL;
}

static inline void *kmap_local_folio(struct folio *folio, size_t offset)
{
	struct page *page = folio_page(folio, offset / PAGE_SIZE);
@@ -180,6 +188,11 @@ static inline void *kmap_local_page(struct page *page)
	return page_address(page);
}

static inline void *kmap_local_page_try_from_panic(struct page *page)
{
	return page_address(page);
}

static inline void *kmap_local_folio(struct folio *folio, size_t offset)
{
	return page_address(&folio->page) + offset;