From: Andrew Holden <andy0x48@linux.ibm.com>
To: qemu-devel@nongnu.org, iii@linux.ibm.com, freude@linux.ibm.com
Cc: qemu-s390x@nongnu.org, richard.henderson@linaro.org,
david@kernel.org, cohuck@redhat.com, farman@linux.ibm.com,
mjrosato@linux.ibm.com, Andrew Holden <andy0x48@linux.ibm.com>
Subject: [PATCH v2 0/3] Fix AES/PAES CPACF register update on faults
Date: Fri, 20 Nov 2026 13:14:40 +0000 [thread overview]
Message-ID: <20261120131443.61606-1-andy0x48@linux.ibm.com> (raw)
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
next reply other threads:[~2026-11-20 13:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 13:14 Andrew Holden [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120131443.61606-1-andy0x48@linux.ibm.com \
--to=andy0x48@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@kernel.org \
--cc=farman@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.