[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 14:31:18 +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=KQdJJxGfBiMUNrgXyhm/E+tiuTsLt47c6AZEW/9sf6Q=; b=FBx4i2WHnEjk4yIbXFbCXw6ilqDX9kWuGPUUnZ7PDy7mvfkwc/bwzxONcW9OlHBzXH0FSh0D6Jx7tOwaViVFYX/Yq+R6m0wA48PoI4BqeAFpbvB5trqPphCYr8OvSUy8qvB4zULZNmn7IGlk1zl8eJ3GTOFm2fNSlgsNAsc88Gr4ZmwpFT3MT8cFwEdbO1PqTYvqULT6jt8SWYIyZpspieWIjdWpdkhI7fselHCZwaV+SmFtYGn8cbePxBdQ3egxC7Wcw3ZZ58Gmb0CmAzEJm0B/ePj4//4Q3Nw11amdpKjoHPfDay2N8Dy96oUSbWHPBitgTHNKVkJmT4PnBpF6jw==
  • 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=KQdJJxGfBiMUNrgXyhm/E+tiuTsLt47c6AZEW/9sf6Q=; b=ORT0jTBUFn2G8s7fREqXo9kIYhAMdK8XkwxFExqIt70W+f3SgQTKKUGpvGcSgaEVlGgbPZWgRbnho/9ZoNv22h1yadTUQ7q56QR9ZUz+xuZVcx1YALQeXcOnrv3Pj2+KOs8C5xo874OYXsxfl8qP4CcoT3Yk4mzuDWpMnGcU2LgWMNaimYBR8ufYvEVp05z2aZJ9aL7zzHweN6/k0xqzu1locOQnFI2eONWjuhDYA8kr9CTZ/2nr+wjARPgRvU0jZq3yC9Gaw5SJ6uhUEgkpOQ+KdIkXLNZ59sxVfoe/AFERjYppGrjwG5nalimX92hT4c/EsbeXIMSxssQ9IwgfdQ==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=jey7VvFTEs3ighi1WgEtVuenMAEtF3770kseqvNpK/jVek86BjQD14R6lLVmEAnt1rBQI3ofT7ItNUQKoCTEJKQXOXdwtC4QmB+0LdZrC6cjZVTZayulhjjD6jSPTisp/dyS9CVnz4Agyk2F/0qLWohP+l6k6/9LdC7EoGptod0hOvr6031zsTmZDJRvy39oXMkpS5OFJx86zknWFwBYtzT8Xlm7AtKtBmudmzHcdGgfTfoje4qGRVLV5/6EOw5uDtuGtwAW+DLzerXjynVRt3P6vbdt4Jh4TBSj7yU3xIaozrG499tgyiKpRX+jHdS9Pb01gJ89AdnDXNfBd8G6Yw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Wh/XryE8Pg+U7ZOb1FdrYykaFKJ944jQbN8Ju02ChcrHrg0tAA5MZfiAI+mlL5dXzJPesJljOj1w/pZ3O6D9jJ6zNKpZRdDRnZklD08BuQQD63tffwiioRozdhsLCuefF8HVzpT72pdIxm+sHIuUM+7+nf4w5FjCkGR6iWzU4iwLXDcQXEnwOxAtg3/U3srs7IGKruWHCVU4V6rADu9I769dcoG86qazJhEv7wFEAl/cKt05iS66lAfEwUdSrmlbWdZmTkI0Pv46t3Tm1CPwe2qdu/6t6d1jGSHvuKPv9i+bD6K0vqMmzHdx9s07BEvcgxlUIB0zukxlfAnuZ4TOcA==
  • 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 14:32:44 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHczBC6OGp5DbFlyEyismnWkcVdqLXgJmgAgAAKXQA=
  • Thread-topic: [PATCH v2] xen/arm: smmuv3: Add support for removing devices


> On 15 Apr 2026, at 14:54, Luca Fancellu <Luca.Fancellu@xxxxxxx> wrote:
> 
> 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

Apologies, I meant arm_smmu_add_device here

> 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®.