All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] Fix AES/PAES CPACF register update on faults
@ 2026-11-20 13:14 Andrew Holden
  2026-11-20 13:14 ` [PATCH v2 1/3] target/s390x: export access_prepare() and byte accessors Andrew Holden
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Holden @ 2026-11-20 13:14 UTC (permalink / raw)
  To: qemu-devel, iii, freude
  Cc: qemu-s390x, richard.henderson, david, cohuck, farman, mjrosato,
	Andrew Holden

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/20261008154455.369004-1-andy0x48@linux.ibm.com/

---

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

-- 
2.56.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-20 13:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 13:14 [PATCH v2 0/3] Fix AES/PAES CPACF register update on faults Andrew Holden
2026-11-20 13:14 ` [PATCH v2 1/3] target/s390x: export access_prepare() and byte accessors Andrew Holden
2026-11-20 13:14 ` [PATCH v2 2/3] target/s390x/tcg: update regs and IV/tweak per block in CPACF AES/PAES Andrew Holden
2026-11-20 13:14 ` [PATCH v2 3/3] tests/s390x/tcg: Add cpacf clear key register update tests Andrew Holden

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.