From: Luca Di Maio <luca@edera.dev>
To: xen-devel@lists.xenproject.org
Cc: "Luca Di Maio" <luca@edera.dev>,
"Jan Beulich" <jbeulich@suse.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Roger Pau Monné" <roger@xenproject.org>,
"Teddy Astie" <teddy.astie@vates.tech>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Bertrand Marquis" <bertrand.marquis@arm.com>,
"Michal Orzel" <michal.orzel@amd.com>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Anthony PERARD" <anthony.perard@vates.tech>
Subject: [PATCH v2 1/4] VT-d: round IOTLB flush ranges up to an aligned power of two
Date: Fri, 6 Nov 2026 09:08:51 +0100 [thread overview]
Message-ID: <20261106080859.2285309-2-luca@edera.dev> (raw)
In-Reply-To: <20261106080859.2285309-1-luca@edera.dev>
Page-selective invalidation takes only aligned power-of-two ranges, so
iommu_flush_iotlb() flushes any other range as the whole domain. A
later patch flushes one range per group of grant unmaps, which rarely
has that shape.
Round the range up to the smallest aligned power of two covering it.
Orders the IOMMU doesn't support still get a domain-selective flush,
and device TLB invalidations use the same range.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Luca Di Maio <luca@edera.dev>
---
Changes in v2:
- New patch, taking the rounding out of the grant unmap batch (Teddy).
---
xen/drivers/passthrough/vtd/iommu.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c
index b41a1d41c8..faf8255f26 100644
--- a/xen/drivers/passthrough/vtd/iommu.c
+++ b/xen/drivers/passthrough/vtd/iommu.c
@@ -742,6 +742,10 @@ static int __must_check cf_check iommu_flush_iotlb(struct domain *d, dfn_t dfn,
{
ASSERT(page_count && !dfn_eq(dfn, INVALID_DFN));
ASSERT(flush_flags);
+
+ /* PSI takes only aligned powers of two: cover the range with one. */
+ page_count = 1UL << flsl(dfn_x(dfn) ^ (dfn_x(dfn) + page_count - 1));
+ dfn = _dfn(dfn_x(dfn) & ~(page_count - 1));
}
/*
--
2.47.3
next prev parent reply other threads:[~2026-11-06 8:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 8:08 [PATCH v2 0/4] x86/HVM: batch the flushes of grant unmaps Luca Di Maio
2026-11-06 8:08 ` Luca Di Maio [this message]
2026-11-06 8:08 ` [PATCH v2 2/4] IOMMU: record the flushes skipped under iommu_dont_flush_iotlb Luca Di Maio
2026-11-06 8:08 ` [PATCH v2 3/4] x86/HVM: defer IOTLB flushes across a grant unmap batch Luca Di Maio
2026-11-06 8:08 ` [PATCH v2 4/4] x86/HVM: defer p2m TLB " Luca Di Maio
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=20261106080859.2285309-2-luca@edera.dev \
--to=luca@edera.dev \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=bertrand.marquis@arm.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=teddy.astie@vates.tech \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.