* [PATCH] mm/highmem: Take kmap_high_get() properly into account
@ 2020-11-12 10:59 Thomas Gleixner
[not found] ` <CGME20201112113851eucas1p296c130142450daf91d5903362db53daa@eucas1p2.samsung.com>
2020-11-12 13:48 ` [tip: core/mm] " tip-bot2 for Thomas Gleixner
0 siblings, 2 replies; 3+ messages in thread
From: Thomas Gleixner @ 2020-11-12 10:59 UTC (permalink / raw)
To: LKML
Cc: vtolkm, Andrew Morton, linux-mm, Sebastian Andrzej Siewior,
Peter Zijlstra
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().
Fixes: 298fa1ad5571 ("highmem: Provide generic variant of kmap_atomic*")
Reported-by: vtolkm@googlemail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
mm/highmem.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -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;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <CGME20201112113851eucas1p296c130142450daf91d5903362db53daa@eucas1p2.samsung.com>]
* Re: [PATCH] mm/highmem: Take kmap_high_get() properly into account
[not found] ` <CGME20201112113851eucas1p296c130142450daf91d5903362db53daa@eucas1p2.samsung.com>
@ 2020-11-12 11:38 ` Marek Szyprowski
0 siblings, 0 replies; 3+ messages in thread
From: Marek Szyprowski @ 2020-11-12 11:38 UTC (permalink / raw)
To: Thomas Gleixner, LKML
Cc: vtolkm, Andrew Morton, linux-mm, Sebastian Andrzej Siewior,
Peter Zijlstra
Hi Thomas,
On 12.11.2020 11:59, Thomas Gleixner wrote:
> 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().
>
> Fixes: 298fa1ad5571 ("highmem: Provide generic variant of kmap_atomic*")
> Reported-by: vtolkm@googlemail.com
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This fixes the issue I've reported here:
https://lore.kernel.org/dri-devel/c07bae0c-68dd-2693-948f-00e8a50f3053@samsung.com/
Thanks!
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> mm/highmem.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> --- a/mm/highmem.c
> +++ b/mm/highmem.c
> @@ -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;
> }
>
>
>
>
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip: core/mm] mm/highmem: Take kmap_high_get() properly into account
2020-11-12 10:59 [PATCH] mm/highmem: Take kmap_high_get() properly into account Thomas Gleixner
[not found] ` <CGME20201112113851eucas1p296c130142450daf91d5903362db53daa@eucas1p2.samsung.com>
@ 2020-11-12 13:48 ` tip-bot2 for Thomas Gleixner
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Thomas Gleixner @ 2020-11-12 13:48 UTC (permalink / raw)
To: linux-tip-commits
Cc: vtolkm, Marek Szyprowski, Thomas Gleixner,
Sebastian Andrzej Siewior, Andrew Morton, x86, linux-kernel
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 <tglx@linutronix.de>
AuthorDate: Thu, 12 Nov 2020 11:59:32 +01:00
Committer: Thomas Gleixner <tglx@linutronix.de>
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().
Fixes: 298fa1ad5571 ("highmem: Provide generic variant of kmap_atomic*")
Reported-by: vtolkm@googlemail.com
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Link: https://lore.kernel.org/r/87y2j6n8mj.fsf@nanos.tec.linutronix.de
---
mm/highmem.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/mm/highmem.c b/mm/highmem.c
index 54bd233..78c481a 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -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;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-12 13:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-12 10:59 [PATCH] mm/highmem: Take kmap_high_get() properly into account Thomas Gleixner
[not found] ` <CGME20201112113851eucas1p296c130142450daf91d5903362db53daa@eucas1p2.samsung.com>
2020-11-12 11:38 ` Marek Szyprowski
2020-11-12 13:48 ` [tip: core/mm] " tip-bot2 for Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).