From: Dan Carpenter <dan.carpenter@linaro.org>
To: hughd@google.com
Cc: linux-mm@kvack.org
Subject: [bug report] mm/pgtable: add rcu_read_lock() and rcu_read_unlock()s
Date: Fri, 23 Feb 2024 17:03:58 +0300 [thread overview]
Message-ID: <33509f8f-0407-4775-a83e-c81c5589fec6@moroto.mountain> (raw)
[ This kind of old and mm is above my pay grade... - dan ]
Hello Hugh Dickins,
The patch a349d72fd9ef: "mm/pgtable: add rcu_read_lock() and
rcu_read_unlock()s" from Jul 11, 2023 (linux-next), leads to the
following Smatch static checker warning:
./include/linux/rmap.h:116 put_anon_vma()
warn: sleeping in atomic context
./include/linux/rmap.h
113 static inline void put_anon_vma(struct anon_vma *anon_vma)
114 {
115 if (atomic_dec_and_test(&anon_vma->refcount))
--> 116 __put_anon_vma(anon_vma);
117 }
move_pages_pte() <- disables preempt
-> folio_get_anon_vma()
-> put_anon_vma()
The relevant bits from move_pages_pte() are here:
mm/userfaultfd.c
1109 mmu_notifier_invalidate_range_start(&range);
1110 retry:
1111 dst_pte = pte_offset_map_nolock(mm, dst_pmd, dst_addr, &dst_ptl);
^^^^^^^^^^^^^^^^^^^^^
1112
1113 /* Retry if a huge pmd materialized from under us */
1114 if (unlikely(!dst_pte)) {
1115 err = -EAGAIN;
1116 goto out;
1117 }
1118
1119 src_pte = pte_offset_map_nolock(mm, src_pmd, src_addr, &src_ptl);
^^^^^^^^^^^^^^^^^^^^^
These call rcu_read_lock() which disables preemption.
[ snip ]
1235 if (!src_anon_vma) {
1236 /*
1237 * folio_referenced walks the anon_vma chain
1238 * without the folio lock. Serialize against it with
1239 * the anon_vma lock, the folio lock is not enough.
1240 */
1241 src_anon_vma = folio_get_anon_vma(src_folio);
^^^^^^^^^^^^^^^^^^
Potentially sleeps. I started to look at if we know that folio_mapped()
will return true, but then I saw that folio_get_anon_vma() actually
checks that twice and it's some kind of parallelism thing. I decided to
give up before I accidentally over heat my brain.
1242 if (!src_anon_vma) {
1243 /* page was unmapped from under us */
1244 err = -EAGAIN;
1245 goto out;
1246 }
1247 if (!anon_vma_trylock_write(src_anon_vma)) {
1248 pte_unmap(&orig_src_pte);
1249 pte_unmap(&orig_dst_pte);
preempt enabled again here.
1250 src_pte = dst_pte = NULL;
1251 /* now we can block and wait */
1252 anon_vma_lock_write(src_anon_vma);
1253 goto retry;
1254 }
1255 }
regards,
dan carpenter
reply other threads:[~2024-02-23 14:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33509f8f-0407-4775-a83e-c81c5589fec6@moroto.mountain \
--to=dan.carpenter@linaro.org \
--cc=hughd@google.com \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox