All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] kprobes: Misc bugfixes
@ 2022-01-13 14:55 Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 1/3] ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t Masami Hiramatsu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2022-01-13 14:55 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Jianhua Liu, Masami Hiramatsu, linux-kernel

Hi,

Here are some bugfixes and cleanup for the kprobe architecture
dependent implementation. 2 of 3 are found by Jianhua Liu on
arm64 optprobe code. I found that the similar issue on ppc64
and arm32 implementation so fixed those. And last one was
reported by kernel test bot.

Thank you,

---

Masami Hiramatsu (3):
      ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t
      powerpc/kprobes: Fix alloc_optinsn_page() to use all area of optinsn_slot
      ia64: kprobes: Cleanup unused 'template' local variable


 arch/arm/include/asm/kprobes.h       |    3 +--
 arch/ia64/kernel/kprobes.c           |    3 ---
 arch/powerpc/include/asm/kprobes.h   |    6 ++++++
 arch/powerpc/kernel/optprobes.c      |   25 +++++++++++++++++++------
 arch/powerpc/kernel/optprobes_head.S |    5 ++---
 5 files changed, 28 insertions(+), 14 deletions(-)

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t
  2022-01-13 14:55 [PATCH 0/3] kprobes: Misc bugfixes Masami Hiramatsu
@ 2022-01-13 14:55 ` Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 2/3] powerpc/kprobes: Fix alloc_optinsn_page() to use all area of optinsn_slot Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 3/3] ia64: kprobes: Cleanup unused 'template' local variable Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2022-01-13 14:55 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Jianhua Liu, Masami Hiramatsu, linux-kernel, Wang Nan

Count the MAX_OPTINSN_SIZE in 'kprobe_opcode_t' instead
of in byte. On arm, the sizeof(kprobe_opcode_t) is u32,
thus the current code consumes 4 times larger memory for
trampoline buffer.

Fixes: 0dc016dbd820 ("ARM: kprobes: enable OPTPROBES for ARM 32")
Reported-by: Jianhua Liu <jianhua.ljh@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
---
 arch/arm/include/asm/kprobes.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/include/asm/kprobes.h b/arch/arm/include/asm/kprobes.h
index e26a278d301a..092263a89102 100644
--- a/arch/arm/include/asm/kprobes.h
+++ b/arch/arm/include/asm/kprobes.h
@@ -56,8 +56,7 @@ extern __visible kprobe_opcode_t optprobe_template_restore_end[];
 
 #define MAX_OPTIMIZED_LENGTH	4
 #define MAX_OPTINSN_SIZE				\
-	((unsigned long)optprobe_template_end -	\
-	 (unsigned long)optprobe_template_entry)
+	(unsigned long)(optprobe_template_end - optprobe_template_entry)
 #define RELATIVEJUMP_SIZE	4
 
 struct arch_optimized_insn {


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] powerpc/kprobes: Fix alloc_optinsn_page() to use all area of optinsn_slot
  2022-01-13 14:55 [PATCH 0/3] kprobes: Misc bugfixes Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 1/3] ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t Masami Hiramatsu
@ 2022-01-13 14:55 ` Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 3/3] ia64: kprobes: Cleanup unused 'template' local variable Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2022-01-13 14:55 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Jianhua Liu, Masami Hiramatsu, linux-kernel, Anju T

When the ppc64 uses 4K page size, most part of the optinsn_slot
is not used because alloc_optinsn_page() is expected to return
only one page-size memory.
To use the remaining memories, make insn_page_in_use as array
to manage page-sized slots and return corresponding memory
address in the optinsn_slot.

Fixes: 51c9c0843993 ("powerpc/kprobes: Implement Optprobes")
Reported-by: Jianhua Liu <jianhua.ljh@gmail.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anju T <anju@linux.vnet.ibm.com>
---
 arch/powerpc/include/asm/kprobes.h   |    6 ++++++
 arch/powerpc/kernel/optprobes.c      |   25 +++++++++++++++++++------
 arch/powerpc/kernel/optprobes_head.S |    5 ++---
 3 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/arch/powerpc/include/asm/kprobes.h b/arch/powerpc/include/asm/kprobes.h
index bab364152b29..e7a5390effa8 100644
--- a/arch/powerpc/include/asm/kprobes.h
+++ b/arch/powerpc/include/asm/kprobes.h
@@ -4,6 +4,8 @@
 
 #include <asm-generic/kprobes.h>
 
+#ifndef __ASSEMBLY__
+
 #ifdef __KERNEL__
 /*
  *  Kernel Probes (KProbes)
@@ -94,4 +96,8 @@ static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
 static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
 #endif /* CONFIG_KPROBES */
 #endif /* __KERNEL__ */
+#endif /* __ASSEMBLY__ */
+
+#define KPROBE_OPTINSN_SLOT_SIZE        65536
+
 #endif	/* _ASM_POWERPC_KPROBES_H */
