Skip to content

Commit 8702048

Browse files
author
Jocelyn Falempe
committed
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: Simona Vetter <simona.vetter@ffwll.ch> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com> Link: https://lore.kernel.org/r/20250407140138.162383-2-jfalempe@redhat.com
1 parent d74cc22 commit 8702048

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/linux/highmem-internal.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ static inline void *kmap_local_page(struct page *page)
7373
return __kmap_local_page_prot(page, kmap_prot);
7474
}
7575

76+
static inline void *kmap_local_page_try_from_panic(struct page *page)
77+
{
78+
if (!PageHighMem(page))
79+
return page_address(page);
80+
/* If the page is in HighMem, it's not safe to kmap it.*/
81+
return NULL;
82+
}
83+
7684
static inline void *kmap_local_folio(struct folio *folio, size_t offset)
7785
{
7886
struct page *page = folio_page(folio, offset / PAGE_SIZE);
@@ -180,6 +188,11 @@ static inline void *kmap_local_page(struct page *page)
180188
return page_address(page);
181189
}
182190

191+
static inline void *kmap_local_page_try_from_panic(struct page *page)
192+
{
193+
return page_address(page);
194+
}
195+
183196
static inline void *kmap_local_folio(struct folio *folio, size_t offset)
184197
{
185198
return page_address(&folio->page) + offset;

0 commit comments

Comments
 (0)