mbox series

[v2,00/15] init_mm: cleanup ARCH's text/data/brk setup code

Message ID 20210604070633.32363-1-wangkefeng.wang@huawei.com (mailing list archive)
Headers show
Series init_mm: cleanup ARCH's text/data/brk setup code | expand

Message

Kefeng Wang June 4, 2021, 7:06 a.m. UTC
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(-)

Comments

Mike Rapoport June 6, 2021, 9:29 p.m. UTC | #1
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
Kefeng Wang June 7, 2021, 12:55 a.m. UTC | #2
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
Christophe Leroy June 7, 2021, 5:48 a.m. UTC | #3
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
Kefeng Wang June 7, 2021, 8:30 a.m. UTC | #4
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
> .
>
Russell King (Oracle) June 7, 2021, 9:31 a.m. UTC | #5
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.