From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Christophe Leroy <christophe.leroy@c-s.fr>,
Michael Ellerman <mpe@ellerman.id.au>,
Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] powerpc/kprobes: Reduce depth of a test
Date: Tue, 18 Feb 2020 20:10:52 +0530 [thread overview]
Message-ID: <1582036273.gp0i4o7fv2.naveen@linux.ibm.com> (raw)
In-Reply-To: <b67d6705956a1a294af600700115930ff87e643c.1581687838.git.christophe.leroy@c-s.fr>
Christophe Leroy wrote:
> if (a) {
> if (b)
> do_something();
> }
>
> Is equivalent to
>
> if (a & b)
> do_something();
>
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> ---
> arch/powerpc/kernel/kprobes.c | 58 +++++++++++++++++------------------
> 1 file changed, 28 insertions(+), 30 deletions(-)
>
> diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
> index 7a925eb76ec0..d7c80a078c1e 100644
> --- a/arch/powerpc/kernel/kprobes.c
> +++ b/arch/powerpc/kernel/kprobes.c
> @@ -277,38 +277,36 @@ int kprobe_handler(struct pt_regs *regs)
>
> /* Check we're not actually recursing */
> p = get_kprobe(addr);
> - if (kprobe_running()) {
> - if (p) {
> - kprobe_opcode_t insn = *p->ainsn.insn;
> - if (kcb->kprobe_status == KPROBE_HIT_SS &&
> - is_trap(insn)) {
> - /* Turn off 'trace' bits */
> - regs->msr &= ~MSR_SINGLESTEP;
> - regs->msr |= kcb->kprobe_saved_msr;
> - goto no_kprobe;
> - }
> - /* We have reentered the kprobe_handler(), since
> - * another probe was hit while within the handler.
> - * We here save the original kprobes variables and
> - * just single step on the instruction of the new probe
> - * without calling any user handlers.
> - */
> - save_previous_kprobe(kcb);
> - set_current_kprobe(p, regs, kcb);
> - kprobes_inc_nmissed_count(p);
> - kcb->kprobe_status = KPROBE_REENTER;
> - if (p->ainsn.boostable >= 0) {
> - ret = try_to_emulate(p, regs);
> -
> - if (ret > 0) {
> - restore_previous_kprobe(kcb);
> - preempt_enable_no_resched();
> - return 1;
> - }
> + if (kprobe_running() && p) {
> + kprobe_opcode_t insn = *p->ainsn.insn;
> +
> + if (kcb->kprobe_status == KPROBE_HIT_SS && is_trap(insn)) {
> + /* Turn off 'trace' bits */
> + regs->msr &= ~MSR_SINGLESTEP;
> + regs->msr |= kcb->kprobe_saved_msr;
> + goto no_kprobe;
> + }
> + /* We have reentered the kprobe_handler(), since
> + * another probe was hit while within the handler.
> + * We here save the original kprobes variables and
> + * just single step on the instruction of the new probe
> + * without calling any user handlers.
> + */
> + save_previous_kprobe(kcb);
> + set_current_kprobe(p, regs, kcb);
> + kprobes_inc_nmissed_count(p);
> + kcb->kprobe_status = KPROBE_REENTER;
> + if (p->ainsn.boostable >= 0) {
> + ret = try_to_emulate(p, regs);
> +
> + if (ret > 0) {
> + restore_previous_kprobe(kcb);
> + preempt_enable_no_resched();
> + return 1;
> }
> - prepare_singlestep(p, regs);
> - return 1;
> }
> + prepare_singlestep(p, regs);
> + return 1;
> }
>
If we move the below !p case before the check for kprobe_running() right
after get_kprobe(), we won't need to check for (p) above and we won't
have any change in logic from Patch 1.
> if (!p) {
- Naveen
next prev parent reply other threads:[~2020-02-18 14:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-14 13:44 [PATCH 1/2] powerpc/kprobes: Remove redundant code Christophe Leroy
2020-02-14 13:44 ` [PATCH 2/2] powerpc/kprobes: Reduce depth of a test Christophe Leroy
2020-02-18 14:40 ` Naveen N. Rao [this message]
2020-02-18 14:39 ` [PATCH 1/2] powerpc/kprobes: Remove redundant code Naveen N. Rao
2020-02-19 7:48 ` Christophe Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1582036273.gp0i4o7fv2.naveen@linux.ibm.com \
--to=naveen.n.rao@linux.vnet.ibm.com \
--cc=benh@kernel.crashing.org \
--cc=christophe.leroy@c-s.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=paulus@samba.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).