linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] um: initramfs doesn't work on uml
@ 2017-04-27  3:14 Masami Hiramatsu
  2017-04-27  3:15 ` [PATCH] um: Fix to call read_initrd after init_bootmem Masami Hiramatsu
  0 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2017-04-27  3:14 UTC (permalink / raw)
  To: Jeff Dike, Richard Weinberger
  Cc: Masami Hiramatsu, user-mode-linux-devel, linux-kernel

Hello,

I found that user-mode-linux kernel doesn't boot with initramfs
(or initrd) as below. I've investigated the reason and found that
the read_initrd@arch/um/kernel/initrd.c tried to allocate memory
for initrd by using alloc_bootmem, but since init_bootmem will
be called from setup_arch afterwards, that alloc_bootmem always
failed.

$ ./vmlinux.um initrd=./initramfs.um 
Core dump limits :
	soft - 0
	hard - NONE
Checking that ptrace can change system call numbers...OK
Checking syscall emulation patch for ptrace...OK
Checking advanced syscall emulation patch for ptrace...OK
Checking environment variables for a tempdir...none found
Checking if /dev/shm is on tmpfs...OK
Checking PROT_EXEC mmap in /dev/shm...OK
Adding 28401664 bytes to physical memory to account for exec-shield gap
kmsg_dump:
<1>[    0.000000] bootmem alloc of 1654667 bytes failed!
<0>[    0.000000] Kernel panic - not syncing: Out of memory
<4>[    0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 4.11.0-rc6-00200-gd5ff081 #1
<6>[    0.000000] Stack:
<4>[    0.000000]  60385e20 6006d399 00000000 6031d32b
<4>[    0.000000]  6009b81e 601c710b 60385e30 601bcb75
<4>[    0.000000]  60385f50 6009b5ec 0000002e 00000000
<6>[    0.000000] Call Trace:
<6>[    0.000000]  [<6009b81e>] ? 
<4>[    0.000000] printk+0x0/0x94
<6>[    0.000000]  [<60020fe0>] 
<4>[    0.000000] show_stack+0x108/0x15e
<6>[    0.000000]  [<6006d399>] ? 
<4>[    0.000000] dump_stack_print_info+0xe4/0xed
<6>[    0.000000]  [<6009b81e>] ? 
<4>[    0.000000] printk+0x0/0x94
<6>[    0.000000]  [<601c710b>] ? 
<4>[    0.000000] bust_spinlocks+0x0/0x3b
<6>[    0.000000]  [<601bcb75>] 
<4>[    0.000000] dump_stack+0x2a/0x2c
<6>[    0.000000]  [<6009b5ec>] 
<4>[    0.000000] panic+0x170/0x321
<6>[    0.000000]  [<6009b47c>] ? 
<4>[    0.000000] panic+0x0/0x321
<6>[    0.000000]  [<6009b81e>] ? 
<4>[    0.000000] printk+0x0/0x94
<6>[    0.000000]  [<60030aec>] ? 
<4>[    0.000000] os_file_size+0x27/0x12d
<6>[    0.000000]  [<6000de0c>] ? 
<4>[    0.000000] alloc_bootmem_core+0x2a/0x10b
<6>[    0.000000]  [<6000dde2>] ? 
<4>[    0.000000] alloc_bootmem_core+0x0/0x10b
<6>[    0.000000]  [<6000daab>] 
<4>[    0.000000] alloc_bootmem_bdata+0x0/0x337
<6>[    0.000000]  [<6000e456>] 
<4>[    0.000000] __alloc_bootmem+0x49/0x52
<6>[    0.000000]  [<600048d5>] 
<4>[    0.000000] read_initrd+0x77/0x132
<6>[    0.000000]  [<60022ada>] 
<4>[    0.000000] uml_finishsetup+0x42/0x59
<6>[    0.000000] 
Aborted

I've tried to make a patch to fix this issue by calling
read_initrd after init_bootmem in setup_arch, but not sure
that follows correctly the design of uml boot process.

Could anyone review that?

Thank you,

---

Masami Hiramatsu (1):
      um: Fix to call read_initrd after init_bootmem


 arch/um/kernel/initrd.c  |    4 +---
 arch/um/kernel/um_arch.c |    6 ++++++
 2 files changed, 7 insertions(+), 3 deletions(-)

--
Masami Hiramatsu <mhiramat@kernel.org>

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

* [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27  3:14 [BUG] um: initramfs doesn't work on uml Masami Hiramatsu
@ 2017-04-27  3:15 ` Masami Hiramatsu
  2017-04-27 13:53   ` Richard Weinberger
  2017-05-03 20:53   ` Richard Weinberger
  0 siblings, 2 replies; 7+ messages in thread
From: Masami Hiramatsu @ 2017-04-27  3:15 UTC (permalink / raw)
  To: Jeff Dike, Richard Weinberger
  Cc: Masami Hiramatsu, user-mode-linux-devel, linux-kernel

