Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3455610ybd; Fri, 28 Jun 2019 08:56:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBLiqCm1yBTLHoHOnvKAKoFyNhzTA4XqoylKZ1OujTKs5U2m3/a0zskhagNKT+HHi3BbDf X-Received: by 2002:a65:6401:: with SMTP id a1mr6548614pgv.42.1561737391052; Fri, 28 Jun 2019 08:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561737391; cv=none; d=google.com; s=arc-20160816; b=eKbm29VgG+QEOL7a8VXuCR/ZMl6GQRk4FOmqp4r21qzKXFpgleAu6GlonW60HbyQAR wL3Jz9rQ6lpEsAnluju73FZi9ATigQ3+6NsaA+GiMHLn6wY291b+HnbSB6HyuKcOXh9z E4YJsrNnHaiV6dtT2XujOIKScsNTUoOPB8prgANzHCe34CjTpkanHGSr54fTzz7CVU9x z/Epa/r7OrRAd4u3ZnwjmFPiPssv7/Fk+TXT+huoJDjfqBBjwNuTrKmt61Z83Du70sg7 cd7Csm/V95vLu1G/U/p0OtLIvoV7ISuD6EueUrX46U0EYAzrjOmreA3l/MjAPgsrYkvw zHjA== 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:message-id :dkim-signature; bh=R+Pqs0Guh4Zj9Xos+EjWx2t1Cce4u53eeSKBdU+J5cY=; b=UkEj88yKwFxQktKd7MPviJCLl2hhsxjXpnm0n/weF3Mnh6xGFtUFpAD/XPaSMd1N1z a/swLfKFV43e4jHoQpmYlsWkCoHN41HYZET7Df7c5PlLNcKFwGTwttDwkWKhT+vr7jwQ lsvN1XTy9s4eiB1MloZkYSeK8pGCZH3eVuY9QS2cXQhLmRWFfRL1vjNi04yFBhjSOJyB 24Pj5MTum1ws/BDKOfMrlJXkMQJy4Im4qH1ONhsKSsd8ZSrdBOpVlv2gEw/i8MVEpU4O /8YSPnqVDQjSi9s9tMN64nZDq6qvu3XlP8dSwpIAKRKS3I33qGJARSyxmJZUdTb5Jk+K hY+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=bRxw57ZP; 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 l123si1358640pfl.216.2019.06.28.08.56.15; Fri, 28 Jun 2019 08:56:31 -0700 (PDT) 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=bRxw57ZP; 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 S1727015AbfF1Pzy (ORCPT + 99 others); Fri, 28 Jun 2019 11:55:54 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:20243 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726780AbfF1Pzy (ORCPT ); Fri, 28 Jun 2019 11:55:54 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 45b1ZZ5XL8zB09ZQ; Fri, 28 Jun 2019 17:55:50 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=bRxw57ZP; 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 9uujxn9F6OOl; Fri, 28 Jun 2019 17:55:50 +0200 (CEST) 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 45b1ZZ4WPCzB09ZP; Fri, 28 Jun 2019 17:55:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1561737350; bh=R+Pqs0Guh4Zj9Xos+EjWx2t1Cce4u53eeSKBdU+J5cY=; h=From:Subject:To:Cc:Date:From; b=bRxw57ZPJq0Z/eFYvtMNaRnm9nNz/i3hxx+reMM0dGHTTIBlZi+kziVunG0UQCsCA 0c8TpfCzcyZ0jSvxdsLKS6b+f2BJu5W7UV0jcFnemcsBNr3oaDFjHGILfAcT3x5p8v zcCaKvwAYQ2aaLSkVTGPA6QHbrhM7CjviRQfC9pA= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 453C48B975; Fri, 28 Jun 2019 17:55:52 +0200 (CEST) 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 NJCT1fiEC2uU; Fri, 28 Jun 2019 17:55:52 +0200 (CEST) Received: from localhost.localdomain (po15451.idsi0.si.c-s.fr [172.25.230.101]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 276278B955; Fri, 28 Jun 2019 17:55:52 +0200 (CEST) Received: by localhost.localdomain (Postfix, from userid 0) id 1525E68DBC; Fri, 28 Jun 2019 15:55:52 +0000 (UTC) Message-Id: From: Christophe Leroy Subject: [PATCH] powerpc/hw_breakpoint: move instruction stepping out of hw_breakpoint_handler() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Fri, 28 Jun 2019 15:55:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8xx, breakpoints stop after executing the instruction, so stepping/emulation is not needed. Move it into a sub-function and remove the #ifdefs. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/hw_breakpoint.c | 60 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c index a293a53b4365..a94142e729bf 100644 --- a/arch/powerpc/kernel/hw_breakpoint.c +++ b/arch/powerpc/kernel/hw_breakpoint.c @@ -198,15 +198,43 @@ void thread_change_pc(struct task_struct *tsk, struct pt_regs *regs) /* * Handle debug exception notifications. */ +static bool stepping_handler(struct pt_regs *regs, struct perf_event *bp, + unsigned long addr) +{ + int stepped; + unsigned int instr; + + /* Do not emulate user-space instructions, instead single-step them */ + if (user_mode(regs)) { + current->thread.last_hit_ubp = bp; + regs->msr |= MSR_SE; + return false; + } + + stepped = 0; + instr = 0; + if (!__get_user_inatomic(instr, (unsigned int *)regs->nip)) + stepped = emulate_step(regs, instr); + + /* + * emulate_step() could not execute it. We've failed in reliably + * handling the hw-breakpoint. Unregister it and throw a warning + * message to let the user know about it. + */ + if (!stepped) { + WARN(1, "Unable to handle hardware breakpoint. Breakpoint at " + "0x%lx will be disabled.", addr); + perf_event_disable_inatomic(bp); + return false; + } + return true; +} + int hw_breakpoint_handler(struct die_args *args) { int rc = NOTIFY_STOP; struct perf_event *bp; struct pt_regs *regs = args->regs; -#ifndef CONFIG_PPC_8xx - int stepped = 1; - unsigned int instr; -#endif struct arch_hw_breakpoint *info; unsigned long dar = regs->dar; @@ -251,32 +279,10 @@ int hw_breakpoint_handler(struct die_args *args) (dar - bp->attr.bp_addr < bp->attr.bp_len))) info->type |= HW_BRK_TYPE_EXTRANEOUS_IRQ; -#ifndef CONFIG_PPC_8xx - /* Do not emulate user-space instructions, instead single-step them */ - if (user_mode(regs)) { - current->thread.last_hit_ubp = bp; - regs->msr |= MSR_SE; + if (!IS_ENABLED(CONFIG_PPC_8xx) && !stepping_handler(regs, bp, info->address)) goto out; - } - - stepped = 0; - instr = 0; - if (!__get_user_inatomic(instr, (unsigned int *) regs->nip)) - stepped = emulate_step(regs, instr); /* - * emulate_step() could not execute it. We've failed in reliably - * handling the hw-breakpoint. Unregister it and throw a warning - * message to let the user know about it. - */ - if (!stepped) { - WARN(1, "Unable to handle hardware breakpoint. Breakpoint at " - "0x%lx will be disabled.", info->address); - perf_event_disable_inatomic(bp); - goto out; - } -#endif - /* * As a policy, the callback is invoked in a 'trigger-after-execute' * fashion */ -- 2.13.3