From: Jens Axboe <[email protected]>
To: io-uring <[email protected]>
Subject: [PATCH] io_uring/memmap: move vm_flags_set() outside of ctx->mmap_lock
Date: Thu, 13 Mar 2025 05:44:47 -0600 [thread overview]
Message-ID: <[email protected]> (raw)
syzbot complaints that sometimes the ordering between ctx->mmap_lock
and vma->vm_lock->lock aren't the same, which obviously makes lockdep
unhappy.
We'd normally expect the ctx->mmap_lock to nest inside the vma lock,
but vm_flags_set() -> vma_start_write() from the ->mmap() patch can
happen in the opposite order.
Move the vm_flags_set() to before ctx->mmap_lock is grabbed. This does
potentially leak the VM_DONT_EXPAND set for that vma, and while that
could get cleared, doesn't look like it's necessary to do so. Hence just
keep it simple.
Reported-by: [email protected]
Link: https://lore.kernel.org/io-uring/[email protected]/
Signed-off-by: Jens Axboe <[email protected]>
---
diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 361134544427..d325b6ab6b99 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -309,7 +309,6 @@ static int io_region_mmap(struct io_ring_ctx *ctx,
{
unsigned long nr_pages = min(mr->nr_pages, max_pages);
- vm_flags_set(vma, VM_DONTEXPAND);
return vm_insert_pages(vma, vma->vm_start, mr->pages, &nr_pages);
}
@@ -322,6 +321,8 @@ __cold int io_uring_mmap(struct file *file, struct vm_area_struct *vma)
struct io_mapped_region *region;
void *ptr;
+ vm_flags_set(vma, VM_DONTEXPAND);
+
guard(mutex)(&ctx->mmap_lock);
ptr = io_uring_validate_mmap_request(file, vma->vm_pgoff, sz);
--
Jens Axboe
reply other threads:[~2025-03-13 11:44 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 \
[email protected] \
[email protected] \
[email protected] \
/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