Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1768413ybv; Fri, 14 Feb 2020 05:44:41 -0800 (PST) X-Google-Smtp-Source: APXvYqzVvKdrfE+Tez+Lt9ivaMb3bdd9rxKbjMy/lENGueSnCW8Ew1WksZHaJvHiq8bja6JAxsau X-Received: by 2002:a05:6808:a9c:: with SMTP id q28mr1911012oij.176.1581687881790; Fri, 14 Feb 2020 05:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581687881; cv=none; d=google.com; s=arc-20160816; b=hlVVbEW5N38XQs+akzYaCAzngQtZZeKuBtZOok8QaLJaMZG7K3jLD3zsD7Ff6v2ZNk cUB51ex8uGdG2be0CGg1lk/wsbU4A6ueOPtNZu/lezmHAEUuVDC/A0qlyqF28BSMWNKK uc2+lTR5wLWNBpTuLOggBkPagEMtIks3BJcGhqWEXsPJaq37fXyT23WfSC6HQcg7vptW jJ+HI1X8BL4VL5qtFNTZI571LXX2W3VnbUugCwA5XzQXZdafm3Qe2a3a9ceJLhvZS1Ea K9GVQgAbw05CHcilqBSyp/4/M0reApktL+kMhMwLUVKkPEweq4UdKxvyw+ajzx86ffyc 6n/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=p5OSchYtuMtDjkKkYQzLUBJDMO3eTkGR/MZiD0IIXe4=; b=qp2Y+V2fHfc3rJzCY4CEu1Z917DGU0CG6ftpa6npoOFzuSjWtirPFQ9+sC3L8mxRED bCqY5u3SQToEfzUVKu8K6j+KrJzSvrDn9wo7/8u90j3T6ejc1jOmpcnkt8pYKb3yCJaQ X4F0F1NneUGYkTwqO6C7dvRDXI5bPgnZjEeOCb5edI32cmEhUp3Xn4u7cgi6/B7961gl ph1kkTWzO7MUFGjUKgLcIQD5k0tkCs7OP8w8n5r3qyxnC8txSS/Yd6G0euRFezkC6Nlf XASHwJeU2GfI1xySAL8fZaCKSFaBbFklc4AJBxdgl5dE0RJFzRlCFCtXuYxb9ATNbZtw 22CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=osJOwHfv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si2726545oih.206.2020.02.14.05.44.29; Fri, 14 Feb 2020 05:44:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=osJOwHfv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729263AbgBNNoT (ORCPT + 99 others); Fri, 14 Feb 2020 08:44:19 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:42541 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728437AbgBNNoS (ORCPT ); Fri, 14 Feb 2020 08:44:18 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48Jvk72V3Vz9vCR9; Fri, 14 Feb 2020 14:44:15 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=osJOwHfv; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 0NoDlu6ms6Qm; Fri, 14 Feb 2020 14:44:15 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48Jvk711Dqz9vCR5; Fri, 14 Feb 2020 14:44:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1581687855; bh=p5OSchYtuMtDjkKkYQzLUBJDMO3eTkGR/MZiD0IIXe4=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=osJOwHfvoWgb3e+1x6J09Y1VkIdNT7TU2Dctc+uxOkG+hxqPMDxZk7Ub6XRLVnkep ddWoKAcvSHjRz95r4OEc+LnqCf9oQj6vHaI5WPbAIC7oXx3GmHXSsx7/smlk5G3tnl zzdHTZCbOeZ2fuz7ebtuRQglRxBSzCtOEp0QnwlA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7D51F8B89C; Fri, 14 Feb 2020 14:44:16 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id uy2nkeZb4FMB; Fri, 14 Feb 2020 14:44:16 +0100 (CET) Received: from pc16570vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.230.102]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2DD4C8B89A; Fri, 14 Feb 2020 14:44:16 +0100 (CET) Received: by pc16570vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 0FD6C65284; Fri, 14 Feb 2020 13:44:16 +0000 (UTC) Message-Id: In-Reply-To: <642c8b4ca59e658be38d8dde00f994e183790a6a.1581687838.git.christophe.leroy@c-s.fr> References: <642c8b4ca59e658be38d8dde00f994e183790a6a.1581687838.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH 2/2] powerpc/kprobes: Reduce depth of a test To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 14 Feb 2020 13:44:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org if (a) { if (b) do_something(); } Is equivalent to if (a & b) do_something(); Signed-off-by: Christophe Leroy --- 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 (!p) { -- 2.25.0