From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BC2BC433E0 for ; Mon, 18 May 2020 15:14:54 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27DBD20756 for ; Mon, 18 May 2020 15:14:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A1RvyEMH"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="lb9iaIhk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27DBD20756 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To: Message-Id:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M+rEnDxrK4ZzGfyAghV2ar0Xq1q0P+M/pYF72Kvbzuc=; b=A1RvyEMHwf0PzU VDi7OzqTSDV2T3sGjsbh8qauQaoUtg2pjhC2/T21fvirVYmvEMo4gpQAqOkSG4hfhYRncL0t+IChD XqWwIepBBM37eVTmxX9Rlh7oJmPwTEheGHv5ZZBoQcPImTZqTti553UAGcA2/zbPKZnPFkFtx97lz YNOWKI0LBMh0aYKn05M3KqO8Szi/eyC3wr32SBICBNdkFA2BldAxg0iG34iVnIm/1GEO5b9lufkbT vPtuAm4Cyp2arWVi0mF3OtALlLTxcKMnm5/PhhftbC3nzo7fKMGQbh4FTiq4oDc+ehjVMUpUmFfp4 rN0f1ihjEi2ZcS8dHzpQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jahTg-0004VP-BO; Mon, 18 May 2020 15:14:52 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jahTd-0004UX-FD for linux-arm-kernel@lists.infradead.org; Mon, 18 May 2020 15:14:50 +0000 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0EA1F20671; Mon, 18 May 2020 15:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589814889; bh=JoM91Et6EiXBZzmbk7OOu4mjYY2QCV5w5R56UhHxUw0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lb9iaIhklsRErpaFfMUhPUpl08X8tH3mCEAf1CEh1g5KABUupNGHfRDvfb7xkhVLC +E9vSBCeQSXDozQBF61RNVDFrR6WlJr+vgZfvONf4nDI24lpboyGpCrLfnP8EnKLMF og2/RXV5tgRWr2Q8ipRcW2O/BIVBDvxj4NqxSFnE= Date: Tue, 19 May 2020 00:14:43 +0900 From: Masami Hiramatsu To: Doug Anderson Subject: Re: [PATCH 2/4] arm64: Extract kprobes_save_local_irqflag() and kprobes_restore_local_irqflag() Message-Id: <20200519001443.a1d1843e7809a7a68530fda5@kernel.org> In-Reply-To: References: <20200509214159.19680-1-liwei391@huawei.com> <20200509214159.19680-3-liwei391@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_081449_541058_E42FE7D6 X-CRM114-Status: GOOD ( 26.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Daniel Thompson , Catalin Marinas , Will Deacon , Marc Zyngier , LKML , liwei1412@163.com, Masami Hiramatsu , Jason Wessel , "liwei \(GF\)" , David Miller , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, 16 May 2020 09:17:21 -0700 Doug Anderson wrote: > Hi, > > On Sat, May 16, 2020 at 1:47 AM liwei (GF) wrote: > > > > >> - kprobes_save_local_irqflag(kcb, regs); > > >> + kernel_prepare_single_step(&kcb->saved_irqflag, regs); > > > > > > Is there some reason to have two functions? It seems like every time > > > you call kernel_enable_single_step() you'd want to call > > > kernel_prepare_single_step(). ...and every time you call > > > kernel_disable_single_step() you'd want to call > > > kernel_cleanup_single_step(). > > > > > > Maybe you can just add the flags parameter to > > > kernel_enable_single_step() / kernel_disable_single_step() and put the > > > code in there? > > > > > > > As kernel_enable_single_step() / kernel_disable_single_step() are also called in > > breakpoint_handler() and watchpoint_handler(), i am not sure it's a right thing > > to put the daif flag prepare/cleanup into them, especially we don't have a context > > to save the flags. > > I think you misunderstood what I was suggesting. Maybe better with > examples? I was suggesting doing this: > > kcb->saved_irqflag = kernel_enable_single_step(regs); > ... > kernel_disable_single_step(kcb->saved_irqflag, regs); > > To me that seems better than what you have now: > > kcb->saved_irqflag = kernel_prepare_single_step(regs); > kernel_enable_single_step(regs); > ... > kernel_cleanup_single_step(kcb->saved_irqflag, regs); > kernel_disable_single_step(); > > ...or am I confused? +1, this sounds good to me. Currently arch/arm64/kernel/probes/kprobes.c has a code which sololy use kernel_disable_single_step() without regs restoring, but it looks like a bug there. So maybe you need following patch. Thank you, ----- From: Masami Hiramatsu Date: Mon, 18 May 2020 23:08:28 +0900 Subject: [PATCH] arm64: kprobes: Restore saved interrupt flag before disabling single step Restore the saved interrupt flag in kprobe_ctlblk to regs->pstate when a page fault happens on single-stepping instruction. Without this fix, we will lose the flag if it happens because kcb->saved_irqflag only knows the previous flag. Fixes: 2dd0e8d2d2a1 ("arm64: Kprobes with single stepping support") Signed-off-by: Masami Hiramatsu Cc: stable@vger.kernel.org --- arch/arm64/kernel/probes/kprobes.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index d1c95dcf1d78..73fb99770f69 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -308,6 +308,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) if (!instruction_pointer(regs)) BUG(); + kprobes_restore_local_irqflag(kcb, regs); kernel_disable_single_step(); if (kcb->kprobe_status == KPROBE_REENTER) -- 2.25.1 -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel