All of lore.kernel.org
 help / color / mirror / Atom feed
* sparc32: Init process fails to load with generic kmap atomic
@ 2020-12-22 17:58 ` Andreas Larsson
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Larsson @ 2020-12-22 17:58 UTC (permalink / raw)
  To: Thomas Gleixner, sparclinux, linux-mm
  Cc: David S. Miller, Arnd Bergmann, linux-kernel, Sam Ravnborg


Unfortunately I did not see this problem before I encountered it in
master. Commit 3293efa9780712ad8504689e0c296d2bd33827d5

    sparc/mm/highmem: Switch to generic kmap atomic

     No reason having the same code in every architecture

     Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
     Cc: "David S. Miller" <davem@davemloft.net>
     Cc: Arnd Bergmann <arnd@arndb.de>
     Link: https://lore.kernel.org/r/20201103095858.197568209@linutronix.de

prevents the init process to be started for me on a sparc32 LEON. On the
commit before this it works. Details below from that commit but I get
the same behavior on current master.

 From as far as I have gotten into hunting down the problem, I get a
failure from load_elf_binary here:

	/* First of all, some simple consistency checks */
	if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0)
		goto out;

at least seemingly due to the kaddr from copy_page_to_iter in
lib/iov_iter.c

	if (i->type & (ITER_BVEC|ITER_KVEC)) {
		void *kaddr = kmap_atomic(page);
		size_t wanted = copy_to_iter(kaddr + offset, bytes, i);

where kaddr points to memory with all zeroes (from an earlier bzero) in 
this context:

#0  _copy_to_iter (addr=0xfcffe000, bytes=0x100, i=0xf201fd78)
                at lib/iov_iter.c:635
#1  copy_to_iter (i=0xf201fd78, bytes=0x1ce, addr=0xfcffe000)
                at include/linux/uio.h:137
#2  copy_page_to_iter (page=0xf137ede0, offset=0x0, bytes=0x1ce, 
i=0xf201fd78)
                at lib/iov_iter.c:920
#3  shmem_file_read_iter (iocb=0xf201fd90, to=0xf201fd78)
                at mm/shmem.c:2661
#4  __kernel_read (file=0xf2103900, buf=0xf241365c, count=0x100, 
pos=0xf201fe80)
                at fs/read_write.c:454
#5  kernel_read (file=0xf2103900, buf=0xf241365c, count=0x100, 
pos=0xf201fe80)
                at fs/read_write.c:472
#6  prepare_binprm (bprm=0xf2413600)
                at fs/exec.c:1633
#7  search_binary_handler (bprm=0xf2413600)
                at fs/exec.c:1687
#8  exec_binprm (bprm=0xf2413600)
                at fs/exec.c:1744
#9  bprm_execve (bprm=0xf2413600, fd=<opt>, filename=<opt>, flags=<opt>)
                at fs/exec.c:1820
#10 kernel_execve (kernel_filename=<opt>,
                    argv=0xf050d4f0 <argv_init>,
                    envp=0xf050d468 <envp_init>)
                at fs/exec.c:1969
#11 kernel_init (unused=0x0)
                at init/main.c:1427

I will have to continue to dig deeper into this in January. If anyone
has any ideas how this could stem from this kmap patch, I am all ears.

-- 
Andreas Larsson
Software Engineer
Cobham Gaisler

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

* sparc32: Init process fails to load with generic kmap atomic
@ 2020-12-22 17:58 ` Andreas Larsson
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Larsson @ 2020-12-22 17:58 UTC (permalink / raw)
  To: Thomas Gleixner, sparclinux, linux-mm
  Cc: David S. Miller, Arnd Bergmann, linux-kernel, Sam Ravnborg


Unfortunately I did not see this problem before I encountered it in
master. Commit 3293efa9780712ad8504689e0c296d2bd33827d5

    sparc/mm/highmem: Switch to generic kmap atomic

     No reason having the same code in every architecture

     Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
     Cc: "David S. Miller" <davem@davemloft.net>
     Cc: Arnd Bergmann <arnd@arndb.de>
     Link: https://lore.kernel.org/r/20201103095858.197568209@linutronix.de

prevents the init process to be started for me on a sparc32 LEON. On the
commit before this it works. Details below from that commit but I get
the same behavior on current master.

 From as far as I have gotten into hunting down the problem, I get a
failure from load_elf_binary here:

	/* First of all, some simple consistency checks */
	if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0)
		goto out;

