Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2803264ybk; Mon, 18 May 2020 08:17:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpR0xyzkZltmxKVsyJieNEWJEga+1xqcZzDyS3QRIFKSntQ+d3mUfSLaj4Uti4iuRnLxba X-Received: by 2002:a17:906:aeca:: with SMTP id me10mr8716028ejb.367.1589815024074; Mon, 18 May 2020 08:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589815024; cv=none; d=google.com; s=arc-20160816; b=Jl11oSjMI3+vCCKPk3uuQdZK7sWJAr1gEowCn7PmLOuO3IV8dK+d0DNOLsOeH6zCNf hYFsRdpl//T5APTThIDMb4rCowgcgNqF4gKIztUxjlOlBI16pSDxdyn3q368NVH8WBGg 9zjubkISIuO9e1lkXH/0G8D6EiTLybezkmhqA0hCcyVDoHsSqZg+B5/WVyVh63Qn241P FCfVccK0aMG39u9B9A/uDAXRwk35wX4fHROTo8i6l5hqsNfEKPfXFR9r4KPGc/x9co4R 9iOCQ+qzp76Nnm2EJDnv2WAd1ve+3Gfj4YfcI7KlYORu7tgVfFCYxNOt7cZ73tEGbEPr 8Vkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=b+K64xhKVZch9Q223VN5j4T4SJzj71Ewc1EzXGAOgxA=; b=k0N+ztdpETAz589sR/LFAKURm2UT5i83wIabwvtIkPz3r1eWj3GlcK1+fqaSLYHf5V tVOinOM+pxyBbUlPRkTB8r/Qt7RlG66CQeOBfLleUO3qc0lXAjk8hXn8tLN5tHuzUZlk TplGJX5E/b1hmRK/w1V6idOtDWShRRwL///6+viq7hsSeBBT+VB9/0w6dp0jR7xo8p3P vQTeq+mIJRpdefpaP/R6CAeAnLrpRqaPLAJYcFXe0zwTk9qr1l3++YGtFZ5TJ3lNl3HG C9u7yCESn/Bz2NfjzJkCM/+BLf0DUR2iXXqigdVID2V7ZxtmQTJy79pYf5G90QpEcX/S VbQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lb9iaIhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs20si7264629ejb.76.2020.05.18.08.16.32; Mon, 18 May 2020 08:17:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lb9iaIhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728079AbgERPOu (ORCPT + 99 others); Mon, 18 May 2020 11:14:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:55808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727006AbgERPOt (ORCPT ); Mon, 18 May 2020 11:14:49 -0400 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 Cc: "liwei (GF)" , Daniel Thompson , Jason Wessel , Marc Zyngier , Mark Rutland , Masami Hiramatsu , David Miller , Will Deacon , Catalin Marinas , Linux ARM , LKML , liwei1412@163.com 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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