linux-stable/arch/s390/mm
Martin Schwidefsky 4136161d67 s390/mm: fix mis-accounting of pgtable_bytes
[ Upstream commit e12e4044ae ]

In case a fork or a clone system fails in copy_process and the error
handling does the mmput() at the bad_fork_cleanup_mm label, the
following warning messages will appear on the console:

  BUG: non-zero pgtables_bytes on freeing mm: 16384

The reason for that is the tricks we play with mm_inc_nr_puds() and
mm_inc_nr_pmds() in init_new_context().

A normal 64-bit process has 3 levels of page table, the p4d level and
the pud level are folded. On process termination the free_pud_range()
function in mm/memory.c will subtract 16KB from pgtable_bytes with a
mm_dec_nr_puds() call, but there actually is not really a pud table.

One issue with this is the fact that pgtable_bytes is usually off
by a few kilobytes, but the more severe problem is that for a failed
fork or clone the free_pgtables() function is not called. In this case
there is no mm_dec_nr_puds() or mm_dec_nr_pmds() that go together with
the mm_inc_nr_puds() and mm_inc_nr_pmds in init_new_context().
The pgtable_bytes will be off by 16384 or 32768 bytes and we get the
BUG message. The message itself is purely cosmetic, but annoying.

To fix this override the mm_pmd_folded, mm_pud_folded and mm_p4d_folded
function to check for the true size of the address space.

Reported-by: Li Wang <liwang@redhat.com>
Tested-by: Li Wang <liwang@redhat.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2018-11-27 16:13:03 +01:00
..
cmm.c s390/cmm: avoid add_timer on concurrently used timer 2018-07-16 15:45:41 +02:00
dump_pagetables.c s390: unify linker symbols usage 2018-02-27 08:05:23 +01:00
extmem.c s390/extmem: fix gcc 8 stringop-overflow warning 2018-07-02 11:24:50 +02:00
fault.c mm: convert return type of handle_mm_fault() caller to vm_fault_t 2018-08-17 16:20:28 -07:00
gmap.c s390/mm: Check for valid vma before zapping in gmap_discard 2018-09-12 14:46:37 +02:00
gup.c mm/gup.c: document return value 2018-04-13 17:10:27 -07:00
hugetlbpage.c s390/mm: Clear skeys for newly mapped huge guest pmds 2018-07-30 11:20:18 +01:00
init.c mm: pass the vmem_altmap to arch_remove_memory and __remove_pages 2018-01-08 11:46:23 -08:00
maccess.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mem_detect.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
mmap.c exec: pass stack rlimit into mm layout functions 2018-04-11 10:28:37 -07:00
page-states.c s390/mm: fix addressing exception after suspend/resume 2018-08-09 08:05:48 +02:00
pageattr.c s390/mm: Clear huge page storage keys on enable_skey 2018-07-30 11:20:18 +01:00
pgalloc.c s390/mm: fix mis-accounting of pgtable_bytes 2018-11-27 16:13:03 +01:00
pgtable.c s390/mm: Add huge page gmap linking support 2018-07-30 23:13:38 +02:00
vmem.c mm: pass the vmem_altmap to vmemmap_free 2018-01-08 11:46:23 -08:00