at least seemingly due to the kaddr from copy_page_to_iter in
lib/iov_iter.c

	if (i->type & (ITER_BVEC|ITER_KVEC)) {
		void *kaddr = kmap_atomic(page);
		size_t wanted = copy_to_iter(kaddr + offset, bytes, i);

where kaddr points to memory with all zeroes (from an earlier bzero) in 
this context:

#0  _copy_to_iter (addr=0xfcffe000, bytes=0x100, i=0xf201fd78)
                at lib/iov_iter.c:635
#1  copy_to_iter (i=0xf201fd78, bytes=0x1ce, addr=0xfcffe000)
                at include/linux/uio.h:137
#2  copy_page_to_iter (page=0xf137ede0, offset=0x0, bytes=0x1ce, 
i=0xf201fd78)
                at lib/iov_iter.c:920
#3  shmem_file_read_iter (iocb=0xf201fd90, to=0xf201fd78)
                at mm/shmem.c:2661
#4  __kernel_read (file=0xf2103900, buf=0xf241365c, count=0x100, 
pos=0xf201fe80)
                at fs/read_write.c:454
#5  kernel_read (file=0xf2103900, buf=0xf241365c, count=0x100, 
pos=0xf201fe80)
                at fs/read_write.c:472
#6  prepare_binprm (bprm=0xf2413600)
                at fs/exec.c:1633
#7  search_binary_handler (bprm=0xf2413600)
                at fs/exec.c:1687
#8  exec_binprm (bprm=0xf2413600)
                at fs/exec.c:1744
#9  bprm_execve (bprm=0xf2413600, fd=<opt>, filename=<opt>, flags=<opt>)
                at fs/exec.c:1820
#10 kernel_execve (kernel_filename=<opt>,
                    argv=0xf050d4f0 <argv_init>,
                    envp=0xf050d468 <envp_init>)
                at fs/exec.c:1969
#11 kernel_init (unused=0x0)
                at init/main.c:1427

I will have to continue to dig deeper into this in January. If anyone
has any ideas how this could stem from this kmap patch, I am all ears.

-- 
Andreas Larsson
Software Engineer
Cobham Gaisler

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

* Re: sparc32: Init process fails to load with generic kmap atomic
  2020-12-22 17:58 ` Andreas Larsson
  (?)
@ 2020-12-22 20:13   ` Arnd Bergmann
  -1 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2020-12-22 20:13 UTC (permalink / raw)
  To: Andreas Larsson
  Cc: Thomas Gleixner, sparclinux, Linux-MM, David S. Miller,
	Arnd Bergmann, linux-kernel, Sam Ravnborg

On Tue, Dec 22, 2020 at 7:01 PM Andreas Larsson <andreas@gaisler.com> wrote:
>
> Unfortunately I did not see this problem before I encountered it in
> master. Commit 3293efa9780712ad8504689e0c296d2bd33827d5
>
...
>
> I will have to continue to dig deeper into this in January. If anyone
> has any ideas how this could stem from this kmap patch, I am all ears.

I don't immediately see it, but an easy thing to try would be to
disable CONFIG_HIGHMEM. I don't know what the limits are
on sparc, but you can often change the virtual address layout
to reserve enough space for mapping all of the physical memory,
as e.g. CONFIG_VMSPLIT_2G does on x86 or arm.

There is also some discussion about eventually removing highmem
support from the kernel entirely.

       Arnd

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

* Re: sparc32: Init process fails to load with generic kmap atomic
@ 2020-12-22 20:13   ` Arnd Bergmann
  0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2020-12-22 20:13 UTC (permalink / raw)
  To: Andreas Larsson
  Cc: Thomas Gleixner, sparclinux, Linux-MM, David S. Miller,
	Arnd Bergmann, linux-kernel, Sam Ravnborg

On Tue, Dec 22, 2020 at 7:01 PM Andreas Larsson <andreas@gaisler.com> wrote:
>
> Unfortunately I did not see this problem before I encountered it in
> master. Commit 3293efa9780712ad8504689e0c296d2bd33827d5
>
...
>
> I will have to continue to dig deeper into this in January. If anyone
> has any ideas how this could stem from this kmap patch, I am all ears.

I don't immediately see it, but an easy thing to try would be to
disable CONFIG_HIGHMEM. I don't know what the limits are
on sparc, but you can often change the virtual address layout
to reserve enough space for mapping all of the physical memory,
as e.g. CONFIG_VMSPLIT_2G does on x86 or arm.

There is also some discussion about eventually removing highmem
support from the kernel entirely.

       Arnd

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

* Re: sparc32: Init process fails to load with generic kmap atomic
@ 2020-12-22 20:13   ` Arnd Bergmann
  0 siblings, 0 replies; 7+ messages in thread
