mbox series

[v3,0/8] Rework the DAIF mask, unmask and track API

Message ID 20240415064758.3250209-1-liaochang1@huawei.com (mailing list archive)
Headers show
Series Rework the DAIF mask, unmask and track API | expand

Message

Liao, Chang April 15, 2024, 6:47 a.m. UTC
This patch series reworks the DAIF mask, unmask, and track API for the
upcoming FEAT_NMI extension added in Armv8.8.

As platform and virtualization[1] supports for FEAT_NMI is emerging, and
Mark Brown's FEAT_NMI patch series[2] highlighted the need for clean up
the existing hacking style approach about DAIF management code before
adding NMI functionality, furthermore, we discover some subtle bugs
during 'perf' and 'ipi_backtrace' transition from PSEUDO_NMI to
FEAT_NMI, in summary, all of these emphasize the importance of rework.

This series of reworking patches follows the suggestion from Mark
Rutland mentioned in Mark Brown's patchset. In summary, he think the
better way for DAIF manangement look likes as following:

(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. 

This patches cherry-pick a part of Mark Brown' FEAT_NMI series, in order
to pass compilation and basic testing, includes perf and ipi_backtrace.

[1] https://lore.kernel.org/all/20240407081733.3231820-1-ruanjinjie@huawei.com/
[2] https://lore.kernel.org/linux-arm-kernel/Y4sH5qX5bK9xfEBp@lpieralisi/

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 (5):
  arm64: daifflags: Add logical exception masks covering DAIF + PMR +
    ALLINT
  arm64: Unify exception masking at entry and exit of exception
  arm64: Deprecate old local_daif_{mask,save,restore}
  irqchip/gic-v3: Improve the maintainability of NMI masking in GIC
    driver
  arm64: kprobe: Keep NMI maskabled while kprobe is stepping xol

Mark Brown (3):
  arm64/sysreg: Add definitions for immediate versions of MSR ALLINT
  arm64/cpufeature: Detect PE support for FEAT_NMI
  arm64/nmi: Add Kconfig for NMI

 arch/arm64/Kconfig                   |  17 ++
 arch/arm64/include/asm/cpufeature.h  |   6 +
 arch/arm64/include/asm/daifflags.h   | 298 ++++++++++++++++++++++-----
 arch/arm64/include/asm/nmi.h         |  27 +++
 arch/arm64/include/asm/sysreg.h      |   2 +
 arch/arm64/include/uapi/asm/ptrace.h |   1 +
 arch/arm64/kernel/acpi.c             |  10 +-
 arch/arm64/kernel/cpufeature.c       |  58 +++++-
 arch/arm64/kernel/debug-monitors.c   |   7 +-
 arch/arm64/kernel/entry-common.c     |  96 +++++----
 arch/arm64/kernel/entry.S            |   2 -
 arch/arm64/kernel/hibernate.c        |   6 +-
 arch/arm64/kernel/irq.c              |   2 +-
 arch/arm64/kernel/machine_kexec.c    |   2 +-
 arch/arm64/kernel/probes/kprobes.c   |   4 +-
 arch/arm64/kernel/setup.c            |   2 +-
 arch/arm64/kernel/smp.c              |   6 +-
 arch/arm64/kernel/suspend.c          |   6 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c      |   6 +-
 arch/arm64/kvm/hyp/vhe/switch.c      |   4 +-
 arch/arm64/mm/mmu.c                  |   6 +-
 arch/arm64/tools/cpucaps             |   2 +
 drivers/irqchip/irq-gic-v3.c         |   6 +-
 23 files changed, 442 insertions(+), 134 deletions(-)
 create mode 100644 arch/arm64/include/asm/nmi.h

Comments

Mark Rutland May 3, 2024, 5:10 p.m. UTC | #1
Hi,

On Mon, Apr 15, 2024 at 06:47:50AM +0000, Liao Chang wrote:
> This patch series reworks the DAIF mask, unmask, and track API for the
> upcoming FEAT_NMI extension added in Armv8.8.
> 
> As platform and virtualization[1] supports for FEAT_NMI is emerging, and
> Mark Brown's FEAT_NMI patch series[2] highlighted the need for clean up
> the existing hacking style approach about DAIF management code before
> adding NMI functionality, furthermore, we discover some subtle bugs
> during 'perf' and 'ipi_backtrace' transition from PSEUDO_NMI to
> FEAT_NMI, in summary, all of these emphasize the importance of rework.
> 
> This series of reworking patches follows the suggestion from Mark
> Rutland mentioned in Mark Brown's patchset. In summary, he think the
> better way for DAIF manangement look likes as following:
> 
> (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. 

I've started looking at this in the series. There are some subtleties here, and
I don't think the helpers in this series are quite right as-is. I will try to
get back to you next week with a description of those; it'll take a short while
to write that up correctly and clearly and I don't trust myself to rush that
last thing on a Friday.

Thanks,
Mark.

> 
> This patches cherry-pick a part of Mark Brown' FEAT_NMI series, in order
> to pass compilation and basic testing, includes perf and ipi_backtrace.
> 
> [1] https://lore.kernel.org/all/20240407081733.3231820-1-ruanjinjie@huawei.com/
> [2] https://lore.kernel.org/linux-arm-kernel/Y4sH5qX5bK9xfEBp@lpieralisi/
> 
> 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 (5):
>   arm64: daifflags: Add logical exception masks covering DAIF + PMR +
>     ALLINT
>   arm64: Unify exception masking at entry and exit of exception
>   arm64: Deprecate old local_daif_{mask,save,restore}
>   irqchip/gic-v3: Improve the maintainability of NMI masking in GIC
>     driver
>   arm64: kprobe: Keep NMI maskabled while kprobe is stepping xol
> 
> Mark Brown (3):
>   arm64/sysreg: Add definitions for immediate versions of MSR ALLINT
>   arm64/cpufeature: Detect PE support for FEAT_NMI
>   arm64/nmi: Add Kconfig for NMI
> 
>  arch/arm64/Kconfig                   |  17 ++
>  arch/arm64/include/asm/cpufeature.h  |   6 +
>  arch/arm64/include/asm/daifflags.h   | 298 ++++++++++++++++++++++-----
>  arch/arm64/include/asm/nmi.h         |  27 +++
>  arch/arm64/include/asm/sysreg.h      |   2 +
>  arch/arm64/include/uapi/asm/ptrace.h |   1 +
>  arch/arm64/kernel/acpi.c             |  10 +-
>  arch/arm64/kernel/cpufeature.c       |  58 +++++-
>  arch/arm64/kernel/debug-monitors.c   |   7 +-
>  arch/arm64/kernel/entry-common.c     |  96 +++++----
>  arch/arm64/kernel/entry.S            |   2 -
>  arch/arm64/kernel/hibernate.c        |   6 +-
>  arch/arm64/kernel/irq.c              |   2 +-
>  arch/arm64/kernel/machine_kexec.c    |   2 +-
>  arch/arm64/kernel/probes/kprobes.c   |   4 +-
>  arch/arm64/kernel/setup.c            |   2 +-
>  arch/arm64/kernel/smp.c              |   6 +-
>  arch/arm64/kernel/suspend.c          |   6 +-
>  arch/arm64/kvm/hyp/vgic-v3-sr.c      |   6 +-
>  arch/arm64/kvm/hyp/vhe/switch.c      |   4 +-
>  arch/arm64/mm/mmu.c                  |   6 +-
>  arch/arm64/tools/cpucaps             |   2 +
>  drivers/irqchip/irq-gic-v3.c         |   6 +-
>  23 files changed, 442 insertions(+), 134 deletions(-)
>  create mode 100644 arch/arm64/include/asm/nmi.h
> 
> -- 
> 2.34.1
> 
>
Liao, Chang May 6, 2024, 12:12 p.m. UTC | #2
在 2024/5/4 1:10, Mark Rutland 写道:
> Hi,
> 
> On Mon, Apr 15, 2024 at 06:47:50AM +0000, Liao Chang wrote:
>> This patch series reworks the DAIF mask, unmask, and track API for the
>> upcoming FEAT_NMI extension added in Armv8.8.
>>
>> As platform and virtualization[1] supports for FEAT_NMI is emerging, and
>> Mark Brown's FEAT_NMI patch series[2] highlighted the need for clean up
>> the existing hacking style approach about DAIF management code before
>> adding NMI functionality, furthermore, we discover some subtle bugs
>> during 'perf' and 'ipi_backtrace' transition from PSEUDO_NMI to
>> FEAT_NMI, in summary, all of these emphasize the importance of rework.
>>
>> This series of reworking patches follows the suggestion from Mark
>> Rutland mentioned in Mark Brown's patchset. In summary, he think the
>> better way for DAIF manangement look likes as following:
>>
>> (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. 
> 
> I've started looking at this in the series. There are some subtleties here, and
> I don't think the helpers in this series are quite right as-is. I will try to
> get back to you next week with a description of those; it'll take a short while
> to write that up correctly and clearly and I don't trust myself to rush that
> last thing on a Friday.
> 
> Thanks,
> Mark.

Hi,Mark

Thanks for your feedback.I apprecaite your interest in this patch series
and look forward to receiving additional comments from you and others in
the community.

I am pleased to inform you that the FEAT_NMI features has been successfully
merged into the upstream QEMU codebase at the "master" branch recently. This
allow for initial testing without requiring hardware support for FEAT_NMI.

To ensure minimal regressions introduced by this patch series, i have done
testing using perf top, hardlokup and ipi nmi for various configurations,
including (1) no NMI (2) use CONFIG_PSEUDO_NMI (3) use CONFIG_ARM64_NMI.

We encourage further discussion and feedback on the patch series. We are
particularly interested in hearing from developers who might have experience
with NMI handling or those using platforms with FEAT_NMI capabilities.

Thank you.

> 
>>
>> This patches cherry-pick a part of Mark Brown' FEAT_NMI series, in order
>> to pass compilation and basic testing, includes perf and ipi_backtrace.
>>
>> [1] https://lore.kernel.org/all/20240407081733.3231820-1-ruanjinjie@huawei.com/
>> [2] https://lore.kernel.org/linux-arm-kernel/Y4sH5qX5bK9xfEBp@lpieralisi/
>>
>> 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 (5):
>>   arm64: daifflags: Add logical exception masks covering DAIF + PMR +
>>     ALLINT
>>   arm64: Unify exception masking at entry and exit of exception
>>   arm64: Deprecate old local_daif_{mask,save,restore}
>>   irqchip/gic-v3: Improve the maintainability of NMI masking in GIC
>>     driver
>>   arm64: kprobe: Keep NMI maskabled while kprobe is stepping xol
>>
>> Mark Brown (3):
>>   arm64/sysreg: Add definitions for immediate versions of MSR ALLINT
>>   arm64/cpufeature: Detect PE support for FEAT_NMI
>>   arm64/nmi: Add Kconfig for NMI
>>
>>  arch/arm64/Kconfig                   |  17 ++
>>  arch/arm64/include/asm/cpufeature.h  |   6 +
>>  arch/arm64/include/asm/daifflags.h   | 298 ++++++++++++++++++++++-----
>>  arch/arm64/include/asm/nmi.h         |  27 +++
>>  arch/arm64/include/asm/sysreg.h      |   2 +
>>  arch/arm64/include/uapi/asm/ptrace.h |   1 +
>>  arch/arm64/kernel/acpi.c             |  10 +-
>>  arch/arm64/kernel/cpufeature.c       |  58 +++++-
>>  arch/arm64/kernel/debug-monitors.c   |   7 +-
>>  arch/arm64/kernel/entry-common.c     |  96 +++++----
>>  arch/arm64/kernel/entry.S            |   2 -
>>  arch/arm64/kernel/hibernate.c        |   6 +-
>>  arch/arm64/kernel/irq.c              |   2 +-
>>  arch/arm64/kernel/machine_kexec.c    |   2 +-
>>  arch/arm64/kernel/probes/kprobes.c   |   4 +-
>>  arch/arm64/kernel/setup.c            |   2 +-
>>  arch/arm64/kernel/smp.c              |   6 +-
>>  arch/arm64/kernel/suspend.c          |   6 +-
>>  arch/arm64/kvm/hyp/vgic-v3-sr.c      |   6 +-
>>  arch/arm64/kvm/hyp/vhe/switch.c      |   4 +-
>>  arch/arm64/mm/mmu.c                  |   6 +-
>>  arch/arm64/tools/cpucaps             |   2 +
>>  drivers/irqchip/irq-gic-v3.c         |   6 +-
>>  23 files changed, 442 insertions(+), 134 deletions(-)
>>  create mode 100644 arch/arm64/include/asm/nmi.h
>>
>> -- 
>> 2.34.1
>>
>>
>