From: Grzegorz Jaszczyk <jaszczyk@chromium.org>
To: tglx@linutronix.de, robh@kernel.org
Cc: mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
x86@kernel.org, hpa@zytor.com, saravanak@google.com,
dmaluka@chromium.org, bgrzesik@google.com, jaszczyk@google.com,
ilpo.jarvinen@linux.intel.com, usamaarif642@gmail.com,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
tnowicki@google.com, mazurekm@google.com, vineethrp@google.com
Subject: [PATCH v2 1/2] of: fdt: allow to register arch specific hook validating reserved region
Date: Fri, 18 Apr 2025 12:47:17 +0000 [thread overview]
Message-ID: <20250418124718.1009563-2-jaszczyk@chromium.org> (raw)
In-Reply-To: <20250418124718.1009563-1-jaszczyk@chromium.org>
From: Grzegorz Jaszczyk <jaszczyk@google.com>
Add a possibility to register arch specific hook which will validate if
reserved-memory region passed by DT is valid (e.g. in case of x86, which
allows to boot with both ACPI and DT at the same time, registered hook
will validate if reserved-memory region passed by DT is covered by E820
reserved region entry).
Signed-off-by: Grzegorz Jaszczyk <jaszczyk@google.com>
---
drivers/of/of_reserved_mem.c | 14 ++++++++++++++
include/linux/of_fdt.h | 4 ++++
2 files changed, 18 insertions(+)
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index ee2e31522d7e..bb66a019e3e2 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -27,6 +27,7 @@
#include "of_private.h"
+static bool __initdata (*arch_is_region_reserved)(phys_addr_t base, phys_addr_t size);
static struct reserved_mem reserved_mem_array[MAX_RESERVED_REGIONS] __initdata;
static struct reserved_mem *reserved_mem __refdata = reserved_mem_array;
static int total_reserved_mem_cnt = MAX_RESERVED_REGIONS;
@@ -131,6 +132,13 @@ static void __init fdt_reserved_mem_save_node(unsigned long node, const char *un
static int __init early_init_dt_reserve_memory(phys_addr_t base,
phys_addr_t size, bool nomap)
{
+ if (arch_is_region_reserved && !arch_is_region_reserved(base, size)) {
+ phys_addr_t end = base + size - 1;
+
+ pr_err("mem %pa-%pa not arch reserved\n", &base, &end);
+ return -EINVAL;
+ }
+
if (nomap) {
/*
* If the memory is already reserved (by another region), we
@@ -146,6 +154,12 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
return memblock_reserve(base, size);
}
+void __init early_init_set_rsv_region_verifier(bool (*is_mem_reserved)(phys_addr_t base,
+ phys_addr_t size))
+{
+ arch_is_region_reserved = is_mem_reserved;
+}
+
/*
* __reserved_mem_reserve_reg() - reserve all memory described in 'reg' property
*/
diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index b8d6c0c20876..c7769323e720 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -65,6 +65,8 @@ extern void early_init_dt_check_for_usable_mem_range(void);
extern int early_init_dt_scan_chosen_stdout(void);
extern void early_init_fdt_scan_reserved_mem(void);
extern void early_init_fdt_reserve_self(void);
+extern void early_init_set_rsv_region_verifier(bool (*is_mem_reserved)(phys_addr_t base,
+ phys_addr_t size));
extern void early_init_dt_add_memory_arch(u64 base, u64 size);
extern u64 dt_mem_next_cell(int s, const __be32 **cellp);
@@ -89,6 +91,8 @@ static inline void early_init_dt_check_for_usable_mem_range(void) {}
static inline int early_init_dt_scan_chosen_stdout(void) { return -ENODEV; }
static inline void early_init_fdt_scan_reserved_mem(void) {}
static inline void early_init_fdt_reserve_self(void) {}
+static inline void early_init_set_rsv_region_verifier(bool (*is_mem_reserved)(phys_addr_t base,
+ phys_addr_t size)) {};
static inline const char *of_flat_dt_get_machine_name(void) { return NULL; }
static inline void unflatten_device_tree(void) {}
static inline void unflatten_and_copy_device_tree(void) {}
--
2.49.0.805.g082f7c87e0-goog
next prev parent reply other threads:[~2025-04-18 12:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 12:47 [PATCH v2 0/2] x86: add support for reserved memory defined by DT Grzegorz Jaszczyk
2025-04-18 12:47 ` Grzegorz Jaszczyk [this message]
2025-04-18 12:47 ` [PATCH v2 2/2] x86/of: " Grzegorz Jaszczyk
2025-04-23 14:09 ` Rob Herring
2025-04-24 18:06 ` Grzegorz Jaszczyk
2025-04-25 19:18 ` Rob Herring
2025-04-30 8:55 ` Grzegorz Jaszczyk
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=20250418124718.1009563-2-jaszczyk@chromium.org \
--to=jaszczyk@chromium.org \
--cc=bgrzesik@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dmaluka@chromium.org \
--cc=hpa@zytor.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jaszczyk@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mazurekm@google.com \
--cc=mingo@redhat.com \
--cc=robh@kernel.org \
--cc=saravanak@google.com \
--cc=tglx@linutronix.de \
--cc=tnowicki@google.com \
--cc=usamaarif642@gmail.com \
--cc=vineethrp@google.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
all inboxes | Powered by JetHome®