linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
@ 2024-06-24 12:37 Yunhui Cui
  2024-07-03 21:37 ` Charlie Jenkins
  0 siblings, 1 reply; 6+ messages in thread
From: Yunhui Cui @ 2024-06-24 12:37 UTC (permalink / raw)
  To: charlie, rppt, paul.walmsley, palmer, aou, alexghiti, akpm, bhe,
	dawei.li, jszhang, namcao, chenjiahao16, bjorn, cuiyunhui,
	vishal.moola, linux-riscv, linux-kernel

Add parsing of 'memmap' to use or reserve a specific region of memory.

Implement the following memmap variants:
- memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
- memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
 arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index e3405e4b99af..8e1d93ae5cb2 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -208,6 +208,52 @@ static int __init early_mem(char *p)
 }
 early_param("mem", early_mem);
 
+static void __init parse_memmap_one(char *p)
+{
+	char *oldp;
+	unsigned long start_at, mem_size;
+
+	if (!p)
+		return;
+
+	oldp = p;
+	mem_size = memparse(p, &p);
+	if (p == oldp)
+		return;
+
+	switch (*p) {
+	case '@':
+		start_at = memparse(p + 1, &p);
+		memblock_add(start_at, mem_size);
+		break;
+
+	case '$':
+		start_at = memparse(p + 1, &p);
+		memblock_reserve(start_at, mem_size);
+		break;
+
+	default:
+		pr_warn("Unrecognized memmap syntax: %s\n", p);
+		break;
+	}
+}
+
+static int __init parse_memmap_opt(char *str)
+{
+	while (str) {
+		char *k = strchr(str, ',');
+
+		if (k)
+			*k++ = 0;
+
+		parse_memmap_one(str);
+		str = k;
+	}
+
+	return 0;
+}
+early_param("memmap", parse_memmap_opt);
+
 static void __init setup_bootmem(void)
 {
 	phys_addr_t vmlinux_end = __pa_symbol(&_end);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
  2024-06-24 12:37 [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter Yunhui Cui
@ 2024-07-03 21:37 ` Charlie Jenkins
  2024-07-11  6:15   ` [External] " yunhui cui
  2024-07-22 21:13   ` Punit Agrawal
  0 siblings, 2 replies; 6+ messages in thread
From: Charlie Jenkins @ 2024-07-03 21:37 UTC (permalink / raw)
  To: Yunhui Cui
  Cc: rppt, paul.walmsley, palmer, aou, alexghiti, akpm, bhe, dawei.li,
	jszhang, namcao, chenjiahao16, bjorn, vishal.moola, linux-riscv,
	linux-kernel

