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

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


  • To: Mykyta Poturai <Mykyta_Poturai@xxxxxxxx>, Stewart Hildebrand <stewart.hildebrand@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Wed, 15 Apr 2026 13:54:12 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=epam.com smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=ixw4pxK1fDBPLFHhWF2pFWbJoAbbrbz1Drpqzf/0oNg=; b=jQs/xqM9hcvz9N46f7fZzptZ2O/D39902jWK6XioJjMqw7crFAKxVKndvgHYroFnDiFy2LwCm7kCjMUhl+lxC/ZvI0w+81XxEg3ZRt5LM30nBbLJJkVof+yTLzJcg1CO3SaxT8WhiHWr4Yx//OXbEfyDnbbIyM/CVsIfmwdaBaQ9mEz/NwJm2rIiF9U+el0LnNvGFnMvn1nonq479l6n1ANtMYtb6knsaw7J/PKq1XCxnSfOi7IIOwu16Z2NeSbf0e65upNj6M5sYdvgjHa5XFT3gre01MtRExl7jJBXWAiEZ8yTSvjC8goOCBWOopWbioz8wzn1Wm5P0ICqsHq+5Q==
  • 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=ixw4pxK1fDBPLFHhWF2pFWbJoAbbrbz1Drpqzf/0oNg=; b=iIn1kO0T4Q5muZ2qFnXD7fLdOmbNOyo6u80iUVPWJQk2zt0BS8d76yX1b/iBZIHDCedAH70vaVofEy/CIMhkRO9QpoGrDyAbP/sCdmqZmYNHNqs9d/L0qzhOnxC9NuQy1zTAKRLHrvpA2ZOdLSmUcnBboUz5SU66OqXbGW4KMdQ8dNF2nC4UFa4XlYRbnmukzCERugzacqw6D6E6x24vTwXh6XG/BT3upSXpPdgbuUILx0WKH9sq81e5cM4lvC3UxyVCXnc1N1VAQqpzLDsM2Fa8s3BE334F5cnPA1fG2SYPuh4I9M9p9tHjTnc177ZvSTaKW2qdmI1NEwye8GyhyQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=QnAtdtz5+lurcmZlwob5lN6btqapw6svmikI54YmOZWwy4l4Ztvw7s/bYEnT3HfAvZtl2Yc+bNhs4lwThMaJo3QikCLahowi7xVH0Oz9EVl8ou+I6z1ETgPZCg1dNkpilAygf8aC50jaglOrPxPvqHc2JFAoPhVzjlLYlcGBWZWCsAMOolOjN+thJvnGWqJGz3h1Fw3rZlWqz8bY9OJV6EsZljoPewynDHr7nbAyJ7rWOoubKbv6rj34MyYLsjqkZfeCM0u/vEWaVvvqrJqjsV2tY7qZwDlR27+CtQBCL4EsdHu4cTOXkNaVCEqkPQFXKP2TXOx7D6btHVrBA/fWfA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xAOTJYTRw8fMviz0zSJPkJmD0i7aVs2+qeBBUz9jhGDcDPEu/vS+wLKmB3qM3PUXyGpwCWF/0sEoAJkjR5cvAt7YZQqYTmBtBvRGCNxc3SCJkTW09ZruIC6r63PkWmnYdsdRVTOU1i+vn02L99iUcni3n+r2quQtQkQae3rluIsfG840uply0GnZzGU/pAETBeUSXXru0OCC4egnuEmlDKKvv25UCBTi9qx6imSx4sKUyjqQZuY/8vY0Aa1OVqUzHtJ65GmeWn+SR3SvLK9ViR4oW0TP/98w0ZlihjaKcwr3wSGTaiNdWmOHx/hStHYF+16HV8SZSWH7ednnBpPUPQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"; dkim=pass header.s=selector1 header.d=arm.com header.i="@arm.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Rahul Singh <Rahul.Singh@xxxxxxx>
  • Delivery-date: Wed, 15 Apr 2026 13:55:27 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHczBC6OGp5DbFlyEyismnWkcVdqLXgJmgA
  • Thread-topic: [PATCH v2] xen/arm: smmuv3: Add support for removing devices

Hi Mykyta,

