Message ID | 20221106100316.2803176-3-chenguokai17@mails.ucas.ac.cn (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add OPTPROBES feature on RISCV | expand |
Context | Check | Description |
---|---|---|
conchuod/patch_count | success | Link |
conchuod/cover_letter | success | Series has a cover letter |
conchuod/tree_selection | success | Guessed tree name to be for-next |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/verify_signedoff | success | Signed-off-by tag matches author and committer |
conchuod/kdoc | success | Errors and warnings before: 0 this patch: 0 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv32_defconfig | success | Build OK |
conchuod/build_warn_rv64 | success | Errors and warnings before: 0 this patch: 0 |
conchuod/dtb_warn_rv64 | success | Errors and warnings before: 0 this patch: 0 |
conchuod/header_inline | success | No static functions without inline keyword in header files |
conchuod/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 37 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 |
On Sun, 6 Nov 2022 18:03:10 +0800 Chen Guokai <chenguokai17@mails.ucas.ac.cn> wrote: > @@ -84,6 +85,30 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) > } > > #ifdef CONFIG_MMU > +#if defined(CONFIG_OPTPROBES) && defined(CONFIG_64BIT) > +void *alloc_optinsn_page(void) > +{ > + void *page; > + > + page = __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, > + MODULES_END, GFP_KERNEL, > + PAGE_KERNEL, 0, NUMA_NO_NODE, > + __builtin_return_address(0)); > + if (!page) > + return NULL; > + > + set_vm_flush_reset_perms(page); > + /* > + * First make the page read-only, and only then make it executable to > + * prevent it from being W+X in between. > + */ > + set_memory_ro((unsigned long)page, 1); > + set_memory_x((unsigned long)page, 1); FYI, the above combination is going to be going away: https://lore.kernel.org/all/Y10OyLCLAAS6rsZv@hirez.programming.kicks-ass.net/ -- Steve > + > + return page; > +} > +#endif > +
在 2022/11/17 9:25, Steven Rostedt 写道: > On Sun, 6 Nov 2022 18:03:10 +0800 > Chen Guokai <chenguokai17@mails.ucas.ac.cn> wrote: > >> @@ -84,6 +85,30 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) >> } >> >> #ifdef CONFIG_MMU >> +#if defined(CONFIG_OPTPROBES) && defined(CONFIG_64BIT) >> +void *alloc_optinsn_page(void) >> +{ >> + void *page; >> + >> + page = __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, >> + MODULES_END, GFP_KERNEL, >> + PAGE_KERNEL, 0, NUMA_NO_NODE, >> + __builtin_return_address(0)); >> + if (!page) >> + return NULL; >> + >> + set_vm_flush_reset_perms(page); >> + /* >> + * First make the page read-only, and only then make it executable to >> + * prevent it from being W+X in between. >> + */ >> + set_memory_ro((unsigned long)page, 1); >> + set_memory_x((unsigned long)page, 1); > > FYI, the above combination is going to be going away: > > https://lore.kernel.org/all/Y10OyLCLAAS6rsZv@hirez.programming.kicks-ass.net/ Thanks for reminding, i will use this API in next revision. > -- Steve > > >> + >> + return page; >> +} >> +#endif >> + >
diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index e6e950b7cf32..034eb7b13b3c 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -12,6 +12,7 @@ #include <asm/cacheflush.h> #include <asm/bug.h> #include <asm/patch.h> +#include <asm/set_memory.h> #include "decode-insn.h" @@ -84,6 +85,30 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p) } #ifdef CONFIG_MMU +#if defined(CONFIG_OPTPROBES) && defined(CONFIG_64BIT) +void *alloc_optinsn_page(void) +{ + void *page; + + page = __vmalloc_node_range(PAGE_SIZE, 1, MODULES_VADDR, + MODULES_END, GFP_KERNEL, + PAGE_KERNEL, 0, NUMA_NO_NODE, + __builtin_return_address(0)); + if (!page) + return NULL; + + set_vm_flush_reset_perms(page); + /* + * First make the page read-only, and only then make it executable to + * prevent it from being W+X in between. + */ + set_memory_ro((unsigned long)page, 1); + set_memory_x((unsigned long)page, 1); + + return page; +} +#endif + void *alloc_insn_page(void) { return __vmalloc_node_range(PAGE_SIZE, 1, VMALLOC_START, VMALLOC_END,