From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 6023FCA9070 for ; Thu, 30 Apr 2020 14:40:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1712120757 for ; Thu, 30 Apr 2020 14:40:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PgNBtasU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1712120757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 238648E0013; Thu, 30 Apr 2020 10:40:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D9388E0010; Thu, 30 Apr 2020 10:40:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E94868E0013; Thu, 30 Apr 2020 10:40:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id C75A08E0010 for ; Thu, 30 Apr 2020 10:40:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8DDBF3CE9 for ; Thu, 30 Apr 2020 14:40:36 +0000 (UTC) X-FDA: 76764782472.29.knot03_5c972b4b35e32 X-HE-Tag: knot03_5c972b4b35e32 X-Filterd-Recvd-Size: 6433 Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Thu, 30 Apr 2020 14:40:36 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id v8so7649408wma.0 for ; Thu, 30 Apr 2020 07:40:36 -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 :mime-version:content-transfer-encoding; bh=6E7EOkoBPCqbsXIu3vkCbOjnxtmfKTDoinxuBew3XSc=; b=PgNBtasUJDfCwJ+wiciq3ECMRIi7prASOACz5goZtVeKxG3VLXxXqWa0RRBkp1Q2OB swIxTh8VulGMoztxfkdRWp3orJORII0ZBf2ye7KDD9SEQAKE65mF8WMxlI1gP5KC0/Ss zJq5vfvmHz9edg8x+NjRVM03W0r6LOS6pbFPVfh6/DSCRzSR0ELc4+c1/eghG/RzpL8l VhpMgYmnX/ZuXWa8AtHc12gmFCTWRHvwLl8IFdqHwmNF+hJpYl3N/kgcrxVZa2GV5Bl5 IG37i3NXqBEYKSGM9UPgrw4U/cUlH/ZrXLg+4RJIAtNDHa8evp7HaNp2BvbQeyFQh88P mw3w== 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:mime-version:content-transfer-encoding; bh=6E7EOkoBPCqbsXIu3vkCbOjnxtmfKTDoinxuBew3XSc=; b=rjjgfhgutYu7/9Rscr6LdSfSoM6aqZREzb6hrtT1ly1Bix5N0FZPbTF2GvV7jw7HKU MbLB2IM3QkN/sOEdWw7YanwUAR4PNZc0KmdkVPLBsN2SnaNv4u9UEoWKh7gtwrTGRBaR zzeVNJGnil8KzzZN5Ihm7WfXx0e+WSN+28H3e1+jhAFbrhfg4KpqaZtYu8hYROh6BCCO D8d7kMXxYNmTihlXUOG1S13Qrxs7n7G1/rxTmyP5HxASZ7XrLLzaCNrIK7MdSAQf4a6I Fm//LGVZlldjvrs0vcJnyFnGuO4HVVsBOQ6OdHa106CwNyiF8eTdaIT7Wa4krdKjhSl/ RrCw== X-Gm-Message-State: AGi0PuYiKWdClm0lZJPExYkD88Jy9eeyz8amaVTaX8ZcMDtJb/7fa83m k+8Dn7GF6lC3Wbpb9lcAS70iLQ== X-Google-Smtp-Source: APiQypLcTr6KBl+3kl22Fwtcelh0vbNq/9m4ShF50NjZnZujoh1tYHRDA2VuCyozRSAPGGx/xEl9ug== X-Received: by 2002:a1c:f418:: with SMTP id z24mr3312168wma.122.1588257635132; Thu, 30 Apr 2020 07:40:35 -0700 (PDT) Received: from localhost.localdomain ([2001:171b:226e:c200:c43b:ef78:d083:b355]) by smtp.gmail.com with ESMTPSA id n2sm4153286wrt.33.2020.04.30.07.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Apr 2020 07:40:34 -0700 (PDT) From: Jean-Philippe Brucker To: iommu@lists.linux-foundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-mm@kvack.org Cc: joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, christian.koenig@amd.com, felix.kuehling@amd.com, zhangfei.gao@linaro.org, jgg@ziepe.ca, xuzaibo@huawei.com, fenghua.yu@intel.com, hch@infradead.org, Jean-Philippe Brucker Subject: [PATCH v6 14/25] iommu/arm-smmu-v3: Enable broadcast TLB maintenance Date: Thu, 30 Apr 2020 16:34:13 +0200 Message-Id: <20200430143424.2787566-15-jean-philippe@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200430143424.2787566-1-jean-philippe@linaro.org> References: <20200430143424.2787566-1-jean-philippe@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The SMMUv3 can handle invalidation targeted at TLB entries with shared ASIDs. If the implementation supports broadcast TLB maintenance, enable i= t and keep track of it in a feature bit. The SMMU will then be affected by inner-shareable TLB invalidations from other agents. A major side-effect of this change is that stage-2 translation contexts are now affected by all invalidations by VMID. VMIDs are all shared and the only ways to prevent over-invalidation, since the stage-2 page tables are not shared between CPU and SMMU, are to either disable BTM or allocat= e different VMIDs. This patch does not address the problem. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 3a70d032d4e71..a562c4b243292 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -56,6 +56,7 @@ #define IDR0_ASID16 (1 << 12) #define IDR0_ATS (1 << 10) #define IDR0_HYP (1 << 9) +#define IDR0_BTM (1 << 5) #define IDR0_COHACC (1 << 4) #define IDR0_TTF GENMASK(3, 2) #define IDR0_TTF_AARCH64 2 @@ -655,6 +656,7 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_VAX (1 << 14) #define ARM_SMMU_FEAT_RANGE_INV (1 << 15) #define ARM_SMMU_FEAT_E2H (1 << 16) +#define ARM_SMMU_FEAT_BTM (1 << 17) u32 features; =20 #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) @@ -3809,11 +3811,14 @@ static int arm_smmu_device_reset(struct arm_smmu_= device *smmu, bool bypass) writel_relaxed(reg, smmu->base + ARM_SMMU_CR1); =20 /* CR2 (random crap) */ - reg =3D CR2_PTM | CR2_RECINVSID; + reg =3D CR2_RECINVSID; =20 if (smmu->features & ARM_SMMU_FEAT_E2H) reg |=3D CR2_E2H; =20 + if (!(smmu->features & ARM_SMMU_FEAT_BTM)) + reg |=3D CR2_PTM; + writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); =20 /* Stream table */ @@ -3924,6 +3929,7 @@ static int arm_smmu_device_hw_probe(struct arm_smmu= _device *smmu) { u32 reg; bool coherent =3D smmu->features & ARM_SMMU_FEAT_COHERENCY; + bool vhe =3D cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN); =20 /* IDR0 */ reg =3D readl_relaxed(smmu->base + ARM_SMMU_IDR0); @@ -3973,10 +3979,19 @@ static int arm_smmu_device_hw_probe(struct arm_sm= mu_device *smmu) =20 if (reg & IDR0_HYP) { smmu->features |=3D ARM_SMMU_FEAT_HYP; - if (cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN)) + if (vhe) smmu->features |=3D ARM_SMMU_FEAT_E2H; } =20 + /* + * If the CPU is using VHE, but the SMMU doesn't support it, the SMMU + * will create TLB entries for NH-EL1 world and will miss the + * broadcasted TLB invalidations that target EL2-E2H world. Don't enabl= e + * BTM in that case. + */ + if (reg & IDR0_BTM && (!vhe || reg & IDR0_HYP)) + smmu->features |=3D ARM_SMMU_FEAT_BTM; + /* * The coherency feature as set by FW is used in preference to the ID * register, but warn on mismatch. --=20 2.26.2