From: Ilya Leoshkevich <iii@linux.ibm.com>
To: freude@linux.ibm.com
Cc: richard.henderson@linaro.org, david@kernel.org, thuth@redhat.com,
berrange@redhat.com, qemu-s390x@nongnu.org,
qemu-devel@nongnu.org, linux-s390@vger.kernel.org,
dengler@linux.ibm.com, borntraeger@linux.ibm.com,
fcallies@linux.ibm.com, cohuck@redhat.com
Subject: Re: [PATCH v13 12/18] target/s390x: Support protected key AES ECB for cpacf km instruction
Date: Wed, 5 Aug 2026 13:17:23 +0200 [thread overview]
Message-ID: <9ae87449-18d5-447b-8a06-59aa10793a0b@linux.ibm.com> (raw)
In-Reply-To: <fd5d369e27953708bdbd43620aa73957@linux.ibm.com>
On 8/5/26 10:28, Harald Freudenberger wrote:
> On 2026-08-05 00:48, Ilya Leoshkevich wrote:
>> On 8/3/26 18:12, Harald Freudenberger wrote:
>>> Support the subfunctions CPACF_KM_PAES_128, CPACF_KM_PAES_192
>>> and CPACF_KM_PAES_256 for the cpacf km instruction.
>>>
>>> Tested-by: Holger Dengler <dengler@linux.ibm.com>
>>> Reviewed-by: Finn Callies <fcallies@linux.ibm.com>
>>> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
>>> ---
>>> target/s390x/gen-features.c | 3 ++
>>> target/s390x/tcg/cpacf.h | 4 ++
>>> target/s390x/tcg/cpacf_aes.c | 91 ++++++++++++++++++++++++++++++++
>>> target/s390x/tcg/crypto_helper.c | 7 +++
>>> 4 files changed, 105 insertions(+)
>>
>> [...]
>>
>>> +
>>> + /* process up to MAX_BLOCKS_PER_RUN aes blocks */
>>> + for (i = 0; i < MAX_BLOCKS_PER_RUN && len >= AES_BLOCK_SIZE; i++) {
>>> + aes_read_block(env, mmu_idx, ra, *src_ptr_reg + done, in);
>>> + if (mod) {
>>> + AES_decrypt(in, out, &exkey);
>>> + } else {
>>> + AES_encrypt(in, out, &exkey);
>>> + }
>>> + aes_write_block(env, mmu_idx, ra, *dst_ptr_reg + done, out);
>>> + len -= AES_BLOCK_SIZE;
>>> + done += AES_BLOCK_SIZE;
>>> + }
>>> +
>>> + *src_ptr_reg = deposit64(*src_ptr_reg, 0, addr_reg_size,
>>> + *src_ptr_reg + done);
>>> + *dst_ptr_reg = deposit64(*dst_ptr_reg, 0, addr_reg_size,
>>> + *dst_ptr_reg + done);
>>> + *src_len_reg -= done;
>>
>> Should we update registers after each iteration?
>> Otherwise there may be interesting effects due to swapped out pages when
>> running in system emulation.
>
> I don't get this. Swapping and interruption of this code should not affect
> the encrypted/decrypted result in memory and also not the register content.
> But I assume that a CPACF instruction itself is some atomic operation. So
> there needs to be a consistent state before and after the instruction. But
> "while" the instruction is executed does not need to be consistent all the
> time. Otherwise for example here the memory write and the update of the
> registers should be atomic.
I agree that the "while" state is in general not important, except for
the special case when we get a memory-related exception in the middle of
processing. Then we end up committing the "while" state and it can be
observed by at least the exception handler. In this specific case I
guess the whole instruction will be restarted and the application code
will not have a chance to observe the inconsistency (memory updated, but
registers are not), but it a) doesn't look very clean and b) has
quadratic complexity: if 10 pages are swapped out, we will perform
1+2+...+10 decryptions.
DFLTCC, which is similar, handles it like this: it processes as many
pages as it can, and if the next page is not accessible, it returns CC3,
updating memory and registers accordingly. Only if the very first page
is not accessible it raises an exception. This makes sure we don't end
up with a quadratic number of bytes decompressed.
>> Blocks crossing the page boundary is a similar issue, not sure if it's
>> that easy to solve.
>
> Well yes. This is a clear issue hanging around in all the memory read/write
> crypto code here. I have no idea on how this could be solved. However,
> sounds
> like there will participate a new guy in the Qemu cpacf area soon. So maybe
> he has some ideas to work this out.
Looking at tcg/mem_helper.c, they use a static access_prepare()
instruction to pre-check the address ranges; this function takes page
crossings into account.
Perhaps it can be made non-static and reused here as is?
>> [...]
next prev parent reply other threads:[~2026-08-05 11:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 16:12 [PATCH v13 00/18] target/s390x: Extend qemu CPACF support Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 01/18] target/s390x: Rework s390 cpacf implementations Harald Freudenberger
2026-08-04 22:23 ` Ilya Leoshkevich
2026-08-05 7:52 ` Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 02/18] target/s390x: Move cpacf sha512 code into a new file Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 03/18] target/s390x: Support cpacf sha256 Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 04/18] target/s390x: Add helper functions for copy memory to and from guest Harald Freudenberger
2026-08-04 21:55 ` Ilya Leoshkevich
2026-08-03 16:12 ` [PATCH v13 05/18] crypto: Add aes-helpers file to support some AES modes Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 06/18] target/s390x: Support AES ECB for cpacf km instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 07/18] target/s390x: Support AES CBC for cpacf kmc instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 08/18] target/s390x: Support AES CTR for cpacf kmctr instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 09/18] target/s390x: Minimal AES XTS support for cpacf pcc instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 10/18] target/s390x: Support AES XTS for cpacf km instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 11/18] target/s390x: Base support for cpacf protected keys and pckmo Harald Freudenberger
2026-08-04 22:00 ` Ilya Leoshkevich
2026-08-05 8:10 ` Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 12/18] target/s390x: Support protected key AES ECB for cpacf km instruction Harald Freudenberger
2026-08-04 22:48 ` Ilya Leoshkevich
2026-08-05 8:28 ` Harald Freudenberger
2026-08-05 11:17 ` Ilya Leoshkevich [this message]
2026-08-03 16:12 ` [PATCH v13 13/18] target/s390x: Support protected key AES CBC for cpacf kmc instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 14/18] target/s390x: Support protected key AES CTR for cpacf kmctr instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 15/18] target/s390x: Minimal protected key AES XTS support for cpacf pcc instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 16/18] target/s390x: Support protected key AES XTS for cpacf km instruction Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 17/18] docs/s390: Document CPACF instructions support Harald Freudenberger
2026-08-03 16:12 ` [PATCH v13 18/18] tests/tcg/s390x: Add tests for CPACF instructions Harald Freudenberger
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=9ae87449-18d5-447b-8a06-59aa10793a0b@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=berrange@redhat.com \
--cc=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@kernel.org \
--cc=dengler@linux.ibm.com \
--cc=fcallies@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thuth@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).