All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald Freudenberger <freude@linux.ibm.com>
To: seiden@linux.ibm.com
Cc: linux-s390@vger.kernel.org
Subject: [PATCH v1 1/1] s390/uv: Prealloc and use one work page
Date: Thu, 27 Mar 2025 16:38:24 +0100	[thread overview]
Message-ID: <20250327153824.61600-2-freude@linux.ibm.com> (raw)
In-Reply-To: <20250327153824.61600-1-freude@linux.ibm.com>

The pkey handler is calling the uv in some circumstances
where no memory allocation is acceptable. As of now only
the uv_get_secret_metadata() function allocates memory.
As this is exactly one page, lets introduce a pre-allocated
work page and protect the concurrent use with a mutex to
remove dynamic memory allocation and free. This page may be
also used with future extension to the uv code.

Signed-off-by: Harald Freudenberger <freude@linux.ibm.com>
---
 arch/s390/kernel/uv.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
index 9f05df2da2f7..71900ec68a23 100644
--- a/arch/s390/kernel/uv.c
+++ b/arch/s390/kernel/uv.c
@@ -37,6 +37,13 @@ EXPORT_SYMBOL(uv_info);
 int __bootdata_preserved(prot_virt_host);
 EXPORT_SYMBOL(prot_virt_host);
 
+/*
+ * Need one work page for ephemeral use by uv_get_secret_metadata()
+ * The concurrent use of this page is protected by a mutex.
+ */
+static u8 *work_page;
+static DEFINE_MUTEX(work_page_lock);
+
 static int __init uv_init(phys_addr_t stor_base, unsigned long stor_len)
 {
 	struct uv_cb_init uvcb = {
@@ -61,6 +68,12 @@ void __init setup_uv(void)
 	if (!is_prot_virt_host())
 		return;
 
+	work_page = (u8 *)__get_free_page(GFP_KERNEL);
+	if (!work_page) {
+		pr_warn("Failed to alloc a working memory page\n");
+		return;
+	}
+
 	uv_stor_base = memblock_alloc_try_nid(
 		uv_info.uv_base_stor_len, SZ_1M, SZ_2G,
 		MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE);
@@ -80,6 +93,7 @@ void __init setup_uv(void)
 	return;
 fail:
 	pr_info("Disabling support for protected virtualization");
+	free_page((unsigned long)work_page);
 	prot_virt_host = 0;
 }
 
@@ -730,11 +744,11 @@ int uv_get_secret_metadata(const u8 secret_id[UV_SECRET_ID_LEN],
 	struct uv_secret_list *buf;
 	int rc;
 
-	buf = kzalloc(sizeof(*buf), GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
+	mutex_lock(&work_page_lock);
+	buf = (struct uv_secret_list *)work_page;
 	rc = find_secret(secret_id, buf, secret);
-	kfree(buf);
+	mutex_unlock(&work_page_lock);
+
 	return rc;
 }
 EXPORT_SYMBOL_GPL(uv_get_secret_metadata);
-- 
2.43.0


  reply	other threads:[~2025-03-27 15:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-27 15:38 [PATCH v1 0/1] Remove the need to alloc memory in uv.c Harald Freudenberger
2025-03-27 15:38 ` Harald Freudenberger [this message]
2025-03-28 10:34   ` [PATCH v1 1/1] s390/uv: Prealloc and use one work page Heiko Carstens
2025-03-28 12:51     ` Harald Freudenberger
2025-03-31  9:35       ` Heiko Carstens

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=20250327153824.61600-2-freude@linux.ibm.com \
    --to=freude@linux.ibm.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.