From: "Christoph Schlameuss" <schlameuss@linux.ibm.com>
To: "Steffen Eiden" <seiden@linux.ibm.com>,
<linux-kernel@vger.kernel.org>, <linux-s390@vger.kernel.org>
Cc: "Ingo Franzki" <ifranzki@linux.ibm.com>,
"Harald Freudenberger" <freude@linux.ibm.com>,
"Janosch Frank" <frankja@linux.ibm.com>,
"Claudio Imbrenda" <imbrenda@linux.ibm.com>
Subject: Re: [PATCH v1 2/6] s390/uv: Retrieve UV secrets support
Date: Tue, 01 Oct 2024 18:06:40 +0200 [thread overview]
Message-ID: <D4KLK3E4C9HH.3W2N6GXGMR4OY@linux.ibm.com> (raw)
In-Reply-To: <20240930131909.2079965-3-seiden@linux.ibm.com>
On Mon Sep 30, 2024 at 3:19 PM CEST, Steffen Eiden wrote:
> Provide a kernel API to retrieve secrets from the UV secret store.
> Add two new functions:
> * `uv_get_secret_metadata` - get metadata for a given secret identifier
> * `uv_retrieve_secret` - get the secret value for the secret index
>
> With those two functions one can extract the secret for a given secret
> id, if the secret is retrievable.
>
> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
> ---
> arch/s390/include/asm/uv.h | 131 ++++++++++++++++++++++++++++++++++++-
> arch/s390/kernel/uv.c | 124 +++++++++++++++++++++++++++++++++++
> 2 files changed, 254 insertions(+), 1 deletion(-)
[...]
> /* Bits in installed uv calls */
> enum uv_cmds_inst {
> @@ -95,6 +96,7 @@ enum uv_cmds_inst {
> BIT_UVC_CMD_ADD_SECRET = 29,
> BIT_UVC_CMD_LIST_SECRETS = 30,
> BIT_UVC_CMD_LOCK_SECRETS = 31,
Is 32 skipped intentionally? Should there be a comment here that it is reserved?
> + BIT_UVC_CMD_RETR_SECRETS = 33,
> };
[...]
> +/**
> + * uv_secret_list - UV secret-metadata list
> + * @num_secr_stored: Number of secrets stored in this list
> + * @total_num_secrets: Number of secrets stored in the UV for this guest
> + * @next_valid_idx: positive number if there are more secrets available or zero
s/next_valid_idx/next_secret_idx/
> + * @secrets: Up to 85 UV-secret metadata entries.
> + */
> +struct uv_secret_list {
> + u16 num_secr_stored;
> + u16 total_num_secrets;
> + u16 next_secret_idx;
> + u16 reserved_06;
> + u64 reserved_08;
> + struct uv_secret_list_item secrets[85];
> +} __packed __aligned(8);
> +static_assert(sizeof(struct uv_secret_list) == PAGE_SIZE);
> +
> static inline int __uv_call(unsigned long r1, unsigned long r2)
> {
> int cc;
> @@ -383,6 +469,45 @@ static inline int uv_cmd_nodata(u64 handle, u16 cmd, u16 *rc, u16 *rrc)
> return cc ? -EINVAL : 0;
> }
>
> +/** uv_list_secrets() - Do a List Secrets UVC
> + * @buf: Buffer to write list into; size of one page
> + * @start_idx: The smallest index that should be included in the list.
> + * For the fist invocation use 0.
> + * @rc: Pointer to store the return code or NULL.
> + * @rrc: Pointer to store the return reason code or NULL.
> + *
> + * This function calls the List Secrets UVC. The result is written into `buf`,
> + * that needs to be at least one page of writable memory.
> + * `buf` consists of:
> + * * %struct uv_secret_list_hdr
> + * * %struct uv_secret_list_item (multiple)
> + *
> + * For `start_idx` use _0_ for the first call. If there are more secrets available
> + * but could not fit into the page then `rc` is `UVC_RC_MORE_DATA`.
> + * In this case use `uv_secret_list_hdr.next_valid_idx` for `start_idx`.
s/next_valid_idx/next_secret_idx/
> + *
> + * Context: might sleep
> + *
> + * Return: The UVC condition code
> + */
> +static inline int uv_list_secrets(u8 *buf, u16 start_idx, u16 *rc, u16 *rrc)
> +{
> + struct uv_cb_list_secrets uvcb = {
> + .header.len = sizeof(uvcb),
> + .header.cmd = UVC_CMD_LIST_SECRETS,
> + .start_idx = start_idx,
> + .list_addr = (u64)buf,
> + };
> + int cc = uv_call_sched(0, (u64)&uvcb);
> +
> + if (rc)
> + *rc = uvcb.header.rc;
> + if (rrc)
> + *rrc = uvcb.header.rrc;
> +
> + return cc;
> +}
> +
> struct uv_info {
> unsigned long inst_calls_list[4];
> unsigned long uv_base_stor_len;
> @@ -469,6 +594,10 @@ static inline int uv_remove_shared(unsigned long addr)
> return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
> }
>
> +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);
> +
> extern int prot_virt_host;
>
> static inline int is_prot_virt_host(void)
> diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
> index 36db065c7cf7..090246efc1fa 100644
> --- a/arch/s390/kernel/uv.c
> +++ b/arch/s390/kernel/uv.c
> @@ -786,3 +786,127 @@ static int __init uv_info_init(void)
> return rc;
> }
> device_initcall(uv_info_init);
> +
> +/*
> + * Find the secret with the secret_id in the provided list.
> + *
> + * Context: might sleep
> + */
The method comment formatting is in general a bit inconsistent. Sometimes with,
sometimes without newlines / dots.
> +static int find_secret_in_page(const u8 secret_id[UV_SECRET_ID_LEN],
> + const struct uv_secret_list *list,
> + struct uv_secret_list_item_hdr *secret)
> +{
> + u16 i;
> +
> + for (i = 0; i < list->total_num_secrets; i++) {
> + if (memcmp(secret_id, list->secrets[i].id, UV_SECRET_ID_LEN) == 0) {
> + *secret = list->secrets[i].hdr;
> + return 0;
> + }
> + }
> + return -ENOENT;
> +}
[...]
> +/**
> + * uv_get_secret_metadata() - get secret metadata for a given secret id
> + * @secret_id: search pattern
> + * @secret: output data, containing the secret's metadata
> + *
> + * Search for a secret with the given secret_id in the Ultravisor secret store.
> + *
> + * Context: might sleep
> + *
> + * Return:
> + * * %0: - Found entry; secret_idx and secret type are valid
You mean secret->index and secret->type?
> + * * %ENOENT - No entry found
> + * * %ENODEV: - Not supported: UV not available or command not available
> + * * %EIO: - Other unexpected UV error
> + */
> +int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN],
> + struct uv_secret_list_item_hdr *secret)
> +{
> + struct uv_secret_list *buf;
> + int rc;
> +
> + buf = kzalloc(sizeof(*buf), GFP_KERNEL);
> + rc = find_secret(secret_id, buf, secret);
> + kfree(buf);
> + return rc;
> +}
> +EXPORT_SYMBOL_GPL(uv_get_secret_metadata);
[...]
next prev parent reply other threads:[~2024-10-01 16:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 13:19 [PATCH v1 0/6] s390/uv: Retrieve Secrets Ultravisor Call support Steffen Eiden
2024-09-30 13:19 ` [PATCH v1 1/6] s390/boot/uv.c: Use a constant for more-data rc Steffen Eiden
2024-10-01 12:10 ` Claudio Imbrenda
2024-10-01 13:56 ` Janosch Frank
2024-09-30 13:19 ` [PATCH v1 2/6] s390/uv: Retrieve UV secrets support Steffen Eiden
2024-10-01 16:06 ` Christoph Schlameuss [this message]
2024-10-02 7:51 ` Janosch Frank
2024-09-30 13:19 ` [PATCH v1 3/6] s390/uvdevice: Add Retrieve Secret IOCTL Steffen Eiden
2024-10-01 16:09 ` Christoph Schlameuss
2024-09-30 13:19 ` [PATCH v1 4/6] s390/uvdevice: Increase indent in IOCTL definitions Steffen Eiden
2024-09-30 13:19 ` [PATCH v1 5/6] s390/uvdevice: Add List Secrets Ext IOCTL Steffen Eiden
2024-10-01 16:19 ` Christoph Schlameuss
2024-09-30 13:19 ` [PATCH v1 6/6] s390/uv: Retrieve UV secrets sysfs support Steffen Eiden
2024-10-01 17:42 ` Christoph Schlameuss
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=D4KLK3E4C9HH.3W2N6GXGMR4OY@linux.ibm.com \
--to=schlameuss@linux.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=freude@linux.ibm.com \
--cc=ifranzki@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=seiden@linux.ibm.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