From patchwork Tue Dec 16 20:08:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 42352 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 485A925E25 for ; Tue, 16 Dec 2014 20:11:19 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf9085787lbv.9 for ; Tue, 16 Dec 2014 12:11:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=gFJHvCIwa3WHEVzi1JA6+RWzAYtERyzXcXzDP+nhnTQ=; b=mCRdD3XPWqyOcegEXVx/EqOF486j3K/80LlgJRt+Mm53l20JltZGJ8We1wswqJWu5J JWQzVgwJ5EqX8S0cXdVqgyvj5taS2qpUOn2zfYRPFwYAiUTaUD8P9/fggZlajZCAmpAP 86Rj50BJ183gui9fQ8cQydQBmuhRQyVzuljnnnIuR1ZUfr7uo5XywxpL1a8MO3BCxZCO QNMO0eAd3yLvxDkJxV/XLgo8LatoiGjcrBslexqF2BsRoMx/Cv7LRSF1gBD7pE7tnmi3 z5/QpkWNGrb0a+szy9XeZbEq4zboNXOHJ9b0+LAphVM3GF002XP1L5QME2Ctwjr/E+HU 0Cdw== X-Gm-Message-State: ALoCoQkjhZLO7Wk0Sjnbh4FU5BrGxHcAljPbp3lXPHnAYoRWttqFlNkp0QRexuoH/x7hjRcU6pGB X-Received: by 10.112.146.104 with SMTP id tb8mr3589lbb.22.1418760678244; Tue, 16 Dec 2014 12:11:18 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.37 with SMTP id ll5ls1049604lac.53.gmail; Tue, 16 Dec 2014 12:11:18 -0800 (PST) X-Received: by 10.112.51.44 with SMTP id h12mr7913978lbo.5.1418760677949; Tue, 16 Dec 2014 12:11:17 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id q15si1785364lal.79.2014.12.16.12.11.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Dec 2014 12:11:17 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id q1so12190030lam.33 for ; Tue, 16 Dec 2014 12:11:17 -0800 (PST) X-Received: by 10.112.135.229 with SMTP id pv5mr37442494lbb.52.1418760677616; Tue, 16 Dec 2014 12:11:17 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp1148883lbb; Tue, 16 Dec 2014 12:11:16 -0800 (PST) X-Received: by 10.224.7.197 with SMTP id e5mr68567716qae.71.1418760673311; Tue, 16 Dec 2014 12:11:13 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id n11si2121346qay.42.2014.12.16.12.11.12 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 16 Dec 2014 12:11:13 -0800 (PST) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y0yRA-0004tU-NO; Tue, 16 Dec 2014 20:09:40 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Y0yR9-0004r7-06 for xen-devel@lists.xenproject.org; Tue, 16 Dec 2014 20:09:39 +0000 Received: from [85.158.137.68] by server-15.bemta-3.messagelabs.com id 1E/B0-17735-28190945; Tue, 16 Dec 2014 20:09:38 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-15.tower-31.messagelabs.com!1418760577!13701295!1 X-Originating-IP: [74.125.82.45] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30414 invoked from network); 16 Dec 2014 20:09:37 -0000 Received: from mail-wg0-f45.google.com (HELO mail-wg0-f45.google.com) (74.125.82.45) by server-15.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 16 Dec 2014 20:09:37 -0000 Received: by mail-wg0-f45.google.com with SMTP id b13so18363402wgh.32 for ; Tue, 16 Dec 2014 12:09:37 -0800 (PST) X-Received: by 10.194.222.98 with SMTP id ql2mr65819715wjc.36.1418760576146; Tue, 16 Dec 2014 12:09:36 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id b10sm3382705wiw.9.2014.12.16.12.09.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Dec 2014 12:09:35 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 16 Dec 2014 20:08:52 +0000 Message-Id: <1418760534-18163-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> References: <1418760534-18163-1-git-send-email-julien.grall@linaro.org> Cc: ian.campbell@citrix.com, Andreas Herrmann , manish.jaggi@caviumnetworks.com, Julien Grall , tim@xen.org, stefano.stabellini@citrix.com, Andreas Herrmann Subject: [Xen-devel] [PATCH for 4.6 11/13] xen/iommu: smmu: Check for duplicate stream IDs when registering master devices X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Andreas Herrmann 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 Signed-off-by: Andreas Herrmann Signed-off-by: Julien Grall --- 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);