> On 14 Apr 2026, at 14:15, Mykyta Poturai <Mykyta_Poturai@xxxxxxxx> wrote:
> 
> 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.
> 
> Rework dt_device_set_protected to accept a boolean parameter, update
> callsites.
> 

Should ...

> Tested on QEMU with SRIOV series[1] by repeatedly enabling/disabling
> VFs.
> 
> [1]: https://patchew.org/Xen/cover.1772806036.git.mykyta._5Fpoturai@xxxxxxxx/

this be omitted from commit message?

> 
> Signed-off-by: Mykyta Poturai <mykyta_poturai@xxxxxxxx>
> ---
> V1-V2:
> * check for phantom functions
> * simplify pci/dt device split
> * improve error handling
> * don't try to free master for unprotected devices
> * rework dt_device_set_protected
> ---
> xen/drivers/passthrough/arm/ipmmu-vmsa.c |  2 +-
> xen/drivers/passthrough/arm/smmu-v3.c    | 57 +++++++++++++++++++++++-
> xen/drivers/passthrough/arm/smmu.c       |  4 +-
> xen/include/xen/device_tree.h            |  5 ++-
> 4 files changed, 62 insertions(+), 6 deletions(-)
> 
> diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c 
> b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> index fa9ab9cb13..0648f9b407 100644
> --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c
> @@ -1367,7 +1367,7 @@ static int ipmmu_add_device(u8 devfn, struct device 
> *dev)
>         }
> 
>         /* Let Xen know that the master device is protected by an IOMMU. */
> -        dt_device_set_protected(dev_to_dt(dev));
> +        dt_device_set_protected(dev_to_dt(dev), true);
>     }
> #ifdef CONFIG_HAS_PCI
>     if ( dev_is_pci(dev) )
> diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
> b/xen/drivers/passthrough/arm/smmu-v3.c
> index bf153227db..8e080cd7d0 100644
> --- a/xen/drivers/passthrough/arm/smmu-v3.c
> +++ b/xen/drivers/passthrough/arm/smmu-v3.c
> @@ -1493,6 +1493,60 @@ 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)
> +{
> + struct arm_smmu_master *master;
> + struct iommu_fwspec *fwspec;

I’m looking into the arm_smmu_remove_device, at some point there we allocate
the iommu_fwspec, but we are not using iommu_fwspec_free() here, I’ve tried
to look around and I’m not able to see what frees that structure apart form
iommu_remove_dt_device().
But pci_remove_device() -> iommu_remove_device() can call this function as 
well, I’m not sure I’ve understood
correctly the framework here so maybe someone with more PCI experience can help
@Stewart Hildebrand ?


> + struct domain *d = NULL;
> +
> + fwspec = dev_iommu_fwspec_get(dev);
> + if ( !fwspec )
> + return -ENODEV;
> +
> + master = dev_iommu_priv_get(dev);
> + if ( !master )
> + return -ENODEV;
> +
> + if ( IS_ENABLED(CONFIG_HAS_PCI) && dev_is_pci(dev) )
> + {
> + struct pci_dev *pdev = dev_to_pci(dev);
> +
> + /* Ignore calls for phantom functions */
> + if ( devfn != pdev->devfn )
> + return 0;
> +
> + d = pdev->domain;
> + }
> + else
> + {
> + if ( !dt_device_is_protected(dev_to_dt(dev)) )
> + {
> + dev_err(dev, "Not added to SMMUv3\n");
> + return -ENODEV;
> + }
> +
> + dt_device_set_protected(dev_to_dt(dev), false);
> + if ( master->domain && master->domain->d )
> + d = master->domain->d;
> + }
> +
> + if ( d )
> + {
> + int ret = arm_smmu_deassign_dev(d, devfn, dev);
> + /* This should never fail because we already checked the domain */
> + ASSERT(!ret);
> + }
> +
> + arm_smmu_disable_pasid(master);
> +
> + dev_info(dev, "Removed master device (SMMUv3 %s StreamIds %u)\n",
> + dev_name(fwspec->iommu_dev), fwspec->num_ids);
> +
> + xfree(master);
> + dev_iommu_priv_set(dev, NULL);
> + return 0;
> +}
> +

Cheers,
Luca


 


Rackspace

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