Skip to content

arm64: alternatives runtime patching

Andre Przywara linux-arm-kernel lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest6 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6arm64: add cpu_capabilities bitmaparch/arm64/include/asm/cpufeature.h arch/arm64/kernel/setup.c+23 -00 replies
2/6arm64: add alternative runtime patchingarch/arm64/include/asm/alternative-asm.h arch/arm64/include/asm/alternative.h arch/arm64/kernel/Makefile +4 more+139 -10 replies
3/6arm64: detect silicon revisions and set cap bits accordinglyarch/arm64/include/asm/cpufeature.h arch/arm64/kernel/Makefile arch/arm64/kernel/cpu_errata.c +1 more+65 -10 replies
4/6arm64: add Cortex-A53 cache errata workaroundarch/arm64/include/asm/alternative-asm.h arch/arm64/include/asm/cpufeature.h arch/arm64/include/asm/cputype.h +2 more+59 -30 replies
5/6arm64: add Cortex-A57 erratum 832075 workaroundarch/arm64/include/asm/cpufeature.h arch/arm64/include/asm/io.h arch/arm64/kernel/cpu_errata.c+29 -60 replies
6/6arm64: protect alternatives workarounds with Kconfig optionsarch/arm64/Kconfig arch/arm64/kernel/cpu_errata.c+121 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/6] arm64: alternatives runtime patching

This series introduces alternatives runtime patching to arm64. This allows to patch assembly instruction at runtime to either fix hardware bugs or optimize for certain hardware features. Look at patch 5/6 for an example on how to use this.

The code is heavily based on the x86 implementation. Currently this is focussed on fixing CPU errata, but in the future runtime optimizations for new CPU features are planned.

Patch 1/6 introduces a new cpu_hwcaps bitmap, which holds kernel internal CPU feature flags. Since elf_hwcaps is also a userspace ABI, I refrained from tinkering with this (tried this, gets messy).

Based on bits in this bitmap, in patch 2/6 we provide a macro to replace (inline) assembly instructions at runtime with alternative instructions. As on x86, those bits go into separate ELF sections. The patching is done using stop_machine() to avoid mayhem in SMP.

Patch 3/6 introduces means to set cpu_hwcaps bits based on detecting a certain CPU revision. Currently this is based on the architectural bits in the MIDR register, but the code is flexible enough to easily introduce more advanced criteria.
To support a heterogenous CPU setup (e.g. big.LITTLE), we scan all CPUs in the system.

Patch 4 and 5 use the new framework to introduce workarounds for two ARM-Cortex errata. Patch 4 introduces some more framework for the detection, while patch 5 should be used as a blueprint for how to add workarounds for CPU errata in the future.

Patch 6/6 finally introduces Kconfig entries for the bugs. Those are meant to
a) document the errata and workarounds and
b) to allow system vendors to remove certain workarounds for custom build kernels.
Though this shouldn't be strictly necessary, experience shows that people will do b) anyway and I deem it better to provide official means rather than provoking random hacks.

The code can be found also in the alternatives/v1 branch of:
http://www.linux-arm.org/git?p=linux-ap.git
git://linux-arm.org/linux-ap.git

Please review and comment!

Cheers,
Andre.

Andre Przywara (6):
arm64: add cpu_capabilities bitmap
arm64: add alternative runtime patching
arm64: detect silicon revisions and set cap bits accordingly
arm64: add Cortex-A53 cache errata workaround
arm64: add Cortex-A57 erratum 832075 workaround
arm64: protect alternatives workarounds with Kconfig options

 arch/arm64/Kconfig                       |  107 +++++++++++++++++++++++++++++
 arch/arm64/include/asm/alternative-asm.h |   29 ++++++++
 arch/arm64/include/asm/alternative.h     |   43 ++++++++++++
 arch/arm64/include/asm/cpufeature.h      |   29 ++++++++
 arch/arm64/include/asm/cputype.h         |    5 ++
 arch/arm64/include/asm/io.h              |   23 +++++--
 arch/arm64/kernel/Makefile               |    2 +-
 arch/arm64/kernel/alternative.c          |   64 +++++++++++++++++
 arch/arm64/kernel/cpu_errata.c           |  110 ++++++++++++++++++++++++++++++
 arch/arm64/kernel/cpuinfo.c              |    3 +
 arch/arm64/kernel/setup.c                |    3 +
 arch/arm64/kernel/smp.c                  |    2 +
 arch/arm64/kernel/vmlinux.lds.S          |   11 +++
 arch/arm64/mm/cache.S                    |    4 +-
 arch/arm64/mm/init.c                     |    2 +
 15 files changed, 431 insertions(+), 6 deletions(-)
 create mode 100644 arch/arm64/include/asm/alternative-asm.h
 create mode 100644 arch/arm64/include/asm/alternative.h
 create mode 100644 arch/arm64/kernel/alternative.c
 create mode 100644 arch/arm64/kernel/cpu_errata.c
Signature · 1 line
1.7.9.5