From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
Ard Biesheuvel <ardb@kernel.org>,
Tom Lendacky <thomas.lendacky@amd.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Borislav Petkov <bp@alien8.de>,
Dionna Amalie Glaze <dionnaglaze@google.com>,
Kevin Loughlin <kevinloughlin@google.com>
Subject: [PATCH v2 1/3] x86/boot: Move accept_memory() into decompressor
Date: Fri, 4 Apr 2025 10:29:23 +0200 [thread overview]
Message-ID: <20250404082921.2767593-6-ardb+git@google.com> (raw)
In-Reply-To: <20250404082921.2767593-5-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
accept_memory() is only called from the decompressor, and uses an API
that will become specific to the decompressor as well, given that the
EFI stub will need to switch to a special memory acceptance API that can
be called while running in the firmware context with the firmware's page
tables.
So move the function into arch/x86/boot/compressed/mem.c
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/boot/compressed/mem.c | 45 ++++++++++++++++++++
drivers/firmware/efi/libstub/unaccepted_memory.c | 45 --------------------
2 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/arch/x86/boot/compressed/mem.c b/arch/x86/boot/compressed/mem.c
index dbba332e4a12..6a888b80669e 100644
--- a/arch/x86/boot/compressed/mem.c
+++ b/arch/x86/boot/compressed/mem.c
@@ -84,3 +84,48 @@ bool init_unaccepted_memory(void)
return true;
}
+
+void accept_memory(phys_addr_t start, unsigned long size)
+{
+ unsigned long range_start, range_end;
+ phys_addr_t end = start + size;
+ unsigned long bitmap_size;
+ u64 unit_size;
+
+ if (!unaccepted_table)
+ return;
+
+ unit_size = unaccepted_table->unit_size;
+
+ /*
+ * Only care for the part of the range that is represented
+ * in the bitmap.
+ */
+ if (start < unaccepted_table->phys_base)
+ start = unaccepted_table->phys_base;
+ if (end < unaccepted_table->phys_base)
+ return;
+
+ /* Translate to offsets from the beginning of the bitmap */
+ start -= unaccepted_table->phys_base;
+ end -= unaccepted_table->phys_base;
+
+ /* Make sure not to overrun the bitmap */
+ if (end > unaccepted_table->size * unit_size * BITS_PER_BYTE)
+ end = unaccepted_table->size * unit_size * BITS_PER_BYTE;
+
+ range_start = start / unit_size;
+ bitmap_size = DIV_ROUND_UP(end, unit_size);
+
+ for_each_set_bitrange_from(range_start, range_end,
+ unaccepted_table->bitmap, bitmap_size) {
+ unsigned long phys_start, phys_end;
+
+ phys_start = range_start * unit_size + unaccepted_table->phys_base;
+ phys_end = range_end * unit_size + unaccepted_table->phys_base;
+
+ arch_accept_memory(phys_start, phys_end);
+ bitmap_clear(unaccepted_table->bitmap,
+ range_start, range_end - range_start);
+ }
+}
diff --git a/drivers/firmware/efi/libstub/unaccepted_memory.c b/drivers/firmware/efi/libstub/unaccepted_memory.c
index 757dbe734a47..02040bd6a330 100644
--- a/drivers/firmware/efi/libstub/unaccepted_memory.c
+++ b/drivers/firmware/efi/libstub/unaccepted_memory.c
@@ -176,48 +176,3 @@ void process_unaccepted_memory(u64 start, u64 end)
bitmap_set(unaccepted_table->bitmap,
start / unit_size, (end - start) / unit_size);
}
-
-void accept_memory(phys_addr_t start, unsigned long size)
-{
- unsigned long range_start, range_end;
- phys_addr_t end = start + size;
- unsigned long bitmap_size;
- u64 unit_size;
-
- if (!unaccepted_table)
- return;
-
- unit_size = unaccepted_table->unit_size;
-
- /*
- * Only care for the part of the range that is represented
- * in the bitmap.
- */
- if (start < unaccepted_table->phys_base)
- start = unaccepted_table->phys_base;
- if (end < unaccepted_table->phys_base)
- return;
-
- /* Translate to offsets from the beginning of the bitmap */
- start -= unaccepted_table->phys_base;
- end -= unaccepted_table->phys_base;
-
- /* Make sure not to overrun the bitmap */
- if (end > unaccepted_table->size * unit_size * BITS_PER_BYTE)
- end = unaccepted_table->size * unit_size * BITS_PER_BYTE;
-
- range_start = start / unit_size;
- bitmap_size = DIV_ROUND_UP(end, unit_size);
-
- for_each_set_bitrange_from(range_start, range_end,
- unaccepted_table->bitmap, bitmap_size) {
- unsigned long phys_start, phys_end;
-
- phys_start = range_start * unit_size + unaccepted_table->phys_base;
- phys_end = range_end * unit_size + unaccepted_table->phys_base;
-
- arch_accept_memory(phys_start, phys_end);
- bitmap_clear(unaccepted_table->bitmap,
- range_start, range_end - range_start);
- }
-}
--
2.49.0.504.g3bcea36a83-goog
next prev parent reply other threads:[~2025-04-04 8:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 8:29 [PATCH v2 0/3] efistub/x86: Fix early SEV-SNP memory acceptance Ard Biesheuvel
2025-04-04 8:29 ` Ard Biesheuvel [this message]
2025-04-04 8:29 ` [PATCH v2 2/3] x86/boot: Use separate API for memory acceptance in the EFI stub Ard Biesheuvel
2025-04-04 8:29 ` [PATCH v2 3/3] x86/boot: Implement early memory acceptance for SEV-SNP Ard Biesheuvel
2025-04-04 8:43 ` Kirill A. Shutemov
2025-04-04 8:46 ` Ard Biesheuvel
2025-04-04 15:07 ` Dionna Amalie Glaze
2025-04-07 9:25 ` Kirill A. Shutemov
2025-04-07 16:44 ` Ingo Molnar
2025-04-07 17:21 ` Ard Biesheuvel
2025-04-07 17:33 ` Kirill A. Shutemov
2025-04-07 17:45 ` Ard Biesheuvel
2025-04-07 21:08 ` Kirill A. Shutemov
2025-04-07 18:05 ` Tom Lendacky
2025-04-07 19:59 ` Ard Biesheuvel
2025-04-08 15:53 ` Tom Lendacky
2025-04-10 13:28 ` Ard Biesheuvel
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=20250404082921.2767593-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dionnaglaze@google.com \
--cc=kevinloughlin@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/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