[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAAfSe-uGeji18yZaqEWAS1W-_3Fmvnq_7PQmGE7hhGs4r+Mcvg@mail.gmail.com>
Date: Wed, 3 Feb 2021 09:45:21 +0800
From: Chunyan Zhang <zhang.lyra@...il.com>
To: Joerg Roedel <joro@...tes.org>
Cc: Robin Murphy <robin.murphy@....com>,
Rob Herring <robh+dt@...nel.org>,
Linux IOMMU <iommu@...ts.linux-foundation.org>,
DTML <devicetree@...r.kernel.org>,
Baolin Wang <baolin.wang7@...il.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Orson Zhai <orsonzhai@...il.com>,
Sheng Xu <sheng.xu@...soc.com>,
Chunyan Zhang <chunyan.zhang@...soc.com>
Subject: Re: [PATCH 2/2] iommu: add Unisoc iommu basic driver
On Tue, 2 Feb 2021 at 22:14, Joerg Roedel <joro@...tes.org> wrote:
>
> On Tue, Feb 02, 2021 at 06:42:57PM +0800, Chunyan Zhang wrote:
> > +static phys_addr_t sprd_iommu_iova_to_phys(struct iommu_domain *domain,
> > + dma_addr_t iova)
> > +{
> > + struct sprd_iommu_domain *dom = to_sprd_domain(domain);
> > + unsigned long flags;
> > + phys_addr_t pa;
> > + unsigned long start = domain->geometry.aperture_start;
> > + unsigned long end = domain->geometry.aperture_end;
> > +
> > + if (iova < start || iova > end)
> > + pr_err("iova (0x%llx) exceed the vpn range[0x%lx-0x%lx]!\n",
> > + iova, start, end);
>
> It is not a good idea to continue here with an out-of-range iova. The
> code below might access random memory for its checks. Better do a
> WARN_ON here and return an invalid physical address.
Yes, I will fix this.
Thanks,
Chunyan
>
> > +
> > + spin_lock_irqsave(&dom->pgtlock, flags);
> > + pa = *(dom->pgt_va + ((iova - start) >> SPRD_IOMMU_PAGE_SHIFT));
> > + pa = (pa << SPRD_IOMMU_PAGE_SHIFT) + ((iova - start) & (SPRD_IOMMU_PAGE_SIZE - 1));
> > + spin_unlock_irqrestore(&dom->pgtlock, flags);
> > +
> > + return pa;
> > +}
> > +
Powered by blists - more mailing lists