Skip to content

Fix AES/PAES CPACF register update on faults

Andrew Holden qemu-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest3 patches 0 repliesNew

Changes in v2 from the cover letter

- Probe src, dst, and IV/tweak ranges with access_prepare() before writing, so a fault leaves block unwritten, incl. block that crosses page boundary.
- Share AES w/r block helper for all functions.
- Extend fix to prot-key functions.
- Squash each cipher mode fix commits into one.
- Include testcases in this series

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3target/s390x: export access_prepare() and byte accessorstarget/s390x/s390x-internal.h target/s390x/tcg/mem_helper.c+33 -250 replies
2/3target/s390x/tcg: update regs and IV/tweak per block in CPACF AES/PAEStarget/s390x/tcg/cpacf_aes.c+259 -1210 replies
3/3tests/s390x/tcg: Add cpacf clear key register update teststests/tcg/s390x/cpacf-km-ecb-fault.c tests/tcg/s390x/cpacf-km-xts-fault.c tests/tcg/s390x/cpacf-kmc-cbc-fault.c +3 more+1846 -260 replies

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH v2 0/3] Fix AES/PAES CPACF register update on faults

This series fixes how the CPACF AES helpers (ECB, CBC, CTR, XTS, with both clear key and protected keys) behave when a guest memory access faults in the middle of an instruction. A fault could leave a block partially written, and the registers, CBC IV and XTS tweak not matching the completed blocks, so the instruction would not continue where it stopped.

Each block is now probed with access_prepare() before anything is written, which applies to the source, destination, and IV/tweak. The registers are now updated last, so a fault leaves the block unwritten and a re-invocation redoes it. Block copying is handled by aes_read_block() and aes_write_block(), shared by the clear-key and prot-key functions.

The IV/tweak range is probed before the block is written, so a fault on this is unlikely. The data and IV stores are still two separate steps however. If the IV/tweak store fails after the data store, e.g. because another thread changed the page post-probe, a re-invocation would not redo the block cleanly when the source and destination overlap. Currently, I can't make the two stores a single operation.

Testing:
qemu-s390x and qemu-system-s390x build, with current cpacf tests passing, along with four fault tests written by Harald Freudenberger - these were built and excercised in linux-user mode, targeting the relevant instructions.

Notes:
- Prot-key functions are covered by existing cpacf tests, but no fault test currently exist.
- Access helpers declared in s390x-internal.h - is this acceptable?

---
Changelog:
v2:
- Probe src, dst, and IV/tweak ranges with access_prepare() before writing, so a fault leaves block unwritten, incl. block that crosses page boundary.
- Share AES w/r block helper for all functions.
- Extend fix to prot-key functions.
- Squash each cipher mode fix commits into one.
- Include testcases in this series

Links:
v1: https://lore.kernel.org/qemu-devel/[email protected]/

---

Andrew Holden (2):
target/s390x: export access_prepare() and byte accessors target/s390x/tcg: update regs and IV/tweak per block in CPACF AES/PAES

Harald Freudenberger (1):
tests/s390x/tcg: Add cpacf clear key register update tests

 target/s390x/s390x-internal.h           |  25 ++
 target/s390x/tcg/cpacf_aes.c            | 380 ++++++++++++------
 target/s390x/tcg/mem_helper.c           |  33 +-
 tests/tcg/s390x/cpacf-km-ecb-fault.c    | 368 +++++++++++++++++
 tests/tcg/s390x/cpacf-km-xts-fault.c    | 511 ++++++++++++++++++++++++
 tests/tcg/s390x/cpacf-kmc-cbc-fault.c   | 472 ++++++++++++++++++++++
 tests/tcg/s390x/cpacf-kmctr-ctr-fault.c | 414 +++++++++++++++++++
 tests/tcg/s390x/cpacf.h                 | 103 +++--
 tests/tcg/s390x/meson.build             |   4 +
 9 files changed, 2138 insertions(+), 172 deletions(-)
 create mode 100644 tests/tcg/s390x/cpacf-km-ecb-fault.c
 create mode 100644 tests/tcg/s390x/cpacf-km-xts-fault.c
 create mode 100644 tests/tcg/s390x/cpacf-kmc-cbc-fault.c
 create mode 100644 tests/tcg/s390x/cpacf-kmctr-ctr-fault.c
Signature · 1 line
2.56.0