All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: ian.campbell@citrix.com,
	Andreas Herrmann <herrmann.der.user@googlemail.com>,
	Julien Grall <julien.grall@linaro.org>,
	tim@xen.org, stefano.stabellini@citrix.com,
	Andreas Herrmann <andreas.herrmann@calxeda.com>
Subject: [PATCH v2 10/12] xen/iommu: smmu: Check for duplicate stream IDs when registering master devices
Date: Fri, 16 Jan 2015 14:24:05 +0000	[thread overview]
Message-ID: <1421418247-30068-11-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1421418247-30068-1-git-send-email-julien.grall@linaro.org>

From: Andreas Herrmann <andreas.herrmann@calxeda.com>

If DT information lists one stream ID twice for the master devices of
an SMMU this can cause a multi match when stream ID matching is used.
For stream ID indexing this might trigger an overwrite of an S2CR that
is already in use.

So better check for duplicates when DT information is parsed.

Taken from the linux ML:
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-January/226099.html

Cc: Andreas Herrmann <herrmann.der.user@googlemail.com>
Signed-off-by: Andreas Herrmann <andreas.herrmann@calxeda.com>
Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/drivers/passthrough/arm/smmu.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c b/xen/drivers/passthrough/arm/smmu.c
index 6cd47b7..bfc1069 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -51,6 +51,9 @@
 /* Maximum number of stream IDs assigned to a single device */
 #define MAX_MASTER_STREAMIDS		MAX_PHANDLE_ARGS
 
+/* Maximum stream ID */
+#define ARM_SMMU_MAX_STREAMID		(SZ_64K - 1)
+
 /* Maximum number of context banks per SMMU */
 #define ARM_SMMU_MAX_CBS		128
 
@@ -519,7 +522,8 @@ static int insert_smmu_master(struct arm_smmu_device *smmu,
 
 static int register_smmu_master(struct arm_smmu_device *smmu,
 				struct device *dev,
-				struct of_phandle_args *masterspec)
+				struct of_phandle_args *masterspec,
+				unsigned long *smmu_sids)
 {
 	int i;
 	struct arm_smmu_master *master;
@@ -556,6 +560,12 @@ static int register_smmu_master(struct arm_smmu_device *smmu,
 				masterspec->np->name, smmu->num_mapping_groups);
 			return -ERANGE;
 		}
+
+		if (test_and_set_bit(streamid, smmu_sids)) {
+			dev_err(dev, "duplicate stream ID (%d)\n", streamid);
+			return -EEXIST;
+		}
+
 		master->cfg.streamids[i] = streamid;
 	}
 	return insert_smmu_master(smmu, master);
@@ -1977,6 +1987,7 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rb_node *node;
 	struct of_phandle_args masterspec;
+	unsigned long *smmu_sids;
 	int num_irqs, i, err;
 
 	smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
@@ -2035,20 +2046,30 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
 	if (err)
 		return err;
 
+	smmu_sids = kzalloc(BITS_TO_LONGS(ARM_SMMU_MAX_STREAMID) *
+			sizeof(long), GFP_KERNEL);
+	if (!smmu_sids) {
+		dev_err(dev,
+			"failed to allocate bitmap for stream ID tracking\n");
+		return -ENOMEM;
+	}
+
 	i = 0;
 	smmu->masters = RB_ROOT;
 	while (!of_parse_phandle_with_args(dev->of_node, "mmu-masters",
 					   "#stream-id-cells", i,
 					   &masterspec)) {
-		err = register_smmu_master(smmu, dev, &masterspec);
+		err = register_smmu_master(smmu, dev, &masterspec, smmu_sids);
 		if (err) {
 			dev_err(dev, "failed to add master %s\n",
 				masterspec.np->name);
+			kfree(smmu_sids);
 			goto out_put_masters;
 		}
 
 		i++;
 	}
+	kfree(smmu_sids);
 	dev_notice(dev, "registered %d master devices\n", i);
 
 	parse_driver_options(smmu);
