Re: [kvm-unit-tests PATCH v1 2/3] lib: s390x: skey: add seed value for storage keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu,  1 Dec 2022 09:46:41 +0100
Nico Boehr <nrb@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx>

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);
>  




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux