From: Liao Chang <liaochang1@huawei.com>
To: <catalin.marinas@arm.com>, <will@kernel.org>, <maz@kernel.org>,
<oliver.upton@linux.dev>, <james.morse@arm.com>,
<suzuki.poulose@arm.com>, <yuzenghui@huawei.com>,
<tglx@linutronix.de>, <mark.rutland@arm.com>, <ardb@kernel.org>,
<broonie@kernel.org>, <liaochang1@huawei.com>,
<anshuman.khandual@arm.com>, <miguel.luis@oracle.com>,
<joey.gouly@arm.com>, <ryan.roberts@arm.com>,
<jeremy.linton@arm.com>, <ericchancf@google.com>,
<kristina.martsenko@arm.com>, <robh@kernel.org>,
<scott@os.amperecomputing.com>, <songshuaishuai@tinylab.org>,
<shijie@os.amperecomputing.com>, <akpm@linux-foundation.org>,
<bhe@redhat.com>, <horms@kernel.org>, <mhiramat@kernel.org>,
<rmk+kernel@armlinux.org.uk>, <shahuang@redhat.com>,
<takakura@valinux.co.jp>, <dianders@chromium.org>,
<swboyd@chromium.org>, <sumit.garg@linaro.org>,
<frederic@kernel.org>, <reijiw@google.com>,
<akihiko.odaki@daynix.com>, <ruanjinjie@huawei.com>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <kvmarm@lists.linux.dev>
Subject: [PATCH v3 8/8] arm64: kprobe: Keep NMI maskabled while kprobe is stepping xol
Date: Mon, 15 Apr 2024 06:47:58 +0000 [thread overview]
Message-ID: <20240415064758.3250209-9-liaochang1@huawei.com> (raw)
In-Reply-To: <20240415064758.3250209-1-liaochang1@huawei.com>
Keeping NMI maskable while executing instruction out of line, otherwise,
add kprobe on the functions invoken while handling NMI will cause kprobe
reenter bug and kernel panic.
Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
arch/arm64/include/asm/daifflags.h | 2 ++
arch/arm64/kernel/probes/kprobes.c | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h
index 1196eb85aa8d..60fd3b25fd73 100644
--- a/arch/arm64/include/asm/daifflags.h
+++ b/arch/arm64/include/asm/daifflags.h
@@ -17,6 +17,8 @@
#define DAIF_PROCCTX_NOIRQ (PSR_I_BIT | PSR_F_BIT)
#define DAIF_ERRCTX (PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
#define DAIF_MASK (PSR_D_BIT | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT)
+#define DAIF_ALLINT_MASK \
+ (system_uses_nmi() ? (ALLINT_ALLINT | DAIF_MASK) : (DAIF_MASK))
/*
* For Arm64 processor support Armv8.8 or later, kernel supports three types
diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 327855a11df2..e8c2b993bbb8 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -187,13 +187,13 @@ static void __kprobes kprobes_save_local_irqflag(struct kprobe_ctlblk *kcb,
struct pt_regs *regs)
{
kcb->saved_irqflag = regs->pstate & DAIF_MASK;
- regs->pstate |= DAIF_MASK;
+ regs->pstate |= DAIF_ALLINT_MASK;
}
static void __kprobes kprobes_restore_local_irqflag(struct kprobe_ctlblk *kcb,
struct pt_regs *regs)
{
- regs->pstate &= ~DAIF_MASK;
+ regs->pstate &= ~DAIF_ALLINT_MASK;
regs->pstate |= kcb->saved_irqflag;
}
--
2.34.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-15 6:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 6:47 [PATCH v3 0/8] Rework the DAIF mask, unmask and track API Liao Chang
2024-04-15 6:47 ` [PATCH v3 1/8] arm64/sysreg: Add definitions for immediate versions of MSR ALLINT Liao Chang
2024-05-03 16:00 ` Mark Rutland
2024-05-06 12:12 ` Liao, Chang
2024-05-06 15:15 ` Mark Brown
2024-05-07 7:41 ` Liao, Chang
2024-05-07 14:52 ` Mark Brown
2024-06-03 3:26 ` Liao, Chang
2024-06-04 13:29 ` Mark Brown
2024-06-05 9:52 ` Liao, Chang
2024-06-14 4:00 ` Liao, Chang
2024-04-15 6:47 ` [PATCH v3 2/8] arm64/cpufeature: Detect PE support for FEAT_NMI Liao Chang
2024-04-15 6:47 ` [PATCH v3 3/8] arm64/nmi: Add Kconfig for NMI Liao Chang
2024-04-15 6:47 ` [PATCH v3 4/8] arm64: daifflags: Add logical exception masks covering DAIF + PMR + ALLINT Liao Chang
2024-04-15 6:47 ` [PATCH v3 5/8] arm64: Unify exception masking at entry and exit of exception Liao Chang
2024-04-15 6:47 ` [PATCH v3 6/8] arm64: Deprecate old local_daif_{mask,save,restore} Liao Chang
2024-04-15 6:47 ` [PATCH v3 7/8] irqchip/gic-v3: Improve the maintainability of NMI masking in GIC driver Liao Chang
2024-04-15 6:47 ` Liao Chang [this message]
2024-05-03 17:10 ` [PATCH v3 0/8] Rework the DAIF mask, unmask and track API Mark Rutland
2024-05-06 12:12 ` Liao, Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240415064758.3250209-9-liaochang1@huawei.com \
--to=liaochang1@huawei.com \
--cc=akihiko.odaki@daynix.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=bhe@redhat.com \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=dianders@chromium.org \
--cc=ericchancf@google.com \
--cc=frederic@kernel.org \
--cc=horms@kernel.org \
--cc=james.morse@arm.com \
--cc=jeremy.linton@arm.com \
--cc=joey.gouly@arm.com \
--cc=kristina.martsenko@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=miguel.luis@oracle.com \
--cc=oliver.upton@linux.dev \
--cc=reijiw@google.com \
--cc=rmk+kernel@armlinux.org.uk \
--cc=robh@kernel.org \
--cc=ruanjinjie@huawei.com \
--cc=ryan.roberts@arm.com \
--cc=scott@os.amperecomputing.com \
--cc=shahuang@redhat.com \
--cc=shijie@os.amperecomputing.com \
--cc=songshuaishuai@tinylab.org \
--cc=sumit.garg@linaro.org \
--cc=suzuki.poulose@arm.com \
--cc=swboyd@chromium.org \
--cc=takakura@valinux.co.jp \
--cc=tglx@linutronix.de \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox