2022-09-13 03:51:33

by Liao, Chang

[permalink] [raw]
Subject: [PATCH V2 0/3] kprobe: Optimize the performance of patching ss

Single-step slot would not be used until kprobe is enabled, that means
no race condition occurs on it under SMP, hence it is safe to pacth ss
slot without stopping machine.

v2:
Backport riscv patch to cksy and arm64.

Liao Chang (3):
riscv/kprobe: Optimize the performance of patching single-step slot
csky/kprobe: Optimize the performance of patching single-step slot
arm64/kprobe: Optimize the performance of patching single-step slot

arch/arm64/kernel/probes/kprobes.c | 5 ++---
arch/csky/kernel/probes/kprobes.c | 6 +++++-
arch/riscv/kernel/probes/kprobes.c | 8 +++++---
3 files changed, 12 insertions(+), 7 deletions(-)

--
2.17.1


2022-09-13 04:13:15

by Liao, Chang

[permalink] [raw]
Subject: [PATCH V2 2/3] csky/kprobe: Optimize the performance of patching single-step slot

Single-step slot would not be used until kprobe is enabled, that means
no race condition occurs on it under SMP, hence it is safe to pacth ss
slot without stopping machine.

Signed-off-by: Liao Chang <[email protected]>
---
arch/csky/kernel/probes/kprobes.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c
index 3c6e5c725d81..4feb5ce16264 100644
--- a/arch/csky/kernel/probes/kprobes.c
+++ b/arch/csky/kernel/probes/kprobes.c
@@ -57,7 +57,11 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p)

p->ainsn.api.restore = (unsigned long)p->addr + offset;

- patch_text(p->ainsn.api.insn, p->opcode);
+ memcpy(p->ainsn.api.insn, &p->opcode, offset);
+ dcache_wb_range((unsigned long)p->ainsn.api.insn,
+ (unsigned long)p->ainsn.api.insn + offset);
+ icache_inv_range((unsigned long)p->ainsn.api.insn,
+ (unsigned long)p->ainsn.api.insn + offset);
}

static void __kprobes arch_prepare_simulate(struct kprobe *p)
--
2.17.1

2022-09-13 04:28:00

by Liao, Chang

[permalink] [raw]
Subject: [PATCH V2 1/3] riscv/kprobe: Optimize the performance of patching single-step slot

Single-step slot would not be used until kprobe is enabled, that means
no race condition occurs on it under SMP, hence it is safe to pacth ss
slot without stopping machine.

Signed-off-by: Liao Chang <[email protected]>
---
arch/riscv/kernel/probes/kprobes.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c
index e6e950b7cf32..bc1f39b96e41 100644
--- a/arch/riscv/kernel/probes/kprobes.c
+++ b/arch/riscv/kernel/probes/kprobes.c
@@ -24,12 +24,14 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
{
unsigned long offset = GET_INSN_LENGTH(p->opcode);
+ kprobe_opcode_t slot[MAX_INSN_SIZE];

p->ainsn.api.restore = (unsigned long)p->addr + offset;

- patch_text(p->ainsn.api.insn, p->opcode);
- patch_text((void *)((unsigned long)(p->ainsn.api.insn) + offset),
- __BUG_INSN_32);
+ memcpy(slot, &p->opcode, offset);
+ *(kprobe_opcode_t *)((unsigned long)slot + offset) = __BUG_INSN_32;
+ patch_text_nosync(p->ainsn.api.insn, slot,
+ offset + GET_INSN_LENGTH(__BUG_INSN_32));
}

static void __kprobes arch_prepare_simulate(struct kprobe *p)
--
2.17.1

2022-09-13 11:42:13

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH V2 0/3] kprobe: Optimize the performance of patching ss

On Tue, 13 Sep 2022 11:34:51 +0800
Liao Chang <[email protected]> wrote:

> Single-step slot would not be used until kprobe is enabled, that means
> no race condition occurs on it under SMP, hence it is safe to pacth ss
> slot without stopping machine.

All these patches look good to me, since single-step slot must not
be executed until it is prepared.

Acked-by: Masami Hiramatsu (Google) <[email protected]>
for this series.

But I need Ack by each architecture maintainer.

Thank you,

>
> v2:
> Backport riscv patch to cksy and arm64.
>
> Liao Chang (3):
> riscv/kprobe: Optimize the performance of patching single-step slot
> csky/kprobe: Optimize the performance of patching single-step slot
> arm64/kprobe: Optimize the performance of patching single-step slot
>
> arch/arm64/kernel/probes/kprobes.c | 5 ++---
> arch/csky/kernel/probes/kprobes.c | 6 +++++-
> arch/riscv/kernel/probes/kprobes.c | 8 +++++---
> 3 files changed, 12 insertions(+), 7 deletions(-)
>
> --
> 2.17.1
>


--
Masami Hiramatsu (Google) <[email protected]>