-- 
2.1.4

  parent reply	other threads:[~2015-01-16 14:25 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-16 14:23 [PATCH v2 00/12] xen/arm: Resync the SMMU driver with the Linux one Julien Grall
2015-01-16 14:23 ` [PATCH v2 01/12] xen/arm: gic-v2: Change the device name in DT_DEVICE_START Julien Grall
2015-01-27 15:52   ` Stefano Stabellini
2015-01-16 14:23 ` [PATCH v2 02/12] xen/arm: vgic: Drop unecessary include asm/device.h Julien Grall
2015-01-27 15:53   ` Stefano Stabellini
2015-01-16 14:23 ` [PATCH v2 03/12] xen/dt: Extend dt_device_match to possibly store data Julien Grall
2015-01-27 15:57   ` Stefano Stabellini
2015-01-27 16:07     ` Julien Grall
2015-01-27 16:10       ` Stefano Stabellini
2015-01-27 16:35         ` Julien Grall
2015-01-27 16:46           ` Stefano Stabellini
2015-01-27 16:49             ` Julien Grall
2015-01-16 14:23 ` [PATCH v2 04/12] xen/arm: device: Rename device_type into device_match Julien Grall
2015-01-27 16:05   ` Stefano Stabellini
2015-01-27 16:09     ` Julien Grall
2015-01-27 16:13       ` Stefano Stabellini
2015-01-27 22:26         ` Julien Grall
2015-01-16 14:24 ` [PATCH v2 05/12] xen/iommu: arm: Remove temporary the SMMU driver Julien Grall
2015-01-27 16:05   ` Stefano Stabellini
2015-01-16 14:24 ` [PATCH v2 06/12] xen/arm: Introduce a generic way to describe device Julien Grall
2015-01-16 14:59   ` Jan Beulich
2015-01-16 15:01     ` Julien Grall
2015-01-27 16:13   ` Stefano Stabellini
2015-01-16 14:24 ` [PATCH v2 07/12] xen/iommu: Consolidate device assignment ops into a single set Julien Grall
2015-01-16 15:03   ` Jan Beulich
2015-01-27 16:16   ` Stefano Stabellini
2015-01-16 14:24 ` [PATCH v2 08/12] xen/arm: Describe device supported by a driver with dt_match_node Julien Grall
2015-01-27 16:28   ` Stefano Stabellini
2015-01-16 14:24 ` [PATCH v2 09/12] xen/iommu: arm: Import the SMMU driver from Linux Julien Grall
2015-01-27 16:28   ` Stefano Stabellini
2015-01-27 16:51     ` Julien Grall
2015-01-16 14:24 ` Julien Grall [this message]
2015-01-27 16:30   ` [PATCH v2 10/12] xen/iommu: smmu: Check for duplicate stream IDs when registering master devices Stefano Stabellini
2015-01-27 16:52     ` Julien Grall
2015-01-27 17:02       ` Stefano Stabellini
2015-01-27 17:33         ` Julien Grall
2015-01-27 17:36           ` Stefano Stabellini
2015-01-27 17:44           ` Ian Campbell
2015-01-27 17:51             ` Julien Grall
2015-01-27 20:54               ` Andreas Herrmann
2015-01-28 10:38               ` Ian Campbell
2015-01-28 11:39                 ` Julien Grall
2015-01-16 14:24 ` [PATCH v2 11/12] xen/iommu: smmu: Introduce automatic stream-id-masking Julien Grall
2015-01-16 14:24 ` [PATCH v2 12/12] xen/iommu: smmu: Add Xen specific code to be able to use the driver Julien Grall
2015-01-27 16:46   ` Stefano Stabellini
2015-01-27 17:05     ` Julien Grall
2015-01-27 17:34       ` Stefano Stabellini
2015-01-28 10:31         ` Ian Campbell
2015-01-28 11:49           ` Julien Grall
2015-01-28 12:13             ` Ian Campbell
2015-01-28 12:15             ` Stefano Stabellini

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=1421418247-30068-11-git-send-email-julien.grall@linaro.org \
    --to=julien.grall@linaro.org \
    --cc=andreas.herrmann@calxeda.com \
    --cc=herrmann.der.user@googlemail.com \
    --cc=ian.campbell@citrix.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xenproject.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 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.