Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7259307ybi; Wed, 5 Jun 2019 14:10:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzCBRMQZlP6Gsetz9RwijqTjGicbKEQENXGAIQiY5yv7+soNAzxrGM6e/oE8hLN0KNCQPYJ X-Received: by 2002:a63:dd05:: with SMTP id t5mr970165pgg.229.1559769030235; Wed, 05 Jun 2019 14:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559769030; cv=none; d=google.com; s=arc-20160816; b=fFnX+mzXmhdZVf+yovwactnXsfdpHn7/OtOcYFBFiM4iIElvloLr5fxi5Yv8IrAu0k A39HsQFoRVfyBRxR8vcs/NsyCOwoUswyfC9HI9AZ3XaJhbS/Hqu0fhDTPDHl8Dx+Nfh5 Ot9l5Ou7yZkBpceN0uTfwCxiobAQVMjXO0I6d9IU22KA1IltIJYUIEElEnLqDe6ZqcBG MUF3V8o108Nh07BO3E1fm9/8BSXLPk+4fVK3eyAu9VFjLoVroydqb3HlAfmWAqHu0zl0 MJJwS6BttB0xqYeMj0ieT48uY6om95j3o/R6U4fLIszG+W3/Y8QRD45IxY+nm9isKEzb +VJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=Ry1vQBxsMbP00vdiIcPrZlm4iIMXw6h5SGLwwG/iVbM=; b=ZWUc66LvMAaronRdlwa8fRPg8KkBl4y+jkMKHxCrv+rysn6ZpBH5Qv0HAOCI7Uqq+7 eA+Vmk7OB1r6k7PIh9Szq4uEC4RjpmIxvXWdc50WQ9C1Lot8VbC17WFDrIweT5dr+K5d TctXBAY9YIacr0wFLfuKlwUpMd3bmQWxb/ZT7N7b9SQqffh9z1p7W4kQ144PohclyhOu ALT2jjrCM6LlugLOiSLyEQWpb7ZfiuBj8cbqeqCnq5V7sLzoGkjfKuKJZNplb/ChjLS5 l4qIn34llPHyNsX2Oi1HdOZdzGoP9LZP+j1Gr1qPg3jaO118sA6p6qoPdGIAJZteVr5S LDQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VxvqG2PW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d62si28773829pga.447.2019.06.05.14.10.13; Wed, 05 Jun 2019 14:10:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VxvqG2PW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726726AbfFEVJD (ORCPT + 99 others); Wed, 5 Jun 2019 17:09:03 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41955 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfFEVJD (ORCPT ); Wed, 5 Jun 2019 17:09:03 -0400 Received: by mail-pf1-f193.google.com with SMTP id q17so61209pfq.8 for ; Wed, 05 Jun 2019 14:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ry1vQBxsMbP00vdiIcPrZlm4iIMXw6h5SGLwwG/iVbM=; b=VxvqG2PW0+5pSp9t5XCA4qowHutScYDHRE+nsLAcjwkD761a4tLnjjrKTbCLu5r/P5 A3y9IdCB35zNuT4KlIhFtfr2gqIzPm2q3CCscrHUC3ttodvJI6lc4/l75psvQbELxPZ9 8lOrONhJe4mXYue0Zaz8Kg413VqyaC+RFEeOZlZGYLCoNaDjIsK0rZ0+crw5uSHC9hqD Y0AR7672VjKnZlm44qEvrfmPKN/h8zW9V/htrWXI1cYQq5fj3cKiM3pjv7BsD1YpDNSp Cz7mECl9WTz15xhD74clwsWi0Da3MuyOIETFx9YDnaBM07TcGGiaGunskRGqq5O0X7Mw 8BZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ry1vQBxsMbP00vdiIcPrZlm4iIMXw6h5SGLwwG/iVbM=; b=gnkQjgCiZ8rhp0JZzpId3nvKg6uOI5O8zrb4S8xN4FirG5HQ7c9ChL9f5oCYFWj2F1 2PSDHApIWKquLt0tWlqbWECL4Isy7Svt9AdYb+ALGiq+w60hZSrDeX3U95KopR9oRFDU 4HtoK4yB0r/hIkH96o/2wqPtDfG+W08u0vm/1PTsg0hZZrdRUufnOFnnf6puF21t8W3U aYpksss5mL+CRjfsytR8Y02ckQDVMGxjq1MTkDBk3qrD1hxhWXPjf+ACxp2VTS7QQFGQ XSNOFqutbrLXzS4FmqAChsv31Z4qNJyr5jKnxslWXRD5te+86e0U+IFAGf3KDSJ3nHkC QTgg== X-Gm-Message-State: APjAAAW9CaGWIT2g1fNLHiipMsxOwO523zS5FiJvAeJNCCOX5BOPuBSN Xg3i1i9XD2capxq7jEoACAMmxw== X-Received: by 2002:a17:90a:b30a:: with SMTP id d10mr22253135pjr.8.1559768941840; Wed, 05 Jun 2019 14:09:01 -0700 (PDT) Received: from localhost.localdomain (104-188-17-28.lightspeed.sndgca.sbcglobal.net. [104.188.17.28]) by smtp.gmail.com with ESMTPSA id z68sm5093374pfb.37.2019.06.05.14.09.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 14:09:01 -0700 (PDT) From: Bjorn Andersson To: Joerg Roedel , Will Deacon , Robin Murphy Cc: Vivek Gautam , Jeffrey Hugo , Patrick Daly , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org Subject: [RFC 2/2] iommu: arm-smmu: Don't blindly use first SMR to calculate mask Date: Wed, 5 Jun 2019 14:08:56 -0700 Message-Id: <20190605210856.20677-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190605210856.20677-1-bjorn.andersson@linaro.org> References: <20190605210856.20677-1-bjorn.andersson@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With the SMRs inherited from the bootloader the first SMR might actually be valid and in use. As such probing the SMR mask using the first SMR might break a stream in use. Search for an unused stream and use this to probe the SMR mask. Signed-off-by: Bjorn Andersson --- drivers/iommu/arm-smmu.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index c8629a656b42..0c6f5fe6f382 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1084,23 +1084,35 @@ static void arm_smmu_test_smr_masks(struct arm_smmu_device *smmu) { void __iomem *gr0_base = ARM_SMMU_GR0(smmu); u32 smr; + int idx; if (!smmu->smrs) return; + for (idx = 0; idx < smmu->num_mapping_groups; idx++) { + smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(idx)); + if (!(smr & SMR_VALID)) + break; + } + + if (idx == smmu->num_mapping_groups) { + dev_err(smmu->dev, "Unable to compute streamid_mask\n"); + return; + } + /* * SMR.ID bits may not be preserved if the corresponding MASK * bits are set, so check each one separately. We can reject * masters later if they try to claim IDs outside these masks. */ smr = smmu->streamid_mask << SMR_ID_SHIFT; - writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0)); - smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0)); + writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(idx)); + smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(idx)); smmu->streamid_mask = smr >> SMR_ID_SHIFT; smr = smmu->streamid_mask << SMR_MASK_SHIFT; - writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0)); - smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0)); + writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(idx)); + smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(idx)); smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT; } -- 2.18.0