Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1759708pxb; Mon, 12 Apr 2021 06:12:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysaIATWwTMdVGUu53hSXW6Nett2U6GQH/zlfQKLVZsLw3l4CWhCHwMYl/EvQoDCKLKkpB7 X-Received: by 2002:aa7:9299:0:b029:21d:7ad1:2320 with SMTP id j25-20020aa792990000b029021d7ad12320mr24954109pfa.22.1618233172406; Mon, 12 Apr 2021 06:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618233172; cv=none; d=google.com; s=arc-20160816; b=jgXUekMYLbHh/jyKwichNbbyY6C/VkR5kWgNF8gz4fDSaSImTjGXUwF7U9jxJOyeid rTYkQlLejSmrpLkALzvMkDqo6s/oZdhWnFbpnEu+XQOqKjZfdMnSr40nVOSEEnOj9Mp8 BhBjYlGvn43Ab3k8kU7PC7EEjIcSR8qbEsTLVTdaacxraBfwRtt1L7/YrnKPFHg7ugCz bNWnEJ8hWPdMJhIxuoPEcCifFZTV84AqV7lV/SnSMAyfBGdCL556ZSlOSf8KD/oVI97W TJxLvQ8PK5wdR7PshDrHu87ePbx7Cgup9DRBYovn1MEkrS9j5dyYcEneMNAA6VMEhdYa pL0w== 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=KTbMz0r6TQ9+wAk6srElZveVoBR/zfo5InbIEoKoX/w=; b=aEZXhsnJZ3//kRzgNmBcJXFehTWKAIt9VWTtRCkvF7b/U2KZsbFgdfh+fJAtmdqLbK uqQOgNCop3BGdqFSSyw9dluTb7l+BpCtSjjQV9PCxz9/UJbPZHV7YrCIl6k+SR88uw1D PioNNpC/vs20z8xr0xavNUKgdqeij05jAPQn6LHveuoAIBpTlszWCbmrPMAKnmkOyaVP wSE/jrGUe3Wb++tcvTlGkTYUMn9EfXp65Gzr+8oI3i7IEEQ8D45F0PZXsFcJvSMcyxmX W/6bhRQljpKgASj4E4lm99O2jIPIhzj3nLYG2QSGZy89CAcXLdD9eVoKjS1+2I7uyObV Demw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TGIPsFVM; 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 j19si13677560pll.225.2021.04.12.06.12.39; Mon, 12 Apr 2021 06:12:52 -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=TGIPsFVM; 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 S241799AbhDLNMH (ORCPT + 99 others); Mon, 12 Apr 2021 09:12:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:36700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238974AbhDLNMG (ORCPT ); Mon, 12 Apr 2021 09:12:06 -0400 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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