[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJs_Fx6qgQFOp16SLQfz-Aaj4mqTo+vCvfpQr_E3UapVTrsu6Q@mail.gmail.com>
Date: Thu, 10 Jun 2021 15:28:15 -0700
From: Rob Clark <robdclark@...omium.org>
To: Xiyu Yang <xiyuyang19@...an.edu.cn>
Cc: Will Deacon <will@...nel.org>, Robin Murphy <robin.murphy@....com>,
Joerg Roedel <joro@...tes.org>,
Jon Hunter <jonathanh@...dia.com>,
Krishna Reddy <vdumpa@...dia.com>,
Jordan Crouse <jordan@...micpenguin.net>,
Sai Prakash Ranjan <saiprakash.ranjan@...eaurora.org>,
"moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)"
<linux-arm-kernel@...ts.infradead.org>,
iommu@...ts.linux-foundation.org,
LKML <linux-kernel@...r.kernel.org>, yuanxzhang@...an.edu.cn,
Xin Tan <tanxin.ctf@...il.com>
Subject: Re: [PATCH v2] iommu/arm-smmu: Fix arm_smmu_device refcount leak in
address translation
On Wed, Jun 9, 2021 at 7:50 PM Xiyu Yang <xiyuyang19@...an.edu.cn> wrote:
>
> The reference counting issue happens in several exception handling paths
> of arm_smmu_iova_to_phys_hard(). When those error scenarios occur, the
> function forgets to decrease the refcount of "smmu" increased by
> arm_smmu_rpm_get(), causing a refcount leak.
>
> Fix this issue by jumping to "out" label when those error scenarios
> occur.
>
> Signed-off-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@...il.com>
> ---
> drivers/iommu/arm/arm-smmu/arm-smmu.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> index 6f72c4d208ca..3a3847277320 100644
> --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c
> +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.c
> @@ -1271,6 +1271,7 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain,
> u64 phys;
> unsigned long va, flags;
> int ret, idx = cfg->cbndx;
> + phys_addr_t addr = 0;
>
> ret = arm_smmu_rpm_get(smmu);
> if (ret < 0)
> @@ -1290,6 +1291,7 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain,
> dev_err(dev,
> "iova to phys timed out on %pad. Falling back to software table walk.\n",
> &iova);
> + arm_smmu_rpm_put(smmu);
> return ops->iova_to_phys(ops, iova);
I suppose you could also:
addr = ops->iov_to_phys(...);
goto out;
but either way,
Reviewed-by: Rob Clark <robdclark@...omium.org>
> }
>
> @@ -1298,12 +1300,14 @@ static phys_addr_t arm_smmu_iova_to_phys_hard(struct iommu_domain *domain,
> if (phys & ARM_SMMU_CB_PAR_F) {
> dev_err(dev, "translation fault!\n");
> dev_err(dev, "PAR = 0x%llx\n", phys);
> - return 0;
> + goto out;
> }
>
> + addr = (phys & GENMASK_ULL(39, 12)) | (iova & 0xfff);
> +out:
> arm_smmu_rpm_put(smmu);
>
> - return (phys & GENMASK_ULL(39, 12)) | (iova & 0xfff);
> + return addr;
> }
>
> static phys_addr_t arm_smmu_iova_to_phys(struct iommu_domain *domain,
> --
> 2.7.4
>
Powered by blists - more mailing lists