All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joro@8bytes.org>
To: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Chunyan Zhang <chunyan.zhang@unisoc.com>,
	Sheng Xu <sheng.xu@unisoc.com>,
	iommu@lists.linux-foundation.org,
	Rob Herring <robh+dt@kernel.org>,
	Baolin Wang <baolin.wang7@gmail.com>,
	Orson Zhai <orsonzhai@gmail.com>,
	Robin Murphy <robin.murphy@arm.com>
Subject: Re: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Date: Tue, 2 Feb 2021 15:13:50 +0100	[thread overview]
Message-ID: <20210202141349.GB32671@8bytes.org> (raw)
In-Reply-To: <20210202104257.736836-1-zhang.lyra@gmail.com>

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.

> +
> +	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;
> +}
> +
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Joerg Roedel <joro@8bytes.org>
To: Chunyan Zhang <zhang.lyra@gmail.com>
Cc: Robin Murphy <robin.murphy@arm.com>,
	Rob Herring <robh+dt@kernel.org>,
	iommu@lists.linux-foundation.org, devicetree@vger.kernel.org,
	Baolin Wang <baolin.wang7@gmail.com>,
	linux-kernel@vger.kernel.org, Orson Zhai <orsonzhai@gmail.com>,
	Sheng Xu <sheng.xu@unisoc.com>,
	Chunyan Zhang <chunyan.zhang@unisoc.com>
Subject: Re: [PATCH 2/2] iommu: add Unisoc iommu basic driver
Date: Tue, 2 Feb 2021 15:13:50 +0100	[thread overview]
Message-ID: <20210202141349.GB32671@8bytes.org> (raw)
In-Reply-To: <20210202104257.736836-1-zhang.lyra@gmail.com>

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.

> +
> +	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;
> +}
> +

  parent reply	other threads:[~2021-02-02 14:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-02  7:32 [PATCH v2 0/2] Add Unisoc iommu basic driver Chunyan Zhang
2021-02-02  7:32 ` Chunyan Zhang
2021-02-02  7:32 ` [PATCH v2 1/2] dt-bindings: iommu: add bindings for sprd iommu Chunyan Zhang
2021-02-02  7:32   ` Chunyan Zhang
2021-02-02  7:32 ` [PATCH v2 2/2] iommu: add Unisoc iommu basic driver Chunyan Zhang
2021-02-02  7:32   ` Chunyan Zhang
2021-02-02 10:42   ` [PATCH " Chunyan Zhang
2021-02-02 10:42     ` Chunyan Zhang
2021-02-02 14:01     ` Joerg Roedel
2021-02-02 14:01       ` Joerg Roedel
2021-02-02 14:34       ` Robin Murphy
2021-02-02 14:34         ` Robin Murphy
2021-02-02 14:41         ` Joerg Roedel
2021-02-02 14:41           ` Joerg Roedel
2021-02-02 18:02           ` Robin Murphy
2021-02-02 18:02             ` Robin Murphy
2021-02-03  1:49             ` Chunyan Zhang
2021-02-03  1:49               ` Chunyan Zhang
2021-02-02 14:13     ` Joerg Roedel [this message]
2021-02-02 14:13       ` Joerg Roedel
2021-02-03  1:45       ` Chunyan Zhang
2021-02-03  1:45         ` Chunyan Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210202141349.GB32671@8bytes.org \
    --to=joro@8bytes.org \
    --cc=baolin.wang7@gmail.com \
    --cc=chunyan.zhang@unisoc.com \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=orsonzhai@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=sheng.xu@unisoc.com \
    --cc=zhang.lyra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.