Skip to content

Commit e5548f8

Browse files
Hugh Dickinsakpm00
authored andcommitted
shmem: fix smaps BUG sleeping while atomic
smaps_pte_hole_lookup() is calling shmem_partial_swap_usage() with page table lock held: but shmem_partial_swap_usage() does cond_resched_rcu() if need_resched(): "BUG: sleeping function called from invalid context". Since shmem_partial_swap_usage() is designed to count across a range, but smaps_pte_hole_lookup() only calls it for a single page slot, just break out of the loop on the last or only page, before checking need_resched(). Link: https://lkml.kernel.org/r/6fe3b3ec-abdf-332f-5c23-6a3b3a3b11a9@google.com Fixes: 2301003 ("mm/smaps: simplify shmem handling of pte holes") Signed-off-by: Hugh Dickins <hughd@google.com> Acked-by: Peter Xu <peterx@redhat.com> Cc: <stable@vger.kernel.org> [5.16+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent f84f62e commit e5548f8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

mm/shmem.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,14 +806,16 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping,
806806
XA_STATE(xas, &mapping->i_pages, start);
807807
struct page *page;
808808
unsigned long swapped = 0;
809+
unsigned long max = end - 1;
809810

810811
rcu_read_lock();
811-
xas_for_each(&xas, page, end - 1) {
812+
xas_for_each(&xas, page, max) {
812813
if (xas_retry(&xas, page))
813814
continue;
814815
if (xa_is_value(page))
815816
swapped++;
816-
817+
if (xas.xa_index == max)
818+
break;
817819
if (need_resched()) {
818820
xas_pause(&xas);
819821
cond_resched_rcu();

0 commit comments

Comments
 (0)