From: Vasant Hegde <vasant.hegde@xxxxxxx> [ Upstream commit 080920e52148b4fbbf9360d5345fdcd7846e4841 ] Current code throws kernel warning if it fails to enable pasid/pri [1]. Do not call pci_disable_[pasid/pri] if pci_enable_[pasid/pri] failed. [1] https://lore.kernel.org/linux-iommu/15d0f9ff-2a56-b3e9-5b45-e6b23300ae3b@xxxxxxxxxxxxx/ Reported-by: Matt Fagnani <matt.fagnani@xxxxxxxx> Signed-off-by: Vasant Hegde <vasant.hegde@xxxxxxx> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> Link: https://lore.kernel.org/r/20230111121503.5931-1-vasant.hegde@xxxxxxx Signed-off-by: Joerg Roedel <jroedel@xxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> --- drivers/iommu/amd_iommu.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 5d5941aca16ad..75c5932d0133a 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -2059,17 +2059,17 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) /* Only allow access to user-accessible pages */ ret = pci_enable_pasid(pdev, 0); if (ret) - goto out_err; + return ret; /* First reset the PRI state of the device */ ret = pci_reset_pri(pdev); if (ret) - goto out_err; + goto out_err_pasid; /* Enable PRI */ ret = pci_enable_pri(pdev, reqs); if (ret) - goto out_err; + goto out_err_pasid; if (reset_enable) { ret = pri_reset_while_enabled(pdev); @@ -2079,12 +2079,14 @@ static int pdev_iommuv2_enable(struct pci_dev *pdev) ret = pci_enable_ats(pdev, PAGE_SHIFT); if (ret) - goto out_err; + goto out_err_pri; return 0; -out_err: +out_err_pri: pci_disable_pri(pdev); + +out_err_pasid: pci_disable_pasid(pdev); return ret; -- 2.39.2