linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrey Ryabinin <arbn@yandex-team.com>
To: linux-kernel@vger.kernel.org
Cc: Alexander Graf <graf@amazon.com>,
	James Gowans <jgowans@amazon.com>,
	Mike Rapoport <rppt@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	Eric Biederman <ebiederm@xmission.com>,
	kexec@lists.infradead.org, Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	linux-trace-kernel@vger.kernel.org, valesini@yandex-team.com,
	Andrey Ryabinin <arbn@yandex-team.com>
Subject: [RFC PATCH 4/7] mm/memblock: Add MEMBLOCK_PRSRV flag
Date: Wed,  2 Oct 2024 18:07:19 +0200	[thread overview]
Message-ID: <20241002160722.20025-5-arbn@yandex-team.com> (raw)
In-Reply-To: <20241002160722.20025-1-arbn@yandex-team.com>

Add MEMBLOCK_PRSRV flag indicating that we don't need to initialize
'struct page' at all. The flag will be used in the following patches
to mark memory intended to be kept intact across kexec.
The 'struct page' for such region assumed to be initialized by the old
kernel, so the new one shouldn't touch it.

This is only initial RFC sketch, in which we assume that 'struct page'
layout doens't change between old and new kernel. The proper solution
would require some form of migration from old 'struct page' to the new
one if layout did change.

Signed-off-by: Andrey Ryabinin <arbn@yandex-team.com>
---
 include/linux/memblock.h |  7 +++++++
 mm/memblock.c            |  9 ++++++++-
 mm/mm_init.c             | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 673d5cae7c813..b3c6029b03624 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -50,6 +50,7 @@ enum memblock_flags {
 	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
 	MEMBLOCK_DRIVER_MANAGED = 0x8,	/* always detected via a driver */
 	MEMBLOCK_RSRV_NOINIT	= 0x10,	/* don't initialize struct pages */
+	MEMBLOCK_PRSRV		= 0x20, /* struct page presreved during kexec, don't initialize */
 };
 
 /**
@@ -132,6 +133,7 @@ int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);
 int memblock_mark_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_clear_nomap(phys_addr_t base, phys_addr_t size);
 int memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t size);
+int memblock_reserved_mark_preserved(phys_addr_t base, phys_addr_t size);
 
 void memblock_free_all(void);
 void memblock_free(void *ptr, size_t size);
@@ -271,6 +273,11 @@ static inline bool memblock_is_reserved_noinit(struct memblock_region *m)
 	return m->flags & MEMBLOCK_RSRV_NOINIT;
 }
 
+static inline bool memblock_is_preserved(struct memblock_region *m)
+{
+	return m->flags & MEMBLOCK_PRSRV;
+}
+
 static inline bool memblock_is_driver_managed(struct memblock_region *m)
 {
 	return m->flags & MEMBLOCK_DRIVER_MANAGED;
diff --git a/mm/memblock.c b/mm/memblock.c
index 0389ce5cd281e..20ab3272cc166 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1048,6 +1048,12 @@ int __init_memblock memblock_reserved_mark_noinit(phys_addr_t base, phys_addr_t
 				    MEMBLOCK_RSRV_NOINIT);
 }
 
+int __init_memblock memblock_reserved_mark_preserved(phys_addr_t base, phys_addr_t size)
+{
+	return memblock_setclr_flag(&memblock.reserved, base, size, 1,
+				    MEMBLOCK_PRSRV);
+}
+
 static bool should_skip_region(struct memblock_type *type,
 			       struct memblock_region *m,
 			       int nid, int flags)
@@ -2181,7 +2187,8 @@ static void __init memmap_init_reserved_pages(void)
 	 * the MEMBLOCK_RSRV_NOINIT flag set
 	 */
 	for_each_reserved_mem_region(region) {
-		if (!memblock_is_reserved_noinit(region)) {
+		if (!memblock_is_reserved_noinit(region) &&
+			!memblock_is_preserved(region)) {
 			nid = memblock_get_region_node(region);
 			start = region->base;
 			end = start + region->size;
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 4ba5607aaf194..b82c13077928f 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -837,6 +837,22 @@ static void __init init_unavailable_range(unsigned long spfn,
 			node, zone_names[zone], pgcnt);
 }
 
+static bool pfn_preserved(unsigned long *pfn)
+{
+	struct memblock_region *r;
+
+	for_each_reserved_mem_region(r) {
+		if (memblock_is_preserved(r)) {
+			if (*pfn >= memblock_region_memory_base_pfn(r) &&
+				*pfn < memblock_region_memory_end_pfn(r)) {
+				*pfn = memblock_region_memory_end_pfn(r);
+				return true;
+			}
+		}
+	}
+	return false;
+}
+
 /*
  * Initially all pages are reserved - free ones are freed
  * up by memblock_free_all() once the early boot process is
@@ -889,6 +905,9 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone
 			}
 		}
 
+		if (pfn_preserved(&pfn))
+			continue;
+
 		page = pfn_to_page(pfn);
 		__init_single_page(page, pfn, zone, nid);
 		if (context == MEMINIT_HOTPLUG) {
-- 
2.45.2



  parent reply	other threads:[~2024-12-05 15:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 16:07 [RFC PATCH 0/7] KSTATE: a mechanism to migrate some part of the kernel state across kexec Andrey Ryabinin
2024-10-02 16:07 ` [RFC PATCH 1/7] kstate: Add kstate - a mechanism to migrate some " Andrey Ryabinin
2024-10-02 16:07 ` [RFC PATCH 2/7] kexec: Hack and abuse crashkernel for the kstate's migration stream Andrey Ryabinin
2024-10-02 16:07 ` [RFC PATCH 3/7] [hack] purgatory: disable purgatory verification Andrey Ryabinin
2024-10-02 16:07 ` Andrey Ryabinin [this message]
2024-10-02 16:07 ` [RFC PATCH 5/7] kstate: Add mechanism to preserved specified memory pages across kexec Andrey Ryabinin
2024-10-02 16:07 ` [RFC PATCH 6/7] kstate, test: add test module for testing kstate subsystem Andrey Ryabinin
2024-10-02 16:07 ` [RFC PATCH 7/7] trace: migrate trace buffers across kexec Andrey Ryabinin

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=20241002160722.20025-5-arbn@yandex-team.com \
    --to=arbn@yandex-team.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiederm@xmission.com \
    --cc=graf@amazon.com \
    --cc=hpa@zytor.com \
    --cc=jgowans@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=valesini@yandex-team.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