Skip to content

Commit 933dd21

Browse files
hfreudehcahca
authored andcommitted
s390/uv: Rename find_secret() to uv_find_secret() and publish
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> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Acked-by: Holger Dengler <dengler@linux.ibm.com> Link: https://lore.kernel.org/r/20250424133619.16495-22-freude@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 15cdc6f commit 933dd21

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

arch/s390/include/asm/uv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ static inline int uv_remove_shared(unsigned long addr)
616616
return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
617617
}
618618

619+
int uv_find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
620+
struct uv_secret_list *list,
621+
struct uv_secret_list_item_hdr *secret);
619622
int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN],
620623
struct uv_secret_list_item_hdr *secret);
621624
int uv_retrieve_secret(u16 secret_idx, u8 *buf, size_t buf_size);

arch/s390/kernel/uv.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,12 @@ static int __init uv_sysfs_init(void)
782782
device_initcall(uv_sysfs_init);
783783

784784
/*
785-
* Find the secret with the secret_id in the provided list.
785+
* Locate a secret in the list by its id.
786+
* @secret_id: search pattern.
787+
* @list: ephemeral buffer space
788+
* @secret: output data, containing the secret's metadata.
789+
*
790+
* Search for a secret with the given secret_id in the Ultravisor secret store.
786791
*
787792
* Context: might sleep.
788793
*/
@@ -803,12 +808,15 @@ static int find_secret_in_page(const u8 secret_id[UV_SECRET_ID_LEN],
803808

804809
/*
805810
* Do the actual search for `uv_get_secret_metadata`.
811+
* @secret_id: search pattern.
812+
* @list: ephemeral buffer space
813+
* @secret: output data, containing the secret's metadata.
806814
*
807815
* Context: might sleep.
808816
*/
809-
static int find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
810-
struct uv_secret_list *list,
811-
struct uv_secret_list_item_hdr *secret)
817+
int uv_find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
818+
struct uv_secret_list *list,
819+
struct uv_secret_list_item_hdr *secret)
812820
{
813821
u16 start_idx = 0;
814822
u16 list_rc;
@@ -830,6 +838,7 @@ static int find_secret(const u8 secret_id[UV_SECRET_ID_LEN],
830838

831839
return -ENOENT;
832840
}
841+
EXPORT_SYMBOL_GPL(uv_find_secret);
833842

834843
/**
835844
* uv_get_secret_metadata() - get secret metadata for a given secret id.
@@ -855,7 +864,7 @@ int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN],
855864
buf = kzalloc(sizeof(*buf), GFP_KERNEL);
856865
if (!buf)
857866
return -ENOMEM;
858-
rc = find_secret(secret_id, buf, secret);
867+
rc = uv_find_secret(secret_id, buf, secret);
859868
kfree(buf);
860869
return rc;
861870
}

0 commit comments

Comments
 (0)