Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1371934

[PATCH 09/10] huge pagecache: mmap_sem is unlocked when truncation splits pmd

From Hugh Dickins <hughd@google.com>
Newsgroups linux.kernel
Subject [PATCH 09/10] huge pagecache: mmap_sem is unlocked when truncation splits pmd
Date 2016-04-05 23:00 +0200
Message-ID <rkGeS-1hF-7@gated-at.bofh.it> (permalink)
References <rkFVw-1aF-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


zap_pmd_range()'s CONFIG_DEBUG_VM !rwsem_is_locked(&mmap_sem) BUG()
will be invalid with huge pagecache, in whatever way it is implemented:
truncation of a hugely-mapped file to an unhugely-aligned size would
easily hit it.

(Although anon THP could in principle apply khugepaged to private file
mappings, which are not excluded by the MADV_HUGEPAGE restrictions, in
practice there's a vm_ops check which excludes them, so it never hits
this BUG() - there's no interface to "truncate" an anonymous mapping.)

We could complicate the test, to check i_mmap_rwsem also when there's a
vm_file; but my inclination was to make zap_pmd_range() more readable by
simply deleting this check.  A search has shown no report of the issue in
the years since commit e0897d75f0b2 ("mm, thp: print useful information
when mmap_sem is unlocked in zap_pmd_range") expanded it from VM_BUG_ON()
- though I cannot point to what commit I would say then fixed the issue.

But there are a couple of other patches now floating around, neither
yet in the tree: let's agree to retain the check as a VM_BUG_ON_VMA(),
as Matthew Wilcox has done; but subject to a vma_is_anonymous() check,
as Kirill Shutemov has done.  And let's get this in, without waiting
for any particular huge pagecache implementation to reach the tree.

Signed-off-by: Hugh Dickins <hughd@google.com>
---
 mm/memory.c |   11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1182,15 +1182,8 @@ static inline unsigned long zap_pmd_rang
 		next = pmd_addr_end(addr, end);
 		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
 			if (next - addr != HPAGE_PMD_SIZE) {
-#ifdef CONFIG_DEBUG_VM
-				if (!rwsem_is_locked(&tlb->mm->mmap_sem)) {
-					pr_err("%s: mmap_sem is unlocked! addr=0x%lx end=0x%lx vma->vm_start=0x%lx vma->vm_end=0x%lx\n",
-						__func__, addr, end,
-						vma->vm_start,
-						vma->vm_end);
-					BUG();
-				}
-#endif
+				VM_BUG_ON_VMA(vma_is_anonymous(vma) &&
+				    !rwsem_is_locked(&tlb->mm->mmap_sem), vma);
 				split_huge_pmd(vma, pmd, addr);
 			} else if (zap_huge_pmd(tlb, vma, pmd, addr))
 				goto next;

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/10] mm: easy preliminaries to THPagecache Hugh Dickins <hughd@google.com> - 2016-04-05 22:40 +0200
  [PATCH 01/10] mm: update_lru_size warn and reset bad lru_size Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
    Re: [PATCH 01/10] mm: update_lru_size warn and reset bad lru_size Vlastimil Babka <vbabka@suse.cz> - 2016-04-14 14:00 +0200
  [PATCH 06/10] mm: /proc/sys/vm/stat_refresh to force vmstat update Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
  [PATCH 03/10] mm: use __SetPageSwapBacked and dont  ClearPageSwapBacked Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
    Re: [PATCH 03/10] mm: use __SetPageSwapBacked and dont  ClearPageSwapBacked Mel Gorman <mgorman@techsingularity.net> - 2016-04-06 12:00 +0200
  [PATCH 02/10] mm: update_lru_size do the __mod_zone_page_state Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
  [PATCH 04/10] tmpfs: preliminary minor tidyups Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
  [PATCH 05/10] tmpfs: mem_cgroup charge fault to vm_mm not current  mm Hugh Dickins <hughd@google.com> - 2016-04-05 22:50 +0200
  [PATCH 09/10] huge pagecache: mmap_sem is unlocked when truncation  splits pmd Hugh Dickins <hughd@google.com> - 2016-04-05 23:00 +0200
    Re: [PATCH 09/10] huge pagecache: mmap_sem is unlocked when  truncation splits pmd "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-04-11 12:40 +0200
    Re: [PATCH 09/10] huge pagecache: mmap_sem is unlocked when  truncation splits pmd Matthew Wilcox <willy@linux.intel.com> - 2016-04-14 19:40 +0200
  [PATCH 07/10] huge mm: move_huge_pmd does not need new_vma Hugh Dickins <hughd@google.com> - 2016-04-05 23:00 +0200
    Re: [PATCH 07/10] huge mm: move_huge_pmd does not need new_vma "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-04-11 12:30 +0200
  [PATCH 08/10] huge pagecache: extend mremap pmd rmap lockout to  files Hugh Dickins <hughd@google.com> - 2016-04-05 23:00 +0200
    Re: [PATCH 08/10] huge pagecache: extend mremap pmd rmap lockout to  files "Kirill A. Shutemov" <kirill@shutemov.name> - 2016-04-11 12:40 +0200
  [PATCH 10/10] arch: fix has_transparent_hugepage() Hugh Dickins <hughd@google.com> - 2016-04-05 23:10 +0200
    Re: [PATCH 10/10] arch: fix has_transparent_hugepage() David Miller <davem@davemloft.net> - 2016-04-06 01:30 +0200
    Re: [PATCH 10/10] arch: fix has_transparent_hugepage() Ingo Molnar <mingo@kernel.org> - 2016-04-06 09:00 +0200
      Re: [PATCH 10/10] arch: fix has_transparent_hugepage() Ingo Molnar <mingo@kernel.org> - 2016-04-07 00:00 +0200
    Re: [PATCH 10/10] arch: fix has_transparent_hugepage() Gerald Schaefer <gerald.schaefer@de.ibm.com> - 2016-04-06 14:00 +0200

csiph-web