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

[PATCH v1] xen/arm: smmuv3: Add support for removing devices


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>
  • Date: Tue, 7 Apr 2026 09:58:34 +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=DM5ctd74HSf9n6McPIthpWnwvO71M4XGIm8bZHpDQj0=; b=Bf0U0tlL0JLRZfk7m8XKZkq89WpW3wno+jKf/m4Pa3rjAZ3eahFMoIWLKQMGxfmMWKxgN6vh5SKNW9GiypjKktX3RGjrjmJx4G2BdKIrq7S13gq0t9LsXttba4aN9wEhq47sAxg18hhOE5I2Nf59iNS7/rtJD2keiVzqNGDeerJyxO6MQizRkEKiSJxaDxQZf+xCNskjY7Js+BltauNFGHhREBKBqXSQa8xxYaKebgj/6mJuQM/4XeRloBX2rlboCVdYX1brlRuWpSQzYzu0O8gpxRiVPJ0h2wpVtyv6Loh4ENtLb8851qBnedd3+x5R0tt1wnB4GMt/a+v4aBPciw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u9wFUJ23GOx0MtbgJ8hY5zZ5mch4YD2hhaxnxdRkKHti1SOZHmzq/SPCKIRnKou5fn+/nfSrtVJx52Io4K6M4MvRgtKsdhR3ZcQAd66LcxQPvjIaGvqOfKS1N36UpYB3nwvNzWF6Y7dIjrf8avwYmDOJiLWbzShXTKLFSpFsbJy48zS4zme1KohqOoj0/XReWk1T5lpbpGafywghxJg/QcybUR2OZ6OohuiGxG86XVhetXob1yX2dsvHPAh1lbGrwAm/z1FbqCAp8Eja2V8XSx4n0COUupuljwUPdLtg6LK5GWh7KhzrsIzgIcLpP4lPuApOU6ILmrY6dV4joRJufA==
  • 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: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>, 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>
  • Delivery-date: Tue, 07 Apr 2026 09:58:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcxnUZYHa+CmL3S0yWL3bconIhZw==
  • Thread-topic: [PATCH v1] xen/arm: smmuv3: Add support for removing devices

Allow for removing devices from SMMUv3. arm_smmu_deassign_dev handles
most of the work by disabling ATS and zeroing STEs. Additionally, unset
the dt_device_is_protected flag and free no longer needed smmu_master.

Tested on QEMU with SRIOV series[1] by repeatedly enabling/disabling
VFs.

[1]: https://patchew.org/Xen/cover.1772806036.git.mykyta._5Fpoturai@xxxxxxxx/

Signed-off-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>
---
 xen/drivers/passthrough/arm/smmu-v3.c | 59 +++++++++++++++++++++++++++
 xen/include/xen/device_tree.h         |  5 +++
 2 files changed, 64 insertions(+)

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index bf153227db..b5b834a7b7 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -1493,6 +1493,64 @@ static int arm_smmu_assign_dev(struct domain *d, u8 
devfn, struct device *dev,
 static int arm_smmu_deassign_dev(struct domain *d, uint8_t devfn,
                                 struct device *dev);
 
+static int arm_smmu_remove_device(u8 devfn, struct device *dev)
+{
+       int ret = 0;
+       struct arm_smmu_master *master;
+       struct iommu_fwspec *fwspec;
+
+       fwspec = dev_iommu_fwspec_get(dev);
+       if ( !fwspec )
+               return -ENODEV;
+
+       master = dev_iommu_priv_get(dev);
+       if ( !master )
+               return -ENODEV;
+
+#ifdef CONFIG_HAS_PCI
+       if ( dev_is_pci(dev) )
+       {
+               struct pci_dev *pdev = dev_to_pci(dev);
+
+               if ( pdev->domain )
+               {
+                       ret = arm_smmu_deassign_dev(pdev->domain, devfn, dev);
+                       if ( ret )
+                               printk(XENLOG_WARNING "Failed to deassign 
device %pp from SMMU\n",
+                                       &pdev->sbdf);
+               }
+       }
+#endif
+
+       if ( !dev_is_pci(dev) )
+       {
+               if ( !dt_device_is_protected(dev_to_dt(dev)) )
+               {
+                       dev_err(dev, "Not added to SMMUv3\n");
+                       ret = -ENODEV;
+                       goto out_free;
+               }
+
+               if ( master->domain && master->domain->d )
+               {
+                       ret = arm_smmu_deassign_dev(master->domain->d, 0, dev);
+                       if ( ret )
+                               dev_warn(dev, "Failed to deassign device from 
SMMU\n");
+               }
+               dt_device_unset_protected(dev_to_dt(dev));
+       }
+
+       arm_smmu_disable_pasid(master);
+
+       dev_info(dev, "Removed master device (SMMUv3 %s StreamIds %u)\n",
+                dev_name(fwspec->iommu_dev), fwspec->num_ids);
+
+out_free:
+       xfree(master);
+       dev_iommu_priv_set(dev, NULL);
+       return ret;
+}
+
 static int arm_smmu_add_device(u8 devfn, struct device *dev)
 {
        int i, ret;
@@ -2867,6 +2925,7 @@ static const struct iommu_ops arm_smmu_iommu_ops = {
        .unmap_page             = arm_iommu_unmap_page,
        .dt_xlate               = arm_smmu_dt_xlate,
        .add_device             = arm_smmu_add_device,
+       .remove_device          = arm_smmu_remove_device,
 };
 
 static __init int arm_smmu_dt_init(struct dt_device_node *dev,
diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h
index 06d7643622..1f9608cdcd 100644
--- a/xen/include/xen/device_tree.h
+++ b/xen/include/xen/device_tree.h
@@ -305,6 +305,11 @@ static inline void dt_device_set_protected(struct 
dt_device_node *device)
     device->is_protected = true;
 }
 
+static inline void dt_device_unset_protected(struct dt_device_node *device)
+{
+    device->is_protected = false;
+}
+
 static inline bool dt_device_is_protected(const struct dt_device_node *device)
 {
     return device->is_protected;
-- 
2.51.2



 


Rackspace

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