From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933169AbcFNBmm (ORCPT ); Mon, 13 Jun 2016 21:42:42 -0400 Received: from mail.kernel.org ([198.145.29.136]:53440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932430AbcFNBml (ORCPT ); Mon, 13 Jun 2016 21:42:41 -0400 Date: Tue, 14 Jun 2016 10:42:28 +0900 From: Masami Hiramatsu To: David Long Cc: Catalin Marinas , Huang Shijie , James Morse , Marc Zyngier , Pratyush Anand , Sandeepa Prabhu , Will Deacon , William Cohen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Steve Capper , Li Bin , Adam Buchbinder , Alex =?UTF-8?B?QmVubsOpZQ==?= , Andrew Morton , Andrey Ryabinin , Ard Biesheuvel , Christoffer Dall , Daniel Thompson , Dave P Martin , Jens Wiklander , Jisheng Zhang , John Blackwood , Mark Rutland , Petr Mladek , Robin Murphy , Suzuki K Poulose , Vladimir Murzin , Yang Shi , Zi Shen Lim , yalin wang , Mark Brown Subject: Re: [PATCH v13 05/10] arm64: Kprobes with single stepping support Message-Id: <20160614104228.0e94341a298b3ca94b2f47c3@kernel.org> In-Reply-To: <1464924384-15269-6-git-send-email-dave.long@linaro.org> References: <1464924384-15269-1-git-send-email-dave.long@linaro.org> <1464924384-15269-6-git-send-email-dave.long@linaro.org> X-Mailer: Sylpheed 3.4.3 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, I have additional comments on this. On Thu, 2 Jun 2016 23:26:19 -0400 David Long wrote: > +/* > + * The D-flag (Debug mask) is set (masked) upon deug exception entry. deug -> debug > + * Kprobes needs to clear (unmask) D-flag -ONLY- in case of recursive > + * probe i.e. when probe hit from kprobe handler context upon > + * executing the pre/post handlers. In this case we return with > + * D-flag clear so that single-stepping can be carried-out. > + * > + * Leave D-flag set in all other cases. > + */ > +static void __kprobes > +spsr_set_debug_flag(struct pt_regs *regs, int mask) > +{ > + unsigned long spsr = regs->pstate; > + > + if (mask) > + spsr |= PSR_D_BIT; > + else > + spsr &= ~PSR_D_BIT; > + > + regs->pstate = spsr; > +} > + [..] > + > +int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) > +{ > + struct kprobe *cur = kprobe_running(); > + struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); > + > + switch (kcb->kprobe_status) { > + case KPROBE_HIT_SS: > + case KPROBE_REENTER: > + /* > + * We are here because the instruction being single > + * stepped caused a page fault. We reset the current > + * kprobe and the ip points back to the probe address > + * and allow the page fault handler to continue as a > + * normal page fault. > + */ > + instruction_pointer(regs) = (unsigned long)cur->addr; > + if (!instruction_pointer(regs)) > + BUG(); As according to the recent x86 kprobe bug on fault handler discussion, here this also need kernel_disable_single_stap() and spsr_set_debug_flag() in case of KPROBE_REENTER as you did in kprobe_single_step_handler(). (Also, those code should be a function for reuse) > + if (kcb->kprobe_status == KPROBE_REENTER) > + restore_previous_kprobe(kcb); > + else > + reset_current_kprobe(); Thanks! -- Masami Hiramatsu