From patchwork Thu Jan 7 09:33:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajay Kumar X-Patchwork-Id: 12003505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E91EC433E0 for ; Thu, 7 Jan 2021 10:33:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CD1D62313B for ; Thu, 7 Jan 2021 10:33:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD1D62313B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:Message-Id:Date:Subject:To:From:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Owner; bh=a3SZbkI6ulLw1UMEE/QKGy5Wo6qpxswRIpnXpSE93EU=; b=c/2Aq3J8ipwvUvFVEn0h973pTg lEvIy40h/IbkMDnyjI0+vyyD0nSJEn23W40rHFjbrBWwLQBbcjnlNg7m9lbxJlTLNaW2KIwEmqJOR u06LXS7awb8u8CeekqcPngcZFdoTz+KwJ36Hma+Upy1zcYj80z9mxuy4tMkxW5FIKYwGLjPvLKpGh z/l9VY7ctJT/L9T/saoszfrPt1thyw1eLFxUxBuwd0gnhFoqbsXk1elUI1JflT5br6H/Nxuc+zGQl amqt2hIY6MKbgq1UsOZ6CghPTYZ2i53duc0W4lY9dQA19K4pt1PNLSs+YJiIooJOHxKsxVWYrt/N1 IT76lSPA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxSZo-00031W-VO; Thu, 07 Jan 2021 10:31:32 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kxSZk-0002zP-Jd for linux-arm-kernel@lists.infradead.org; Thu, 07 Jan 2021 10:31:30 +0000 Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20210107103121epoutp044df73acebf67d0e0bae91ea55bd3d061~X7Iz2sKKX3265232652epoutp04y for ; Thu, 7 Jan 2021 10:31:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20210107103121epoutp044df73acebf67d0e0bae91ea55bd3d061~X7Iz2sKKX3265232652epoutp04y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1610015482; bh=zgnGkAl5H6GoKUAcYr+wE27/PBdE+8JptgJAmhAjafY=; h=From:To:Cc:Subject:Date:References:From; b=jbUuGpct6UFoDu/hTwtofLLe09pRuvs7uq4N5cZUaDkUcYiMsD0pQ9mxyN9gIlPco w+r/1POzrzXlT17HNqdHdP4ByLDen8AelFRPa89DUoFNOVWLKtTKdEMsg8bkoh6R/y wgHQS8OYyuO1As0BS1OUAekYBreImQnsDcbihJIQ= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20210107103121epcas5p2a322f86c7f7f9d4734f37bddee79ddc1~X7IzbAEcp1382213822epcas5p2B; Thu, 7 Jan 2021 10:31:21 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 44.8D.33964.9F2E6FF5; Thu, 7 Jan 2021 19:31:21 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20210107092826epcas5p100f2c57a63715baa2b3fa7219ab58c7b~X6R4CDmyx1773217732epcas5p1v; Thu, 7 Jan 2021 09:28:26 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210107092826epsmtrp28d27298a12781770605a65a82b78e522~X6R4Acp9C2963029630epsmtrp23; Thu, 7 Jan 2021 09:28:26 +0000 (GMT) X-AuditID: b6c32a4b-ea1ff700000184ac-26-5ff6e2f95641 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 26.A2.08745.A34D6FF5; Thu, 7 Jan 2021 18:28:26 +0900 (KST) Received: from Jaguar.sa.corp.samsungelectronics.net (unknown [107.108.73.139]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20210107092825epsmtip28c5b3966d940a0ebee719140eb1f8f94~X6R2s12Ec1431714317epsmtip2O; Thu, 7 Jan 2021 09:28:25 +0000 (GMT) From: Ajay Kumar To: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, joro@8bytes.org, robh+dt@kernel.org, mark.rutland@arm.com, will@kernel.org, robin.murphy@arm.com Subject: [PATCH] iommu/arm-smmu-v3: Handle duplicated Stream IDs from other masters Date: Thu, 7 Jan 2021 15:03:40 +0530 Message-Id: <20210107093340.15279-1-ajaykumar.rs@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJIsWRmVeSWpSXmKPExsWy7bCmpu7PR9/iDXbMlLQ48P4gi8WC/dYW nbM3sFtsenyN1eLyrjlsFkuvX2SyaN17hN3i4IcnrBYtd0wdOD2eHJzH5LFm3hpGj02rOtk8 Ni+p95h8YzmjR9+WVYwenzfJBbBHcdmkpOZklqUW6dslcGXcb1nNVvBCuOL45dnMDYwLBLoY OTkkBEwk/nRcYeti5OIQEtjNKDHvxCQ2kISQwCdGiZbeQojEZ0aJzuvHmGA69l19zA6R2MUo 8XvSVaiOFiaJ9tXMIDabgLbEtuk3WUCKRATOMUpMWD8TLMEsoCmxdGk3mC0sECqx7nM3Yxcj BweLgKrE5M+GIGFeAVuJWd/+MkMsk5dYveEAM8gcCYFT7BK3Ht1kg0i4SLz9PI8dwhaWeHV8 C5QtJfH53V42iIZ+Romn9/9Ada9mlHjw8ALUWHuJA1fmsIBsBrlo/S59iLCsxNRT65ggDuWT 6P39BOplXokd80BsDiBbTWLrCj+IsIzEmYNXoEo8JGb+2skOCYhYifufN7FMYJSdhbBgASPj KkbJ1ILi3PTUYtMC47zUcr3ixNzi0rx0veT83E2M4NSg5b2D8dGDD3qHGJk4GA8xSnAwK4nw Whz7Ei/Em5JYWZValB9fVJqTWnyIUZqDRUmcd4fBg3ghgfTEktTs1NSC1CKYLBMHp1QDk5KD m/GEjc1/2Peodh/Zz3QoYf+fD7IyGp9auf+l9sas5o2/dV8l54bc4gbHI4bVT/6ZVXYErLWu ULw5y5x79XSus3YvPh9iSGvgPnZtUo1FxAqTsBkRSflzb1l3MOVqnTn2ur/izKYbn3IUY+w2 njl8c4b3whsaUknn5Q7/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jZytcrn1nNv1/Q9+Aa1Vx1u4s+y0L mxbucPKp+JK3782E7b66SizFGYmGWsxFxYkARhXFXqECAAA= X-CMS-MailID: 20210107092826epcas5p100f2c57a63715baa2b3fa7219ab58c7b X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P X-CMS-RootMailID: 20210107092826epcas5p100f2c57a63715baa2b3fa7219ab58c7b References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210107_053129_191007_032F05BE X-CRM114-Status: GOOD ( 18.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ajay Kumar MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When PCI function drivers(ex:pci-endpoint-test) are probed for already initialized PCIe-RC(Root Complex), and PCIe-RC is already bound to SMMU, then we encounter a situation where the function driver tries to attach itself to the smmu with the same stream-id as PCIe-RC and re-initialize an already initialized STE. This causes ste_live BUG_ON() in the driver. There is an already existing check in the driver to manage duplicated ids if duplicated ids are added in same master device, but there can be scenarios like above where we need to extend the check for other masters using the same stream-id. Signed-off-by: Ajay Kumar --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index e634bbe60573..a91c3c0e9ee8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2022,10 +2022,26 @@ static __le64 *arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid) return step; } +static bool arm_smmu_check_duplicated_sid(struct arm_smmu_master *master, + int sid) +{ + int i; + + for (i = 0; i < master->num_sids; ++i) + if (master->sids[i] == sid) + return true; + + return false; +} + static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) { + bool sid_in_other_masters; int i, j; struct arm_smmu_device *smmu = master->smmu; + unsigned long flags; + struct arm_smmu_domain *smmu_domain = master->domain; + struct arm_smmu_master *other_masters; for (i = 0; i < master->num_sids; ++i) { u32 sid = master->sids[i]; @@ -2038,6 +2054,23 @@ static void arm_smmu_install_ste_for_dev(struct arm_smmu_master *master) if (j < i) continue; + /* Check for stream-ID duplication in masters in given domain */ + sid_in_other_masters = false; + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(other_masters, &smmu_domain->devices, + domain_head) { + sid_in_other_masters = + arm_smmu_check_duplicated_sid(other_masters, + sid); + if (sid_in_other_masters) + break; + } + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + + /* Skip STE re-init if stream-id found in other masters */ + if (sid_in_other_masters) + continue; + arm_smmu_write_strtab_ent(master, sid, step); } }