]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/kmap: Add kmap_local_page_try_from_panic()
authorJocelyn Falempe <jfalempe@redhat.com>
Mon, 7 Apr 2025 13:42:25 +0000 (15:42 +0200)
committerJocelyn Falempe <jfalempe@redhat.com>
Thu, 10 Apr 2025 08:50:57 +0000 (10:50 +0200)
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
include/linux/highmem-internal.h

index dd100e849f5e0a1c1e7b4cef5255848aa50daa3b..9a7683d79a4b12673d168dd1f5741075c68bc716 100644 (file)
@@ -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;