diff mbox series

[RESEND] riscv: fix kprobe __user string arg print fault issue

Message ID 20230423012912.890965-1-ruanjinjie@huawei.com (mailing list archive)
State Superseded
Headers show
Series [RESEND] riscv: fix kprobe __user string arg print fault issue | expand

Checks

Context Check Description
conchuod/cover_letter success Single patches do not need cover letters
conchuod/tree_selection success Guessed tree name to be for-next at HEAD 310c33dc7a12
conchuod/fixes_present success Fixes tag not required for -next series
conchuod/maintainers_pattern success MAINTAINERS pattern errors before the patch: 1 and now 1
conchuod/verify_signedoff success Signed-off-by tag matches author and committer
conchuod/kdoc success Errors and warnings before: 0 this patch: 0
conchuod/build_rv64_clang_allmodconfig success Errors and warnings before: 23 this patch: 23
conchuod/module_param success Was 0 now: 0
conchuod/build_rv64_gcc_allmodconfig fail Errors and warnings before: 70 this patch: 71
conchuod/build_rv32_defconfig success Build OK
conchuod/dtb_warn_rv64 success Errors and warnings before: 3 this patch: 3
conchuod/header_inline success No static functions without inline keyword in header files
conchuod/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
conchuod/source_inline success Was 0 now: 0
conchuod/build_rv64_nommu_k210_defconfig success Build OK
conchuod/verify_fixes success No Fixes tag
conchuod/build_rv64_nommu_virt_defconfig success Build OK

Commit Message

Jinjie Ruan April 23, 2023, 1:29 a.m. UTC
On riscv qemu platform, when add kprobe event on do_sys_open() to show
filename string arg, it just print fault as follow:

echo 'p:myprobe do_sys_open dfd=$arg1 filename=+0($arg2):string flags=$arg3
mode=$arg4' > kprobe_events

bash-166     [000] ...1.   360.195367: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6

bash-166     [000] ...1.   360.219369: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6

bash-191     [000] ...1.   360.378827: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x98800 mode=0x0

As riscv do not select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE,
the +0($arg2) addr is processed as a kernel address though it is a
userspace address, cause the above filename=(fault) print. So select
ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE to avoid the issue, after that the
kprobe trace is ok as below:

bash-166     [000] ...1.    96.767641: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6

bash-166     [000] ...1.    96.793751: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6

bash-177     [000] ...1.    96.962354: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/sys/kernel/debug/tracing/events/kprobes/"
flags=0x98800 mode=0x0

Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)

Comments

Conor Dooley April 23, 2023, 8:56 a.m. UTC | #1
On 23 April 2023 02:29:12 IST, ruanjinjie <ruanjinjie@huawei.com> wrote:
>On riscv qemu platform, when add kprobe event on do_sys_open() to show
>filename string arg, it just print fault as follow:
>
>echo 'p:myprobe do_sys_open dfd=$arg1 filename=+0($arg2):string flags=$arg3
>mode=$arg4' > kprobe_events
>
>bash-166     [000] ...1.   360.195367: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6
>
>bash-166     [000] ...1.   360.219369: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6
>
>bash-191     [000] ...1.   360.378827: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename=(fault) flags=0x98800 mode=0x0
>
>As riscv do not select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE,
>the +0($arg2) addr is processed as a kernel address though it is a
>userspace address, cause the above filename=(fault) print. So select
>ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE to avoid the issue, after that the
>kprobe trace is ok as below:
>
>bash-166     [000] ...1.    96.767641: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6
>
>bash-166     [000] ...1.    96.793751: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6
>
>bash-177     [000] ...1.    96.962354: myprobe: (do_sys_open+0x0/0x84)
>dfd=0xffffffffffffff9c filename="/sys/kernel/debug/tracing/events/kprobes/"
>flags=0x98800 mode=0x0
>
>Signed-off-by: ruanjinjie <ruanjinjie@huawei.com>
>---
> arch/riscv/Kconfig | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>index eb7f29a412f8..c51f0d3227af 100644
>--- a/arch/riscv/Kconfig
>+++ b/arch/riscv/Kconfig
>@@ -26,6 +26,7 @@ config RISCV
> 	select ARCH_HAS_KCOV
> 	select ARCH_HAS_MMIOWB
> 	select ARCH_HAS_PMEM_API
>+	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE

Please add this in alphabetical order, thanks.

> 	select ARCH_HAS_PTE_SPECIAL
> 	select ARCH_HAS_SET_DIRECT_MAP if MMU
> 	select ARCH_HAS_SET_MEMORY if MMU
diff mbox series

Patch

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index eb7f29a412f8..c51f0d3227af 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -26,6 +26,7 @@  config RISCV
 	select ARCH_HAS_KCOV
 	select ARCH_HAS_MMIOWB
 	select ARCH_HAS_PMEM_API
+	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SET_DIRECT_MAP if MMU
 	select ARCH_HAS_SET_MEMORY if MMU