Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1836740pxb; Mon, 12 Apr 2021 07:50:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrW15yAFR4ruTWD4Rj61uZnS/i8up4J9Tt+Zp4xZwrd058SBswh8WCD5s6o3ZFyUKi5zsb X-Received: by 2002:a05:6402:4405:: with SMTP id y5mr30340310eda.32.1618239030841; Mon, 12 Apr 2021 07:50:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618239030; cv=none; d=google.com; s=arc-20160816; b=eFH/cAn80oX0dMLB5d6JtdzjmaIsGFE7ggrc87FOVjjhP9S2XmjZeKFUWhXO5vvXZb kERen76vFxYa0gykH8JAjAoRpZFUXoAk641Om9MMwC29aKzB2tEqhXa/Y4T96QFG0MUn 5rUHycDxbtcdT4u2j4MCuzAa9r9OCLf35gPhmFm+JpsHxlxKVrIsraJ6Cj+F9hvD832p gdDRSXK7LYwbvKVD5WokbvO8uby+2TgKFl+o4gywZ5BfZnoQ2VzGWmoEmtJDxQo3kRU/ 6TNEowPZEmqcP1S3kcI6SyJrCFdzc1+NdZDUSgLov4XRum6maBY09/PdHZJ1KcmGXRWV tgsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=GeNRNc4ZmAEDUPtdCjkWjj3WPRB1AaCUQP/xKVba4ec=; b=bcAAUXjeqiWKCJBvGS1Bn780RG9uHrb07ZAlBHuJWqe6vkqahUGk/sGUHG3RBvM9p8 YXqlGW57pHL9Dy9OuZIewOWKt+l5+ELT7FpbD8MrCWlHUkJZ+AtYwd3Fhe0Y68wQcCYR 44QQA7mnVzXPgHFpUZVWbHkHIFuv7d1QOzPx7nqLQHhGQC/9m67Gevq6YLUfncvQuJcQ MUxughenyreCqDXUJP+IwHBliJXJOuC9B3HvSK1eD8KD/EDS/UwxL10aVnPYsG/M0gE6 hBvh1RP7K3exzCwgCEPEEGc468vb1ShEqFrGFp3guzUROWmcOBYUc1BfBiwc/Y38i47t sMcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ToYYimUB; 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 4si8588806edc.257.2021.04.12.07.50.07; Mon, 12 Apr 2021 07:50:30 -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=k20201202 header.b=ToYYimUB; 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 S242394AbhDLOrG (ORCPT + 99 others); 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