[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230922190552.3963067-1-riel@surriel.com>
Date: Fri, 22 Sep 2023 15:02:28 -0400
From: riel@...riel.com
To: linux-kernel@...r.kernel.org
Cc: kernel-team@...a.com, linux-mm@...ck.org,
akpm@...ux-foundation.org, muchun.song@...ux.dev,
mike.kravetz@...cle.com, leit@...a.com, willy@...radead.org
Subject: [PATCH v2 0/3] hugetlbfs: close race between MADV_DONTNEED and page fault
v2: fix the locking bug found with the libhugetlbfs tests.
Malloc libraries, like jemalloc and tcalloc, take decisions on when
to call madvise independently from the code in the main application.
This sometimes results in the application page faulting on an address,
right after the malloc library has shot down the backing memory with
MADV_DONTNEED.
Usually this is harmless, because we always have some 4kB pages
sitting around to satisfy a page fault. However, with hugetlbfs
systems often allocate only the exact number of huge pages that
the application wants.
Due to TLB batching, hugetlbfs MADV_DONTNEED will free pages outside of
any lock taken on the page fault path, which can open up the following
race condition:
CPU 1 CPU 2
MADV_DONTNEED
unmap page
shoot down TLB entry
page fault
fail to allocate a huge page
killed with SIGBUS
free page
Fix that race by extending the hugetlb_vma_lock locking scheme to also
cover private hugetlb mappings (with resv_map), and pulling the locking
from __unmap_hugepage_final_range into helper functions called from
zap_page_range_single. This ensures page faults stay locked out of
the MADV_DONTNEED VMA until the huge pages have actually been freed.
The third patch in the series is more of an RFC. Using the
invalidate_lock instead of the hugetlb_vma_lock greatly simplifies
the code, but at the cost of turning a per-VMA lock into a lock
per backing hugetlbfs file, which could slow things down when
multiple processes are mapping the same hugetlbfs file.
Powered by blists - more mailing lists