Skip to content

RFC Add DEXCR support

Benjamin Gray linux-hardening linuxppc-dev lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest13 patches 15 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13powerpc/book3s: Add missing <linux/sched.h> includearch/powerpc/include/asm/book3s/64/kup.h+1 -01 reply
2/13powerpc: Add initial Dynamic Execution Control Register (DEXCR) supportarch/powerpc/include/asm/book3s/64/kexec.h arch/powerpc/include/asm/cputable.h arch/powerpc/include/asm/processor.h +6 more+75 -22 replies
3/13powerpc/dexcr: Handle hashchk exceptionarch/powerpc/include/asm/ppc-opcode.h arch/powerpc/include/asm/processor.h arch/powerpc/kernel/dexcr.c +1 more+35 -02 replies
4/13powerpc/dexcr: Support userspace ROP protectionarch/powerpc/include/asm/book3s/64/kexec.h arch/powerpc/include/asm/processor.h arch/powerpc/include/asm/reg.h +1 more+17 -03 replies
5/13prctl: Define PowerPC DEXCR interfaceinclude/uapi/linux/prctl.h kernel/sys.c+30 -01 reply
6/13powerpc/dexcr: Add prctl implementationarch/powerpc/include/asm/processor.h arch/powerpc/kernel/dexcr.c arch/powerpc/kernel/process.c+151 -11 reply
7/13powerpc/dexcr: Add sysctl entry for SBHE system overridearch/powerpc/kernel/dexcr.c+125 -02 replies
8/13powerpc/dexcr: Add enforced userspace ROP protection configarch/powerpc/Kconfig arch/powerpc/kernel/dexcr.c+16 -40 replies
9/13selftests/powerpc: Add more utility macrostools/testing/selftests/powerpc/include/utils.h+44 -00 replies
10/13selftests/powerpc: Add hashst/hashchk testtools/testing/selftests/powerpc/Makefile tools/testing/selftests/powerpc/dexcr/.gitignore tools/testing/selftests/powerpc/dexcr/Makefile +4 more+414 -00 replies
11/13selftests/powerpc: Add DEXCR prctl, sysctl interface testtools/testing/selftests/powerpc/dexcr/.gitignore tools/testing/selftests/powerpc/dexcr/Makefile tools/testing/selftests/powerpc/dexcr/cap.c +3 more+336 -20 replies
12/13selftests/powerpc: Add DEXCR status utility lsdexcrtools/testing/selftests/powerpc/dexcr/.gitignore tools/testing/selftests/powerpc/dexcr/Makefile tools/testing/selftests/powerpc/dexcr/lsdexcr.c+181 -00 replies
13/13Documentation: Document PowerPC kernel DEXCR interfaceDocumentation/powerpc/dexcr.rst Documentation/powerpc/index.rst+184 -02 replies

Reviews trailers per patch

4 of 13 patches have a Reviewed-by or Acked-by.

PatchNicholas Piggin
1/13R-b
2/13R-b
3/13
4/13R-b
5/13R-b
6/13
7/13
8/13
9/13
10/13
11/13
12/13
13/13

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 00/13] Add DEXCR support

This series is based on initial work by Chris Riedl that was not sent to the list.

Adds a kernel interface for userspace to interact with the DEXCR. The DEXCR is a SPR that allows control over various execution 'aspects', such as indirect branch prediction and enabling the hashst/hashchk instructions. Further details are in ISA 3.1B Book 3 chapter 12.

This RFC proposes an interface for users to interact with the DEXCR. It aims to support

* Querying supported aspects
* Getting/setting aspects on a per-process level
* Allowing global overrides across all processes

There are some parts that I'm not sure on the best way to approach (hence RFC):

* The feature names in arch/powerpc/kernel/dt_cpu_ftrs.c appear to be unimplemented in skiboot, so are being defined by this series. Is being so verbose fine?
* What aspects should be editable by a process? E.g., SBHE has
effects that potentially bleed into other processes. Should
it only be system wide configurable?
* Should configuring certain aspects for the process be non-privileged? E.g., Is there harm in always allowing configuration of IBRTPD, SRAPD? The *FORCE_SET* action prevents further process local changes regardless of privilege.
* The tests fail Patchwork CI because of the new prctl macros, and the CI doesn't run headers_install and add -isystem <buildpath>/usr/include to the make command.
* On handling an exception, I don't check if the NPHIE bit is enabled in the DEXCR. To do so would require reading both the DEXCR and HDEXCR, for little gain (it should only matter that the current instruction was a hashchk. If so, the only reason it would cause an exception is the failed check. If the instruction is rewritten between exception and check we'd be wrong anyway).

