All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
@ 2014-08-23  0:12 ` Olav Haugan
  0 siblings, 0 replies; 8+ messages in thread
From: Olav Haugan @ 2014-08-23  0:12 UTC (permalink / raw)
  To: will.deacon-5wv7dgnIgG8
  Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

The number of S2CR registers is not properly set when stream
matching is not supported. Fix this and add check that we do not try to
access outside of the number of S2CR regisrers.

Signed-off-by: Olav Haugan <ohaugan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
---
 drivers/iommu/arm-smmu.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 9fd8754d..1d06ca8 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -548,9 +548,18 @@ static int register_smmu_master(struct arm_smmu_device *smmu,
 	master->of_node			= masterspec->np;
 	master->cfg.num_streamids	= masterspec->args_count;
 
-	for (i = 0; i < master->cfg.num_streamids; ++i)
-		master->cfg.streamids[i] = masterspec->args[i];
-
+	for (i = 0; i < master->cfg.num_streamids; ++i) {
+		u16 streamid = masterspec->args[i];
+
+		if (!(smmu->features & ARM_SMMU_FEAT_STREAM_MATCH) &&
+		     (streamid >= smmu->num_mapping_groups)) {
+			dev_err(dev,
+				"stream ID for master device %s greater than maximum allowed (%d)\n",
+				masterspec->np->name, smmu->num_mapping_groups);
+			return -ERANGE;
+		}
+		master->cfg.streamids[i] = streamid;
+	}
 	return insert_smmu_master(smmu, master);
 }
 
@@ -1734,7 +1743,7 @@ static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
 
 	/* Mark all SMRn as invalid and all S2CRn as bypass */
 	for (i = 0; i < smmu->num_mapping_groups; ++i) {
-		writel_relaxed(~SMR_VALID, gr0_base + ARM_SMMU_GR0_SMR(i));
+		writel_relaxed(0, gr0_base + ARM_SMMU_GR0_SMR(i));
 		writel_relaxed(S2CR_TYPE_BYPASS,
 			gr0_base + ARM_SMMU_GR0_S2CR(i));
 	}
@@ -1875,6 +1884,9 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 		dev_notice(smmu->dev,
 			   "\tstream matching with %u register groups, mask 0x%x",
 			   smmu->num_mapping_groups, mask);
+	} else {
+		smmu->num_mapping_groups = (id >> ID0_NUMSIDB_SHIFT) &
+					   ID0_NUMSIDB_MASK;
 	}
 	smmu->idr[0] = id;
 
@@ -2011,6 +2023,10 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 		smmu->irqs[i] = irq;
 	}
 
+	err = arm_smmu_device_cfg_probe(smmu);
+	if (err)
+		return err;
+
 	i = 0;
 	smmu->masters = RB_ROOT;
 	while (!of_parse_phandle_with_args(dev->of_node, "mmu-masters",
@@ -2027,10 +2043,6 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 	}
 	dev_notice(dev, "registered %d master devices\n", i);
 
-	err = arm_smmu_device_cfg_probe(smmu);
-	if (err)
-		goto out_put_masters;
-
 	parse_driver_options(smmu);
 
 	if (smmu->version > 1 &&
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
@ 2014-08-23  0:12 ` Olav Haugan
  0 siblings, 0 replies; 8+ messages in thread
From: Olav Haugan @ 2014-08-23  0:12 UTC (permalink / raw)
  To: linux-arm-kernel

The number of S2CR registers is not properly set when stream
matching is not supported. Fix this and add check that we do not try to
access outside of the number of S2CR regisrers.

Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
---
 drivers/iommu/arm-smmu.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 9fd8754d..1d06ca8 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -548,9 +548,18 @@ static int register_smmu_master(struct arm_smmu_device *smmu,
 	master->of_node			= masterspec->np;
 	master->cfg.num_streamids	= masterspec->args_count;
 
-	for (i = 0; i < master->cfg.num_streamids; ++i)
-		master->cfg.streamids[i] = masterspec->args[i];
-
+	for (i = 0; i < master->cfg.num_streamids; ++i) {
+		u16 streamid = masterspec->args[i];
+
+		if (!(smmu->features & ARM_SMMU_FEAT_STREAM_MATCH) &&
+		     (streamid >= smmu->num_mapping_groups)) {
+			dev_err(dev,
+				"stream ID for master device %s greater than maximum allowed (%d)\n",
+				masterspec->np->name, smmu->num_mapping_groups);
+			return -ERANGE;
+		}
+		master->cfg.streamids[i] = streamid;
+	}
 	return insert_smmu_master(smmu, master);
 }
 
