[PATCH OLK-6.6] iommufd: Rollback IOPF and refcount when iopf/sva enabling fails
Offering: HULK hulk inclusion category: bugfix bugzilla: https://gitcode.com/openeuler/kernel/issues/10441 ------------------ iommufd_fault_iopf_enable() has two state-consistency problems on the failure paths, both introduced by commit 6b45626422f7 ("iommufd: enable SVA when IOPF enabled"): 1. When IOMMU_DEV_FEAT_SVA enabling fails, the function returns without disabling the already-enabled IOMMU_DEV_FEAT_IOPF and without undoing the incremented idev->iopf_enabled. The leftover refcount makes the next enable() hit the "already enabled" shortcut and return success while SVA was never actually enabled, so the device is attached to a fault domain with SVA silently missing. 2. When IOMMU_DEV_FEAT_IOPF enabling fails, the error is not propagated: the code keeps going and enables SVA, overwriting the return value. If SVA happens to succeed, the function returns 0 although IOPF is off and the refcount is back to 0, and the later disable() path hits WARN_ON(iopf_enabled == 0). Fix both by jumping to a common undo path when IOPF enabling fails, rolling back IOPF when SVA enabling fails, and dropping the refcount on any failure, so that a failed enable() leaves the device exactly as it was found, which is the contract its callers rely on. The unlock also converges back to a single exit, superseding the previous partial fix. Fixes: 6b45626422f7 ("iommufd: enable SVA when IOPF enabled") Signed-off-by: Zhang Yuwei <zhangyuwei20@huawei.com> --- drivers/iommu/iommufd/fault.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 5935c44c58e2..66015cb5e4da 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -44,14 +44,15 @@ static int iommufd_fault_iopf_enable(struct iommufd_device *idev) ret = iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_IOPF); if (ret) - --idev->iopf_enabled; + goto out_undo; - ret = iommu_dev_enable_feature(idev->dev, IOMMU_DEV_FEAT_SVA); - if (ret) { - mutex_unlock(&idev->iopf_lock); - return ret; - } + ret = iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_SVA); + if (ret) + iommu_dev_disable_feature(dev, IOMMU_DEV_FEAT_IOPF); +out_undo: + if (ret) + --idev->iopf_enabled; mutex_unlock(&idev->iopf_lock); return ret; -- 2.22.0
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,转换为PR失败! 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/RBA... 失败原因:应用补丁/补丁集失败,Patch failed at 0001 iommufd: Rollback IOPF and refcount when iopf/sva enabling fails 建议解决方法:请查看失败原因, 确认补丁是否可以应用在当前期望分支的最新代码上 FeedBack: The patch(es) which you have sent to kernel@openeuler.org has been converted to PR failed! Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/RBA... Failed Reason: apply patch(es) failed, Patch failed at 0001 iommufd: Rollback IOPF and refcount when iopf/sva enabling fails Suggest Solution: please checkout if the failed patch(es) can work on the newest codes in expected branch
participants (2)
-
patchwork bot -
Zhang Yuwei