The series is based on the earlier selftest utils series[1], so the tests won't build at all without applying that first. The kernel side should build fine on ppc/next 247f34f7b80357943234f93f247a1ae6b6c3a740 though.

[1]: https://patchwork.ozlabs.org/project/linuxppc-dev/cover/[email protected]/

Benjamin Gray (13):
powerpc/book3s: Add missing <linux/sched.h> include
powerpc: Add initial Dynamic Execution Control Register (DEXCR)
support
powerpc/dexcr: Handle hashchk exception powerpc/dexcr: Support userspace ROP protection
prctl: Define PowerPC DEXCR interface
powerpc/dexcr: Add prctl implementation powerpc/dexcr: Add sysctl entry for SBHE system override powerpc/dexcr: Add enforced userspace ROP protection config selftests/powerpc: Add more utility macros selftests/powerpc: Add hashst/hashchk test selftests/powerpc: Add DEXCR prctl, sysctl interface test selftests/powerpc: Add DEXCR status utility lsdexcr
Documentation: Document PowerPC kernel DEXCR interface

 Documentation/powerpc/dexcr.rst               | 183 +++++++++++
 Documentation/powerpc/index.rst               |   1 +
 arch/powerpc/Kconfig                          |   5 +
 arch/powerpc/include/asm/book3s/64/kexec.h    |   6 +
 arch/powerpc/include/asm/book3s/64/kup.h      |   1 +
 arch/powerpc/include/asm/cputable.h           |   8 +-
 arch/powerpc/include/asm/ppc-opcode.h         |   1 +
 arch/powerpc/include/asm/processor.h          |  33 ++
 arch/powerpc/include/asm/reg.h                |   7 +
 arch/powerpc/kernel/Makefile                  |   1 +
 arch/powerpc/kernel/dexcr.c                   | 310 ++++++++++++++++++
 arch/powerpc/kernel/dt_cpu_ftrs.c             |   4 +
 arch/powerpc/kernel/process.c                 |  31 +-
 arch/powerpc/kernel/prom.c                    |   4 +
 arch/powerpc/kernel/traps.c                   |   6 +
 include/uapi/linux/prctl.h                    |  14 +
 kernel/sys.c                                  |  16 +
 tools/testing/selftests/powerpc/Makefile      |   1 +
 .../selftests/powerpc/dexcr/.gitignore        |   3 +
 .../testing/selftests/powerpc/dexcr/Makefile  |  11 +
 tools/testing/selftests/powerpc/dexcr/cap.c   |  72 ++++
 tools/testing/selftests/powerpc/dexcr/cap.h   |  18 +
 tools/testing/selftests/powerpc/dexcr/dexcr.c | 118 +++++++
 tools/testing/selftests/powerpc/dexcr/dexcr.h |  54 +++
 .../selftests/powerpc/dexcr/dexcr_test.c      | 241 ++++++++++++++
 .../selftests/powerpc/dexcr/hashchk_test.c    | 229 +++++++++++++
 .../testing/selftests/powerpc/dexcr/lsdexcr.c | 178 ++++++++++
 tools/testing/selftests/powerpc/include/reg.h |   4 +
 .../testing/selftests/powerpc/include/utils.h |  44 +++
 29 files changed, 1602 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/powerpc/dexcr.rst
 create mode 100644 arch/powerpc/kernel/dexcr.c
 create mode 100644 tools/testing/selftests/powerpc/dexcr/.gitignore
 create mode 100644 tools/testing/selftests/powerpc/dexcr/Makefile
 create mode 100644 tools/testing/selftests/powerpc/dexcr/cap.c
 create mode 100644 tools/testing/selftests/powerpc/dexcr/cap.h
 create mode 100644 tools/testing/selftests/powerpc/dexcr/dexcr.c
 create mode 100644 tools/testing/selftests/powerpc/dexcr/dexcr.h
 create mode 100644 tools/testing/selftests/powerpc/dexcr/dexcr_test.c
 create mode 100644 tools/testing/selftests/powerpc/dexcr/hashchk_test.c
 create mode 100644 tools/testing/selftests/powerpc/dexcr/lsdexcr.c

base-commit: 9dc58a6040662faaf24c8932861f485670fce7ff --
2.38.1