From: Greg Kroah-Hartman Date: Tue, 7 Feb 2023 08:52:14 +0000 (+0100) Subject: 4.14-stable patches X-Git-Tag: v5.15.93~40 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d8a8bbe3812306e8e77a9b26e73ac184d15d44b2;p=thirdparty%2Fkernel%2Fstable-queue.git 4.14-stable patches added patches: mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps.patch --- diff --git a/queue-4.14/mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps.patch b/queue-4.14/mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps.patch new file mode 100644 index 00000000000..efa042bfe64 --- /dev/null +++ b/queue-4.14/mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps.patch @@ -0,0 +1,147 @@ +From 3489dbb696d25602aea8c3e669a6d43b76bd5358 Mon Sep 17 00:00:00 2001 +From: Mike Kravetz +Date: Thu, 26 Jan 2023 14:27:20 -0800 +Subject: mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps + +From: Mike Kravetz + +commit 3489dbb696d25602aea8c3e669a6d43b76bd5358 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: 25ee01a2fca0 ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps") +Signed-off-by: Mike Kravetz +Acked-by: Peter Xu +Cc: David Hildenbrand +Cc: James Houghton +Cc: Matthew Wilcox +Cc: Michal Hocko +Cc: Muchun Song +Cc: Naoya Horiguchi +Cc: Vishal Moola (Oracle) +Cc: Yang Shi +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + +From 3489dbb696d25602aea8c3e669a6d43b76bd5358 Mon Sep 17 00:00:00 2001 +From: Mike Kravetz +Date: Thu, 26 Jan 2023 14:27:20 -0800 +Subject: mm: hugetlb: proc: check for hugetlb shared PMD in /proc/PID/smaps + +From: Mike Kravetz + +commit 3489dbb696d25602aea8c3e669a6d43b76bd5358 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: 25ee01a2fca0 ("mm: hugetlb: proc: add hugetlb-related fields to /proc/PID/smaps") +Signed-off-by: Mike Kravetz +Acked-by: Peter Xu +Cc: David Hildenbrand +Cc: James Houghton +Cc: Matthew Wilcox +Cc: Michal Hocko +Cc: Muchun Song +Cc: Naoya Horiguchi +Cc: Vishal Moola (Oracle) +Cc: Yang Shi +Cc: +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + fs/proc/task_mmu.c | 4 +--- + include/linux/hugetlb.h | 13 +++++++++++++ + 2 files changed, 14 insertions(+), 3 deletions(-) + +--- a/fs/proc/task_mmu.c ++++ b/fs/proc/task_mmu.c +@@ -728,9 +728,7 @@ static int smaps_hugetlb_range(pte_t *pt + page = device_private_entry_to_page(swpent); + } + if (page) { +- int mapcount = page_mapcount(page); +- +- if (mapcount >= 2) ++ if (page_mapcount(page) >= 2 || hugetlb_pmd_shared(pte)) + mss->shared_hugetlb += huge_page_size(hstate_vma(vma)); + else + mss->private_hugetlb += huge_page_size(hstate_vma(vma)); +--- a/include/linux/hugetlb.h ++++ b/include/linux/hugetlb.h +@@ -7,6 +7,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -616,4 +617,16 @@ static inline spinlock_t *huge_pte_lock( + return ptl; + } + ++#ifdef CONFIG_ARCH_WANT_HUGE_PMD_SHARE ++static inline bool hugetlb_pmd_shared(pte_t *pte) ++{ ++ return page_count(virt_to_page(pte)) > 1; ++} ++#else ++static inline bool hugetlb_pmd_shared(pte_t *pte) ++{ ++ return false; ++} ++#endif ++ + #endif /* _LINUX_HUGETLB_H */ diff --git a/queue-4.14/series b/queue-4.14/series index 3b0f6dc3a5a..674b48db9cc 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -18,3 +18,4 @@ iio-adc-berlin2-adc-add-missing-of_node_put-in-error-path.patch iio-adc-twl6030-enable-measurements-of-vusb-vbat-and-others.patch parisc-fix-return-code-of-pdc_iodc_print.patch parisc-wire-up-ptrace_getregs-ptrace_setregs-for-compat-case.patch +mm-hugetlb-proc-check-for-hugetlb-shared-pmd-in-proc-pid-smaps.patch