From: Jason Gunthorpe <jgg@ziepe.ca>
To: Stanislav Kinsburskii <skinsburskii@gmail.com>
Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org,
david@kernel.org, corbet@lwn.net, leon@kernel.org,
ljs@kernel.org, mhocko@suse.com, rppt@kernel.org,
shuah@kernel.org, skhan@linuxfoundation.org, surenb@google.com,
vbabka@kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH v5 2/3] mm/hmm: add hmm_range_fault_unlockable() for mmap lock-drop support
Date: Thu, 2 Jul 2026 15:17:23 -0300 [thread overview]
Message-ID: <20260702181723.GV7525@ziepe.ca> (raw)
In-Reply-To: <178301356964.373695.14274584821659522979.stgit@skinsburskii>
On Thu, Jul 02, 2026 at 10:32:49AM -0700, Stanislav Kinsburskii wrote:
> + int driver_populate_range_unlockable(...)
> + {
> + struct hmm_range range;
> + int locked;
> + ...
> +
> + range.notifier = &interval_sub;
> + range.start = ...;
> + range.end = ...;
> + range.hmm_pfns = ...;
> +
> + if (!mmget_not_zero(interval_sub.mm))
> + return -EFAULT;
> +
> + again:
> + range.notifier_seq = mmu_interval_read_begin(&interval_sub);
> + locked = 1;
> + mmap_read_lock(mm);
> + ret = hmm_range_fault_unlockable(&range, &locked);
> + if (locked)
> + mmap_read_unlock(mm);
> + if (ret) {
> + if (ret == -EBUSY)
> + goto again;
> + return ret;
> + }
> + if (!locked)
> + goto again;
Why does this sequence make any sense? I think the caller holding the
mmap_read_lock() is some historical artifact, shouldn't it be pushed
down into the hmm function itself? Looking at the callers it seems
like almost all of them want that.
I can't guess why drm_gpusvm_range_find_or_insert() is mucking around
with VMAs, a hmm user should never do that. I think I gave this
feedback many times.
Also, why the goto again? If it needs to loop again it should return
EBUSY.
> @@ -715,7 +804,7 @@ int hmm_range_fault(struct hmm_range *range)
> } while (ret == -EBUSY);
> return ret;
> }
> -EXPORT_SYMBOL(hmm_range_fault);
> +EXPORT_SYMBOL(hmm_range_fault_unlockable);
Don't export new symbols without adding users please.
I suggest you add a hmm_range_fault_unlocked() instead and convert the
places that can obviously use it to use it.
Then maybe come with the unlockable version with an intree user and a
strong justification why something needs to hold the mmap lock
externally.
Jason
next prev parent reply other threads:[~2026-07-03 0:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-02 17:32 [PATCH v5 0/3] mm/hmm: Add mmap lock-drop support for userfaultfd-backed mappings Stanislav Kinsburskii
2026-07-02 17:32 ` [PATCH v5 1/3] mm/hmm: move page fault handling out of walk callbacks Stanislav Kinsburskii
2026-07-02 17:32 ` [PATCH v5 2/3] mm/hmm: add hmm_range_fault_unlockable() for mmap lock-drop support Stanislav Kinsburskii
2026-07-02 18:17 ` Jason Gunthorpe [this message]
2026-07-02 17:32 ` [PATCH v5 3/3] selftests/mm: add userfaultfd test for HMM unlockable path Stanislav Kinsburskii
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=20260702181723.GV7525@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=leon@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=skinsburskii@gmail.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.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