Go to file
Hugh Dickins 69f21c4e54 mm/thp: unmap_mapping_page() to fix THP truncate_cleanup_page()
BugLink: https://bugs.launchpad.net/bugs/1936242

[ Upstream commit 22061a1ffa ]

There is a race between THP unmapping and truncation, when truncate sees
pmd_none() and skips the entry, after munmap's zap_huge_pmd() cleared
it, but before its page_remove_rmap() gets to decrement
compound_mapcount: generating false "BUG: Bad page cache" reports that
the page is still mapped when deleted.  This commit fixes that, but not
in the way I hoped.

The first attempt used try_to_unmap(page, TTU_SYNC|TTU_IGNORE_MLOCK)
instead of unmap_mapping_range() in truncate_cleanup_page(): it has
often been an annoyance that we usually call unmap_mapping_range() with
no pages locked, but there apply it to a single locked page.
try_to_unmap() looks more suitable for a single locked page.

However, try_to_unmap_one() contains a VM_BUG_ON_PAGE(!pvmw.pte,page):
it is used to insert THP migration entries, but not used to unmap THPs.
Copy zap_huge_pmd() and add THP handling now? Perhaps, but their TLB
needs are different, I'm too ignorant of the DAX cases, and couldn't
decide how far to go for anon+swap.  Set that aside.

The second attempt took a different tack: make no change in truncate.c,
but modify zap_huge_pmd() to insert an invalidated huge pmd instead of
clearing it initially, then pmd_clear() between page_remove_rmap() and
unlocking at the end.  Nice.  But powerpc blows that approach out of the
water, with its serialize_against_pte_lookup(), and interesting pgtable
usage.  It would need serious help to get working on powerpc (with a
minor optimization issue on s390 too).  Set that aside.

Just add an "if (page_mapped(page)) synchronize_rcu();" or other such
delay, after unmapping in truncate_cleanup_page()? Perhaps, but though
that's likely to reduce or eliminate the number of incidents, it would
give less assurance of whether we had identified the problem correctly.

This successful iteration introduces "unmap_mapping_page(page)" instead
of try_to_unmap(), and goes the usual unmap_mapping_range_tree() route,
with an addition to details.  Then zap_pmd_range() watches for this
case, and does spin_unlock(pmd_lock) if so - just like
page_vma_mapped_walk() now does in the PVMW_SYNC case.  Not pretty, but
safe.

Note that unmap_mapping_page() is doing a VM_BUG_ON(!PageLocked) to
assert its interface; but currently that's only used to make sure that
page->mapping is stable, and zap_pmd_range() doesn't care if the page is
locked or not.  Along these lines, in invalidate_inode_pages2_range()
move the initial unmap_mapping_range() out from under page lock, before
then calling unmap_mapping_page() under page lock if still mapped.

Link: https://lkml.kernel.org/r/a2a4a148-cdd8-942c-4ef8-51b77f643dbe@google.com
Fixes: fc127da085 ("truncate: handle file thp")
Signed-off-by: Hugh Dickins <hughd@google.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Yang Shi <shy828301@gmail.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jue Wang <juew@google.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Xu <peterx@redhat.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Wang Yugui <wangyugui@e16-tech.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Note on stable backport: fixed up call to truncate_cleanup_page()
in truncate_inode_pages_range().  Use hpage_nr_pages() in
unmap_mapping_page().

Signed-off-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2021-08-13 09:44:27 +02:00
Documentation mm/slub: clarify verification reporting 2021-07-15 19:27:46 +02:00
LICENSES
arch PCI: Add AMD RS690 quirk to enable 64-bit DMA 2021-08-13 09:44:23 +02:00
block blk-mq: Swap two calls in blk_mq_exit_queue() 2021-06-18 15:02:18 +02:00
certs certs: Fix blacklist flag type confusion 2021-04-14 18:31:30 +02:00
crypto crypto: rng - fix crypto_rng_reset() refcounting when !CRYPTO_STATS 2021-05-19 10:59:48 +02:00
debian UBUNTU: update dkms package versions 2021-07-15 19:58:19 +02:00
debian.master UBUNTU: upstream stable to v5.4.128 2021-08-13 09:44:12 +02:00
drivers i2c: robotfuzz-osif: fix control-request directions 2021-08-13 09:44:24 +02:00
fs nilfs2: fix memory leak in nilfs_sysfs_delete_device_group 2021-08-13 09:44:24 +02:00
include mm/thp: unmap_mapping_page() to fix THP truncate_cleanup_page() 2021-08-13 09:44:27 +02:00
init kbuild: add CONFIG_LD_IS_LLD 2021-08-13 09:44:14 +02:00
ipc
kernel kthread: prevent deadlock when kthread_mod_delayed_work() races with kthread_cancel_delayed_work_sync() 2021-08-13 09:44:25 +02:00
lib lib/lz4: explicitly support in-place decompression 2021-07-15 19:27:11 +02:00
mm mm/thp: unmap_mapping_page() to fix THP truncate_cleanup_page() 2021-08-13 09:44:27 +02:00
net net/packet: annotate accesses to po->ifindex 2021-08-13 09:44:20 +02:00
samples samples: vfio-mdev: fix error handing in mdpy_fb_probe() 2021-07-15 19:27:01 +02:00
scripts recordmcount: Correct st_shndx handling 2021-08-13 09:44:22 +02:00
security security: commoncap: fix -Wstringop-overread warning 2021-05-19 10:59:48 +02:00
sound ASoC: rt5659: Fix the lost powers for the HDA header 2021-07-15 19:27:41 +02:00
tools KVM: selftests: Fix kvm_check_cap() assertion 2021-08-13 09:44:22 +02:00
ubuntu UBUNTU: [Packaging] Add support for ODM drivers 2021-01-26 17:27:59 -07:00
usr
virt KVM: do not allow mapping valid but non-reference-counted pages 2021-08-13 09:44:24 +02:00
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS UBUNTU: ODM: MAINTAINERS: Add Advantech AHC1EC0 embedded controller entry 2021-02-19 16:45:06 +01:00
Makefile Linux 5.4.128 2021-07-15 19:27:49 +02:00
README
dropped.txt
snapcraft.yaml
update-version-dkms

README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.