Re: [PATCH v4 21/24] s390/uv: Rename find_secret() to uv_find_secret() and publish

Harald Freudenberger
2025-04-14T15:15:41Z

On 2025-04-14 10:08, Steffen Eiden wrote:
> On Wed, Apr 09, 2025 at 04:03:02PM +0200, Harald Freudenberger wrote:
>> Rename the internal UV function find_secret() to uv_find_secret()
>> and publish it as new UV API in-kernel function.
>>
>> The pkey uv handler may be called in a do-not-allocate memory
>> situation where sleeping is allowed but allocating memory which
>> may cause IO operations is not. For example when an encrypted
>> swap file is used and the encryption is done via UV retrievable
>> secrets with protected keys.
>>
>> The UV API function uv_get_secret_metadata() allocates memory
>> and then calls the find_secret() function. By exposing the
>> find_secret() function as a new UV API function uv_find_secret()
>> it is possible to retrieve UV secret meta data without any
>> memory allocations from the UV when the caller offers space
>> for one struct uv_secret_list.
>>
>> Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
>
> With the documentation improved:
>
> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
>
>> ---
>> arch/s390/include/asm/uv.h | 3 +++
>> arch/s390/kernel/uv.c | 12 ++++++++----
>> 2 files changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/arch/s390/include/asm/uv.h b/arch/s390/include/asm/uv.h
>> index b11f5b6d0bd1..8d7e00fa2bf0 100644
>> --- a/arch/s390/include/asm/uv.h
>> +++ b/arch/s390/include/asm/uv.h
>> @@ -616,6 +616,9 @@ static inline int uv_remove_shared(unsigned long
>> addr)
>> return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
>> }
>>
>> +int uv_find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
>> + struct uv_secret_list *list,
>> + struct uv_secret_list_item_hdr *secret);
>> int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN],
>> struct uv_secret_list_item_hdr *secret);
>> int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size);
>> diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
>> index 9f05df2da2f7..4acbbdff568f 100644
>> --- a/arch/s390/kernel/uv.c
>> +++ b/arch/s390/kernel/uv.c
>> @@ -681,12 +681,15 @@ static int find_secret_in_page(const u8
>> secret_id[UV_SECRET_ID_LEN],
>>
>> /*
> This documentation string does not make sense for an exported function.
> Let's
> add documentation from the get_metadata function.
>
>> * Do the actual search for `uv_get_secret_metadata`.
> Change this to something like:
>
> Locate a secret in the list by its id.
>
>> + * @secret_id: search pattern.
>> + * @list: ephemeral buffer space
>> + * @secret: output data, containing the secret's metadata.
>> *
> Add:
> * Search for a secret with the given secret_id in the Ultravisor
> secret store.
>
>> * Context: might sleep.
>> */
>> -static int find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
>> - struct uv_secret_list *list,
>> - struct uv_secret_list_item_hdr *secret)
>> +int uv_find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
>> + struct uv_secret_list *list,
>> + struct uv_secret_list_item_hdr *secret)
>
> ...

Done as you suggested.
Thanks