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=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 ABACBC433B4 for ; Mon, 12 Apr 2021 13:13:46 +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 3D44E61288 for ; Mon, 12 Apr 2021 13:13:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D44E61288 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=YSPtXq1K0MBaU+14TtrJT3pnUeOPlw21Yt2u21qn7Qk=; b=ddH8IIQVjr9n0KBYCU5iHgRpX /40r22EzSQau1wM3AJ0ALPFEuL0lzFyC8qJdF4J2DRWTcocxAGPjuCP3Ekvqufy2IcxpIrHJFzWwU 4dCDPuZ5iKO4GPuGC2b+XETFfFAu0MbkiGiFfXV0e7CEkU4wRFT27DYSFT3k9BnK3d4P36r3zcmtN H/rx7L1L8xJOG36U4FesDMxwZEwrJCXdPEsSRlEPvTYTVS8XuhHCDhsxKAI12b5Edvs6E34bCxCvU 4Lyokf81AA9RQsv7GdHs7CO/1sUSat6IkosbqSiIZR/nWPtYd+7JZ4f0sBfktmH3tDVs68ZEMCM/Q kXoOhVxLw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lVwMC-006n53-4h; Mon, 12 Apr 2021 13:12:00 +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 1lVwM7-006n4T-9O for linux-arm-kernel@desiato.infradead.org; Mon, 12 Apr 2021 13:11:56 +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=KTbMz0r6TQ9+wAk6srElZveVoBR/zfo5InbIEoKoX/w=; b=sLWk7GW0mtc/VWQjAeYO++Tz0e hpSchcTkbo8DRhf9KxfNsQLrGaL9bpi8rOdJIJZfGCFoqP9qKO69T6752mxkhWjNH1ILq8vFPnPrT hEn3MLL5QD6jazqBTpQTfAJDh5qY4DK8ISacTzl888Wc50XSPcPzL1neIQI0I6F1xsSiF9EDBk+Xy O4CdX+zZDVbvAVz35zZeJ49rN300kSGf4fqcfqQuLcYzSsx+Ckwrz3zCXLwtOnd8Y+ysj6WqxH9wR zxtdzD9ncy/tMaqO/xTvfR7D8p0Fu/+qOYaTidNiz8MJE+71SleMngWc5uCzN8atDtLscZLcJ+fXm pHliNESA==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lVwM1-006Fm2-FT for linux-arm-kernel@lists.infradead.org; Mon, 12 Apr 2021 13:11:54 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 08BDE610CA; Mon, 12 Apr 2021 13:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618233108; bh=Zanz5qvZw0cWJyNWZgIdn36zowK6B/3y64wJX8xDVA0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TGIPsFVMVdByjHtg3ZVGZQe83imde/ahXjWUUC0f52OPHnHSZdmq2u+i8uodJHcSN WyCoJPZNRpVnItYzdn59iJesvqXUci73lG3JI+y6ZQ5NlYzxZCTDFrhfenfdhZW98v 6R3nbLNVw2sF29Gs/Ul5MCXioUPK3m3V4UwJptkWwuSjaL3YrXIbhmEN9zZ4hUF6fT scp3MBlonnl38LasRQvpC+lwV+cmeIhsMNb8L5z0S0NLF2oBtygExcVYFneXtBhuIY yMUHAr4Cwi3cIkHvy6lCQq4Jiq+bZYGb+d9T+lAVcZcnc0XEjrQzw/kIo/piJY8RUq IOyKsRf3pJhlA== Date: Mon, 12 Apr 2021 22:11:44 +0900 From: Masami Hiramatsu To: Jisheng Zhang Cc: 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: <20210412221144.2da50e902df14cda0d86eeaa@kernel.org> In-Reply-To: <20210412174101.6bfb0594@xhacker.debian> References: <20210412174101.6bfb0594@xhacker.debian> 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_061149_598788_CA4C07FA X-CRM114-Status: GOOD ( 21.54 ) 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 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. 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel