linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
@ 2021-06-04  7:06 Kefeng Wang
  2021-06-04  7:06 ` [PATCH v2 01/15] mm: add setup_initial_init_mm() helper Kefeng Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Kefeng Wang @ 2021-06-04  7:06 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel
  Cc: linux-mm, Kefeng Wang, linux-snps-arc, linux-arm-kernel,
	linux-csky, uclinux-h8-devel, linux-m68k, openrisc, linuxppc-dev,
	linux-riscv, linux-sh, linux-s390

Add setup_initial_init_mm() helper, then use it
to cleanup the text, data and brk setup code.

v2:
- change argument from "char *" to "void *" setup_initial_init_mm()
  suggested by Geert Uytterhoeven
- use NULL instead of (void *)0 on h8300 and m68k
- collect ACKs

Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-csky@vger.kernel.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-m68k@lists.linux-m68k.org
Cc: openrisc@lists.librecores.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-riscv@lists.infradead.org
Cc: linux-sh@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Kefeng Wang (15):
  mm: add setup_initial_init_mm() helper
  arc: convert to setup_initial_init_mm()
  arm: convert to setup_initial_init_mm()
  arm64: convert to setup_initial_init_mm()
  csky: convert to setup_initial_init_mm()
  h8300: convert to setup_initial_init_mm()
  m68k: convert to setup_initial_init_mm()
  nds32: convert to setup_initial_init_mm()
  nios2: convert to setup_initial_init_mm()
  openrisc: convert to setup_initial_init_mm()
  powerpc: convert to setup_initial_init_mm()
  riscv: convert to setup_initial_init_mm()
  s390: convert to setup_initial_init_mm()
  sh: convert to setup_initial_init_mm()
  x86: convert to setup_initial_init_mm()

 arch/arc/mm/init.c                 | 5 +----
 arch/arm/kernel/setup.c            | 5 +----
 arch/arm64/kernel/setup.c          | 5 +----
 arch/csky/kernel/setup.c           | 5 +----
 arch/h8300/kernel/setup.c          | 5 +----
 arch/m68k/kernel/setup_mm.c        | 5 +----
 arch/m68k/kernel/setup_no.c        | 5 +----
 arch/nds32/kernel/setup.c          | 5 +----
 arch/nios2/kernel/setup.c          | 5 +----
 arch/openrisc/kernel/setup.c       | 5 +----
 arch/powerpc/kernel/setup-common.c | 5 +----
 arch/riscv/kernel/setup.c          | 5 +----
 arch/s390/kernel/setup.c           | 5 +----
 arch/sh/kernel/setup.c             | 5 +----
 arch/x86/kernel/setup.c            | 5 +----
 include/linux/mm_types.h           | 8 ++++++++
 16 files changed, 23 insertions(+), 60 deletions(-)

-- 
2.26.2


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

* [PATCH v2 01/15] mm: add setup_initial_init_mm() helper
  2021-06-04  7:06 [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Kefeng Wang
@ 2021-06-04  7:06 ` Kefeng Wang
  2021-06-06 21:31   ` Mike Rapoport
  2021-06-04  7:06 ` [PATCH v2 14/15] sh: convert to setup_initial_init_mm() Kefeng Wang
  2021-06-06 21:29 ` [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Mike Rapoport
  2 siblings, 1 reply; 11+ messages in thread
From: Kefeng Wang @ 2021-06-04  7:06 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel
  Cc: linux-mm, Kefeng Wang, linux-snps-arc, linux-arm-kernel,
	linux-csky, uclinux-h8-devel, linux-m68k, openrisc, linuxppc-dev,
	linux-riscv, linux-sh, linux-s390, x86

Add setup_initial_init_mm() helper to setup kernel text,
data and brk.

Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-csky@vger.kernel.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-m68k@lists.linux-m68k.org
Cc: openrisc@lists.librecores.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-riscv@lists.infradead.org
Cc: linux-sh@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: x86@kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 include/linux/mm_types.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 5aacc1c10a45..e1d2429089a4 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -572,6 +572,14 @@ struct mm_struct {
 };
 
 extern struct mm_struct init_mm;
+static inline void setup_initial_init_mm(void *start_code, void *end_code,
+					 void *end_data, void *brk)
+{
+	init_mm.start_code = (unsigned long)start_code;
+	init_mm.end_code = (unsigned long)end_code;
+	init_mm.end_data = (unsigned long)end_data;
+	init_mm.brk = (unsigned long)brk;
+}
 
 /* Pointer magic because the dynamic array size confuses some compilers. */
 static inline void mm_init_cpumask(struct mm_struct *mm)
-- 
2.26.2


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

* [PATCH v2 14/15] sh: convert to setup_initial_init_mm()
  2021-06-04  7:06 [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Kefeng Wang
  2021-06-04  7:06 ` [PATCH v2 01/15] mm: add setup_initial_init_mm() helper Kefeng Wang
@ 2021-06-04  7:06 ` Kefeng Wang
  2021-06-06 21:29 ` [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Mike Rapoport
  2 siblings, 0 replies; 11+ messages in thread
From: Kefeng Wang @ 2021-06-04  7:06 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel
  Cc: linux-mm, Kefeng Wang, Yoshinori Sato, Rich Felker, linux-sh

Use setup_initial_init_mm() helper to simplify code.

Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 arch/sh/kernel/setup.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index 4144be650d41..1fcb6659822a 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -294,10 +294,7 @@ void __init setup_arch(char **cmdline_p)
 
 	if (!MOUNT_ROOT_RDONLY)
 		root_mountflags &= ~MS_RDONLY;
-	init_mm.start_code = (unsigned long) _text;
-	init_mm.end_code = (unsigned long) _etext;
-	init_mm.end_data = (unsigned long) _edata;
-	init_mm.brk = (unsigned long) _end;
+	setup_initial_init_mm(_text, _etext, _edata, _end);
 
 	code_resource.start = virt_to_phys(_text);
 	code_resource.end = virt_to_phys(_etext)-1;
-- 
2.26.2


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

* Re: [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
  2021-06-04  7:06 [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Kefeng Wang
  2021-06-04  7:06 ` [PATCH v2 01/15] mm: add setup_initial_init_mm() helper Kefeng Wang
  2021-06-04  7:06 ` [PATCH v2 14/15] sh: convert to setup_initial_init_mm() Kefeng Wang
@ 2021-06-06 21:29 ` Mike Rapoport
  2021-06-07  0:55   ` Kefeng Wang
  2 siblings, 1 reply; 11+ messages in thread
From: Mike Rapoport @ 2021-06-06 21:29 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, linux-kernel, linux-mm, linux-snps-arc,
	linux-arm-kernel, linux-csky, uclinux-h8-devel, linux-m68k,
	openrisc, linuxppc-dev, linux-riscv, linux-sh, linux-s390

Hello Kefeng,

On Fri, Jun 04, 2021 at 03:06:18PM +0800, Kefeng Wang wrote:
> Add setup_initial_init_mm() helper, then use it
> to cleanup the text, data and brk setup code.
> 
> v2:
> - change argument from "char *" to "void *" setup_initial_init_mm()
>   suggested by Geert Uytterhoeven
> - use NULL instead of (void *)0 on h8300 and m68k
> - collect ACKs
> 
> Cc: linux-snps-arc@lists.infradead.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-csky@vger.kernel.org
> Cc: uclinux-h8-devel@lists.sourceforge.jp
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: openrisc@lists.librecores.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-sh@vger.kernel.org
> Cc: linux-s390@vger.kernel.org
> Kefeng Wang (15):
>   mm: add setup_initial_init_mm() helper
>   arc: convert to setup_initial_init_mm()
>   arm: convert to setup_initial_init_mm()
>   arm64: convert to setup_initial_init_mm()
>   csky: convert to setup_initial_init_mm()
>   h8300: convert to setup_initial_init_mm()
>   m68k: convert to setup_initial_init_mm()
>   nds32: convert to setup_initial_init_mm()
>   nios2: convert to setup_initial_init_mm()
>   openrisc: convert to setup_initial_init_mm()
>   powerpc: convert to setup_initial_init_mm()
>   riscv: convert to setup_initial_init_mm()
>   s390: convert to setup_initial_init_mm()
>   sh: convert to setup_initial_init_mm()
>   x86: convert to setup_initial_init_mm()

I might be missing something, but AFAIU the init_mm.start_code and other
fields are not used really early so the new setup_initial_init_mm()
function can be called in the generic code outside setup_arch(), e.g in
mm_init().
 
>  arch/arc/mm/init.c                 | 5 +----
>  arch/arm/kernel/setup.c            | 5 +----
>  arch/arm64/kernel/setup.c          | 5 +----
>  arch/csky/kernel/setup.c           | 5 +----
>  arch/h8300/kernel/setup.c          | 5 +----
>  arch/m68k/kernel/setup_mm.c        | 5 +----
>  arch/m68k/kernel/setup_no.c        | 5 +----
>  arch/nds32/kernel/setup.c          | 5 +----
>  arch/nios2/kernel/setup.c          | 5 +----
>  arch/openrisc/kernel/setup.c       | 5 +----
>  arch/powerpc/kernel/setup-common.c | 5 +----
>  arch/riscv/kernel/setup.c          | 5 +----
>  arch/s390/kernel/setup.c           | 5 +----
>  arch/sh/kernel/setup.c             | 5 +----
>  arch/x86/kernel/setup.c            | 5 +----
>  include/linux/mm_types.h           | 8 ++++++++
>  16 files changed, 23 insertions(+), 60 deletions(-)
> 
> -- 
> 2.26.2
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

-- 
Sincerely yours,
Mike.

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

* Re: [PATCH v2 01/15] mm: add setup_initial_init_mm() helper
  2021-06-04  7:06 ` [PATCH v2 01/15] mm: add setup_initial_init_mm() helper Kefeng Wang
@ 2021-06-06 21:31   ` Mike Rapoport
  2021-06-07  1:50     ` Kefeng Wang
  2021-06-07  2:36     ` [PATCH v3] " Kefeng Wang
  0 siblings, 2 replies; 11+ messages in thread
From: Mike Rapoport @ 2021-06-06 21:31 UTC (permalink / raw)
  To: Kefeng Wang
  Cc: Andrew Morton, linux-kernel, linux-mm, linux-snps-arc,
	linux-arm-kernel, linux-csky, uclinux-h8-devel, linux-m68k,
	openrisc, linuxppc-dev, linux-riscv, linux-sh, linux-s390, x86

Hello Kefeng,

On Fri, Jun 04, 2021 at 03:06:19PM +0800, Kefeng Wang wrote:
> Add setup_initial_init_mm() helper to setup kernel text,
> data and brk.
> 
> Cc: linux-snps-arc@lists.infradead.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-csky@vger.kernel.org
> Cc: uclinux-h8-devel@lists.sourceforge.jp
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: openrisc@lists.librecores.org
> Cc: linuxppc-dev@lists.ozlabs.org
> Cc: linux-riscv@lists.infradead.org
> Cc: linux-sh@vger.kernel.org
> Cc: linux-s390@vger.kernel.org
> Cc: x86@kernel.org
> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
> ---
>  include/linux/mm_types.h | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 5aacc1c10a45..e1d2429089a4 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -572,6 +572,14 @@ struct mm_struct {
>  };
>  
>  extern struct mm_struct init_mm;
> +static inline void setup_initial_init_mm(void *start_code, void *end_code,
> +					 void *end_data, void *brk)

I think it's not that performance sensitive to make it inline. It can be
placed in mm/init-mm.c with a forward declaration in mm.h

> +{
> +	init_mm.start_code = (unsigned long)start_code;
> +	init_mm.end_code = (unsigned long)end_code;
> +	init_mm.end_data = (unsigned long)end_data;
> +	init_mm.brk = (unsigned long)brk;
> +}
  
>  /* Pointer magic because the dynamic array size confuses some compilers. */
>  static inline void mm_init_cpumask(struct mm_struct *mm)
> -- 
> 2.26.2
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

-- 
Sincerely yours,
Mike.

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

* Re: [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
  2021-06-06 21:29 ` [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Mike Rapoport
@ 2021-06-07  0:55   ` Kefeng Wang
  2021-06-07  5:48     ` Christophe Leroy
  0 siblings, 1 reply; 11+ messages in thread
From: Kefeng Wang @ 2021-06-07  0:55 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, linux-kernel, linux-mm, linux-snps-arc,
	linux-arm-kernel, linux-csky, uclinux-h8-devel, linux-m68k,
	openrisc, linuxppc-dev, linux-riscv, linux-sh, linux-s390


On 2021/6/7 5:29, Mike Rapoport wrote:
> Hello Kefeng,
>
> On Fri, Jun 04, 2021 at 03:06:18PM +0800, Kefeng Wang wrote:
>> Add setup_initial_init_mm() helper, then use it
>> to cleanup the text, data and brk setup code.
>>
>> v2:
>> - change argument from "char *" to "void *" setup_initial_init_mm()
>>    suggested by Geert Uytterhoeven
>> - use NULL instead of (void *)0 on h8300 and m68k
>> - collect ACKs
>>
>> Cc: linux-snps-arc@lists.infradead.org
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-csky@vger.kernel.org
>> Cc: uclinux-h8-devel@lists.sourceforge.jp
>> Cc: linux-m68k@lists.linux-m68k.org
>> Cc: openrisc@lists.librecores.org
>> Cc: linuxppc-dev@lists.ozlabs.org
>> Cc: linux-riscv@lists.infradead.org
>> Cc: linux-sh@vger.kernel.org
>> Cc: linux-s390@vger.kernel.org
>> Kefeng Wang (15):
>>    mm: add setup_initial_init_mm() helper
>>    arc: convert to setup_initial_init_mm()
>>    arm: convert to setup_initial_init_mm()
>>    arm64: convert to setup_initial_init_mm()
>>    csky: convert to setup_initial_init_mm()
>>    h8300: convert to setup_initial_init_mm()
>>    m68k: convert to setup_initial_init_mm()
>>    nds32: convert to setup_initial_init_mm()
>>    nios2: convert to setup_initial_init_mm()
>>    openrisc: convert to setup_initial_init_mm()
>>    powerpc: convert to setup_initial_init_mm()
>>    riscv: convert to setup_initial_init_mm()
>>    s390: convert to setup_initial_init_mm()
>>    sh: convert to setup_initial_init_mm()
>>    x86: convert to setup_initial_init_mm()
> I might be missing something, but AFAIU the init_mm.start_code and other
> fields are not used really early so the new setup_initial_init_mm()
> function can be called in the generic code outside setup_arch(), e.g in
> mm_init().

Hi Mike, each architecture has their own value, not the same, eg m68K and

h8300, also the name of the text/code/brk is different in some arch, so 
I keep

unchanged.

>   
>>   arch/arc/mm/init.c                 | 5 +----
>>   arch/arm/kernel/setup.c            | 5 +----
>>   arch/arm64/kernel/setup.c          | 5 +----
>>   arch/csky/kernel/setup.c           | 5 +----
>>   arch/h8300/kernel/setup.c          | 5 +----
>>   arch/m68k/kernel/setup_mm.c        | 5 +----
>>   arch/m68k/kernel/setup_no.c        | 5 +----
>>   arch/nds32/kernel/setup.c          | 5 +----
>>   arch/nios2/kernel/setup.c          | 5 +----
>>   arch/openrisc/kernel/setup.c       | 5 +----
>>   arch/powerpc/kernel/setup-common.c | 5 +----
>>   arch/riscv/kernel/setup.c          | 5 +----
>>   arch/s390/kernel/setup.c           | 5 +----
>>   arch/sh/kernel/setup.c             | 5 +----
>>   arch/x86/kernel/setup.c            | 5 +----
>>   include/linux/mm_types.h           | 8 ++++++++
>>   16 files changed, 23 insertions(+), 60 deletions(-)
>>
>> -- 
>> 2.26.2
>>
>>
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* Re: [PATCH v2 01/15] mm: add setup_initial_init_mm() helper
  2021-06-06 21:31   ` Mike Rapoport
@ 2021-06-07  1:50     ` Kefeng Wang
  2021-06-07  2:36     ` [PATCH v3] " Kefeng Wang
  1 sibling, 0 replies; 11+ messages in thread
From: Kefeng Wang @ 2021-06-07  1:50 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Andrew Morton, linux-kernel, linux-mm, linux-snps-arc,
	linux-arm-kernel, linux-csky, uclinux-h8-devel, linux-m68k,
	openrisc, linuxppc-dev, linux-riscv, linux-sh, linux-s390, x86


On 2021/6/7 5:31, Mike Rapoport wrote:
> Hello Kefeng,
>
> On Fri, Jun 04, 2021 at 03:06:19PM +0800, Kefeng Wang wrote:
>> Add setup_initial_init_mm() helper to setup kernel text,
>> data and brk.
>>
>> Cc: linux-snps-arc@lists.infradead.org
>> Cc: linux-arm-kernel@lists.infradead.org
>> Cc: linux-csky@vger.kernel.org
>> Cc: uclinux-h8-devel@lists.sourceforge.jp
>> Cc: linux-m68k@lists.linux-m68k.org
>> Cc: openrisc@lists.librecores.org
>> Cc: linuxppc-dev@lists.ozlabs.org
>> Cc: linux-riscv@lists.infradead.org
>> Cc: linux-sh@vger.kernel.org
>> Cc: linux-s390@vger.kernel.org
>> Cc: x86@kernel.org
>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
>> ---
>>   include/linux/mm_types.h | 8 ++++++++
>>   1 file changed, 8 insertions(+)
>>
>> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
>> index 5aacc1c10a45..e1d2429089a4 100644
>> --- a/include/linux/mm_types.h
>> +++ b/include/linux/mm_types.h
>> @@ -572,6 +572,14 @@ struct mm_struct {
>>   };
>>   
>>   extern struct mm_struct init_mm;
>> +static inline void setup_initial_init_mm(void *start_code, void *end_code,
>> +					 void *end_data, void *brk)
> I think it's not that performance sensitive to make it inline. It can be
> placed in mm/init-mm.c with a forward declaration in mm.h

Ok, I will send a update one with this change.

>
>> +{
>> +	init_mm.start_code = (unsigned long)start_code;
>> +	init_mm.end_code = (unsigned long)end_code;
>> +	init_mm.end_data = (unsigned long)end_data;
>> +	init_mm.brk = (unsigned long)brk;
>> +}
>    
>>   /* Pointer magic because the dynamic array size confuses some compilers. */
>>   static inline void mm_init_cpumask(struct mm_struct *mm)
>> -- 
>> 2.26.2
>>
>>
>> _______________________________________________
>> linux-riscv mailing list
>> linux-riscv@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv

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

* [PATCH v3] mm: add setup_initial_init_mm() helper
  2021-06-06 21:31   ` Mike Rapoport
  2021-06-07  1:50     ` Kefeng Wang
@ 2021-06-07  2:36     ` Kefeng Wang
  1 sibling, 0 replies; 11+ messages in thread
From: Kefeng Wang @ 2021-06-07  2:36 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel
  Cc: linux-mm, Kefeng Wang, linux-snps-arc, linux-arm-kernel,
	linux-csky, uclinux-h8-devel, linux-m68k, openrisc, linuxppc-dev,
	linux-riscv, linux-sh, linux-s390, x86

Add setup_initial_init_mm() helper to setup kernel text,
data and brk.

Cc: linux-snps-arc@lists.infradead.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-csky@vger.kernel.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-m68k@lists.linux-m68k.org
Cc: openrisc@lists.librecores.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-riscv@lists.infradead.org
Cc: linux-sh@vger.kernel.org
Cc: linux-s390@vger.kernel.org
Cc: x86@kernel.org
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
v3: declaration in mm.h, implemention in init-mm.c
 include/linux/mm.h | 3 +++
 mm/init-mm.c       | 9 +++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index c274f75efcf9..02aa057540b7 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -244,6 +244,9 @@ int __add_to_page_cache_locked(struct page *page, struct address_space *mapping,
 
 #define lru_to_page(head) (list_entry((head)->prev, struct page, lru))
 
+void setup_initial_init_mm(void *start_code, void *end_code,
+			   void *end_data, void *brk);
+
 /*
  * Linux kernel virtual memory manager primitives.
  * The idea being to have a "virtual" mm in the same way
diff --git a/mm/init-mm.c b/mm/init-mm.c
index 153162669f80..b4a6f38fb51d 100644
--- a/mm/init-mm.c
+++ b/mm/init-mm.c
@@ -40,3 +40,12 @@ struct mm_struct init_mm = {
 	.cpu_bitmap	= CPU_BITS_NONE,
 	INIT_MM_CONTEXT(init_mm)
 };
+
+void setup_initial_init_mm(void *start_code, void *end_code,
+			   void *end_data, void *brk)
+{
+	init_mm.start_code = (unsigned long)start_code;
+	init_mm.end_code = (unsigned long)end_code;
+	init_mm.end_data = (unsigned long)end_data;
+	init_mm.brk = (unsigned long)brk;
+}
-- 
2.26.2


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

* Re: [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
  2021-06-07  0:55   ` Kefeng Wang
@ 2021-06-07  5:48     ` Christophe Leroy
  2021-06-07  8:30       ` Kefeng Wang
  2021-06-07  9:31       ` Russell King (Oracle)
  0 siblings, 2 replies; 11+ messages in thread
From: Christophe Leroy @ 2021-06-07  5:48 UTC (permalink / raw)
  To: Kefeng Wang, Mike Rapoport
  Cc: uclinux-h8-devel, linux-s390, linux-sh, linux-kernel, linux-csky,
	linux-mm, linux-m68k, openrisc, Andrew Morton, linux-snps-arc,
	linuxppc-dev, linux-riscv, linux-arm-kernel

Hi Kefeng,

Le 07/06/2021 à 02:55, Kefeng Wang a écrit :
> 
> On 2021/6/7 5:29, Mike Rapoport wrote:
>> Hello Kefeng,
>>
>> On Fri, Jun 04, 2021 at 03:06:18PM +0800, Kefeng Wang wrote:
>>> Add setup_initial_init_mm() helper, then use it
>>> to cleanup the text, data and brk setup code.
>>>
>>> v2:
>>> - change argument from "char *" to "void *" setup_initial_init_mm()
>>>    suggested by Geert Uytterhoeven
>>> - use NULL instead of (void *)0 on h8300 and m68k
>>> - collect ACKs
>>>
>>> Cc: linux-snps-arc@lists.infradead.org
>>> Cc: linux-arm-kernel@lists.infradead.org
>>> Cc: linux-csky@vger.kernel.org
>>> Cc: uclinux-h8-devel@lists.sourceforge.jp
>>> Cc: linux-m68k@lists.linux-m68k.org
>>> Cc: openrisc@lists.librecores.org
>>> Cc: linuxppc-dev@lists.ozlabs.org
>>> Cc: linux-riscv@lists.infradead.org
>>> Cc: linux-sh@vger.kernel.org
>>> Cc: linux-s390@vger.kernel.org
>>> Kefeng Wang (15):
>>>    mm: add setup_initial_init_mm() helper
>>>    arc: convert to setup_initial_init_mm()
>>>    arm: convert to setup_initial_init_mm()
>>>    arm64: convert to setup_initial_init_mm()
>>>    csky: convert to setup_initial_init_mm()
>>>    h8300: convert to setup_initial_init_mm()
>>>    m68k: convert to setup_initial_init_mm()
>>>    nds32: convert to setup_initial_init_mm()
>>>    nios2: convert to setup_initial_init_mm()
>>>    openrisc: convert to setup_initial_init_mm()
>>>    powerpc: convert to setup_initial_init_mm()
>>>    riscv: convert to setup_initial_init_mm()
>>>    s390: convert to setup_initial_init_mm()
>>>    sh: convert to setup_initial_init_mm()
>>>    x86: convert to setup_initial_init_mm()
>> I might be missing something, but AFAIU the init_mm.start_code and other
>> fields are not used really early so the new setup_initial_init_mm()
>> function can be called in the generic code outside setup_arch(), e.g in
>> mm_init().
> 
> Hi Mike, each architecture has their own value, not the same, eg m68K and
> 
> h8300, also the name of the text/code/brk is different in some arch, so I keep
> 
> unchanged.

What you could do is to define a __weak function that architectures can override and call that 
function from mm_init() as suggested by Mike,

Something like:

void __weak setup_initial_init_mm(void)
{
	init_mm.start_code = (unsigned long)_stext;
	init_mm.end_code = (unsigned long)_etext;
	init_mm.end_data = (unsigned long)_edata;
	init_mm.brk = (unsigned long)_end;
}

Then only the few architecture that are different would override it.

I see a few archictectures are usigne PAGE_OFFSET to set .start_code, but it is likely that this is 
equivalent to _stext.

Christophe

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

* Re: [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
  2021-06-07  5:48     ` Christophe Leroy
@ 2021-06-07  8:30       ` Kefeng Wang
  2021-06-07  9:31       ` Russell King (Oracle)
  1 sibling, 0 replies; 11+ messages in thread
From: Kefeng Wang @ 2021-06-07  8:30 UTC (permalink / raw)
  To: Christophe Leroy, Mike Rapoport
  Cc: uclinux-h8-devel, linux-s390, linux-sh, linux-kernel, linux-csky,
	linux-mm, linux-m68k, openrisc, Andrew Morton, linux-snps-arc,
	linuxppc-dev, linux-riscv, linux-arm-kernel


On 2021/6/7 13:48, Christophe Leroy wrote:
> Hi Kefeng,
>
> Le 07/06/2021 à 02:55, Kefeng Wang a écrit :
>>
>> On 2021/6/7 5:29, Mike Rapoport wrote:
>>> Hello Kefeng,
>>>
>>> On Fri, Jun 04, 2021 at 03:06:18PM +0800, Kefeng Wang wrote:
>>>> Add setup_initial_init_mm() helper, then use it
>>>> to cleanup the text, data and brk setup code.
>>>>
>>>> v2:
>>>> - change argument from "char *" to "void *" setup_initial_init_mm()
>>>>    suggested by Geert Uytterhoeven
>>>> - use NULL instead of (void *)0 on h8300 and m68k
>>>> - collect ACKs
>>>>
>>>> Cc: linux-snps-arc@lists.infradead.org
>>>> Cc: linux-arm-kernel@lists.infradead.org
>>>> Cc: linux-csky@vger.kernel.org
>>>> Cc: uclinux-h8-devel@lists.sourceforge.jp
>>>> Cc: linux-m68k@lists.linux-m68k.org
>>>> Cc: openrisc@lists.librecores.org
>>>> Cc: linuxppc-dev@lists.ozlabs.org
>>>> Cc: linux-riscv@lists.infradead.org
>>>> Cc: linux-sh@vger.kernel.org
>>>> Cc: linux-s390@vger.kernel.org
>>>> Kefeng Wang (15):
>>>>    mm: add setup_initial_init_mm() helper
>>>>    arc: convert to setup_initial_init_mm()
>>>>    arm: convert to setup_initial_init_mm()
>>>>    arm64: convert to setup_initial_init_mm()
>>>>    csky: convert to setup_initial_init_mm()
>>>>    h8300: convert to setup_initial_init_mm()
>>>>    m68k: convert to setup_initial_init_mm()
>>>>    nds32: convert to setup_initial_init_mm()
>>>>    nios2: convert to setup_initial_init_mm()
>>>>    openrisc: convert to setup_initial_init_mm()
>>>>    powerpc: convert to setup_initial_init_mm()
>>>>    riscv: convert to setup_initial_init_mm()
>>>>    s390: convert to setup_initial_init_mm()
>>>>    sh: convert to setup_initial_init_mm()
>>>>    x86: convert to setup_initial_init_mm()
>>> I might be missing something, but AFAIU the init_mm.start_code and 
>>> other
>>> fields are not used really early so the new setup_initial_init_mm()
>>> function can be called in the generic code outside setup_arch(), e.g in
>>> mm_init().
>>
>> Hi Mike, each architecture has their own value, not the same, eg m68K 
>> and
>>
>> h8300, also the name of the text/code/brk is different in some arch, 
>> so I keep
>>
>> unchanged.
>
> What you could do is to define a __weak function that architectures 
> can override and call that function from mm_init() as suggested by Mike,
>
> Something like:
>
> void __weak setup_initial_init_mm(void)
> {
>     init_mm.start_code = (unsigned long)_stext;
>     init_mm.end_code = (unsigned long)_etext;
>     init_mm.end_data = (unsigned long)_edata;
>     init_mm.brk = (unsigned long)_end;
> }
>
> Then only the few architecture that are different would override it.
>
> I see a few archictectures are usigne PAGE_OFFSET to set .start_code, 
> but it is likely that this is equivalent to _stext.


Yes,  the __weak function is option, but the change is only covered 14 
archs, there are 7 other archs(alpha  hexagon  ia64

microblaze  mips sparc  um xtensa)without related setup code. Also like 
x86, it has own brk , maybe there are some

other different in some arch, so I think let's keep unchanged for now,  
thanks.

>
> Christophe
> .
>

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

* Re: [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code
  2021-06-07  5:48     ` Christophe Leroy
  2021-06-07  8:30       ` Kefeng Wang
@ 2021-06-07  9:31       ` Russell King (Oracle)
  1 sibling, 0 replies; 11+ messages in thread
From: Russell King (Oracle) @ 2021-06-07  9:31 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: Kefeng Wang, Mike Rapoport, uclinux-h8-devel, linux-s390,
	linux-sh, linux-kernel, linux-csky, linux-mm, linux-m68k,
	openrisc, Andrew Morton, linux-snps-arc, linuxppc-dev,
	linux-riscv, linux-arm-kernel

On Mon, Jun 07, 2021 at 07:48:54AM +0200, Christophe Leroy wrote:
> Hi Kefeng,
> 
> What you could do is to define a __weak function that architectures can
> override and call that function from mm_init() as suggested by Mike,

The problem with weak functions is that they bloat the kernel. Each
time a weak function is overriden, it becomes dead unreachable code
within the kernel image.

At some point we're probabily going to have to enable -ffunction-sections
to (hopefully) allow the dead code to be discarded.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

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

end of thread, other threads:[~2021-06-07  9:31 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04  7:06 [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Kefeng Wang
2021-06-04  7:06 ` [PATCH v2 01/15] mm: add setup_initial_init_mm() helper Kefeng Wang
2021-06-06 21:31   ` Mike Rapoport
2021-06-07  1:50     ` Kefeng Wang
2021-06-07  2:36     ` [PATCH v3] " Kefeng Wang
2021-06-04  7:06 ` [PATCH v2 14/15] sh: convert to setup_initial_init_mm() Kefeng Wang
2021-06-06 21:29 ` [PATCH v2 00/15] init_mm: cleanup ARCH's text/data/brk setup code Mike Rapoport
2021-06-07  0:55   ` Kefeng Wang
2021-06-07  5:48     ` Christophe Leroy
2021-06-07  8:30       ` Kefeng Wang
2021-06-07  9:31       ` Russell King (Oracle)

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).