From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: Nico Boehr <nrb@linux.ibm.com>
Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, thuth@redhat.com,
pbonzini@redhat.com
Subject: Re: [kvm-unit-tests PATCH v1 2/3] lib: s390x: skey: add seed value for storage keys
Date: Thu, 1 Dec 2022 14:27:58 +0100 [thread overview]
Message-ID: <20221201142758.4ac860d2@p-imbrenda> (raw)
In-Reply-To: <20221201084642.3747014-3-nrb@linux.ibm.com>
On Thu, 1 Dec 2022 09:46:41 +0100
Nico Boehr <nrb@linux.ibm.com> wrote:
> Upcoming changes will change storage keys in a loop. To make sure each
> iteration of the loops sets different keys, add variants of the storage
> key library functions which allow to specify a seed.
>
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
I wonder if you can simply merge this patch with the previous one
> ---
> lib/s390x/skey.c | 12 +++++++-----
> lib/s390x/skey.h | 14 ++++++++++++--
> 2 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/lib/s390x/skey.c b/lib/s390x/skey.c
> index 100f0949a244..4ab0828ee98f 100644
> --- a/lib/s390x/skey.c
> +++ b/lib/s390x/skey.c
> @@ -14,10 +14,11 @@
> #include <skey.h>
>
> /*
> - * Set storage keys on pagebuf.
> + * Set storage keys on pagebuf with a seed for the storage keys.
> * pagebuf must point to page_count consecutive pages.
> + * Only the lower seven bits of the seed are considered.
> */
> -void skey_set_keys(uint8_t *pagebuf, unsigned long page_count)
> +void skey_set_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed)
> {
> unsigned char key_to_set;
> unsigned long i;
> @@ -30,7 +31,7 @@ void skey_set_keys(uint8_t *pagebuf, unsigned long page_count)
> * protection as well as reference and change indication for
> * some keys.
> */
> - key_to_set = i * 2;
> + key_to_set = (i ^ seed) * 2;
> set_storage_key(pagebuf + i * PAGE_SIZE, key_to_set, 1);
> }
> }
> @@ -38,13 +39,14 @@ void skey_set_keys(uint8_t *pagebuf, unsigned long page_count)
> /*
> * Verify storage keys on pagebuf.
> * Storage keys must have been set by skey_set_keys on pagebuf before.
> + * skey_set_keys must have been called with the same seed value.
> *
> * If storage keys match the expected result, will return a skey_verify_result
> * with verify_failed false. All other fields are then invalid.
> * If there is a mismatch, returned struct will have verify_failed true and will
> * be filled with the details on the first mismatch encountered.
> */
> -struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count)
> +struct skey_verify_result skey_verify_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed)
> {
> union skey expected_key, actual_key;
> struct skey_verify_result result = {
> @@ -56,7 +58,7 @@ struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_
> for (i = 0; i < page_count; i++) {
> cur_page = pagebuf + i * PAGE_SIZE;
> actual_key.val = get_storage_key(cur_page);
> - expected_key.val = i * 2;
> + expected_key.val = (i ^ seed) * 2;
>
> /*
> * The PoP neither gives a guarantee that the reference bit is
> diff --git a/lib/s390x/skey.h b/lib/s390x/skey.h
> index a0f8caa1270b..bba1c131276d 100644
> --- a/lib/s390x/skey.h
> +++ b/lib/s390x/skey.h
> @@ -23,9 +23,19 @@ struct skey_verify_result {
> unsigned long page_mismatch_addr;
> };
>
> -void skey_set_keys(uint8_t *pagebuf, unsigned long page_count);
> +void skey_set_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed);
>
> -struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count);
> +static inline void skey_set_keys(uint8_t *pagebuf, unsigned long page_count)
> +{
> + skey_set_keys_with_seed(pagebuf, page_count, 0);
> +}
> +
> +struct skey_verify_result skey_verify_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed);
> +
> +static inline struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count)
> +{
> + return skey_verify_keys_with_seed(pagebuf, page_count, 0);
> +}
>
> void skey_report_verify(struct skey_verify_result * const result);
>
next prev parent reply other threads:[~2022-12-01 13:29 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-01 8:46 [kvm-unit-tests PATCH v1 0/3] s390x: test storage keys during migration Nico Boehr
2022-12-01 8:46 ` [kvm-unit-tests PATCH v1 1/3] s390x: add library for skey-related functions Nico Boehr
2022-12-01 13:16 ` Claudio Imbrenda
2022-12-01 15:55 ` Nico Boehr
2022-12-01 16:46 ` Claudio Imbrenda
2022-12-02 9:03 ` Janosch Frank
2022-12-02 9:09 ` Thomas Huth
2022-12-02 10:44 ` Nico Boehr
2022-12-02 11:32 ` Thomas Huth
2022-12-02 11:56 ` Janosch Frank
2022-12-02 12:48 ` Thomas Huth
2022-12-02 12:56 ` Claudio Imbrenda
2022-12-09 9:02 ` Nico Boehr
2022-12-02 10:39 ` Nico Boehr
2022-12-02 11:20 ` Janosch Frank
2022-12-02 11:29 ` Claudio Imbrenda
2022-12-01 8:46 ` [kvm-unit-tests PATCH v1 2/3] lib: s390x: skey: add seed value for storage keys Nico Boehr
2022-12-01 13:27 ` Claudio Imbrenda [this message]
2022-12-01 15:16 ` Nico Boehr
2022-12-01 8:46 ` [kvm-unit-tests PATCH v1 3/3] s390x: add storage key test during migration Nico Boehr
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=20221201142758.4ac860d2@p-imbrenda \
--to=imbrenda@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=nrb@linux.ibm.com \
--cc=pbonzini@redhat.com \
--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