From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>,
Dave Hansen <dave.hansen@intel.com>,
Sean Christopherson <seanjc@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Joerg Roedel <jroedel@suse.de>, Ard Biesheuvel <ardb@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>,
Kuppuswamy Sathyanarayanan
<sathyanarayanan.kuppuswamy@linux.intel.com>,
David Rientjes <rientjes@google.com>,
Vlastimil Babka <vbabka@suse.cz>,
Tom Lendacky <thomas.lendacky@amd.com>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
Dario Faggioli <dfaggioli@suse.com>,
Mike Rapoport <rppt@kernel.org>,
David Hildenbrand <david@redhat.com>,
Mel Gorman <mgorman@techsingularity.net>,
marcelo.cerri@canonical.com, tim.gardner@canonical.com,
khalid.elmously@canonical.com, philip.cox@canonical.com,
aarcange@redhat.com, peterx@redhat.com, x86@kernel.org,
linux-mm@kvack.org, linux-coco@lists.linux.dev,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Mike Rapoport <rppt@linux.ibm.com>
Subject: [PATCHv10 06/11] x86/mm: Reserve unaccepted memory bitmap
Date: Mon, 8 May 2023 02:46:13 +0300 [thread overview]
Message-ID: <20230507234618.18067-7-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20230507234618.18067-1-kirill.shutemov@linux.intel.com>
A given page of memory can only be accepted once. The kernel has to
accept memory both in the early decompression stage and during normal
runtime.
A bitmap is used to communicate the acceptance state of each page
between the decompression stage and normal runtime.
boot_params is used to communicate location of the bitmap throughout
the boot. The bitmap is allocated and initially populated in EFI stub.
Decompression stage accepts pages required for kernel/initrd and marks
these pages accordingly in the bitmap. The main kernel picks up the
bitmap from the same boot_params and uses it to determine what has to
be accepted on allocation.
In the runtime kernel, reserve the bitmap's memory to ensure nothing
overwrites it.
The size of bitmap is determined with e820__end_of_ram_pfn() which
relies on setup_e820() marking unaccepted memory as E820_TYPE_RAM.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Mike Rapoport <rppt@linux.ibm.com>
---
arch/x86/kernel/e820.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index fb8cf953380d..483c36a28d2e 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -1316,6 +1316,23 @@ void __init e820__memblock_setup(void)
int i;
u64 end;
+ /*
+ * Mark unaccepted memory bitmap reserved.
+ *
+ * This kind of reservation usually done from early_reserve_memory(),
+ * but early_reserve_memory() called before e820__memory_setup(), so
+ * e820_table is not finalized and e820__end_of_ram_pfn() cannot be
+ * used to get correct RAM size.
+ */
+ if (boot_params.unaccepted_memory) {
+ unsigned long size;
+
+ /* One bit per 2MB */
+ size = DIV_ROUND_UP(e820__end_of_ram_pfn() * PAGE_SIZE,
+ PMD_SIZE * BITS_PER_BYTE);
+ memblock_reserve(boot_params.unaccepted_memory, size);
+ }
+
/*
* The bootstrap memblock region count maximum is 128 entries
* (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries
--
2.39.3
next prev parent reply other threads:[~2023-05-07 23:46 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-07 23:46 [PATCHv10 00/11] mm, x86/cc: Implement support for unaccepted memory Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 01/11] mm: Add " Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 02/11] efi/x86: Get full memory map in allocate_e820() Kirill A. Shutemov
2023-05-08 7:19 ` Ard Biesheuvel
2023-05-07 23:46 ` [PATCHv10 03/11] x86/boot: Add infrastructure required for unaccepted memory support Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 04/11] efi/x86: Implement support for unaccepted memory Kirill A. Shutemov
2023-05-08 7:30 ` Ard Biesheuvel
2023-05-08 19:00 ` Kirill A. Shutemov
2023-05-08 22:11 ` Ard Biesheuvel
2023-05-09 0:56 ` Kirill A. Shutemov
2023-05-09 6:47 ` Ard Biesheuvel
2023-05-12 1:59 ` Kirill A. Shutemov
2023-05-12 7:39 ` Ard Biesheuvel
2023-05-12 10:59 ` Kirill A. Shutemov
2023-05-12 11:01 ` Ard Biesheuvel
2023-05-07 23:46 ` [PATCHv10 05/11] x86/boot/compressed: Handle " Kirill A. Shutemov
2023-05-08 7:31 ` Ard Biesheuvel
2023-05-07 23:46 ` Kirill A. Shutemov [this message]
2023-05-07 23:46 ` [PATCHv10 07/11] x86/mm: Provide helpers for " Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 08/11] x86/mm: Avoid load_unaligned_zeropad() stepping into " Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 09/11] x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 10/11] x86/tdx: Refactor try_accept_one() Kirill A. Shutemov
2023-05-07 23:46 ` [PATCHv10 11/11] x86/tdx: Add unaccepted memory support Kirill A. Shutemov
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=20230507234618.18067-7-kirill.shutemov@linux.intel.com \
--to=kirill.shutemov@linux.intel.com \
--cc=aarcange@redhat.com \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=david@redhat.com \
--cc=dfaggioli@suse.com \
--cc=jroedel@suse.de \
--cc=khalid.elmously@canonical.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=marcelo.cerri@canonical.com \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=philip.cox@canonical.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=rppt@linux.ibm.com \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--cc=tim.gardner@canonical.com \
--cc=vbabka@suse.cz \
--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