Linux-HyperV List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Stanislav Kinsburskii" <skinsburskii@gmail.com>
Cc: linux-hyperv@vger.kernel.org
Subject: Re: [PATCH v6 2/4] mm/hmm: add hmm_range_fault_unlocked() for mmap lock-drop support
Date: Mon, 06 Jul 2026 18:16:11 +0000	[thread overview]
Message-ID: <20260706181611.830E31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <178336050736.504354.6052508493877924780.stgit@skinsburskii>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] `hmm_range_fault_unlocked()` uses uninterruptible `mmap_read_lock()` inside a retry sequence, which can delay or block fatal signals.
- [High] Unconditional dereference of `hmm_vma_walk->locked` in `hmm_do_fault()` can cause a kernel panic if a buggy fault handler returns `VM_FAULT_RETRY` or `VM_FAULT_COMPLETED` without `FAULT_FLAG_ALLOW_RETRY`.
--

commit 0808f6917e681bb06bd68894103530cfbabe07b9
Author: Stanislav Kinsburskii <skinsburskii@gmail.com>

mm/hmm: add hmm_range_fault_unlocked() for mmap lock-drop support

This commit adds hmm_range_fault_unlocked() for callers that do not
need to hold mmap_lock across any work outside the HMM fault itself.
It takes mmap_read_lock() internally and allows handle_mm_fault() to
drop it during fault handling.

> diff --git a/mm/hmm.c b/mm/hmm.c
> index 2129b1ee4c35b..316116994209c 100644
> --- a/mm/hmm.c
> +++ b/mm/hmm.c
[ ... ]
> @@ -651,37 +663,33 @@ static int hmm_do_fault(struct mm_struct *mm,
>  		fault_flags |= FAULT_FLAG_WRITE;
>  	}
>  
> -	for (; addr < end; addr += PAGE_SIZE)
> -		if (handle_mm_fault(vma, addr, fault_flags, NULL) &
> -		    VM_FAULT_ERROR)
> -			return -EFAULT;
> +	for (; addr < end; addr += PAGE_SIZE) {
> +		vm_fault_t ret;
> +
> +		ret = handle_mm_fault(vma, addr, fault_flags, NULL);
> +
> +		if (ret & (VM_FAULT_COMPLETED | VM_FAULT_RETRY)) {
> +			*hmm_vma_walk->locked = 0;

[Severity: High]
Can this result in a NULL pointer dereference?

When the legacy hmm_range_fault() is called, it passes NULL for the
locked parameter, meaning hmm_vma_walk->locked will be NULL.

If a buggy fault handler incorrectly returns VM_FAULT_RETRY even when
FAULT_FLAG_ALLOW_RETRY is not set, it seems this would unconditionally
dereference the NULL pointer here.

> +			return HMM_FAULT_UNLOCKED;
> +		}
[ ... ]
> +int hmm_range_fault_unlocked(struct hmm_range *range)
> +{
> +	struct mm_struct *mm = range->notifier->mm;
> +	int locked = 1;
> +	int ret;
> +
> +	mmap_read_lock(mm);

[Severity: High]
Should this use mmap_read_lock_killable() instead of the uninterruptible
mmap_read_lock()?

Since this function is designed to be called inside a retry loop, if the
mmap lock is highly contended, it appears a task could enter an
uninterruptible sleep here and block fatal signals indefinitely. This might
defeat the purpose of the FAULT_FLAG_KILLABLE flag that is set during the
actual fault.

> +	ret = hmm_range_fault_locked(range, &locked);
> +	if (locked)
> +		mmap_read_unlock(mm);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL(hmm_range_fault_unlocked);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/178336023903.504354.7500950448226027718.stgit@skinsburskii?part=2

  parent reply	other threads:[~2026-07-06 18:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 17:54 [PATCH v6 0/4] mm/hmm: Add mmap lock-drop support for userfaultfd-backed mappings Stanislav Kinsburskii
2026-07-06 17:55 ` [PATCH v6 1/4] mm/hmm: move page fault handling out of walk callbacks Stanislav Kinsburskii
2026-07-06 17:55 ` [PATCH v6 2/4] mm/hmm: add hmm_range_fault_unlocked() for mmap lock-drop support Stanislav Kinsburskii
2026-07-06 18:02   ` Jason Gunthorpe
2026-07-06 18:16   ` sashiko-bot [this message]
2026-07-06 17:55 ` [PATCH v6 3/4] selftests/mm: add userfaultfd test for HMM unlocked path Stanislav Kinsburskii
2026-07-06 17:55 ` [PATCH v6 4/4] mshv: Use hmm_range_fault_unlocked() for region faults Stanislav Kinsburskii
2026-07-06 18:16   ` Jason Gunthorpe
2026-07-06 18:21   ` sashiko-bot

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=20260706181611.830E31F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skinsburskii@gmail.com \
    /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