On Mon, Jun 24, 2024 at 08:37:39PM +0800, Yunhui Cui wrote:
> Add parsing of 'memmap' to use or reserve a specific region of memory.
> 
> Implement the following memmap variants:
> - memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
> - memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;
> 
> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> ---
>  arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index e3405e4b99af..8e1d93ae5cb2 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -208,6 +208,52 @@ static int __init early_mem(char *p)
>  }
>  early_param("mem", early_mem);
>  
> +static void __init parse_memmap_one(char *p)
> +{
> +	char *oldp;
> +	unsigned long start_at, mem_size;
> +
> +	if (!p)
> +		return;
> +
> +	oldp = p;
> +	mem_size = memparse(p, &p);
> +	if (p == oldp)
> +		return;
> +
> +	switch (*p) {
> +	case '@':
> +		start_at = memparse(p + 1, &p);
> +		memblock_add(start_at, mem_size);
> +		break;
> +
> +	case '$':
> +		start_at = memparse(p + 1, &p);
> +		memblock_reserve(start_at, mem_size);
> +		break;
> +
> +	default:
> +		pr_warn("Unrecognized memmap syntax: %s\n", p);
> +		break;
> +	}
> +}
> +
> +static int __init parse_memmap_opt(char *str)
> +{
> +	while (str) {
> +		char *k = strchr(str, ',');
> +
> +		if (k)
> +			*k++ = 0;
> +
> +		parse_memmap_one(str);
> +		str = k;
> +	}
> +
> +	return 0;
> +}
> +early_param("memmap", parse_memmap_opt);
> +
>  static void __init setup_bootmem(void)
>  {
>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
> -- 
> 2.20.1
> 

Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [External] Re: [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
  2024-07-03 21:37 ` Charlie Jenkins
@ 2024-07-11  6:15   ` yunhui cui
  2024-07-22 21:13   ` Punit Agrawal
  1 sibling, 0 replies; 6+ messages in thread
From: yunhui cui @ 2024-07-11  6:15 UTC (permalink / raw)
  To: Charlie Jenkins
  Cc: rppt, paul.walmsley, palmer, aou, alexghiti, akpm, bhe, dawei.li,
	jszhang, namcao, chenjiahao16, bjorn, vishal.moola, linux-riscv,
	linux-kernel, punit.agrawal

Add punit in the loop.


On Thu, Jul 4, 2024 at 5:37 AM Charlie Jenkins <charlie@rivosinc.com> wrote:
>
> On Mon, Jun 24, 2024 at 08:37:39PM +0800, Yunhui Cui wrote:
> > Add parsing of 'memmap' to use or reserve a specific region of memory.
> >
> > Implement the following memmap variants:
> > - memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
> > - memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;
> >
> > Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> > ---
> >  arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 46 insertions(+)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index e3405e4b99af..8e1d93ae5cb2 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -208,6 +208,52 @@ static int __init early_mem(char *p)
> >  }
> >  early_param("mem", early_mem);
> >
> > +static void __init parse_memmap_one(char *p)
> > +{
> > +     char *oldp;
> > +     unsigned long start_at, mem_size;
> > +
> > +     if (!p)
> > +             return;
> > +
> > +     oldp = p;
> > +     mem_size = memparse(p, &p);
> > +     if (p == oldp)
> > +             return;
> > +
> > +     switch (*p) {
> > +     case '@':
> > +             start_at = memparse(p + 1, &p);
> > +             memblock_add(start_at, mem_size);
> > +             break;
> > +
> > +     case '$':
> > +             start_at = memparse(p + 1, &p);
> > +             memblock_reserve(start_at, mem_size);
> > +             break;
> > +
> > +     default:
> > +             pr_warn("Unrecognized memmap syntax: %s\n", p);
> > +             break;
> > +     }
> > +}
> > +
> > +static int __init parse_memmap_opt(char *str)
> > +{
> > +     while (str) {
> > +             char *k = strchr(str, ',');
> > +
> > +             if (k)
> > +                     *k++ = 0;
> > +
> > +             parse_memmap_one(str);
> > +             str = k;
> > +     }
> > +
> > +     return 0;
> > +}
> > +early_param("memmap", parse_memmap_opt);
> > +
> >  static void __init setup_bootmem(void)
> >  {
> >       phys_addr_t vmlinux_end = __pa_symbol(&_end);
> > --
> > 2.20.1
> >
>
> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
>

Thanks,
Yunhui

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
  2024-07-03 21:37 ` Charlie Jenkins
  2024-07-11  6:15   ` [External] " yunhui cui
@ 2024-07-22 21:13   ` Punit Agrawal
  2024-09-14  8:21     ` Palmer Dabbelt
  1 sibling, 1 reply; 6+ messages in thread
From: Punit Agrawal @ 2024-07-22 21:13 UTC (permalink / raw)
  To: palmer
  Cc: Yunhui Cui, rppt, paul.walmsley, aou, alexghiti, akpm, bhe,
	dawei.li, jszhang, namcao, chenjiahao16, bjorn, vishal.moola,
	linux-riscv, linux-kernel, Charlie Jenkins

Hi Palmer,

Charlie Jenkins <charlie@rivosinc.com> writes:

> On Mon, Jun 24, 2024 at 08:37:39PM +0800, Yunhui Cui wrote:
>> Add parsing of 'memmap' to use or reserve a specific region of memory.
>> 
>> Implement the following memmap variants:
>> - memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
>> - memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;
>> 
>> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>> ---
>>  arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 46 insertions(+)
>> 
>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>> index e3405e4b99af..8e1d93ae5cb2 100644
>> --- a/arch/riscv/mm/init.c
>> +++ b/arch/riscv/mm/init.c
>> @@ -208,6 +208,52 @@ static int __init early_mem(char *p)
>>  }
>>  early_param("mem", early_mem);
>>  
>> +static void __init parse_memmap_one(char *p)
>> +{
>> +	char *oldp;
>> +	unsigned long start_at, mem_size;
>> +
>> +	if (!p)
>> +		return;
>> +
>> +	oldp = p;
>> +	mem_size = memparse(p, &p);
>> +	if (p == oldp)
>> +		return;
>> +
>> +	switch (*p) {
>> +	case '@':
>> +		start_at = memparse(p + 1, &p);
>> +		memblock_add(start_at, mem_size);
>> +		break;
>> +
>> +	case '$':
>> +		start_at = memparse(p + 1, &p);
>> +		memblock_reserve(start_at, mem_size);
>> +		break;
>> +
>> +	default:
>> +		pr_warn("Unrecognized memmap syntax: %s\n", p);
>> +		break;
>> +	}
>> +}
>> +
>> +static int __init parse_memmap_opt(char *str)
>> +{
>> +	while (str) {
>> +		char *k = strchr(str, ',');
>> +
>> +		if (k)
>> +			*k++ = 0;
>> +
>> +		parse_memmap_one(str);
>> +		str = k;
>> +	}
>> +
>> +	return 0;
>> +}
>> +early_param("memmap", parse_memmap_opt);
>> +
>>  static void __init setup_bootmem(void)
>>  {
>>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
>> -- 
>> 2.20.1
>> 
>
> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>

Another patch that looks good to get merged if there are no further
comments.

Any chance this can be picked up for this cycle?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
  2024-07-22 21:13   ` Punit Agrawal
@ 2024-09-14  8:21     ` Palmer Dabbelt
  2024-09-18  3:27       ` [External] " yunhui cui
  0 siblings, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2024-09-14  8:21 UTC (permalink / raw)
  To: punit.agrawal
  Cc: cuiyunhui, rppt, Paul Walmsley, aou, alexghiti, akpm, bhe,
	dawei.li, jszhang, namcao, chenjiahao16, Bjorn Topel,
	vishal.moola, linux-riscv, linux-kernel, Charlie Jenkins

On Mon, 22 Jul 2024 14:13:14 PDT (-0700), punit.agrawal@bytedance.com wrote:
> Hi Palmer,
>
> Charlie Jenkins <charlie@rivosinc.com> writes:
>
>> On Mon, Jun 24, 2024 at 08:37:39PM +0800, Yunhui Cui wrote:
>>> Add parsing of 'memmap' to use or reserve a specific region of memory.
>>>
>>> Implement the following memmap variants:
>>> - memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
>>> - memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;
>>>
>>> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
>>> ---
>>>  arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
>>>  1 file changed, 46 insertions(+)
>>>
>>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
>>> index e3405e4b99af..8e1d93ae5cb2 100644
>>> --- a/arch/riscv/mm/init.c
>>> +++ b/arch/riscv/mm/init.c
>>> @@ -208,6 +208,52 @@ static int __init early_mem(char *p)
>>>  }
>>>  early_param("mem", early_mem);
>>>
>>> +static void __init parse_memmap_one(char *p)
>>> +{
>>> +	char *oldp;
>>> +	unsigned long start_at, mem_size;
>>> +
>>> +	if (!p)
>>> +		return;
>>> +
>>> +	oldp = p;
>>> +	mem_size = memparse(p, &p);
>>> +	if (p == oldp)
>>> +		return;
>>> +
>>> +	switch (*p) {
>>> +	case '@':
>>> +		start_at = memparse(p + 1, &p);
>>> +		memblock_add(start_at, mem_size);
>>> +		break;
>>> +
>>> +	case '$':
>>> +		start_at = memparse(p + 1, &p);
>>> +		memblock_reserve(start_at, mem_size);
>>> +		break;
>>> +
>>> +	default:
>>> +		pr_warn("Unrecognized memmap syntax: %s\n", p);
>>> +		break;
>>> +	}
>>> +}
>>> +
>>> +static int __init parse_memmap_opt(char *str)
>>> +{
>>> +	while (str) {
>>> +		char *k = strchr(str, ',');
>>> +
>>> +		if (k)
>>> +			*k++ = 0;
>>> +
>>> +		parse_memmap_one(str);
>>> +		str = k;
>>> +	}
>>> +
>>> +	return 0;
>>> +}
>>> +early_param("memmap", parse_memmap_opt);
>>> +
>>>  static void __init setup_bootmem(void)
>>>  {
>>>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
>>> --
>>> 2.20.1
>>>
>>
>> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
>
> Another patch that looks good to get merged if there are no further
> comments.
>
> Any chance this can be picked up for this cycle?

Sorry for being slow here, but I don't understand the use case for this: 
we already get the memory map from the firmware, it seems like 
overriding that is just asking for issues.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [External] Re: [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter
  2024-09-14  8:21     ` Palmer Dabbelt
@ 2024-09-18  3:27       ` yunhui cui
  0 siblings, 0 replies; 6+ messages in thread
From: yunhui cui @ 2024-09-18  3:27 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: punit.agrawal, rppt, Paul Walmsley, aou, alexghiti, akpm, bhe,
	dawei.li, jszhang, namcao, chenjiahao16, Bjorn Topel,
	vishal.moola, linux-riscv, linux-kernel, Charlie Jenkins

Hi Palmer,

On Sat, Sep 14, 2024 at 4:21 PM Palmer Dabbelt <palmer@dabbelt.com> wrote:
>
> On Mon, 22 Jul 2024 14:13:14 PDT (-0700), punit.agrawal@bytedance.com wrote:
> > Hi Palmer,
> >
> > Charlie Jenkins <charlie@rivosinc.com> writes:
> >
> >> On Mon, Jun 24, 2024 at 08:37:39PM +0800, Yunhui Cui wrote:
> >>> Add parsing of 'memmap' to use or reserve a specific region of memory.
> >>>
> >>> Implement the following memmap variants:
> >>> - memmap=nn[KMG]@ss[KMG]: force usage of a specific region of memory;
> >>> - memmap=nn[KMG]$ss[KMG]: mark specified memory as reserved;
> >>>
> >>> Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
> >>> ---
> >>>  arch/riscv/mm/init.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
> >>>  1 file changed, 46 insertions(+)
> >>>
> >>> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> >>> index e3405e4b99af..8e1d93ae5cb2 100644
> >>> --- a/arch/riscv/mm/init.c
> >>> +++ b/arch/riscv/mm/init.c
> >>> @@ -208,6 +208,52 @@ static int __init early_mem(char *p)
> >>>  }
> >>>  early_param("mem", early_mem);
> >>>
> >>> +static void __init parse_memmap_one(char *p)
> >>> +{
> >>> +   char *oldp;
> >>> +   unsigned long start_at, mem_size;
> >>> +
> >>> +   if (!p)
> >>> +           return;
> >>> +
> >>> +   oldp = p;
> >>> +   mem_size = memparse(p, &p);
> >>> +   if (p == oldp)
> >>> +           return;
> >>> +
> >>> +   switch (*p) {
> >>> +   case '@':
> >>> +           start_at = memparse(p + 1, &p);
> >>> +           memblock_add(start_at, mem_size);
> >>> +           break;
> >>> +
> >>> +   case '$':
> >>> +           start_at = memparse(p + 1, &p);
> >>> +           memblock_reserve(start_at, mem_size);
> >>> +           break;
> >>> +
> >>> +   default:
> >>> +           pr_warn("Unrecognized memmap syntax: %s\n", p);
> >>> +           break;
> >>> +   }
> >>> +}
> >>> +
> >>> +static int __init parse_memmap_opt(char *str)
> >>> +{
> >>> +   while (str) {
> >>> +           char *k = strchr(str, ',');
> >>> +
> >>> +           if (k)
> >>> +                   *k++ = 0;
> >>> +
> >>> +           parse_memmap_one(str);
> >>> +           str = k;
> >>> +   }
> >>> +
> >>> +   return 0;
> >>> +}
> >>> +early_param("memmap", parse_memmap_opt);
> >>> +
> >>>  static void __init setup_bootmem(void)
> >>>  {
> >>>     phys_addr_t vmlinux_end = __pa_symbol(&_end);
> >>> --
> >>> 2.20.1
> >>>
> >>
> >> Reviewed-by: Charlie Jenkins <charlie@rivosinc.com>
> >
> > Another patch that looks good to get merged if there are no further
> > comments.
> >
> > Any chance this can be picked up for this cycle?
>
> Sorry for being slow here, but I don't understand the use case for this:
> we already get the memory map from the firmware, it seems like
> overriding that is just asking for issues.

Without modifying the firmware, it is more convenient to complete the
reservation of the memory block in this way.
This parameter is also mentioned in Documentation/admin - guide/kernel
- parameters.txt.

Thanks,
Yunhui

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-09-18  3:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-24 12:37 [PATCH v2] RISC-V: cmdline: Add support for 'memmap' parameter Yunhui Cui
2024-07-03 21:37 ` Charlie Jenkins
2024-07-11  6:15   ` [External] " yunhui cui
2024-07-22 21:13   ` Punit Agrawal
2024-09-14  8:21     ` Palmer Dabbelt
2024-09-18  3:27       ` [External] " yunhui cui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).