@@ -1734,7 +1743,7 @@ static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
 
 	/* Mark all SMRn as invalid and all S2CRn as bypass */
 	for (i = 0; i < smmu->num_mapping_groups; ++i) {
-		writel_relaxed(~SMR_VALID, gr0_base + ARM_SMMU_GR0_SMR(i));
+		writel_relaxed(0, gr0_base + ARM_SMMU_GR0_SMR(i));
 		writel_relaxed(S2CR_TYPE_BYPASS,
 			gr0_base + ARM_SMMU_GR0_S2CR(i));
 	}
@@ -1875,6 +1884,9 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 		dev_notice(smmu->dev,
 			   "\tstream matching with %u register groups, mask 0x%x",
 			   smmu->num_mapping_groups, mask);
+	} else {
+		smmu->num_mapping_groups = (id >> ID0_NUMSIDB_SHIFT) &
+					   ID0_NUMSIDB_MASK;
 	}
 	smmu->idr[0] = id;
 
@@ -2011,6 +2023,10 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 		smmu->irqs[i] = irq;
 	}
 
+	err = arm_smmu_device_cfg_probe(smmu);
+	if (err)
+		return err;
+
 	i = 0;
 	smmu->masters = RB_ROOT;
 	while (!of_parse_phandle_with_args(dev->of_node, "mmu-masters",
@@ -2027,10 +2043,6 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 	}
 	dev_notice(dev, "registered %d master devices\n", i);
 
-	err = arm_smmu_device_cfg_probe(smmu);
-	if (err)
-		goto out_put_masters;
-
 	parse_driver_options(smmu);
 
 	if (smmu->version > 1 &&
-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
  2014-08-23  0:12 ` Olav Haugan
@ 2014-08-26 10:37     ` Will Deacon
  -1 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2014-08-26 10:37 UTC (permalink / raw)
  To: Olav Haugan
  Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

Hi Olav,

On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
> The number of S2CR registers is not properly set when stream
> matching is not supported. Fix this and add check that we do not try to
> access outside of the number of S2CR regisrers.

Sorry for the bother, but could you base this on either iommu/devel or
iommu/staging please? Now that the merge window is well and truly over, I
moved those branches forward, so you needn't worry about iommu/pci anymore
(which, as you pointed out, contains a bunch of WIP patches which should
hold-up useful fixes like this one).

Cheers,

Will

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
@ 2014-08-26 10:37     ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2014-08-26 10:37 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Olav,

On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
> The number of S2CR registers is not properly set when stream
> matching is not supported. Fix this and add check that we do not try to
> access outside of the number of S2CR regisrers.

Sorry for the bother, but could you base this on either iommu/devel or
iommu/staging please? Now that the merge window is well and truly over, I
moved those branches forward, so you needn't worry about iommu/pci anymore
(which, as you pointed out, contains a bunch of WIP patches which should
hold-up useful fixes like this one).

Cheers,

Will

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
  2014-08-26 10:37     ` Will Deacon
@ 2014-08-28 10:55         ` Will Deacon
  -1 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2014-08-28 10:55 UTC (permalink / raw)
  To: Olav Haugan
  Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r

On Tue, Aug 26, 2014 at 11:37:30AM +0100, Will Deacon wrote:
> On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
> > The number of S2CR registers is not properly set when stream
> > matching is not supported. Fix this and add check that we do not try to
> > access outside of the number of S2CR regisrers.
> 
> Sorry for the bother, but could you base this on either iommu/devel or
> iommu/staging please? Now that the merge window is well and truly over, I
> moved those branches forward, so you needn't worry about iommu/pci anymore
> (which, as you pointed out, contains a bunch of WIP patches which should
> hold-up useful fixes like this one).

Actually, it looks like this was eaten by our sorry excuse for an email
service. I've managed to apply a version from the archive, thanks.

Will

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
@ 2014-08-28 10:55         ` Will Deacon
  0 siblings, 0 replies; 8+ messages in thread
From: Will Deacon @ 2014-08-28 10:55 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Aug 26, 2014 at 11:37:30AM +0100, Will Deacon wrote:
> On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
> > The number of S2CR registers is not properly set when stream
> > matching is not supported. Fix this and add check that we do not try to
> > access outside of the number of S2CR regisrers.
> 
> Sorry for the bother, but could you base this on either iommu/devel or
> iommu/staging please? Now that the merge window is well and truly over, I
> moved those branches forward, so you needn't worry about iommu/pci anymore
> (which, as you pointed out, contains a bunch of WIP patches which should
> hold-up useful fixes like this one).

Actually, it looks like this was eaten by our sorry excuse for an email
service. I've managed to apply a version from the archive, thanks.

Will

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
  2014-08-28 10:55         ` Will Deacon
@ 2014-09-13 15:36           ` Olav Haugan
  -1 siblings, 0 replies; 8+ messages in thread
From: Olav Haugan @ 2014-09-13 15:36 UTC (permalink / raw)
  To: Will Deacon; +Cc: linux-arm-msm, iommu, mitchelh, linux-arm-kernel

On 8/28/2014 3:55 AM, Will Deacon wrote:
> On Tue, Aug 26, 2014 at 11:37:30AM +0100, Will Deacon wrote:
>> On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
>>> The number of S2CR registers is not properly set when stream
>>> matching is not supported. Fix this and add check that we do not try to
>>> access outside of the number of S2CR regisrers.
>>
>> Sorry for the bother, but could you base this on either iommu/devel or
>> iommu/staging please? Now that the merge window is well and truly over, I
>> moved those branches forward, so you needn't worry about iommu/pci anymore
>> (which, as you pointed out, contains a bunch of WIP patches which should
>> hold-up useful fixes like this one).
> 
> Actually, it looks like this was eaten by our sorry excuse for an email
> service. I've managed to apply a version from the archive, thanks.
> 

Thanks Will. Sorry for the late reply. I have been OoO.

Thanks,

Olav

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers
@ 2014-09-13 15:36           ` Olav Haugan
  0 siblings, 0 replies; 8+ messages in thread
From: Olav Haugan @ 2014-09-13 15:36 UTC (permalink / raw)
  To: linux-arm-kernel

On 8/28/2014 3:55 AM, Will Deacon wrote:
> On Tue, Aug 26, 2014 at 11:37:30AM +0100, Will Deacon wrote:
>> On Sat, Aug 23, 2014 at 01:12:32AM +0100, Olav Haugan wrote:
>>> The number of S2CR registers is not properly set when stream
>>> matching is not supported. Fix this and add check that we do not try to
>>> access outside of the number of S2CR regisrers.
>>
>> Sorry for the bother, but could you base this on either iommu/devel or
>> iommu/staging please? Now that the merge window is well and truly over, I
>> moved those branches forward, so you needn't worry about iommu/pci anymore
>> (which, as you pointed out, contains a bunch of WIP patches which should
>> hold-up useful fixes like this one).
> 
> Actually, it looks like this was eaten by our sorry excuse for an email
> service. I've managed to apply a version from the archive, thanks.
> 

Thanks Will. Sorry for the late reply. I have been OoO.

Thanks,

Olav

-- 
The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-13 15:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-23  0:12 [PATCH v4 1/1] iommu/arm-smmu: Do not access non-existing S2CR registers Olav Haugan
2014-08-23  0:12 ` Olav Haugan
     [not found] ` <1408752752-15601-1-git-send-email-ohaugan-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-08-26 10:37   ` Will Deacon
2014-08-26 10:37     ` Will Deacon
     [not found]     ` <20140826103730.GE23445-5wv7dgnIgG8@public.gmane.org>
2014-08-28 10:55       ` Will Deacon
2014-08-28 10:55         ` Will Deacon
2014-09-13 15:36         ` Olav Haugan
2014-09-13 15:36           ` Olav Haugan

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.