Skip to contentSkip to conversation

mm/highmem: Fix fallout from generic kmap_local conversions

PATCH Applied Thomas Gleixner 3 participants 7 messages Jan 12, 2021 – Jan 13, 2021

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover mm/highmem: Fix fallout from generic kmap_local conversions

VGhlIGttYXBfbG9jYWwgY29udmVyc2lvbiB3cmVja2FnZWQgc3BhcmMsIG1pcHMgYW5kIHBvd2Vy cGMgYXMgaXQgbWlzc2VkCnNvbWUgb2YgdGhlIGRldGFpbHMgaW4gdGhlIG9yaWdpbmFsIGltcGxl bWVudGF0aW9uLgoKVGhlIGZvbGxvd2luZyBzZXJpZXMgYWRkcmVzc2VzIHRoYXQuCgpUaGFua3Ms CgoJdGdseAotLS0KIGFyY2gvbWlwcy9pbmNsdWRlL2FzbS9oaWdobWVtLmggICAgICB8ICAgIDEg KwogYXJjaC9zcGFyYy9pbmNsdWRlL2FzbS9oaWdobWVtLmggICAgIHwgICAgOSArKysrKy0tLS0K IGIvYXJjaC9wb3dlcnBjL2luY2x1ZGUvYXNtL2hpZ2htZW0uaCB8ICAgIDIgKysKIG1tL2hpZ2ht ZW0uYyAgICAgICAgICAgICAgICAgICAgICAgICB8ICAgIDcgKysrKysrLQogNCBmaWxlcyBjaGFu Z2VkLCAxNCBpbnNlcnRpb25zKCspLCA1IGRlbGV0aW9ucygtKQoKCg=

#1 lore raw

PATCH 1/4 sparc/mm/highmem: Flush cache and TLB

The recent conversion to the generic kmap_local infrastructure failed to assign the proper pre/post map/unmap flush operations for sparc.

Sparc requires cache flush before map/unmap and tlb flush afterwards.

Fixes 3293efa97807 ("sparc/mm/highmem: Switch to generic kmap atomic")
Cc "David S. Miller" <[email protected]>
---
 arch/sparc/include/asm/highmem.h |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/sparc/include/asm/highmem.h +5 -4
@@ -50,10 +50,11 @@ extern pte_t *pkmap_page_table;
 
 #define flush_cache_kmaps()	flush_cache_all()
 
-/* FIXME: Use __flush_tlb_one(vaddr) instead of flush_cache_all() -- Anton */
-#define arch_kmap_local_post_map(vaddr, pteval)	flush_cache_all()
-#define arch_kmap_local_post_unmap(vaddr)	flush_cache_all()
-
+/* FIXME: Use __flush_*_one(vaddr) instead of flush_*_all() -- Anton */
+#define arch_kmap_local_pre_map(vaddr, pteval)	flush_cache_all()
+#define arch_kmap_local_pre_unmap(vaddr)	flush_cache_all()
+#define arch_kmap_local_post_map(vaddr, pteval)	flush_tlb_all()
+#define arch_kmap_local_post_unmap(vaddr)	flush_tlb_all()
 
 #endif /* __KERNEL__ */
 
maintainer Tested-by on v1 1/4
#2 lore raw

Re: [patch 1/4] sparc/mm/highmem: Flush cache and TLB

Quoted 21 lines · Thomas Gleixner

The recent conversion to the generic kmap_local infrastructure failed to assign the proper pre/post map/unmap flush operations for sparc.

Sparc requires cache flush before map/unmap and tlb flush afterwards.

Fixes 3293efa97807 ("sparc/mm/highmem: Switch to generic kmap atomic")
Cc "David S. Miller" <[email protected]>
---
  arch/sparc/include/asm/highmem.h |    9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
arch/sparc/include/asm/highmem.h +0 -1
@@ -50,10 +50,11 @@ extern pte_t *pkmap_page_table;
 
  #define flush_cache_kmaps()	flush_cache_all()
 
-/* FIXME: Use __flush_tlb_one(vaddr) instead of flush_cache_all() -- Anton */

arch/sparc/include/asm/highmem.h extern pte_t *pkmap_page_table; · line 59

Quoted 10 lines
arch/sparc/include/asm/highmem.h +5 -3
-#define arch_kmap_local_post_map(vaddr, pteval)	flush_cache_all()
-#define arch_kmap_local_post_unmap(vaddr)	flush_cache_all()
-
+/* FIXME: Use __flush_*_one(vaddr) instead of flush_*_all() -- Anton */
+#define arch_kmap_local_pre_map(vaddr, pteval)	flush_cache_all()
+#define arch_kmap_local_pre_unmap(vaddr)	flush_cache_all()
+#define arch_kmap_local_post_map(vaddr, pteval)	flush_tlb_all()
+#define arch_kmap_local_post_unmap(vaddr)	flush_tlb_all()
 
  #endif /* __KERNEL__ */

Yes! I found, just an hour before your patched was posted, that an equivalent fix helped back where the switch-to-generic patch first occurred. This patch was successfully tested on master.

Signature · 2 lines
Andreas Larsson
Cobham Gaisler
#3 lore raw

PATCH 2/4 mm/highmem: Prepare for overriding set_pte_at()

In reply to Thomas Gleixner

The generic kmap_local() map function uses set_pte_at(), but MIPS requires set_pte() and PowerPC wants __set_pte_at().

Provide arch_kmap_local_set_pte() and default it to set_pte_at().

---
 mm/highmem.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
mm/highmem.c +6 -1
@@ -473,6 +473,11 @@ static inline void *arch_kmap_local_high
 }
 #endif
 
+#ifndef arch_kmap_local_set_pte
+#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev)	\
+	set_pte_at(mm, vaddr, ptep, ptev)
+#endif
+
 /* Unmap a local mapping which was obtained by kmap_high_get() */
 static inline bool kmap_high_unmap_local(unsigned long vaddr)
 {
@@ -515,7 +520,7 @@ void *__kmap_local_pfn_prot(unsigned lon
 	vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
 	BUG_ON(!pte_none(*(kmap_pte - idx)));
 	pteval = pfn_pte(pfn, prot);
-	set_pte_at(&init_mm, vaddr, kmap_pte - idx, pteval);
+	arch_kmap_local_set_pte(&init_mm, vaddr, kmap_pte - idx, pteval);
 	arch_kmap_local_post_map(vaddr, pteval);
 	current->kmap_ctrl.pteval[kmap_local_idx()] = pteval;
 	preempt_enable();
#4 lore raw

PATCH 3/4 mips/mm/highmem: Use set_pte() for kmap_local()

In reply to Thomas Gleixner

set_pte_at() on MIPS invokes update_cache() which might recurse into kmap_local(). Use set_pte() like the original MIPS highmem implementation did.

Fixes a4c33e83bca1 ("mips/mm/highmem: Switch to generic kmap atomic")
---
 arch/mips/include/asm/highmem.h |    1 +
 1 file changed, 1 insertion(+)
arch/mips/include/asm/highmem.h +1 -0
@@ -51,6 +51,7 @@ extern void kmap_flush_tlb(unsigned long
 
 #define flush_cache_kmaps()	BUG_ON(cpu_has_dc_aliases)
 
+#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev)	set_pte(ptep, ptev)
 #define arch_kmap_local_post_map(vaddr, pteval)	local_flush_tlb_one(vaddr)
 #define arch_kmap_local_post_unmap(vaddr)	local_flush_tlb_one(vaddr)
 
maintainer Acked-by on v1 3/4
#5 lore raw

Re: [patch 3/4] mips/mm/highmem: Use set_pte() for kmap_local()

Quoted 11 lines · Thomas Gleixner

set_pte_at() on MIPS invokes update_cache() which might recurse into kmap_local(). Use set_pte() like the original MIPS highmem implementation did.

Fixes a4c33e83bca1 ("mips/mm/highmem: Switch to generic kmap atomic")
---
 arch/mips/include/asm/highmem.h |    1 +
 1 file changed, 1 insertion(+)
Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#6 lore raw

PATCH 4/4 powerpc/mm/highmem: Use __set_pte_at() for kmap_local()

In reply to Thomas Gleixner

The original PowerPC highmem mapping function used __set_pte_at() to denote that the mapping is per CPU. This got lost with the conversion to the generic implementation.

Override the default map function.

Fixes 47da42b27a56 ("powerpc/mm/highmem: Switch to generic kmap atomic")
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/include/asm/highmem.h |    2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/include/asm/highmem.h +2 -0
@@ -58,6 +58,8 @@ extern pte_t *pkmap_page_table;
 
 #define flush_cache_kmaps()	flush_cache_all()
 
+#define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev)	\
+	__set_pte_at(mm, vaddr, ptep, ptev, 1)
 #define arch_kmap_local_post_map(vaddr, pteval)	\
 	local_flush_tlb_page(NULL, vaddr)
 #define arch_kmap_local_post_unmap(vaddr)	\