Tiezhu Yang (3):
MIPS: Return -EINVAL if mem parameter is empty in early_parse_mem()
MIPS: Return -EINVAL if mem parameter is invalid in early_parse_mem()
MIPS: Use memblock_add_node() in early_parse_mem() under CONFIG_NUMA
arch/mips/kernel/setup.c | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
--
2.1.0
In the current code, the users usually need to make sure the value
of mem parameter is correct, but it is better to do some check to
avoid potential boot hangs.
This commit checks whether mem parameter is empty, if yes, return
-EINVAL before call memblock_remove() and memblock_add().
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/mips/kernel/setup.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index f979adf..14aa8bd 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -344,6 +344,11 @@ static int __init early_parse_mem(char *p)
{
phys_addr_t start, size;
+ if (!p) {
+ pr_err("mem parameter is empty, do nothing\n");
+ return -EINVAL;
+ }
+
/*
* If a user specifies memory size, we
* blow away any automatically generated
--
2.1.0
In the current code, the users usually need to make sure the value
of mem parameter is correct, but it is better to do some check to
avoid potential boot hangs.
This commit checks whether the first mem parameter is invalid, if
yes, return -EINVAL before call memblock_remove() and memblock_add().
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/mips/kernel/setup.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 14aa8bd..c8c8f60 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -343,12 +343,19 @@ static int usermem __initdata;
static int __init early_parse_mem(char *p)
{
phys_addr_t start, size;
+ phys_addr_t pa_start, pa_end;
+ u64 idx;
if (!p) {
pr_err("mem parameter is empty, do nothing\n");
return -EINVAL;
}
+ start = 0;
+ size = memparse(p, &p);
+ if (*p == '@')
+ start = memparse(p + 1, &p);
+
/*
* If a user specifies memory size, we
* blow away any automatically generated
@@ -356,13 +363,20 @@ static int __init early_parse_mem(char *p)
*/
if (usermem == 0) {
usermem = 1;
+ for_each_mem_range(idx, &pa_start, &pa_end) {
+ if (start >= pa_start && size <= pa_end - pa_start)
+ break;
+
+ if (idx < memblock.memory.cnt)
+ continue;
+
+ usermem = -1;
+ pr_err("mem parameter is invalid, do nothing\n");
+ return -EINVAL;
+ }
memblock_remove(memblock_start_of_DRAM(),
memblock_end_of_DRAM() - memblock_start_of_DRAM());
}
- start = 0;
- size = memparse(p, &p);
- if (*p == '@')
- start = memparse(p + 1, &p);
memblock_add(start, size);
@@ -638,7 +652,7 @@ static void __init arch_mem_init(char **cmdline_p)
parse_early_param();
- if (usermem)
+ if (usermem == 1)
pr_info("User-defined physical RAM map overwrite\n");
check_kernel_sections_mem();
--
2.1.0
On 03/18/2022 11:05 PM, Tiezhu Yang wrote:
> Tiezhu Yang (3):
> MIPS: Return -EINVAL if mem parameter is empty in early_parse_mem()
> MIPS: Return -EINVAL if mem parameter is invalid in early_parse_mem()
> MIPS: Use memblock_add_node() in early_parse_mem() under CONFIG_NUMA
>
> arch/mips/kernel/setup.c | 35 +++++++++++++++++++++++++++++------
> 1 file changed, 29 insertions(+), 6 deletions(-)
>
Hi Thomas,
Any comments? Are you OK with these changes?
https://lore.kernel.org/linux-mips/[email protected]/T/#u
Thanks,
Tiezhu
On Mon, May 09, 2022 at 03:30:11PM +0800, Tiezhu Yang wrote:
>
>
> On 03/18/2022 11:05 PM, Tiezhu Yang wrote:
> > Tiezhu Yang (3):
> > MIPS: Return -EINVAL if mem parameter is empty in early_parse_mem()
> > MIPS: Return -EINVAL if mem parameter is invalid in early_parse_mem()
> > MIPS: Use memblock_add_node() in early_parse_mem() under CONFIG_NUMA
> >
> > arch/mips/kernel/setup.c | 35 +++++++++++++++++++++++++++++------
> > 1 file changed, 29 insertions(+), 6 deletions(-)
> >
>
> Hi Thomas,
>
> Any comments? Are you OK with these changes?
first and last patch are ok with me. The second patch changes semantics
for mem=, which I don't want to change. Iirc the latest idea to solve
your problem was to use mem=XX@ syntax to limit detected memory, which
is the preferred way for me, too.
If you want I'll take patch 1 and 3 out of this series.
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
On 05/23/2022 09:28 PM, Thomas Bogendoerfer wrote:
> On Mon, May 09, 2022 at 03:30:11PM +0800, Tiezhu Yang wrote:
>>
>>
>> On 03/18/2022 11:05 PM, Tiezhu Yang wrote:
>>> Tiezhu Yang (3):
>>> MIPS: Return -EINVAL if mem parameter is empty in early_parse_mem()
>>> MIPS: Return -EINVAL if mem parameter is invalid in early_parse_mem()
>>> MIPS: Use memblock_add_node() in early_parse_mem() under CONFIG_NUMA
>>>
>>> arch/mips/kernel/setup.c | 35 +++++++++++++++++++++++++++++------
>>> 1 file changed, 29 insertions(+), 6 deletions(-)
>>>
>>
>> Hi Thomas,
>>
>> Any comments? Are you OK with these changes?
>
> first and last patch are ok with me. The second patch changes semantics
> for mem=, which I don't want to change. Iirc the latest idea to solve
> your problem was to use mem=XX@ syntax to limit detected memory, which
> is the preferred way for me, too.
>
> If you want I'll take patch 1 and 3 out of this series.
>
> Thomas.
>
OK, thank you.
Let me rebase and send v2 later.
Thanks,
Tiezhu