Skip to contentSkip to conversation

riscv:uprobe remove set/clear SR_SPIE in arch_uprobe_pre/post/abort_xol

PATCH Superseded Yipeng Zou 2 participants 3 messages Jul 11, 2022 – Jul 20, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yipeng Zou

author
#0 lore raw

PATCH 1/1 riscv:uprobe remove set/clear SR_SPIE in arch_uprobe_pre/post/abort_xol

In riscv the process of uprobe going to clear spie before exec the origin insn,and set spie after that.But When access the page which origin insn has been placed a page fault may happen and irq was disabled in arch_uprobe_pre_xol function,It cause a WARN as follows.
There is no need to clear/set spie in arch_uprobe_pre/post/abort_xol. We can just remove it.

[   31.684157] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1488
[   31.684677] in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 76, name: work
[   31.684929] preempt_count: 0, expected: 0
[   31.685969] CPU: 2 PID: 76 Comm: work Tainted: G
[   31.686542] Hardware name: riscv-virtio,qemu (DT)
[   31.686797] Call Trace:
[   31.687053] [<ffffffff80006442>] dump_backtrace+0x30/0x38
[   31.687699] [<ffffffff80812118>] show_stack+0x40/0x4c
[   31.688141] [<ffffffff8081817a>] dump_stack_lvl+0x44/0x5c
[   31.688396] [<ffffffff808181aa>] dump_stack+0x18/0x20
[   31.688653] [<ffffffff8003e454>] __might_resched+0x114/0x122
[   31.688948] [<ffffffff8003e4b2>] __might_sleep+0x50/0x7a
[   31.689435] [<ffffffff80822676>] down_read+0x30/0x130
[   31.689728] [<ffffffff8000b650>] do_page_fault+0x166/x446
[   31.689997] [<ffffffff80003c0c>] ret_from_exception+0x0/0xc
---
 arch/riscv/kernel/probes/uprobes.c | 6 ------
 1 file changed, 6 deletions(-)
arch/riscv/kernel/probes/uprobes.c +0 -6
index 7a057b5f0adc..c976a21cd4bd 100644
@@ -59,8 +59,6 @@ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
 	instruction_pointer_set(regs, utask->xol_vaddr);
 
-	regs->status &= ~SR_SPIE;
-
 	return 0;
 }
 
@@ -72,8 +70,6 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
 	instruction_pointer_set(regs, utask->vaddr + auprobe->insn_size);
 
-	regs->status |= SR_SPIE;
-
 	return 0;
 }
 
@@ -111,8 +107,6 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 	 * address.
 	 */
 	instruction_pointer_set(regs, utask->vaddr);
-
-	regs->status &= ~SR_SPIE;
 }
 
 bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
Signature · 7 lines
2.17.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Yipeng Zou

In riscv the process of uprobe going to clear spie before exec the origin insn,and set spie after that.But When access the page which origin insn has been placed a page fault may happen and irq was disabled in arch_uprobe_pre_xol function,It cause a WARN as follows.
There is no need to clear/set spie in arch_uprobe_pre/post/abort_xol. We can just remove it.

Seems there is no side effect on an interrupt in xol. I also checked arm64, x86, MIPS, and csky (also written by me), which are the same as yours (No irq mask). I forgot why I mask irq for userspace xol.

Quoted 17 lines
[   31.684157] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1488
[   31.684677] in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 76, name: work
[   31.684929] preempt_count: 0, expected: 0
[   31.685969] CPU: 2 PID: 76 Comm: work Tainted: G
[   31.686542] Hardware name: riscv-virtio,qemu (DT)
[   31.686797] Call Trace:
[   31.687053] [<ffffffff80006442>] dump_backtrace+0x30/0x38
[   31.687699] [<ffffffff80812118>] show_stack+0x40/0x4c
[   31.688141] [<ffffffff8081817a>] dump_stack_lvl+0x44/0x5c
[   31.688396] [<ffffffff808181aa>] dump_stack+0x18/0x20
[   31.688653] [<ffffffff8003e454>] __might_resched+0x114/0x122
[   31.688948] [<ffffffff8003e4b2>] __might_sleep+0x50/0x7a
[   31.689435] [<ffffffff80822676>] down_read+0x30/0x130
[   31.689728] [<ffffffff8000b650>] do_page_fault+0x166/x446
[   31.689997] [<ffffffff80003c0c>] ret_from_exception+0x0/0xc
Quoted 1 line

