iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Andreas Herrmann <andreas.herrmann@calxeda.com>
Cc: "iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH 2/7] iommu/arm-smmu: Calculate SMMU_CB_BASE from smmu register values
Date: Tue, 24 Sep 2013 16:34:57 +0100	[thread overview]
Message-ID: <20130924153457.GC20774@mudshark.cambridge.arm.com> (raw)
In-Reply-To: <1380035221-11576-3-git-send-email-andreas.herrmann@calxeda.com>

On Tue, Sep 24, 2013 at 04:06:56PM +0100, Andreas Herrmann wrote:
> Currently it is derived from smmu resource size. If the resource size
> is wrongly specified (e.g. too large) this leads to a miscalculation
> and can cause undefined behaviour when context bank registers are
> modified.
> 
> Signed-off-by: Andreas Herrmann <andreas.herrmann@calxeda.com>
> ---
>  drivers/iommu/arm-smmu.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
> index 97b764b..f5a856e 100644
> --- a/drivers/iommu/arm-smmu.c
> +++ b/drivers/iommu/arm-smmu.c
> @@ -207,7 +207,7 @@
>  #define CBA2R_RW64_64BIT		(1 << 0)
>  
>  /* Translation context bank */
> -#define ARM_SMMU_CB_BASE(smmu)		((smmu)->base + ((smmu)->size >> 1))
> +#define ARM_SMMU_CB_BASE(smmu)		((smmu)->cb_base)
>  #define ARM_SMMU_CB(smmu, n)		((n) * (smmu)->pagesize)
>  
>  #define ARM_SMMU_CB_SCTLR		0x0
> @@ -339,6 +339,7 @@ struct arm_smmu_device {
>  	struct device_node		*parent_of_node;
>  
>  	void __iomem			*base;
> +	void __iomem			*cb_base;
>  	unsigned long			size;
>  	unsigned long			pagesize;
>  
> @@ -1701,7 +1702,9 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
>  
>  	/* Check that we ioremapped enough */
>  	size = 1 << (((id >> ID1_NUMPAGENDXB_SHIFT) & ID1_NUMPAGENDXB_MASK) + 1);
> -	size *= (smmu->pagesize << 1);
> +	size *= smmu->pagesize;
> +	smmu->cb_base = smmu->base + size;
> +	size *= 2;
>  	if (smmu->size < size)
>  		dev_warn(smmu->dev,
>  			 "device is 0x%lx bytes but only mapped 0x%lx!\n",

Hmm, this is a tricky one. We know that we have an inconsistency (i.e. the
DT and the hardware don't agree on the size of the device) but we warn and
attempt to continue with the value from the DT. I don't think that trusting
the hardware is the right thing to do in this case, since it's not possible
to change so we should let the DT act as an override.

In other words: if the device tree is wrong, go fix it.

Will

  reply	other threads:[~2013-09-24 15:34 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 15:06 [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Andreas Herrmann
2013-09-24 15:06 ` [PATCH 1/7] iommu/arm-smmu: Switch to arch_initcall for driver registration Andreas Herrmann
2013-09-24 15:14   ` Andreas Herrmann
2013-09-24 15:19     ` Will Deacon
2013-09-24 15:06 ` [PATCH 2/7] iommu/arm-smmu: Calculate SMMU_CB_BASE from smmu register values Andreas Herrmann
2013-09-24 15:34   ` Will Deacon [this message]
     [not found]     ` <20130924153457.GC20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 18:07       ` Andreas Herrmann
2013-09-25 16:43         ` Will Deacon
2013-09-24 15:06 ` [PATCH 3/7] ARM: dma-mapping: Always pass proper prot flags to iommu_map() Andreas Herrmann
     [not found]   ` <1380035221-11576-4-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:36     ` Will Deacon
     [not found]       ` <20130924153625.GD20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 17:40         ` Andreas Herrmann
2013-09-24 15:06 ` [PATCH 4/7] iommu/arm-smmu: Check for num_context_irqs > 0 to avoid divide by zero exception Andreas Herrmann
     [not found]   ` <1380035221-11576-5-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:40     ` Will Deacon
     [not found]       ` <20130924154048.GE20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 10:50         ` Andreas Herrmann
2013-09-24 15:06 ` [PATCH 5/7] iommu/arm-smmu: Add function that isolates all masters for all SMMUs Andreas Herrmann
2013-09-24 15:07 ` [PATCH 6/7] iommu/arm-smmu: Add module parameter arm-smmu=off|force_isolation Andreas Herrmann
     [not found]   ` <1380035221-11576-7-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:42     ` Will Deacon
     [not found]       ` <20130924154218.GF20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 14:56         ` Andreas Herrmann
2013-09-25 15:57         ` Joerg Roedel
2013-09-24 15:07 ` [PATCH 7/7] iommu/arm-smmu: Clear global and context bank fault status and syndrome registers Andreas Herrmann
     [not found]   ` <1380035221-11576-8-git-send-email-andreas.herrmann-bsGFqQB8/DxBDgjK7y7TUQ@public.gmane.org>
2013-09-24 15:42     ` Will Deacon
     [not found]       ` <20130924154252.GG20774-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-24 18:32         ` Andreas Herrmann
2013-09-25 16:49           ` Will Deacon
     [not found]             ` <20130925164917.GG14502-MRww78TxoiP5vMa5CHWGZ34zcgK1vI+I0E9HWUfgJXw@public.gmane.org>
2013-09-25 18:20               ` Andreas Herrmann
2013-09-24 15:31 ` [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Will Deacon

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=20130924153457.GC20774@mudshark.cambridge.arm.com \
    --to=will.deacon@arm.com \
    --cc=andreas.herrmann@calxeda.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).