[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250522105658.1338331-1-liaochang1@huawei.com>
Date: Thu, 22 May 2025 10:56:56 +0000
From: Liao Chang <liaochang1@...wei.com>
To: <catalin.marinas@....com>, <will@...nel.org>, <maz@...nel.org>,
<oliver.upton@...ux.dev>, <joey.gouly@....com>, <suzuki.poulose@....com>,
<yuzenghui@...wei.com>, <mark.rutland@....com>, <broonie@...nel.org>,
<liaochang1@...wei.com>, <puranjay@...nel.org>, <sgsu.park@...sung.com>,
<frederic@...nel.org>, <gshan@...hat.com>, <sudeep.holla@....com>,
<guohanjun@...wei.com>, <ryan.roberts@....com>,
<Jonathan.Cameron@...wei.com>, <liuwei09@...tc.cn>,
<shameerali.kolothum.thodi@...wei.com>, <james.morse@....com>,
<hardevsinh.palaniya@...iconsignals.io>, <ptosi@...gle.com>,
<kristina.martsenko@....com>, <vschneid@...hat.com>,
<thiago.bauermann@...aro.org>, <yang@...amperecomputing.com>,
<david@...hat.com>, <minhuadotchen@...il.com>, <tglx@...utronix.de>,
<farbere@...zon.com>, <arnd@...db.de>, <rppt@...nel.org>,
<mcgrof@...nel.org>, <guoweikang.kernel@...il.com>, <robh@...nel.org>,
<andreyknvl@...il.com>, <usamaarif642@...il.com>,
<samuel.holland@...ive.com>, <kevin.brodsky@....com>, <Dave.Martin@....com>,
<rmk+kernel@...linux.org.uk>, <jean-philippe@...aro.org>,
<ruanjinjie@...wei.com>, <dianders@...omium.org>, <pcc@...gle.com>,
<bigeasy@...utronix.de>, <jintack@...columbia.edu>,
<christoffer.dall@....com>, <tabba@...gle.com>, <robin.murphy@....com>,
<ziy@...dia.com>, <wangkefeng.wang@...wei.com>, <quic_zhenhuah@...cinc.com>,
<anshuman.khandual@....com>, <yangyicong@...ilicon.com>
CC: <linux-arm-kernel@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
<kvmarm@...ts.linux.dev>
Subject: [PATCH v5 0/2] Rework Arm64 exception mask helpers
This patch series is a significant rework of the exception mask helpers,
building upon the discussions from a year ago [1]. The need for this
reworking has become increasingly apparent with the emerging platform
and virtualization support for FEAT_NMI [2], and Mark Brown's FEAT_NMI
patch series [3] really highlighted the existing "hacking style"
approach to DAIF management that needed addressing before NMI
functionality could be properly integrated.
Furthermore, with Jonathan has platform that now support FEAT_NMI,
there's a strong desire to see Mark Brown's FEAT_NMI patchset merged
soon. All of these factors emphasize the importance of a robust and
clean exception mask rework. Therefore, I'm pushing this patchset again
and would greatly appreciate your review.
This series broadly follows the suggestions made by Mark Rutland in
response [4] to Mark Brown's FEAT_NMI patchset. To summarize his
thoughts on DAIF + PMR + ALLINT management:
(a) Adding entry-specific helpers to manipulate abstract exception masks
covering DAIF + PMR + ALLINT. Those need unmask-at-entry and
mask-at-exit behaviour, and today only need to manage DAIF + PMR.
It should be possible to do this ahead of ALLINT / NMI support.
(b) Adding new "logical exception mask" helpers that treat DAIF + PMR +
ALLINT as separate elements.
While attempting to follow Mark Rutland's guidance, I may have initially
misunderstood some nuances, leading to a complete redesign and recoding
of this patchset. As a result, it looks rather different from the previous
revision.
In short summary, to reduce the complexity of a single, monolithic
function trying to handle every scenario, this patchset now introduces
two distinct series of logical exception mask helpers. Each series is
tailored for a specific kernel configuration and use case. I believe
this policy makes the behavior of each exception mask helper much more
explicit for any given situation, and simplifies the future integration
of FEAT_NMI support without introducing further complexity.
Thanks,
[1] https://lore.kernel.org/all/20240614034433.602622-1-liaochang1@huawei.com/
[2] https://lore.kernel.org/all/20240407081733.3231820-1-ruanjinjie@huawei.com/
[3] https://lore.kernel.org/linux-arm-kernel/20221112151708.175147-1-broonie@kernel.org/
[4] https://lore.kernel.org/linux-arm-kernel/Y5c9SLeJacLYHmP7@FVFF77S0Q05N/
v5->v4:
1. The rework has been fully redesigned, you'll find all the details in
the first patch.
2. The rework focus on replacing the helpers defined in daifflags.h, so
less patches in this series, it will be easier to review and discuss.
v4->v3:
General Enhancements
--------------------
Commit messages of [PATCH 04/05/06] have been enriched to outline the
implementation details, motivations and potential effects. This might
improve develper understanding and review efficiency.
Specific Changes
----------------
1. [PATCH 01] new utilize the existing helper maco in sysregs.h to
generate the "MSR ALLLINT, #Imm1" instruction. Additionally, helper
names have been renamed to start with msr_pstate_ for better
discoverability (as suggested by Mark Brown).
2. For [PATCH 04], due to the barrier side-effect of writing to PSTATE
fields, it is unnecessary to call pmr_sync() in
__pmr_local_allint_restore(). Add a table in comments to depict the
relationship between the type of interrupt masking and hardware
register configuration.
3. For [PATCH 05/06], function names have been revised to better reflect
their purpose:
local_errint_enable() -> local_irq_serror_enable()
local_errint_disable() -> local_nmi_serror_disable()
local_allint_mark_enabled() -> local_irq_mark_enabled()
local_allint_disable() -> local_nmi_disable()
local_errnmi_enable() -> local_nmi_serror_enable()
4. For [PATCH 07], A bug in local_nmi_enable() has been fixed. The v3
version is overly complex and included an unnecessary write operation
to PSTATE.DAIF.
5. [PATCH 09] introduce a slight optimization for NMI handling. Since
the intermediate step of marking IRQ TO-BE enabled is no longer
required, dropping PMR before acknowledge PSEUDO_NMI is also
unnecessary.
6. [PATCH 10] migrates CPU idle contex save/restore operation to the
newly introduced logical interrupt masking helper functions.
v3->v2:
1. Squash two commits that address two minor issues into Mark Brown's
origin patch for detecting FEAT_NMI.
2. Add one patch resolves the kprobe reenter panic while testing
FEAT_NMI on QEMU.
v2->v1:
Add SoB tags following the origin author's SoBs.
---
Liao Chang (2):
arm64: New exception mask helpers to manage DAIF, PMR and ALLINT
arm64: Deprecate the old daifflags helpers
arch/arm64/include/asm/daifflags.h | 144 -------------------
arch/arm64/include/asm/exception_mask.h | 137 ++++++++++++++++++
arch/arm64/include/asm/kvm_host.h | 2 +-
arch/arm64/include/asm/mmu_context.h | 2 +-
arch/arm64/kernel/Makefile | 2 +-
arch/arm64/kernel/acpi.c | 10 +-
arch/arm64/kernel/cpufeature.c | 3 +
arch/arm64/kernel/debug-monitors.c | 6 +-
arch/arm64/kernel/entry-common.c | 81 +++++------
arch/arm64/kernel/exception_mask.c | 177 ++++++++++++++++++++++++
arch/arm64/kernel/hibernate.c | 6 +-
arch/arm64/kernel/irq.c | 4 +-
arch/arm64/kernel/machine_kexec.c | 4 +-
arch/arm64/kernel/probes/kprobes.c | 2 +-
arch/arm64/kernel/setup.c | 4 +-
arch/arm64/kernel/signal.c | 2 +-
arch/arm64/kernel/smp.c | 10 +-
arch/arm64/kernel/suspend.c | 6 +-
arch/arm64/kernel/traps.c | 2 +-
arch/arm64/kvm/hyp/vgic-v3-sr.c | 4 +-
arch/arm64/kvm/hyp/vhe/switch.c | 4 +-
arch/arm64/mm/fault.c | 2 +-
arch/arm64/mm/mmu.c | 6 +-
23 files changed, 397 insertions(+), 223 deletions(-)
delete mode 100644 arch/arm64/include/asm/daifflags.h
create mode 100644 arch/arm64/include/asm/exception_mask.h
create mode 100644 arch/arm64/kernel/exception_mask.c
--
2.34.1
Powered by blists - more mailing lists