lkml.org 
[lkml]   [2016]   [Dec]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 01/21] MIPS memblock: Unpin dts memblock sanity check method
Date
It's necessary to check whether retrieved from dts memory regions
fits to page alignment and limits restrictions. Sometimes it is
necessary to perform the same checks, but ito add the memory regions
into a different subsystem. MIPS is going to be that case.

Signed-off-by: Serge Semin <fancer.lancer@gmail.com>
---
drivers/of/fdt.c | 47 +++++++++++++++++++++++---------
include/linux/of_fdt.h | 1 +
2 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 1f98156..1ee958f 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -983,44 +983,65 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
#define MAX_MEMBLOCK_ADDR ((phys_addr_t)~0)
#endif

-void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+int __init sanity_check_dt_memory(phys_addr_t *out_base,
+ phys_addr_t *out_size)
{
+ phys_addr_t base = *out_base, size = *out_size;
const u64 phys_offset = MIN_MEMBLOCK_ADDR;

if (!PAGE_ALIGNED(base)) {
if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
- pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
+ pr_err("Memblock 0x%llx - 0x%llx isn't page aligned\n",
base, base + size);
- return;
+ return -EINVAL;
}
+ pr_warn("Memblock 0x%llx - 0x%llx shifted to ",
+ base, base + size);
size -= PAGE_SIZE - (base & ~PAGE_MASK);
base = PAGE_ALIGN(base);
+ pr_cont("0x%llx - 0x%llx\n", base, base + size);
}
size &= PAGE_MASK;

if (base > MAX_MEMBLOCK_ADDR) {
- pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
- base, base + size);
- return;
+ pr_err("Memblock 0x%llx - 0x%llx exceeds max address\n",
+ base, base + size);
+ return -EINVAL;
}

if (base + size - 1 > MAX_MEMBLOCK_ADDR) {
- pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
- ((u64)MAX_MEMBLOCK_ADDR) + 1, base + size);
+ pr_warn("Memblock 0x%llx - 0x%llx truncated to ",
+ base, base + size);
size = MAX_MEMBLOCK_ADDR - base + 1;
+ pr_cont("0x%llx - 0x%llx\n", base, base + size);
}

if (base + size < phys_offset) {
- pr_warning("Ignoring memory block 0x%llx - 0x%llx\n",
- base, base + size);
- return;
+ pr_err("Memblock 0x%llx - 0x%llx is below phys offset\n",
+ base, base + size);
+ return -EINVAL;
}
+
if (base < phys_offset) {
- pr_warning("Ignoring memory range 0x%llx - 0x%llx\n",
- base, phys_offset);
+ pr_warn("Memblock 0x%llx - 0x%llx truncated to ",
+ base, base + size);
size -= phys_offset - base;
base = phys_offset;
+ pr_cont("0x%llx - 0x%llx\n", base, base + size);
}
+
+ /* Set the output base address and size */
+ *out_base = base;
+ *out_size = size;
+
+ return 0;
+}
+
+void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
+{
+ if (sanity_check_dt_memory(&base, &size))
+ return;
+
memblock_add(base, size);
}

diff --git a/include/linux/of_fdt.h b/include/linux/of_fdt.h
index df9ef38..ddf93c5 100644
--- a/include/linux/of_fdt.h
+++ b/include/linux/of_fdt.h
@@ -84,6 +84,7 @@ extern const void *of_flat_dt_match_machine(const void *default_match,
const void * (*get_next_compat)(const char * const**));

/* Other Prototypes */
+extern int sanity_check_dt_memory(phys_addr_t *base, phys_addr_t *size);
extern void unflatten_device_tree(void);
extern void unflatten_and_copy_device_tree(void);
extern void early_init_devtree(void *);
--
2.6.6
\
 
 \ /
  Last update: 2016-12-19 03:27    [W:1.177 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site