[PATCH v2 1/2] mm/kmap: Add kmap_local_page_try_from_panic()

Jocelyn Falempe posted 2 patches 9 months ago
There is a newer version of this series
[PATCH v2 1/2] mm/kmap: Add kmap_local_page_try_from_panic()
Posted by Jocelyn Falempe 9 months ago
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>
Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
---
 include/linux/highmem-internal.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-internal.h
index dd100e849f5e0..5d089b0ca56de 100644
--- a/include/linux/highmem-internal.h
+++ b/include/linux/highmem-internal.h
@@ -73,6 +73,13 @@ 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);
+	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 +187,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;
-- 
2.47.1
Re: [PATCH v2 1/2] mm/kmap: Add kmap_local_page_try_from_panic()
Posted by Thomas Gleixner 8 months, 2 weeks ago
On Fri, Mar 21 2025 at 12:16, Jocelyn Falempe wrote:
> 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.

I think this is a reasonable solution and the highmem case can suffer
from not getting the reliable panic output.

> Suggested-by: Simona Vetter <simona.vetter@ffwll.ch>
> Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
> ---
>  include/linux/highmem-internal.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-internal.h
> index dd100e849f5e0..5d089b0ca56de 100644
> --- a/include/linux/highmem-internal.h
> +++ b/include/linux/highmem-internal.h
> @@ -73,6 +73,13 @@ 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);
> +	return NULL;

A comment explaining the reason why the highmem mapping cannot work here
would be appreciated.

Aside of that:

      Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

Thanks,

        tglx