linux-stable/fs/proc
Mike Kravetz 400723777e mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps
commit 3489dbb696 upstream.

Patch series "Fixes for hugetlb mapcount at most 1 for shared PMDs".

This issue of mapcount in hugetlb pages referenced by shared PMDs was
discussed in [1].  The following two patches address user visible behavior
caused by this issue.

[1] https://lore.kernel.org/linux-mm/Y9BF+OCdWnCSilEu@monkey/


This patch (of 2):

A hugetlb page will have a mapcount of 1 if mapped by multiple processes
via a shared PMD.  This is because only the first process increases the
map count, and subsequent processes just add the shared PMD page to their
page table.

page_mapcount is being used to decide if a hugetlb page is shared or
private in /proc/PID/smaps.  Pages referenced via a shared PMD were
incorrectly being counted as private.

To fix, check for a shared PMD if mapcount is 1.  If a shared PMD is found
count the hugetlb page as shared.  A new helper to check for a shared PMD
is added.

[akpm@linux-foundation.org: simplification, per David]
[akpm@linux-foundation.org: hugetlb.h: include page_ref.h for page_count()]
Link: https://lkml.kernel.org/r/20230126222721.222195-2-mike.kravetz@oracle.com
Fixes: 25ee01a2fc ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps")
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
Acked-by: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: James Houghton <jthoughton@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Naoya Horiguchi <naoya.horiguchi@linux.dev>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Yang Shi <shy828301@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-02-22 12:47:15 +01:00
..
array.c fs/proc/array.c: allow reporting eip/esp for all coredumping threads 2019-07-03 13:14:44 +02:00
base.c proc: Avoid mixing integer types in mem_rw() 2021-07-28 11:13:49 +02:00
cmdline.c
consoles.c
cpuinfo.c
devices.c
fd.c
fd.h
generic.c proc: fix dentry/inode overinstantiating under /proc/${pid}/net 2022-06-14 16:59:25 +02:00
inode.c proc: Use new_inode not new_inode_pseudo 2020-06-22 09:05:06 +02:00
internal.h proc: fix lookup in /proc/net subdirectories after setns(2) 2021-01-12 20:10:17 +01:00
interrupts.c
Kconfig
kcore.c x86/gart: Exclude GART aperture from kcore 2019-04-20 09:15:59 +02:00
kmsg.c
loadavg.c
Makefile
meminfo.c
namespaces.c
nommu.c
page.c fs/proc/page.c: don't access uninitialized memmaps in fs/proc/page.c 2019-10-29 09:19:56 +01:00
proc_net.c proc: fix dentry/inode overinstantiating under /proc/${pid}/net 2022-06-14 16:59:25 +02:00
proc_sysctl.c sysctl: add a new register_sysctl_init() interface 2023-02-06 07:49:44 +01:00
proc_tty.c
root.c
self.c proc: don't allow async path resolution of /proc/self components 2020-12-02 08:48:09 +01:00
softirqs.c
stat.c
task_mmu.c mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps 2023-02-22 12:47:15 +01:00
task_nommu.c proc: use down_read_killable mmap_sem for /proc/pid/maps 2019-07-31 07:27:09 +02:00
thread_self.c proc: Use new_inode not new_inode_pseudo 2020-06-22 09:05:06 +02:00
uptime.c
util.c
version.c
vmcore.c proc/vmcore: fix clearing user buffer by properly using clear_user() 2021-12-01 09:27:39 +01:00