]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.9-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 6 Mar 2022 10:47:32 +0000 (11:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 6 Mar 2022 10:47:32 +0000 (11:47 +0100)
added patches:
memfd-fix-f_seal_write-after-shmem-huge-page-allocated.patch

queue-4.9/memfd-fix-f_seal_write-after-shmem-huge-page-allocated.patch [new file with mode: 0644]
queue-4.9/series

diff --git a/queue-4.9/memfd-fix-f_seal_write-after-shmem-huge-page-allocated.patch b/queue-4.9/memfd-fix-f_seal_write-after-shmem-huge-page-allocated.patch
new file mode 100644 (file)
index 0000000..fcaff76
--- /dev/null
@@ -0,0 +1,75 @@
+From f2b277c4d1c63a85127e8aa2588e9cc3bd21cb99 Mon Sep 17 00:00:00 2001
+From: Hugh Dickins <hughd@google.com>
+Date: Fri, 4 Mar 2022 20:29:01 -0800
+Subject: memfd: fix F_SEAL_WRITE after shmem huge page allocated
+
+From: Hugh Dickins <hughd@google.com>
+
+commit f2b277c4d1c63a85127e8aa2588e9cc3bd21cb99 upstream.
+
+Wangyong reports: after enabling tmpfs filesystem to support transparent
+hugepage with the following command:
+
+  echo always > /sys/kernel/mm/transparent_hugepage/shmem_enabled
+
+the docker program tries to add F_SEAL_WRITE through the following
+command, but it fails unexpectedly with errno EBUSY:
+
+  fcntl(5, F_ADD_SEALS, F_SEAL_WRITE) = -1.
+
+That is because memfd_tag_pins() and memfd_wait_for_pins() were never
+updated for shmem huge pages: checking page_mapcount() against
+page_count() is hopeless on THP subpages - they need to check
+total_mapcount() against page_count() on THP heads only.
+
+Make memfd_tag_pins() (compared > 1) as strict as memfd_wait_for_pins()
+(compared != 1): either can be justified, but given the non-atomic
+total_mapcount() calculation, it is better now to be strict.  Bear in
+mind that total_mapcount() itself scans all of the THP subpages, when
+choosing to take an XA_CHECK_SCHED latency break.
+
+Also fix the unlikely xa_is_value() case in memfd_wait_for_pins(): if a
+page has been swapped out since memfd_tag_pins(), then its refcount must
+have fallen, and so it can safely be untagged.
+
+Link: https://lkml.kernel.org/r/a4f79248-df75-2c8c-3df-ba3317ccb5da@google.com
+Signed-off-by: Hugh Dickins <hughd@google.com>
+Reported-by: Zeal Robot <zealci@zte.com.cn>
+Reported-by: wangyong <wang.yong12@zte.com.cn>
+Cc: Mike Kravetz <mike.kravetz@oracle.com>
+Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
+Cc: CGEL ZTE <cgel.zte@gmail.com>
+Cc: Kirill A. Shutemov <kirill@shutemov.name>
+Cc: Song Liu <songliubraving@fb.com>
+Cc: Yang Yang <yang.yang29@zte.com.cn>
+Cc: <stable@vger.kernel.org>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ mm/shmem.c |    7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+--- a/mm/shmem.c
++++ b/mm/shmem.c
+@@ -2478,7 +2478,8 @@ static void shmem_tag_pins(struct addres
+                               slot = radix_tree_iter_retry(&iter);
+                               continue;
+                       }
+-              } else if (page_count(page) - page_mapcount(page) > 1) {
++              } else if (!PageTail(page) && page_count(page) !=
++                         hpage_nr_pages(page) + total_mapcount(page)) {
+                       radix_tree_tag_set(&mapping->page_tree, iter.index,
+                                          SHMEM_TAG_PINNED);
+               }
+@@ -2538,8 +2539,8 @@ static int shmem_wait_for_pins(struct ad
+                               page = NULL;
+                       }
+-                      if (page &&
+-                          page_count(page) - page_mapcount(page) != 1) {
++                      if (page && page_count(page) !=
++                          hpage_nr_pages(page) + total_mapcount(page)) {
+                               if (scan < LAST_SCAN)
+                                       goto continue_resched;
index 02009dbeebffaf595840182030cfe5749c301467..c3e6629375487d67d5ebbf2afab821a2645898a8 100644 (file)
@@ -28,3 +28,4 @@ net-chelsio-cxgb3-check-the-return-value-of-pci_find.patch
 input-elan_i2c-move-regulator_able-out-of-elan_able_power.patch
 input-elan_i2c-fix-regulator-enable-count-imbalance-after-suspend-resume.patch
 hid-add-mapping-for-key_all_applications.patch
+memfd-fix-f_seal_write-after-shmem-huge-page-allocated.patch