Since read_initrd() invokes alloc_bootmem() for allocating
memory to load initrd image, it must be called after init_bootmem.

This makes read_initrd() called directly from setup_arch()
after init_bootmem() and mem_total_pages().

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 arch/um/kernel/initrd.c  |    4 +---
 arch/um/kernel/um_arch.c |    6 ++++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/um/kernel/initrd.c b/arch/um/kernel/initrd.c
index 48bae81..6f6e789 100644
--- a/arch/um/kernel/initrd.c
+++ b/arch/um/kernel/initrd.c
@@ -14,7 +14,7 @@
 static char *initrd __initdata = NULL;
 static int load_initrd(char *filename, void *buf, int size);
 
-static int __init read_initrd(void)
+int __init read_initrd(void)
 {
 	void *area;
 	long long size;
@@ -46,8 +46,6 @@ static int __init read_initrd(void)
 	return 0;
 }
 
-__uml_postsetup(read_initrd);
-
 static int __init uml_initrd_setup(char *line, int *add)
 {
 	initrd = line;
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 4b85acd..64a1fd0 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -338,11 +338,17 @@ int __init linux_main(int argc, char **argv)
 	return start_uml();
 }
 
+int __init __weak read_initrd(void)
+{
+	return 0;
+}
+
 void __init setup_arch(char **cmdline_p)
 {
 	stack_protections((unsigned long) &init_thread_info);
 	setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
 	mem_total_pages(physmem_size, iomem_size, highmem);
+	read_initrd();
 
 	paging_init();
 	strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);

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

* Re: [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27  3:15 ` [PATCH] um: Fix to call read_initrd after init_bootmem Masami Hiramatsu
@ 2017-04-27 13:53   ` Richard Weinberger
  2017-04-27 22:04     ` Masami Hiramatsu
  2017-05-03 20:53   ` Richard Weinberger
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Weinberger @ 2017-04-27 13:53 UTC (permalink / raw)
  To: Masami Hiramatsu, Jeff Dike; +Cc: user-mode-linux-devel, linux-kernel

Masami,

Am 27.04.2017 um 05:15 schrieb Masami Hiramatsu:
> Since read_initrd() invokes alloc_bootmem() for allocating
> memory to load initrd image, it must be called after init_bootmem.
> 
> This makes read_initrd() called directly from setup_arch()
> after init_bootmem() and mem_total_pages().

Thanks for fixing this! Did you figure since when this is broken?
I think that should go into -stable.

Thanks,
//richard

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

* Re: [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27 13:53   ` Richard Weinberger
@ 2017-04-27 22:04     ` Masami Hiramatsu
  2017-04-27 22:40       ` Masami Hiramatsu
  0 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2017-04-27 22:04 UTC (permalink / raw)
  To: Richard Weinberger; +Cc: Jeff Dike, user-mode-linux-devel, linux-kernel

Hi Richard,

On Thu, 27 Apr 2017 15:53:25 +0200
Richard Weinberger <richard@nod.at> wrote:

> Masami,
> 
> Am 27.04.2017 um 05:15 schrieb Masami Hiramatsu:
> > Since read_initrd() invokes alloc_bootmem() for allocating
> > memory to load initrd image, it must be called after init_bootmem.
> > 
> > This makes read_initrd() called directly from setup_arch()
> > after init_bootmem() and mem_total_pages().
> 
> Thanks for fixing this! Did you figure since when this is broken?
> I think that should go into -stable.

Thank you for quick response!
As far as I can see, v4.9 kernel has this issue, but v4.4 is OK.
Let me bisect it.

Thank you,

> 
> Thanks,
> //richard


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27 22:04     ` Masami Hiramatsu
@ 2017-04-27 22:40       ` Masami Hiramatsu
  2017-04-27 22:43         ` Richard Weinberger
  0 siblings, 1 reply; 7+ messages in thread
From: Masami Hiramatsu @ 2017-04-27 22:40 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Masami Hiramatsu, Jeff Dike, user-mode-linux-devel, linux-kernel

On Fri, 28 Apr 2017 07:04:14 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Hi Richard,
> 
> On Thu, 27 Apr 2017 15:53:25 +0200
> Richard Weinberger <richard@nod.at> wrote:
> 
> > Masami,
> > 
> > Am 27.04.2017 um 05:15 schrieb Masami Hiramatsu:
> > > Since read_initrd() invokes alloc_bootmem() for allocating
> > > memory to load initrd image, it must be called after init_bootmem.
> > > 
> > > This makes read_initrd() called directly from setup_arch()
> > > after init_bootmem() and mem_total_pages().
> > 
> > Thanks for fixing this! Did you figure since when this is broken?
> > I think that should go into -stable.
> 
> Thank you for quick response!
> As far as I can see, v4.9 kernel has this issue, but v4.4 is OK.
> Let me bisect it.

Finally, git bisect shows that below commit caused this issue.

b63236972e1344b247750451e2be0a06cd125f21 is the first bad commit
commit b63236972e1344b247750451e2be0a06cd125f21
Author: Richard Weinberger <richard@nod.at>
Date:   Sun Jun 12 21:56:42 2016 +0200

    um: Setup physical memory in setup_arch()
    
    Currently UML sets up physical memory very early,
    long before setup_arch() was called by the kernel main
    function.
    This can cause problems when code paths in UML's memory setup
    code assume that the kernel is already running.
    i.e. when kmemleak is enabled it will evaluate current()
    in free_bootmem(). That early current() is undefined and
    UML explodes.
    
    Solve the problem by setting up physical memory in setup_arch(),
    at this stage the kernel has materialized and basic infrastructure
    such as current() works.
    
    Signed-off-by: Richard Weinberger <richard@nod.at>

:040000 040000 94b9403e37b4d14b54f801198af71aed66b07a30 641f2309b7badd723f1996f141aad962255dd689 M	arch

For the stable, any kernel later than v4.8 has this issue.

Thank you,

-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27 22:40       ` Masami Hiramatsu
@ 2017-04-27 22:43         ` Richard Weinberger
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2017-04-27 22:43 UTC (permalink / raw)
  To: Masami Hiramatsu; +Cc: Jeff Dike, user-mode-linux-devel, linux-kernel

Masami,

Am 28.04.2017 um 00:40 schrieb Masami Hiramatsu:
> Finally, git bisect shows that below commit caused this issue.
> 
> b63236972e1344b247750451e2be0a06cd125f21 is the first bad commit
> commit b63236972e1344b247750451e2be0a06cd125f21
> Author: Richard Weinberger <richard@nod.at>

Meh, it's always me. ;-)

> 
> For the stable, any kernel later than v4.8 has this issue.

Thanks,
//richard

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

* Re: [PATCH] um: Fix to call read_initrd after init_bootmem
  2017-04-27  3:15 ` [PATCH] um: Fix to call read_initrd after init_bootmem Masami Hiramatsu
  2017-04-27 13:53   ` Richard Weinberger
@ 2017-05-03 20:53   ` Richard Weinberger
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Weinberger @ 2017-05-03 20:53 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Jeff Dike, Richard Weinberger, user-mode-linux-devel, LKML

On Thu, Apr 27, 2017 at 5:15 AM, Masami Hiramatsu <mhiramat@kernel.org> wrote:
> Since read_initrd() invokes alloc_bootmem() for allocating
> memory to load initrd image, it must be called after init_bootmem.
>
> This makes read_initrd() called directly from setup_arch()
> after init_bootmem() and mem_total_pages().
>
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> ---
>  arch/um/kernel/initrd.c  |    4 +---
>  arch/um/kernel/um_arch.c |    6 ++++++
>  2 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/arch/um/kernel/initrd.c b/arch/um/kernel/initrd.c
> index 48bae81..6f6e789 100644
> --- a/arch/um/kernel/initrd.c
> +++ b/arch/um/kernel/initrd.c
> @@ -14,7 +14,7 @@
>  static char *initrd __initdata = NULL;
>  static int load_initrd(char *filename, void *buf, int size);
>
> -static int __init read_initrd(void)
> +int __init read_initrd(void)
>  {
>         void *area;
>         long long size;
> @@ -46,8 +46,6 @@ static int __init read_initrd(void)
>         return 0;
>  }
>
> -__uml_postsetup(read_initrd);
> -
>  static int __init uml_initrd_setup(char *line, int *add)
>  {
>         initrd = line;
> diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
> index 4b85acd..64a1fd0 100644
> --- a/arch/um/kernel/um_arch.c
> +++ b/arch/um/kernel/um_arch.c
> @@ -338,11 +338,17 @@ int __init linux_main(int argc, char **argv)
>         return start_uml();
>  }
>
> +int __init __weak read_initrd(void)
> +{
> +       return 0;
> +}
> +
>  void __init setup_arch(char **cmdline_p)
>  {
>         stack_protections((unsigned long) &init_thread_info);
>         setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
>         mem_total_pages(physmem_size, iomem_size, highmem);
> +       read_initrd();
>
>         paging_init();
>         strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
>

Applied.

-- 
Thanks,
//richard

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

end of thread, other threads:[~2017-05-03 20:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27  3:14 [BUG] um: initramfs doesn't work on uml Masami Hiramatsu
2017-04-27  3:15 ` [PATCH] um: Fix to call read_initrd after init_bootmem Masami Hiramatsu
2017-04-27 13:53   ` Richard Weinberger
2017-04-27 22:04     ` Masami Hiramatsu
2017-04-27 22:40       ` Masami Hiramatsu
2017-04-27 22:43         ` Richard Weinberger
2017-05-03 20:53   ` Richard Weinberger

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