From: Arnd Bergmann @ 2020-12-22 20:13 UTC (permalink / raw)
  To: Andreas Larsson
  Cc: Thomas Gleixner, sparclinux, Linux-MM, David S. Miller,
	Arnd Bergmann, linux-kernel, Sam Ravnborg

On Tue, Dec 22, 2020 at 7:01 PM Andreas Larsson <andreas@gaisler.com> wrote:
>
> Unfortunately I did not see this problem before I encountered it in
> master. Commit 3293efa9780712ad8504689e0c296d2bd33827d5
>
...
>
> I will have to continue to dig deeper into this in January. If anyone
> has any ideas how this could stem from this kmap patch, I am all ears.

I don't immediately see it, but an easy thing to try would be to
disable CONFIG_HIGHMEM. I don't know what the limits are
on sparc, but you can often change the virtual address layout
to reserve enough space for mapping all of the physical memory,
as e.g. CONFIG_VMSPLIT_2G does on x86 or arm.

There is also some discussion about eventually removing highmem
support from the kernel entirely.

       Arnd


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

* Re: sparc32: Init process fails to load with generic kmap atomic
  2020-12-22 17:58 ` Andreas Larsson
@ 2020-12-22 23:52   ` Thomas Gleixner
  -1 siblings, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2020-12-22 23:52 UTC (permalink / raw)
  To: Andreas Larsson, sparclinux, linux-mm
  Cc: David S. Miller, Arnd Bergmann, linux-kernel, Sam Ravnborg

On Tue, Dec 22 2020 at 18:58, Andreas Larsson wrote:
>  From as far as I have gotten into hunting down the problem, I get a
> failure from load_elf_binary here:
>
> 	/* First of all, some simple consistency checks */
> 	if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0)
> 		goto out;
>
> at least seemingly due to the kaddr from copy_page_to_iter in
> lib/iov_iter.c
>
> 	if (i->type & (ITER_BVEC|ITER_KVEC)) {
> 		void *kaddr = kmap_atomic(page);
> 		size_t wanted = copy_to_iter(kaddr + offset, bytes, i);
>
> where kaddr points to memory with all zeroes (from an earlier bzero) in 
> this context:

The kaddr might be misleading you here. If the code flow is:

    kaddr1 = kmap_atomic(page1);
    ...
    kunmap_atomic(kaddr1);

    kaddr2 = kmap_atomic(page2);

Then kaddr1 == kaddr2, but first it maps page1 and then page2, but that
was the same in the original code.

> I will have to continue to dig deeper into this in January. If anyone
> has any ideas how this could stem from this kmap patch, I am all ears.

I can't spot it either. I'll send you a debug patch after the holidays.

Thanks,

        tglx

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

* Re: sparc32: Init process fails to load with generic kmap atomic
@ 2020-12-22 23:52   ` Thomas Gleixner
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2020-12-22 23:52 UTC (permalink / raw)
  To: Andreas Larsson, sparclinux, linux-mm
  Cc: David S. Miller, Arnd Bergmann, linux-kernel, Sam Ravnborg

On Tue, Dec 22 2020 at 18:58, Andreas Larsson wrote:
>  From as far as I have gotten into hunting down the problem, I get a
> failure from load_elf_binary here:
>
> 	/* First of all, some simple consistency checks */
> 	if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0)
> 		goto out;
>
> at least seemingly due to the kaddr from copy_page_to_iter in
> lib/iov_iter.c
>
> 	if (i->type & (ITER_BVEC|ITER_KVEC)) {
> 		void *kaddr = kmap_atomic(page);
> 		size_t wanted = copy_to_iter(kaddr + offset, bytes, i);
>
> where kaddr points to memory with all zeroes (from an earlier bzero) in 
> this context:

The kaddr might be misleading you here. If the code flow is:

    kaddr1 = kmap_atomic(page1);
    ...
    kunmap_atomic(kaddr1);

    kaddr2 = kmap_atomic(page2);

Then kaddr1 = kaddr2, but first it maps page1 and then page2, but that
was the same in the original code.

> I will have to continue to dig deeper into this in January. If anyone
> has any ideas how this could stem from this kmap patch, I am all ears.

I can't spot it either. I'll send you a debug patch after the holidays.

Thanks,

        tglx

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

end of thread, other threads:[~2020-12-22 23:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-22 17:58 sparc32: Init process fails to load with generic kmap atomic Andreas Larsson
2020-12-22 17:58 ` Andreas Larsson
2020-12-22 20:13 ` Arnd Bergmann
2020-12-22 20:13   ` Arnd Bergmann
2020-12-22 20:13   ` Arnd Bergmann
2020-12-22 23:52 ` Thomas Gleixner
2020-12-22 23:52   ` Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.