From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net,
graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
masahiroy@kernel.org, ojeda@kernel.org,
pasha.tatashin@soleen.com, pratyush@kernel.org,
rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org,
jasonmiu@google.com, dmatlack@google.com, skhawaja@google.com
Subject: [PATCH v6 09/10] liveupdate: kho: Increase metadata bitmap size to PAGE_SIZE
Date: Sat, 18 Oct 2025 13:17:55 -0400 [thread overview]
Message-ID: <20251018171756.1724191-10-pasha.tatashin@soleen.com> (raw)
In-Reply-To: <20251018171756.1724191-1-pasha.tatashin@soleen.com>
Metadata is preserved via 512-bytes, which requires using slabs. Slabs
are not safe to be used with KHO because of kfence, and because partial
slabs may lead leaks to the next kernel. Change the size to be
PAGE_SIZE.
While this change could potentially increase metadata overhead on
systems with sparsely preserved memory, this is being mitigated by
ongoing work to reduce sparseness during preservation via 1G guest
pages. Furthermore, this change aligns with future work on a stateless
KHO, which will also use page-sized bitmaps for its radix tree metadata.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
kernel/liveupdate/kexec_handover.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index ebfc31814d16..7c8e89a6b953 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -67,10 +67,10 @@ early_param("kho", kho_parse_enable);
* Keep track of memory that is to be preserved across KHO.
*
* The serializing side uses two levels of xarrays to manage chunks of per-order
- * 512 byte bitmaps. For instance if PAGE_SIZE = 4096, the entire 1G order of a
- * 1TB system would fit inside a single 512 byte bitmap. For order 0 allocations
- * each bitmap will cover 16M of address space. Thus, for 16G of memory at most
- * 512K of bitmap memory will be needed for order 0.
+ * PAGE_SIZE byte bitmaps. For instance if PAGE_SIZE = 4096, the entire 1G order
+ * of a 8TB system would fit inside a single 4096 byte bitmap. For order 0
+ * allocations each bitmap will cover 128M of address space. Thus, for 16G of
+ * memory at most 512K of bitmap memory will be needed for order 0.
*
* This approach is fully incremental, as the serialization progresses folios
* can continue be aggregated to the tracker. The final step, immediately prior
@@ -78,12 +78,14 @@ early_param("kho", kho_parse_enable);
* successor kernel to parse.
*/
-#define PRESERVE_BITS (512 * 8)
+#define PRESERVE_BITS (PAGE_SIZE * 8)
struct kho_mem_phys_bits {
DECLARE_BITMAP(preserve, PRESERVE_BITS);
};
+static_assert(sizeof(struct kho_mem_phys_bits) == PAGE_SIZE);
+
struct kho_mem_phys {
/*
* Points to kho_mem_phys_bits, a sparse bitmap array. Each bit is sized
@@ -130,19 +132,19 @@ static struct kho_out kho_out = {
.finalized = false,
};
-static void *xa_load_or_alloc(struct xarray *xa, unsigned long index, size_t sz)
+static void *xa_load_or_alloc(struct xarray *xa, unsigned long index)
{
void *res = xa_load(xa, index);
if (res)
return res;
- void *elm __free(kfree) = kzalloc(sz, GFP_KERNEL);
+ void *elm __free(kfree) = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!elm)
return ERR_PTR(-ENOMEM);
- if (WARN_ON(kho_scratch_overlap(virt_to_phys(elm), sz)))
+ if (WARN_ON(kho_scratch_overlap(virt_to_phys(elm), PAGE_SIZE)))
return ERR_PTR(-EINVAL);
res = xa_cmpxchg(xa, index, NULL, elm, GFP_KERNEL);
@@ -222,8 +224,7 @@ static int __kho_preserve_order(struct kho_mem_track *track, unsigned long pfn,
}
}
- bits = xa_load_or_alloc(&physxa->phys_bits, pfn_high / PRESERVE_BITS,
- sizeof(*bits));
+ bits = xa_load_or_alloc(&physxa->phys_bits, pfn_high / PRESERVE_BITS);
if (IS_ERR(bits))
return PTR_ERR(bits);
--
2.51.0.915.g61a8936c21-goog
next prev parent reply other threads:[~2025-10-18 17:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-18 17:17 [PATCH v6 00/10] liveupdate: Rework KHO for in-kernel users & Fix memory corruption Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 01/10] kho: allow to drive kho from within kernel Pasha Tatashin
2025-10-20 7:43 ` Mike Rapoport
2025-10-21 16:08 ` Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 02/10] kho: make debugfs interface optional Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 03/10] kho: drop notifiers Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 04/10] kho: add interfaces to unpreserve folios and page ranes Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 05/10] kho: don't unpreserve memory during abort Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 06/10] liveupdate: kho: move to kernel/liveupdate Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 07/10] kho: move kho debugfs directory to liveupdate Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 08/10] liveupdate: kho: warn and fail on metadata or preserved memory in scratch area Pasha Tatashin
2025-10-20 7:56 ` Mike Rapoport
2025-10-20 21:56 ` Pasha Tatashin
2025-10-18 17:17 ` Pasha Tatashin [this message]
2025-10-20 8:03 ` [PATCH v6 09/10] liveupdate: kho: Increase metadata bitmap size to PAGE_SIZE Mike Rapoport
2025-10-20 22:09 ` Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 10/10] liveupdate: kho: allocate metadata directly from the buddy allocator Pasha Tatashin
2025-10-20 8:05 ` Mike Rapoport
2025-10-20 22:17 ` Pasha Tatashin
2025-10-20 8:34 ` [PATCH v6 00/10] liveupdate: Rework KHO for in-kernel users & Fix memory corruption Mike Rapoport
2025-10-20 13:46 ` Pasha Tatashin
2025-10-20 13:47 ` Pasha Tatashin
2025-10-20 18:12 ` Mike Rapoport
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=20251018171756.1724191-10-pasha.tatashin@soleen.com \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=masahiroy@kernel.org \
--cc=ojeda@kernel.org \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=skhawaja@google.com \
--cc=tj@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