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=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 A1141C433ED for ; Mon, 12 Apr 2021 14:46:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D61B61355 for ; Mon, 12 Apr 2021 14:46:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242429AbhDLOrG (ORCPT ); Mon, 12 Apr 2021 10:47:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237806AbhDLOrF (ORCPT ); Mon, 12 Apr 2021 10:47:05 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D2DE61352; Mon, 12 Apr 2021 14:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618238807; bh=3gfDcxeacAXXyz6lAWhNAkYUSGR6A53k3reCsT6Fy2A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ToYYimUBhVqYQOoLpK5Zx8bV45GJSLDZHHo8sYw9hJ1rWlfHGxJiXV2QV5UgAwdUP FsI6OlfR4vPcRz/cDmwWdqn5e+nAzBw60afxfXLiTyM1AiHKWzrsS4QbQIuQcxE42/ o15ZQ6rbBOry6hQqgCzbwhWubGSomNJVVAeZ6k21pYJui1jDzEZeYvaEDkKZD04DZt 6nsTDs4nx9KJWSS0dRDmqQh3P0Kv+i7DJa0drtJjNZWEoNgh1+NEeMrTOSxNllt2YR W62cTWKHCq+alSgWsSZ3hliKm7ufCElo+5+loC5uBpPgEuJKAt/kgoOZquerr+ttQl VmGXE91ySJP3Q== Date: Mon, 12 Apr 2021 23:46:43 +0900 From: Masami Hiramatsu To: Masami Hiramatsu Cc: Jisheng Zhang , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liao Chang Subject: Re: [PATCH] arm64: kprobes: Restore local irqflag if kprobes is cancelled Message-Id: <20210412234643.08a0a8578fb456190c50bc70@kernel.org> In-Reply-To: <20210412221144.2da50e902df14cda0d86eeaa@kernel.org> References: <20210412174101.6bfb0594@xhacker.debian> <20210412221144.2da50e902df14cda0d86eeaa@kernel.org> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 12 Apr 2021 22:11:44 +0900 Masami Hiramatsu wrote: > Hi Jisheng, > > On Mon, 12 Apr 2021 17:41:01 +0800 > Jisheng Zhang wrote: > > > If instruction being single stepped caused a page fault, the kprobes > > is cancelled to let the page fault handler continue as a normal page > > fault. But the local irqflags are disabled so cpu will restore pstate > > with DAIF masked. After pagefault is serviced, the kprobes is > > triggerred again, we overwrite the saved_irqflag by calling > > kprobes_save_local_irqflag(). NOTE, DAIF is masked in this new saved > > irqflag. After kprobes is serviced, the cpu pstate is retored with > > DAIF masked. > > > > This patch is inspired by one patch for riscv from Liao Chang. > > Thanks for pointing it out. But I think kprobes_restore_local_irqflag() > is also needed for kcb->kprobe_status == KPROBE_REENTER case...no. > This is more complicated. In the reenter case, I think we have to retry > the kpreprobe_fault_handler() with recovered previous kprobes so that > it can handle page fault in its handler. Ah, this is another issue, and needs another fix. So this patch itself is good to me. Acked-by: Masami Hiramatsu Thanks! > > Hmm, RISC-V and other code also needs same fix. > > Thank you, > > > > > Signed-off-by: Jisheng Zhang > > --- > > arch/arm64/kernel/probes/kprobes.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c > > index 66aac2881ba8..85645b2b0c7a 100644 > > --- a/arch/arm64/kernel/probes/kprobes.c > > +++ b/arch/arm64/kernel/probes/kprobes.c > > @@ -267,10 +267,12 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) > > if (!instruction_pointer(regs)) > > BUG(); > > > > - if (kcb->kprobe_status == KPROBE_REENTER) > > + if (kcb->kprobe_status == KPROBE_REENTER) { > > restore_previous_kprobe(kcb); > > - else > > + } else { > > + kprobes_restore_local_irqflag(kcb, regs); > > reset_current_kprobe(); > > + } > > > > break; > > case KPROBE_HIT_ACTIVE: > > -- > > 2.31.0 > > > > > -- > Masami Hiramatsu -- Masami Hiramatsu 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=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,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 42D5AC433B4 for ; Mon, 12 Apr 2021 14:48:22 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B2FE061289 for ; Mon, 12 Apr 2021 14:48:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2FE061289 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+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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Mime-Version:References:In-Reply-To:Message-Id: Subject:Cc: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=Ibck2jAgIF45G6rERqDMjTF0Bil5UZ6+sqByhQcTD44=; b=RAuRnJQBKMBcO8VEISrddjXZP lytWmpI/17nemf+4adY4FZyN0DfRlcFlmTmZ5duhwfvAuUejn+zujdRDKmRO9MyLJyIjQGO5GbTw3 mRSgD0AhvRsk81z/L6W7ztFVGsWsrHeYxWplw1R74CLto/DV0DVL4DCdOUJFONk8rv/rgroYgrMYb Nn1bqFqquef2q/JHWM9+ztqS4rY6VN2CKL14WbkEEHIc1yry1t1ut1oPI/hWRWr3ceBJhucFTVDHT MkVEccXOPqdINPcGcNrBa3d6RkVLhJx1UOjJuRl52eUBy4dIJxjD3fxfXE04F2xjx768qOuWGJgup IfN86CQSw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lVxq1-006zxW-LG; Mon, 12 Apr 2021 14:46:53 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVxpy-006zxC-Fm for linux-arm-kernel@desiato.infradead.org; Mon, 12 Apr 2021 14:46:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:Mime-Version:References:In-Reply-To:Message-Id:Subject:Cc:To: From:Date:Sender:Reply-To:Content-ID:Content-Description; bh=GeNRNc4ZmAEDUPtdCjkWjj3WPRB1AaCUQP/xKVba4ec=; b=Hu3+QfTqSRzshr6W+S51r/rcF1 AmvlVCyRgJFhlRXLmSKg5j7n2OG5Qu087fN4zN7gJAgnh1SD+Xw6jjbFRoXpv3rHZkeNJA/ya8yxc Jv5DhoTzFg4I47fGFIZaL3uLiRSZGDvrqADy2QtahyPliOpVa8vUf7mhaacY4EQBYscRDBcf/vbcM 6Ebj9H2nHaNGpbWxzxflrxXVXiMbYb4+W5emshQJsQyLkHp8DTsPA/EM2yYn6Xs7F4vMHzBuCJBcR hoaC05cYkckTytU5tz/ekcM2gtYTsG9hyZPH6mV3NPqZK+rGLvvz3Cq6XCD3VGS7Ui/DrpGzZ97OD SXWMU5xg==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVxpv-006Jyi-Pr for linux-arm-kernel@lists.infradead.org; Mon, 12 Apr 2021 14:46:49 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3D2DE61352; Mon, 12 Apr 2021 14:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618238807; bh=3gfDcxeacAXXyz6lAWhNAkYUSGR6A53k3reCsT6Fy2A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ToYYimUBhVqYQOoLpK5Zx8bV45GJSLDZHHo8sYw9hJ1rWlfHGxJiXV2QV5UgAwdUP FsI6OlfR4vPcRz/cDmwWdqn5e+nAzBw60afxfXLiTyM1AiHKWzrsS4QbQIuQcxE42/ o15ZQ6rbBOry6hQqgCzbwhWubGSomNJVVAeZ6k21pYJui1jDzEZeYvaEDkKZD04DZt 6nsTDs4nx9KJWSS0dRDmqQh3P0Kv+i7DJa0drtJjNZWEoNgh1+NEeMrTOSxNllt2YR W62cTWKHCq+alSgWsSZ3hliKm7ufCElo+5+loC5uBpPgEuJKAt/kgoOZquerr+ttQl VmGXE91ySJP3Q== Date: Mon, 12 Apr 2021 23:46:43 +0900 From: Masami Hiramatsu To: Masami Hiramatsu Cc: Jisheng Zhang , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Liao Chang Subject: Re: [PATCH] arm64: kprobes: Restore local irqflag if kprobes is cancelled Message-Id: <20210412234643.08a0a8578fb456190c50bc70@kernel.org> In-Reply-To: <20210412221144.2da50e902df14cda0d86eeaa@kernel.org> References: <20210412174101.6bfb0594@xhacker.debian> <20210412221144.2da50e902df14cda0d86eeaa@kernel.org> 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-20210412_074647_891697_FA796F1E X-CRM114-Status: GOOD ( 27.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 12 Apr 2021 22:11:44 +0900 Masami Hiramatsu wrote: > Hi Jisheng, > > On Mon, 12 Apr 2021 17:41:01 +0800 > Jisheng Zhang wrote: > > > If instruction being single stepped caused a page fault, the kprobes > > is cancelled to let the page fault handler continue as a normal page > > fault. But the local irqflags are disabled so cpu will restore pstate > > with DAIF masked. After pagefault is serviced, the kprobes is > > triggerred again, we overwrite the saved_irqflag by calling > > kprobes_save_local_irqflag(). NOTE, DAIF is masked in this new saved > > irqflag. After kprobes is serviced, the cpu pstate is retored with > > DAIF masked. > > > > This patch is inspired by one patch for riscv from Liao Chang. > > Thanks for pointing it out. But I think kprobes_restore_local_irqflag() > is also needed for kcb->kprobe_status == KPROBE_REENTER case...no. > This is more complicated. In the reenter case, I think we have to retry > the kpreprobe_fault_handler() with recovered previous kprobes so that > it can handle page fault in its handler. Ah, this is another issue, and needs another fix. So this patch itself is good to me. Acked-by: Masami Hiramatsu Thanks! > > Hmm, RISC-V and other code also needs same fix. > > Thank you, > > > > > Signed-off-by: Jisheng Zhang > > --- > > arch/arm64/kernel/probes/kprobes.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c > > index 66aac2881ba8..85645b2b0c7a 100644 > > --- a/arch/arm64/kernel/probes/kprobes.c > > +++ b/arch/arm64/kernel/probes/kprobes.c > > @@ -267,10 +267,12 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr) > > if (!instruction_pointer(regs)) > > BUG(); > > > > - if (kcb->kprobe_status == KPROBE_REENTER) > > + if (kcb->kprobe_status == KPROBE_REENTER) { > > restore_previous_kprobe(kcb); > > - else > > + } else { > > + kprobes_restore_local_irqflag(kcb, regs); > > reset_current_kprobe(); > > + } > > > > break; > > case KPROBE_HIT_ACTIVE: > > -- > > 2.31.0 > > > > > -- > Masami Hiramatsu -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel