From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9AEFC2B9F8 for ; Tue, 25 May 2021 14:45:29 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68D8661284 for ; Tue, 25 May 2021 14:45:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68D8661284 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=owNCr2+fTsUQGWyHp10e88AyZUGxB+OMocBbr8bP8RU=; b=0dH+bSLp3q21hg LLpDP0xkeW0e5Q88k+1UoPdxztXYg/4l0qShDGbdc1EVtShkCAmD122AzDhy7Thj/oLkXo73qSUkS 5Af5XeMtqm95MycPsckgCha62b0mdj0HM19geYCWCOA3B+S18yCEBgHbkc/g3u7b8WSHBThsYkb7Q Z2kqVRBppfmoMJMi8rub4rh5mTzmbbl/SPvQnuN6KoauFULs2DkIk/K4OGINwSRkLgvneOuQSh7Vp rTbhTNAr1b4dc2mXSSz13BS2CP7wrIGToSxm2YYB1kPiGdcwVxb6+lFPBDHNg3V5vQbLi1fdlRAIY TfzjQc5dUpqbtY8QDjjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1llYJ0-005jaB-1e; Tue, 25 May 2021 14:45:14 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1llYIx-005jYc-DX for linux-riscv@lists.infradead.org; Tue, 25 May 2021 14:45:13 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id B958A6141C; Tue, 25 May 2021 14:45:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621953911; bh=jfWp5vialmXhYcXsdvLggfVIv1bcNp7z6bzNnIfhMJs=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lyU0XUfjokFn6Duv+OPmiSjb1JOVme62avzrZz2hHvx1oFvh07TXcqjNc7vTtydze 9GU04pIGPwo1dv0rmUZZaX068G8FEAM+YtGrLHhYLfsvEwTrP8DWcmSaHoZff6IH3a qKhyCIxNvROpdTzWZeJdKieBQj0EFkzeAmOYmvxmnMeesMpvQV2AuJ3ci3i3JVmMLU VrpviY6aghQ2FKhDrEXVejZQ4kPEJOr9f6OrUwWz7Zlzm40CXnnouGPHqLE5tQx2BB te+qUNejwrTWcjIPdEHR2BPVyDZmBtyB/j4Ra11amW2TL4jCbYm437zf/Mlkn3YAXD WQZ9fr5DvMEqQ== Date: Tue, 25 May 2021 23:45:07 +0900 From: Masami Hiramatsu To: Jisheng Zhang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] riscv: kprobes: Remove redundant kprobe_step_ctx Message-Id: <20210525234507.2a576f91d157eba18eb4306a@kernel.org> In-Reply-To: <20210512225819.6756c0b0@xhacker> References: <20210419002919.1a0a539d@xhacker> <20210512225819.6756c0b0@xhacker> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210525_074511_556107_BAECA8DA X-CRM114-Status: GOOD ( 26.98 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Hi Jisheng, On Wed, 12 May 2021 22:58:19 +0800 Jisheng Zhang wrote: > On Mon, 19 Apr 2021 00:29:19 +0800 > Jisheng Zhang wrote: > > > From: Jisheng Zhang > > > > Inspired by commit ba090f9cafd5 ("arm64: kprobes: Remove redundant > > kprobe_step_ctx"), the ss_pending and match_addr of kprobe_step_ctx > > are redundant because those can be replaced by KPROBE_HIT_SS and > > &cur_kprobe->ainsn.api.insn[0] + GET_INSN_LENGTH(cur->opcode) > > respectively. > > > > Remove the kprobe_step_ctx to simplify the code. > > Hi all, > > This patch can still be applied to 5.13-rc1, could you please review? Let me > know if a rebase on 5.13-rc1 is needed. As far as I compared with arm64 code, this looks good to me. Reviewed-by: Masami Hiramatsu Thanks, > > Thanks > > > > > Signed-off-by: Jisheng Zhang > > --- > > arch/riscv/include/asm/kprobes.h | 7 ------ > > arch/riscv/kernel/probes/kprobes.c | 40 +++++++----------------------- > > 2 files changed, 9 insertions(+), 38 deletions(-) > > > > diff --git a/arch/riscv/include/asm/kprobes.h b/arch/riscv/include/asm/kprobes.h > > index 4647d38018f6..9ea9b5ec3113 100644 > > --- a/arch/riscv/include/asm/kprobes.h > > +++ b/arch/riscv/include/asm/kprobes.h > > @@ -29,18 +29,11 @@ struct prev_kprobe { > > unsigned int status; > > }; > > > > -/* Single step context for kprobe */ > > -struct kprobe_step_ctx { > > - unsigned long ss_pending; > > - unsigned long match_addr; > > -}; > > - > > /* per-cpu kprobe control block */ > > struct kprobe_ctlblk { > > unsigned int kprobe_status; > > unsigned long saved_status; > > struct prev_kprobe prev_kprobe; > > - struct kprobe_step_ctx ss_ctx; > > }; > > > > void arch_remove_kprobe(struct kprobe *p); > > diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c > > index 8c1f7a30aeed..4c1ad5536748 100644 > > --- a/arch/riscv/kernel/probes/kprobes.c > > +++ b/arch/riscv/kernel/probes/kprobes.c > > @@ -17,7 +17,7 @@ DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; > > DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk); > > > > static void __kprobes > > -post_kprobe_handler(struct kprobe_ctlblk *, struct pt_regs *); > > +post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *); > > > > static void __kprobes arch_prepare_ss_slot(struct kprobe *p) > > { > > @@ -43,7 +43,7 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs) > > p->ainsn.api.handler((u32)p->opcode, > > (unsigned long)p->addr, regs); > > > > - post_kprobe_handler(kcb, regs); > > + post_kprobe_handler(p, kcb, regs); > > } > > > > int __kprobes arch_prepare_kprobe(struct kprobe *p) > > @@ -149,21 +149,6 @@ static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb, > > regs->status = kcb->saved_status; > > } > > > > -static void __kprobes > > -set_ss_context(struct kprobe_ctlblk *kcb, unsigned long addr, struct kprobe *p) > > -{ > > - unsigned long offset = GET_INSN_LENGTH(p->opcode); > > - > > - kcb->ss_ctx.ss_pending = true; > > - kcb->ss_ctx.match_addr = addr + offset; > > -} > > - > > -static void __kprobes clear_ss_context(struct kprobe_ctlblk *kcb) > > -{ > > - kcb->ss_ctx.ss_pending = false; > > - kcb->ss_ctx.match_addr = 0; > > -} > > - > > static void __kprobes setup_singlestep(struct kprobe *p, > > struct pt_regs *regs, > > struct kprobe_ctlblk *kcb, int reenter) > > @@ -182,8 +167,6 @@ static void __kprobes setup_singlestep(struct kprobe *p, > > /* prepare for single stepping */ > > slot = (unsigned long)p->ainsn.api.insn; > > > > - set_ss_context(kcb, slot, p); /* mark pending ss */ > > - > > /* IRQs and single stepping do not mix well. */ > > kprobes_save_local_irqflag(kcb, regs); > > > > @@ -219,13 +202,8 @@ static int __kprobes reenter_kprobe(struct kprobe *p, > > } > > > > static void __kprobes > > -post_kprobe_handler(struct kprobe_ctlblk *kcb, struct pt_regs *regs) > > +post_kprobe_handler(struct kprobe *cur, struct kprobe_ctlblk *kcb, struct pt_regs *regs) > > { > > - struct kprobe *cur = kprobe_running(); > > - > > - if (!cur) > > - return; > > - > > /* return addr restore if non-branching insn */ > > if (cur->ainsn.api.restore != 0) > > regs->epc = cur->ainsn.api.restore; > > @@ -355,16 +333,16 @@ bool __kprobes > > kprobe_single_step_handler(struct pt_regs *regs) > > { > > struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); > > + unsigned long addr = instruction_pointer(regs); > > + struct kprobe *cur = kprobe_running(); > > > > - if ((kcb->ss_ctx.ss_pending) > > - && (kcb->ss_ctx.match_addr == instruction_pointer(regs))) { > > - clear_ss_context(kcb); /* clear pending ss */ > > - > > + if (cur && (kcb->kprobe_status & (KPROBE_HIT_SS | KPROBE_REENTER)) && > > + ((unsigned long)&cur->ainsn.api.insn[0] + GET_INSN_LENGTH(cur->opcode) == addr)) { > > kprobes_restore_local_irqflag(kcb, regs); > > - > > - post_kprobe_handler(kcb, regs); > > + post_kprobe_handler(cur, kcb, regs); > > return true; > > } > > + /* not ours, kprobes should ignore it */ > > return false; > > } > > > > -- Masami Hiramatsu _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv