Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3618561ybd; Tue, 25 Jun 2019 05:50:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqz42DHsoqrq3RXNTUzINDvP8dt/kZTmdKmebXmZI1Z+yeqeiFCw9F/49ZWrJNTfq929todC X-Received: by 2002:a65:404a:: with SMTP id h10mr39605950pgp.262.1561467034191; Tue, 25 Jun 2019 05:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561467034; cv=none; d=google.com; s=arc-20160816; b=RRR7kFljahH7Bdkug1y2BfvhogR+Kcwp93Qf0vUCDTY2Uw/ficjfg1w8RCG1Pim2lE vtPk9AJRBduFMaPRFkvLMOzOYKcfmIHX27Zg/nwc72XwbIL/b+MZvmAj3WGJDqWIOHM1 0GCjDM0rhu+D0a6JdJ095S59e2yn08NkHLMWbhL/ezWrxjHKOZt2tTxnZbgy3MF3kp+W ekMD2eZDbphLyWtpsJp7qn4HHJD0ZA6k0aOjQTuEymigWXIfVkAVAIkzGHrcG3McZpgl DRlRjr+uhur9zq1UYyaxBaZCWoTgvr3rh1MN+S58+V9o3EYP5/xo8V7hEt8MP8txtabb FmUQ== 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=0qZwQpr4MSd6rLow6MYfEuYxvZJpdGewNYEX+NzmT+w=; b=wObmsnH9jeG/OrV651HoAjkbG1IHuqcoWlpmgChGLbB4YiRgAomjf5q7CE3cWG104w keBY1ODIDi1o9QggJj6DNCfzl5mKVf/aBnhHAEE9G3IHM3HKi4n4XIWwQneNcVfg1427 yPkyegKq1yC1Vc3bSjNuSIYze/oc/4SQwZs+mvC/KSJcQ8YtLu33MzSL/pNNu7kV30BI R1CfYqpnXXO767GPBSNsamT2X4vo63Uf4N964dQ8leXxSE6Oh2E+MWWBUSZwfFUvB1+0 Hnhr9v/P1X2IAAGYiJFgeZ4+eEH0v9x07MME+4woObaClAJFlDerCs0LCFO5DuuDQjtD aZZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=aOgxNM5v; 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 v21si13307224pfm.18.2019.06.25.05.50.18; Tue, 25 Jun 2019 05:50:34 -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=aOgxNM5v; 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 S1732347AbfFYK6f (ORCPT + 99 others); Tue, 25 Jun 2019 06:58:35 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:18162 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732305AbfFYK6Y (ORCPT ); Tue, 25 Jun 2019 06:58:24 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 45Y36j4bwXz9v17h; Tue, 25 Jun 2019 12:58:21 +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=aOgxNM5v; 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 Fa8GvaOu9h1B; Tue, 25 Jun 2019 12:58:21 +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 45Y36j3bmrz9v17d; Tue, 25 Jun 2019 12:58:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1561460301; bh=0qZwQpr4MSd6rLow6MYfEuYxvZJpdGewNYEX+NzmT+w=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=aOgxNM5v9od8NAMRJ7xXJVy75EleSN4MzA0JwePexW1XghuoBRKJIM9TXJ/yVvpzg gdmaUE6etLhQuUzeodyl5JyegwKPgZnwMaJbQgJeZJ7/5eNqEKIM8blLhXaKNiJrrU iqh5Hce11gbPCrNbpegGU8N3yl+KBjMlpiVmWkbQ= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A432B8B879; Tue, 25 Jun 2019 12:58:22 +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 lBAx_H-bhUvc; Tue, 25 Jun 2019 12:58:22 +0200 (CEST) Received: from pc17473vm.idsi0.si.c-s.fr (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6410F8B874; Tue, 25 Jun 2019 12:58:22 +0200 (CEST) Received: by pc17473vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 35EE668E1B; Tue, 25 Jun 2019 10:58:19 +0000 (UTC) Message-Id: <347a44cbfdd864c8ab5440d8915710cb1648a05a.1561459984.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [RFC PATCH v1 13/13] powerpc/hw_breakpoint: move instruction stepping out of hw_breakpoint_handler() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , mikey@neuling.org Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Tue, 25 Jun 2019 10:58:19 +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 b71d3837d673..a6a509b9fd13 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,31 +279,9 @@ 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