[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] xen/arm: smmuv1: remove iommu group when deassign a device
- To: Julien Grall <julien@xxxxxxx>
- From: Rahul Singh <Rahul.Singh@xxxxxxx>
- Date: Fri, 29 Apr 2022 14:33:17 +0000
- Accept-language: en-US
- Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org 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=armh.onmicrosoft.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=arcselector9901; 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=B8UqTu4o0IYoUCHO1jrwbDByB81Vgr7jktqWisZeiy4=; b=BlGTa6g8XwJJ85u9/YC7rAqZX8CY73KNcCjF8GWw1wbzh7oS9K65PmoraKGjP1aKbhpHthkrlBsX4xOtaTyEPNG2cMGCU8GwCJoyty0uIbzlTnLPiOvGKCu3GuCH06c8VYoeG2fTOkI76vNRGqUNDsacGhFBLIBTxVQ8KePOhFHyyAMjFkZafTODlQEgw2QvKV+U9xWWkeqLJDfsr7+DywgF0iBeW1TubK8cud89PnJAFRgiwONbpTvnwBQZUVkWi8LR/539h4B+TRuPHyZaUGZhy8v673IAcuYex4P14k7/wvNTuj4hlVJ5dEtEFVFutWwnEjfjrYdBP4mlrS5yBQ==
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=B8UqTu4o0IYoUCHO1jrwbDByB81Vgr7jktqWisZeiy4=; b=G6jnIf9fFzEzCDVTesWwX5zCdlDoTywY4F+gAO9h661rKECutgsxKGresAMD7+Hvm0CJBp3nry6i+evmc0ts+qB7+yXtEIed/EYwWD58CLHd6V+SiuhLlgrPUCEXEESUHmcVEuLXD5wwtHthxY0OpQjKKcy5aw3GWC2ND4vGuuPqwtMLK5l2Xu6jlqO1u7NgzR+7/9hoSjXpCbdnm0WnZfwMC7blhY25/C13Y68yHRKjjEQExbbdwCgfy9uroorn9vZl8ZhY08mGae95sHRUYhwLiU3042kjIVaxqNjTSkDpdhxNtu5aiVnCS4vFXNXcMctWeFTf36JBBoXbAhF2WA==
- Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=OTCuXrZY6D9pq/oNQQdI4cvkjYc77y8Ukf5/TB37fkXDoPQjT4OMbVgKoooKRwHQ0uifvG/sOOa2fQNOBrVaMFlVe0vY2Pfqjy45ro6fuDqy55eal9GZhosbmK7Jm/ylcvrLkHbx1a9Fi0trBO7/FRCyal4FJTkCSF73HfKi/59kf2gIxfPvZzgtlIbQPpUQebxUTTJNIjhIyRB3rdL52amQqCOmJ1h2ZPHBmmEwwqhLbkscfQgiJiPvbRAMEFnw1NshxBe8sBHtXsayT2G8Z+v1PMS02RVUmCMMNdULocq8ZTAkwxm/VeRIw2mFEj2ja7my2WxAY+JZpR7O5+g9JA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fPwBPnT7mPIhZYL1KVu9/ue2+6K2twuUfUjK0kVfxsjRtG/2irHv7hyyh2jeNMyEF5PbJu8BzDVCofBcqI/b/QxnWnCUnXDTZ0b+eM1eVuEMeSeg3aqgxwUiPsDavtya8YyQqsvoUwcClGkYPHix6SoPQ1pvjMiFu+b23eN1W0fpoIZ6IBv+QA+xhqWESsLBjBy5fKmSNPEHS+d72Xkz8eD2eNmnNGGQmcx2PBKs6vk1MlD67QU/AGH0z46+vRXgW4/hqArOHWO5MX8Ids3fK84JHVNuVhSkauMYIWe27LNJWvZYivv6ZHZvULeNePTZC2RovdVCFooFTB+N4cW+Ig==
- Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
- Delivery-date: Fri, 29 Apr 2022 14:33:48 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Nodisclaimer: true
- Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
- Thread-index: AQHYWlIekEFYa4Z+ZkOKg6prrRxnv60EB7eAgALvxoA=
- Thread-topic: [PATCH] xen/arm: smmuv1: remove iommu group when deassign a device
Hi Julien,
> On 27 Apr 2022, at 6:42 pm, Julien Grall <julien@xxxxxxx> wrote:
>
> Hi,
>
> On 27/04/2022 17:15, Rahul Singh wrote:
>> When a device is deassigned from the domain it is required to remove the
>> iommu group.
>
> This read wrong to me. We should not need to re-create the IOMMU group (and
> call arm_smmu_add_device()) every time a device is re-assigned.
Ok.
>
>> If we don't remove the group, the next time when we assign
>> a device, SME and S2CR will not be setup correctly for the device
>> because of that SMMU fault will be observed.
>
> I think this is a bug fix for 0435784cc75dcfef3b5f59c29deb1dbb84265ddb. If
> so, please add a Fixes tag.
Ok Let me add the Fixes tag in next version.
>
>> Signed-off-by: Rahul Singh <rahul.singh@xxxxxxx>
>> ---
>> xen/drivers/passthrough/arm/smmu.c | 2 ++
>> 1 file changed, 2 insertions(+)
>> diff --git a/xen/drivers/passthrough/arm/smmu.c
>> b/xen/drivers/passthrough/arm/smmu.c
>> index 5cacb2dd99..9a31c332d0 100644
>> --- a/xen/drivers/passthrough/arm/smmu.c
>> +++ b/xen/drivers/passthrough/arm/smmu.c
>> @@ -1690,6 +1690,8 @@ static void arm_smmu_detach_dev(struct iommu_domain
>> *domain, struct device *dev)
>> if (cfg)
>> arm_smmu_master_free_smes(cfg);
>> + iommu_group_put(dev_iommu_group(dev));
>> + dev_iommu_group(dev) = NULL;
>> }
>
> The goal of arm_smmu_detach_dev() is to revert the change made in
> arm_smmu_attach_dev(). But looking at the code, neither the IOMMU group nor
> the smes are allocated in arm_smmu_attach_dev().
>
> Are the SMES meant to be re-allocated everytime we assign to a different
> domain? If yes, the allocation should be done in arm_smmu_attach_dev().
Yes SMES have to be re-allocated every time a device is assigned.
Is that okay if I will move the function arm_smmu_master_alloc_smes() from
arm_smmu_add_device() to arm_smmu_attach_dev().
In this case we don’t need to remove the IOMMU group and also
arm_smmu_detach_dev() will also revert the change made in
arm_smmu_attach_dev().
diff --git a/xen/drivers/passthrough/arm/smmu.c
b/xen/drivers/passthrough/arm/smmu.c
index 5cacb2dd99..ff1b73d3d8 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -1680,6 +1680,10 @@ static int arm_smmu_attach_dev(struct iommu_domain
*domain, struct device *dev)
if (!cfg)
return -ENODEV;
+ ret = arm_smmu_master_alloc_smes(dev);
+ if (ret)
+ return ret;
+
return arm_smmu_domain_add_master(smmu_domain, cfg);
}
@@ -2075,7 +2079,7 @@ static int arm_smmu_add_device(struct device *dev)
iommu_group_add_device(group, dev);
iommu_group_put(group);
- return arm_smmu_master_alloc_smes(dev);
+ return 0;
}
Regards,
Rahul
>
> If not, then we should not free the SMES here
>
> IIUC, the SMES have to be re-allocated every time a device is assigned.
> Therefore, I think we should move the call to arm_smmu_master_alloc_smes()
> out of the detach callback and in a helper that would be used when removing a
> device (not yet supported by Xen).
>
> Cheers,
>
> --
> Julien Grall
|