mm/highmem: Take kmap_high_get() properly into account
Subsystems (2)
PATCH 1/1 mm/highmem: Take kmap_high_get() properly into account
kunmap_local() warns when the virtual address to unmap is below PAGE_OFFSET. This is correct except for the case that the mapping was obtained via kmap_high_get() because the PKMAP addresses are right below PAGE_OFFSET.
Cure it by skipping the WARN_ON() when the unmap was handled by kunmap_high().
--- mm/highmem.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
mm/highmem.c +13 -6
@@ -426,12 +426,15 @@ static inline void *arch_kmap_local_high#endif /* Unmap a local mapping which was obtained by kmap_high_get() */ -static inline void kmap_high_unmap_local (unsigned long vaddr) +static inline bool kmap_high_unmap_local (unsigned long vaddr) {#ifdef ARCH_NEEDS_KMAP_HIGH_GET -if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) +if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) {kunmap_high (pte_page (pkmap_page_table[PKMAP_NR (vaddr)])); +return true; + }#endif +return false; }static inline int kmap_local_calc_idx (int idx)
@@ -491,10 +494,14 @@ void kunmap_local_indexed(void *vaddr)if (addr <__fix_to_virt (FIX_KMAP_END ) || addr >__fix_to_virt (FIX_KMAP_BEGIN )) { -WARN_ON_ONCE (addr <PAGE_OFFSET ); - -/* Handle mappings which were obtained by kmap_high_get() */ -kmap_high_unmap_local (addr); +/* +* Handle mappings which were obtained by kmap_high_get() +* first as the virtual address of such mappings is below +* PAGE_OFFSET. Warn for all other addresses which are in +* the user space part of the virtual address space. +*/ +if (!kmap_high_unmap_local (addr)) +WARN_ON_ONCE (addr <PAGE_OFFSET );return ; }
Hi Thomas,
Quoted 11 lines · Thomas Gleixner
kunmap_local()warns when the virtual address to unmap is belowPAGE_OFFSET. This is correct except for the case that the mapping was obtained viakmap_high_get()because the PKMAP addresses are right belowPAGE_OFFSET.Cure it by skipping the
WARN_ON()when the unmap was handled bykunmap_high().Fixes 298fa1ad5571 ("highmem: Provide generic variant of kmap_atomic*")Reported-by [email protected]Signed-off-by Thomas Gleixner <[email protected]>
This fixes the issue I've reported here:
https://lore.kernel.org/dri-devel/[email protected]/
Thanks!
Quoted 36 lines
--- mm/highmem.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)mm/highmem.c +6
-6@@ -426,12 +426,15 @@ static inline void *arch_kmap_local_high#endif /* Unmap a local mapping which was obtained by kmap_high_get() */ -static inline void kmap_high_unmap_local (unsigned long vaddr) +static inline bool kmap_high_unmap_local (unsigned long vaddr) {#ifdef ARCH_NEEDS_KMAP_HIGH_GET -if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) +if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) {kunmap_high (pte_page (pkmap_page_table[PKMAP_NR (vaddr)])); +return true; + }#endif +return false; }static inline int kmap_local_calc_idx (int idx)@@ -491,10 +494,14 @@ void kunmap_local_indexed(void *vaddr)if (addr <__fix_to_virt (FIX_KMAP_END ) || addr >__fix_to_virt (FIX_KMAP_BEGIN )) { -WARN_ON_ONCE (addr <PAGE_OFFSET ); - -/* Handle mappings which were obtained by kmap_high_get() */ -kmap_high_unmap_local (addr); +/*
mm/highmem.c void kunmap_local_indexed(void *vaddr) · line 507
Quoted 10 lines
mm/highmem.c +7
-0+* Handle mappings which were obtained by kmap_high_get() +* first as the virtual address of such mappings is below +* PAGE_OFFSET. Warn for all other addresses which are in +* the user space part of the virtual address space. +*/ +if (!kmap_high_unmap_local (addr)) +WARN_ON_ONCE (addr <PAGE_OFFSET );return ; }
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
The following commit has been merged into the core/mm branch of tip:
The following commit has been merged into the core/mm branch of tip:
Commit-ID: 2a656cad337e0e1ca582f58847d7b0c7eeba4dc8 Gitweb: https://git.kernel.org/tip/2a656cad337e0e1ca582f58847d7b0c7eeba4dc8 Author: Thomas Gleixner <[email protected]> AuthorDate: Thu, 12 Nov 2020 11:59:32 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 12 Nov 2020 14:44:38 +01:00
mm/highmem: Take kmap_high_get() properly into account
kunmap_local() warns when the virtual address to unmap is below PAGE_OFFSET. This is correct except for the case that the mapping was obtained via kmap_high_get() because the PKMAP addresses are right below PAGE_OFFSET.
Cure it by skipping the WARN_ON() when the unmap was handled by kunmap_high().
--- mm/highmem.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
mm/highmem.c +13 -6
@@ -426,12 +426,15 @@ static inline void *arch_kmap_local_high_get(struct page *page)#endif /* Unmap a local mapping which was obtained by kmap_high_get() */ -static inline void kmap_high_unmap_local (unsigned long vaddr) +static inline bool kmap_high_unmap_local (unsigned long vaddr) {#ifdef ARCH_NEEDS_KMAP_HIGH_GET -if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) +if (vaddr >=PKMAP_ADDR (0 ) && vaddr <PKMAP_ADDR (LAST_PKMAP )) {kunmap_high (pte_page (pkmap_page_table[PKMAP_NR (vaddr)])); +return true; + }#endif +return false; }static inline int kmap_local_calc_idx (int idx)
@@ -491,10 +494,14 @@ void kunmap_local_indexed(void *vaddr)if (addr <__fix_to_virt (FIX_KMAP_END ) || addr >__fix_to_virt (FIX_KMAP_BEGIN )) { -WARN_ON_ONCE (addr <PAGE_OFFSET ); - -/* Handle mappings which were obtained by kmap_high_get() */ -kmap_high_unmap_local (addr); +/* +* Handle mappings which were obtained by kmap_high_get() +* first as the virtual address of such mappings is below +* PAGE_OFFSET. Warn for all other addresses which are in +* the user space part of the virtual address space. +*/ +if (!kmap_high_unmap_local (addr)) +WARN_ON_ONCE (addr <PAGE_OFFSET );return ; }