[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen/arm: smmuv3: invalidate TLB when freeing a VMID


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Leonid Komarianskyi <Leonid_Komarianskyi@xxxxxxxx>
  • Date: Mon, 26 Oct 2026 13:25:47 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=t+MYzgUOpIBvdKGtiejpP31vPoplzCjuNPQukK5VP10=; b=ZZMiLGz+mpnFgEVRjqZnXrYnv1bG9DpDwOnmefS5G1xFpo0mHBZiebHqi7z3uVej8F1CcIKCVrPrw4WjD2y/AA7uhMnukvXwe/KbvWuepQuec7/G6KLkjQ0bZvCxsNxopembeRODdCRH3zV5BTOoCU6wNidQQPQWkAT+wUpICJ2I+Y07wfq8wBygcuqhs04cYEpsZ1QejATEE5IGOVq3hBhPoe4tjDw4dHJ428RVN70uLmZbNpq5TyBntWGk/Nws/1SeRRtvF/IW9RNtSy8RTwUzmBesOby0HQ4Oc4H8An253ToqzR9MSwVr+BAuVz9sbiKswjdlNkiTs6wE0poW2g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dgf5hGDG2z9AWHJvv7+rkd3cxYkTwudQrWwJBy22gvCCXf6LkionpXEbw0XxutZ6QPUPvtPlDYf2y/yVfrD7464vQPupIK4QwHTONZ0MYNGmYToCQ0WG5UGPfUPFebb8g8ZYTqvT+FDAsFTBg/OB+PmLG9lEX25SydQ+CqLjb8T0DjJLfqXxDm83j9ZmpEXzJZcrsu4GeFEx0rUuYkT6uR466tW1Olx3HoVEbEqjtwtVQk/uBZnErv70ntqB5tQXsO7/ncObyny5bo9DduuPumMHHhlvTWzEfaD6+nSQi1/9RAF7WoyMUcEBCQi/UjwyPQ7Gt0ZGn/syANAI3oWIGQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:x-ms-exchange-senderadcheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Bertrand Marquis <bertrand.marquis@xxxxxxx>, Rahul Singh <rahul.singh@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Leonid Komarianskyi <Leonid_Komarianskyi@xxxxxxxx>
  • Delivery-date: Mon, 26 Oct 2026 13:25:52 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHdZU2CvV133olROUKhJSegs8l4mg==
  • Thread-topic: [PATCH] xen/arm: smmuv3: invalidate TLB when freeing a VMID

arm_smmu_domain_free() releases the VMID without invalidating the SMMU
TLB entries tagged with it. The VMID allocator (arm_smmu_bitmap_alloc)
always returns the first free VMID, so a new domain usually gets the
same VMID as the domain that was just destroyed. As a result, DMA from
a device assigned to the new domain can use stale TLB entries and access
memory of the old domain, which may already be in use by Xen or by
another domain.

In Linux, this invalidation is done by free_io_pgtable_ops(), which
calls the tlb_flush_all callback (arm_smmu_tlb_inv_context()) before
the VMID is released. The call was dropped when the io-pgtable code
was removed during the port to Xen, and nothing replaced it.

Linux guests that modify their P2M early in boot (e.g. by mapping
shared_info in the xen_guest_init initcall) hide the problem, because
the resulting IOTLB flush clears the stale entries. However, guests
without Xen support (e.g. Linux with CONFIG_XEN disabled) do not modify
the P2M early in boot, so the device keeps using stale SMMU TLB entries.
This was observed as GPU rendering corruption after "xl destroy" and "xl
create" of the same guest with CONFIG_XEN disabled.

To fix the problem, issue a TLB invalidation for the VMID before
releasing it.

Fixes: b3be6ffb009c ("xen/arm: smmuv3: Remove Linux specific code that is not 
usable in XEN")
Signed-off-by: Leonid Komarianskyi <leonid_komarianskyi@xxxxxxxx>
---
 xen/drivers/passthrough/arm/smmu-v3.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index bf153227dbd..93176e2fb21 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -1153,8 +1153,14 @@ static void arm_smmu_domain_free(struct iommu_domain 
*domain)
        struct arm_smmu_device *smmu = smmu_domain->smmu;
        struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
 
-       if (cfg->vmid)
+       if (cfg->vmid) {
+               /*
+                * Invalidate all entries tagged with this VMID
+                * before it can be handed to another domain.
+                */
+               arm_smmu_tlb_inv_context(smmu_domain);
                arm_smmu_bitmap_free(smmu->vmid_map, cfg->vmid);
+       }
 
        xfree(smmu_domain);
 }
-- 
2.34.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.