diff --git a/arch/powerpc/kernel/optprobes.c b/arch/powerpc/kernel/optprobes.c
index ce1903064031..eec2776ad2fd 100644
--- a/arch/powerpc/kernel/optprobes.c
+++ b/arch/powerpc/kernel/optprobes.c
@@ -25,19 +25,32 @@
 #define TMPL_INSN_IDX		(optprobe_template_insn - optprobe_template_entry)
 #define TMPL_END_IDX		(optprobe_template_end - optprobe_template_entry)
 
-static bool insn_page_in_use;
+#define OPTINSN_SLOT_PAGES (KPROBE_OPTINSN_SLOT_SIZE / PAGE_SIZE)
+
+static bool insn_page_in_use[OPTINSN_SLOT_PAGES];
 
 void *alloc_optinsn_page(void)
 {
-	if (insn_page_in_use)
-		return NULL;
-	insn_page_in_use = true;
-	return &optinsn_slot;
+	int i;
+
+	for (i = 0; i < OPTINSN_SLOT_PAGES; i++) {
+		if (!insn_page_in_use[i]) {
+			insn_page_in_use[i] = true;
+			return (void *)((unsigned long)&optinsn_slot + PAGE_SIZE * i);
+		}
+	}
+	return NULL;
 }
 
 void free_optinsn_page(void *page)
 {
-	insn_page_in_use = false;
+	unsigned long idx = (unsigned long)page - (unsigned long)&optinsn_slot;
+
+	WARN_ON_ONCE(idx & (PAGE_SIZE - 1));
+	idx >>= PAGE_SHIFT;
+	if (WARN_ON_ONCE(idx >= OPTINSN_SLOT_PAGES))
+		return;
+	insn_page_in_use[idx] = false;
 }
 
 /*
diff --git a/arch/powerpc/kernel/optprobes_head.S b/arch/powerpc/kernel/optprobes_head.S
index 19ea3312403c..bf2106836cc6 100644
--- a/arch/powerpc/kernel/optprobes_head.S
+++ b/arch/powerpc/kernel/optprobes_head.S
@@ -8,6 +8,7 @@
 #include <asm/ppc_asm.h>
 #include <asm/ptrace.h>
 #include <asm/asm-offsets.h>
+#include <asm/kprobes.h>
 
 #ifdef CONFIG_PPC64
 #define SAVE_30GPRS(base) SAVE_10GPRS(2,base); SAVE_10GPRS(12,base); SAVE_10GPRS(22,base)
@@ -19,8 +20,6 @@
 #define TEMPLATE_FOR_IMM_LOAD_INSNS	nop; nop; nop
 #endif
 
-#define	OPT_SLOT_SIZE	65536
-
 	.balign	4
 
 	/*
@@ -30,7 +29,7 @@
 	 */
 	.global optinsn_slot
 optinsn_slot:
-	.space	OPT_SLOT_SIZE
+	.space	KPROBE_OPTINSN_SLOT_SIZE
 
 	/*
 	 * Optprobe template:


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] ia64: kprobes: Cleanup unused 'template' local variable
  2022-01-13 14:55 [PATCH 0/3] kprobes: Misc bugfixes Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 1/3] ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t Masami Hiramatsu
  2022-01-13 14:55 ` [PATCH 2/3] powerpc/kprobes: Fix alloc_optinsn_page() to use all area of optinsn_slot Masami Hiramatsu
@ 2022-01-13 14:55 ` Masami Hiramatsu
  2 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2022-01-13 14:55 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: Jianhua Liu, Masami Hiramatsu, linux-kernel, kernel test robot,
	Anil S Keshavamurthy

Remove unused 'template' local variable. This seems to be introduced
accidentally by a cleanup patch.

Fixes: a5403183d84d ("[PATCH] Kprobes IA64: arch_prepare_kprobes() cleanup")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
---
 arch/ia64/kernel/kprobes.c |    3 ---
 1 file changed, 3 deletions(-)

diff --git a/arch/ia64/kernel/kprobes.c b/arch/ia64/kernel/kprobes.c
index 1a7bab1c5d7c..31ed086d61c9 100644
--- a/arch/ia64/kernel/kprobes.c
+++ b/arch/ia64/kernel/kprobes.c
@@ -322,9 +322,6 @@ static void __kprobes get_kprobe_inst(bundle_t *bundle, uint slot,
 	       	unsigned long *kprobe_inst, uint *major_opcode)
 {
 	unsigned long kprobe_inst_p0, kprobe_inst_p1;
-	unsigned int template;
-
-	template = bundle->quad0.template;
 
 	switch (slot) {
 	  case 0:


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-13 14:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 14:55 [PATCH 0/3] kprobes: Misc bugfixes Masami Hiramatsu
2022-01-13 14:55 ` [PATCH 1/3] ARM: kprobes: Count MAX_OPTINSN_SIZE in kprobe_opcode_t Masami Hiramatsu
2022-01-13 14:55 ` [PATCH 2/3] powerpc/kprobes: Fix alloc_optinsn_page() to use all area of optinsn_slot Masami Hiramatsu
2022-01-13 14:55 ` [PATCH 3/3] ia64: kprobes: Cleanup unused 'template' local variable Masami Hiramatsu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.