Please add the Fixes tag.

Then:

Quoted 38 lines
---
 arch/riscv/kernel/probes/uprobes.c | 6 ------
 1 file changed, 6 deletions(-)
arch/riscv/kernel/probes/uprobes.c +0 -7
index 7a057b5f0adc..c976a21cd4bd 100644
@@ -59,8 +59,6 @@ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
        instruction_pointer_set(regs, utask->xol_vaddr);
 
-       regs->status &= ~SR_SPIE;
-
        return 0;
 }
 
@@ -72,8 +70,6 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
        instruction_pointer_set(regs, utask->vaddr + auprobe->insn_size);
 
-       regs->status |= SR_SPIE;
-
        return 0;
 }
 
@@ -111,8 +107,6 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
         * address.
         */
        instruction_pointer_set(regs, utask->vaddr);
-
-       regs->status &= ~SR_SPIE;
 }
 
 bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
--

2.17.1

Signature · 7 lines
Best Regards
 Guo Ren

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#2 lore raw
Quoted 28 lines · Guo Ren
Quoted 7 lines · Yipeng Zou

In riscv the process of uprobe going to clear spie before exec the origin insn,and set spie after that.But When access the page which origin insn has been placed a page fault may happen and irq was disabled in arch_uprobe_pre_xol function,It cause a WARN as follows.
There is no need to clear/set spie in arch_uprobe_pre/post/abort_xol. We can just remove it.

Seems there is no side effect on an interrupt in xol. I also checked arm64, x86, MIPS, and csky (also written by me), which are the same as yours (No irq mask). I forgot why I mask irq for userspace xol.

Quoted 16 lines
[   31.684157] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1488
[   31.684677] in_atomic(): 0, irqs_disabled(): 1, non_block: 0, pid: 76, name: work
[   31.684929] preempt_count: 0, expected: 0
[   31.685969] CPU: 2 PID: 76 Comm: work Tainted: G
[   31.686542] Hardware name: riscv-virtio,qemu (DT)
[   31.686797] Call Trace:
[   31.687053] [<ffffffff80006442>] dump_backtrace+0x30/0x38
[   31.687699] [<ffffffff80812118>] show_stack+0x40/0x4c
[   31.688141] [<ffffffff8081817a>] dump_stack_lvl+0x44/0x5c
[   31.688396] [<ffffffff808181aa>] dump_stack+0x18/0x20
[   31.688653] [<ffffffff8003e454>] __might_resched+0x114/0x122
[   31.688948] [<ffffffff8003e4b2>] __might_sleep+0x50/0x7a
[   31.689435] [<ffffffff80822676>] down_read+0x30/0x130
[   31.689728] [<ffffffff8000b650>] do_page_fault+0x166/x446
[   31.689997] [<ffffffff80003c0c>] ret_from_exception+0x0/0xc
Quoted 6 lines
Quoted 1 line

Please add the Fixes tag.

Then:

Allready send v2 patch(add Fixes tag) and thanks for review.

Quoted 39 lines
Quoted 38 lines
---
  arch/riscv/kernel/probes/uprobes.c | 6 ------
  1 file changed, 6 deletions(-)
arch/riscv/kernel/probes/uprobes.c +0 -7
index 7a057b5f0adc..c976a21cd4bd 100644
@@ -59,8 +59,6 @@ int arch_uprobe_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
         instruction_pointer_set(regs, utask->xol_vaddr);
 
-       regs->status &= ~SR_SPIE;
-
         return 0;
  }
 
@@ -72,8 +70,6 @@ int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
 
         instruction_pointer_set(regs, utask->vaddr + auprobe->insn_size);
 
-       regs->status |= SR_SPIE;
-
         return 0;
  }
 
@@ -111,8 +107,6 @@ void arch_uprobe_abort_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)
          * address.
          */
         instruction_pointer_set(regs, utask->vaddr);
-
-       regs->status &= ~SR_SPIE;
  }
 
  bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx,
--

2.17.1

Signature · 8 lines
Regards,
Yipeng Zou


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv