Skip to contentSkip to conversation

sparc64: uprobes: use kmap_local_page() in copy_to_page()

PATCH In review Danish Khateeb 2 participants 2 messages Sep 22

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

PATCH 1/1 sparc64: uprobes: use kmap_local_page() in copy_to_page()

kmap_atomic() is deprecated in favour of kmap_local_page(), as described in Documentation/mm/highmem.rst.

The generic uprobes code and arch_uprobe_copy_ixol() on arm, arm64, mips and riscv were converted in v7.0, see commit a491c02c2770 ("uprobes: use kmap_local_page() for temporary page mappings") and the arch patches that came with it. sparc64 was not part of that series: its arch_uprobe_copy_ixol() writes the XOL slot through a copy_to_page() helper, which still uses kmap_atomic().

The mapping only covers a memcpy() of one instruction into the XOL page, so it needs neither the pagefault_disable() nor the preempt_disable() implied by kmap_atomic(). Uprobes is only built for sparc64, which has no HIGHMEM, so kmap_local_page() is just page_address() here and the only effect is that the copy no longer runs with page faults and preemption disabled.

Tested under QEMU (sun4u) with CONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT, lockdep and CONFIG_DEBUG_ATOMIC_SLEEP: a test program put a uprobe and a uretprobe on one of its own functions, then called it 1000 times in one child process and 100 times in another. Every call returned the right value, all 1100 returns went through the uretprobe trampoline, and a kprobe counted 1102 calls to arch_uprobe_copy_ixol(): one per hit, plus the trampoline for each of the two XOL areas. No kernel warnings while it ran.

Assisted-by LLM sparse
---
 arch/sparc/kernel/uprobes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/sparc/kernel/uprobes.c +2 -2
index c8cac64e9988..1b54f9e72e8c 100644
@@ -33,10 +33,10 @@ unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
 static void copy_to_page(struct page *page, unsigned long vaddr,
 			 const void *src, int len)
 {
-	void *kaddr = kmap_atomic(page);
+	void *kaddr = kmap_local_page(page);
 
 	memcpy(kaddr + (vaddr & ~PAGE_MASK), src, len);
-	kunmap_atomic(kaddr);
+	kunmap_local(kaddr);
 }
 
 /* Fill in the xol area with the probed instruction followed by the

base-commit: 93f51579e7df248780214094418f205253383cc5

Signature · 1 line
2.55.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Danish Khateeb

arch/sparc/kernel/uprobes.c unsigned long uprobe_get_swbp_addr(struct pt_regs *regs) · line 40

Quoted 10 lines
arch/sparc/kernel/uprobes.c +2 -2
@@ -33,10 +33,10 @@ unsigned long uprobe_get_swbp_addr(struct pt_regs *regs)
 static void copy_to_page(struct page *page, unsigned long vaddr,
 			 const void *src, int len)
 {
-	void *kaddr = kmap_atomic(page);
+	void *kaddr = kmap_local_page(page);
 
 	memcpy(kaddr + (vaddr & ~PAGE_MASK), src, len);
-	kunmap_atomic(kaddr);
+	kunmap_local(kaddr);
 }