Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aaron Lewis" <aaronlewis@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] iommufd: Periodically reschedule when unmapping
Date: Tue, 14 Jul 2026 21:34:32 +0000	[thread overview]
Message-ID: <20260714213433.02BA81F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260714210303.3967981-3-aaronlewis@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The `cond_resched()` rate limiter is circumvented for fragmented memory because the loop counter `i` is local and resets on every batch, leaving the scheduler warning unresolved.
- [High] Using `BIT(PUD_ORDER)` to rate-limit `cond_resched()` to 1GB is unportable and scales incorrectly on architectures with larger page sizes, preventing rescheduling.
--

--- Patch [2]: [PATCH 2/2] iommufd: Periodically reschedule when unmapping ---
commit 32d4b71fc4dce755ccc1bb27abe57a685f82b576
Author: Aaron Lewis <aaronlewis@google.com>

iommufd: Periodically reschedule when unmapping

This patch adds a cond_resched() call to batch_from_domain() to avoid
scheduler warnings during large DMA unmaps. It attempts to rate-limit
the yields to approximately once per 1GB of processed memory.

> diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c
> index 03c8379bbc347..e7abb3350b235 100644
> --- a/drivers/iommu/iommufd/pages.c
> +++ b/drivers/iommu/iommufd/pages.c
> @@ -412,6 +412,7 @@ static void batch_from_domain(struct pfn_batch *batch,
>  	unsigned int page_offset = 0;
>  	unsigned long iova;
>  	phys_addr_t phys;
> +	int i = 0;
>  
>  	iova = iopt_area_index_to_iova(area, start_index);
>  	if (start_index == iopt_area_index(area))
> @@ -428,6 +429,9 @@ static void batch_from_domain(struct pfn_batch *batch,
>  		iova += PAGE_SIZE - page_offset;
>  		page_offset = 0;
>  		start_index++;
> +
> +		if ((++i % BIT(PUD_ORDER)) == 0)
> +			cond_resched();

[Severity: High]
Does this regression mean the counter fails to trigger cond_resched() when
operating on fragmented memory?

Because i is a local variable, it resets to 0 on every call to
batch_from_domain(). For highly fragmented memory, batch_add_pfn() will
fill its array and return false early (limited to roughly 5,461 pages by
TEMP_MEMORY_LIMIT).

This early return causes the outer loops, such as iopt_area_unpin_domain(),
to repeatedly call batch_from_domain(). This continuously resets i to 0
before it can ever reach the threshold, meaning cond_resched() is never
called and scheduler lockups can still occur.

[Severity: High]
Is this a regression on architectures where BIT(PUD_ORDER) does not equal 1GB?

The commit message mentions limiting the cond_resched() call to once per 1GB.
While this holds true on architectures like x86_64, it scales incorrectly
on architectures with larger page sizes.

For example, on ARM64 with 64KB pages and 3-level page tables, PUD_ORDER
is 26. BIT(26) iterations of 64KB pages corresponds to 4TB of memory,
not 1GB. The loop will only yield once every 4TB, which effectively defeats
the mitigation on these architectures.

>  	}
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714210303.3967981-1-aaronlewis@google.com?part=2

      reply	other threads:[~2026-07-14 21:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 21:03 [PATCH 0/2] vfio/iommufd: Prevent scheduler warnings when unmapping large regions Aaron Lewis
2026-07-14 21:03 ` [PATCH 1/2] vfio/type1: Periodically try rescheduling when unmapping Aaron Lewis
2026-07-14 21:15   ` sashiko-bot
2026-07-14 21:03 ` [PATCH 2/2] iommufd: Periodically reschedule " Aaron Lewis
2026-07-14 21:34   ` sashiko-bot [this message]

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=20260714213433.02BA81F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aaronlewis@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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