From patchwork Fri May 11 19:06:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10394995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E222060153 for ; Fri, 11 May 2018 19:09:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFA0128F8B for ; Fri, 11 May 2018 19:09:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C438A28F95; Fri, 11 May 2018 19:09:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F0A928F8E for ; Fri, 11 May 2018 19:09:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F206B6B06B1; Fri, 11 May 2018 15:09:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EA7966B06B4; Fri, 11 May 2018 15:09:57 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D481E6B06B5; Fri, 11 May 2018 15:09:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by kanga.kvack.org (Postfix) with ESMTP id A65C66B06B1 for ; Fri, 11 May 2018 15:09:57 -0400 (EDT) Received: by mail-oi0-f69.google.com with SMTP id t66-v6so3485602oih.9 for ; Fri, 11 May 2018 12:09:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=sba1TymF4uZ9iJpq4mPBMjnrM+s9MZVzeQhlbexODj4=; b=fqhYHiku+LQWO4kymqFACAyy28gRT2Ygqw0LScyLWvczHUpxCnrDqc7WiBs3ZpxNFn bYx1s2cBnJVjKtFQjUufxp5dKu9RxFlxAzBkStE/65LiIa/fqK8DVgaZKqxCzDNG81Mp I52BG0nqJCJfQtWoTMedW9po06c40YE/wg72KEZPozmsF6bcSI8Q1c7IKE66fClCPNJM k9l/7EwyeFjjjRVQGAS4h6xeCYN3uUxOMDdbj/93U31iMrA1ut34lpLQgkD0wuNWurO7 DvgHwa0S/GXYJF4jURdrqTB3otlr7rwG46o+FlEYUZtyCXxuJ0qYZZOz1/FRpk0VEI3Y 8zxA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com X-Gm-Message-State: ALKqPwfkTp0RbHTtFFbTOERik8CF8A0xWSZgX9Xf68He3jmcqhpCr9lR 8J8wvwk5ulPlMdPcWGACCJ04Ihh1MJB7pgxjleVQfucBVfgHYtc+gA+xEXOzJf4pGXIystL3SKQ AX0vv79PVhp9FRamzkp65DM6EDOH0eMCa9dTm3BE8b/LmPtbH33q6XkhBNxS1Nq60zg== X-Received: by 2002:aca:bf03:: with SMTP id p3-v6mr166oif.331.1526065797444; Fri, 11 May 2018 12:09:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrIhRJQSNbQ/4R3Z8Yyo/yoRBZxfZKyrgaNRUkwQoy+vuSGhk6zzYfPbCQhOY8ebsSUtUDj X-Received: by 2002:aca:bf03:: with SMTP id p3-v6mr132oif.331.1526065796634; Fri, 11 May 2018 12:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526065796; cv=none; d=google.com; s=arc-20160816; b=vAJevYNZcZOLJj/amBnN3fa0TzsnwxNXVG0d4BzOTlV4hWoMVXBItd3YAfJzURISNk yP0zzW7qfY26pl23LSa5Al46EWyup8dKCBLprAm99n81RxzgHyeDkhwacuMyhqL7aTXU XaoTZE+XtwCsraTQsIDIiTROUGocF9UU5wg/tEKJCo9adCg/D6b1hdAa5KyqGQhWd7tD xrNNWKuT3Sz6gPlwuIdBY+dA5Cb5L5gAHqO/BuswoM5ij0Ptx7qa5+IEqDS73f8cX8T3 CmSa/po7vGjLaulUp/fPotYVTMVvswTtalJQSbvGt8lcO+TBi6wl3sPsU6k/Kd0/yYpx 2hvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=sba1TymF4uZ9iJpq4mPBMjnrM+s9MZVzeQhlbexODj4=; b=dfdsw/XiZQAPm8E9Q4VKB4SxwBP7shQUU/gMenGDuycbhVD3U8ZOqZsbLdLQDxapX8 0KMrPjGsmr1d7ynpFC+/ye7kdufyVL+GkNZcSG2pg0vHPLlIwV/cJViSH4m10CGUd4j5 X00i3SF9TdCwMmOkx77gua8Z16p2VaLmsAtCM2fSXguM7jLFH/FgEpxYRuWztzVCnPnF E5G5IpURaUtjsIoYvMe9Z1UWgAoaQjEB8dIU9RHjV+XMeQffQuWWCYIYOpsIYzxjj3si yj50bgc3kA00KesYOywxe8s5c1EojlNmFOqClBC2vlU0vro1IKcGAIU+6q9ZDhbEMOxL se1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Received: from foss.arm.com (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id r13-v6si1165228oie.363.2018.05.11.12.09.56 for ; Fri, 11 May 2018 12:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jean-philippe.brucker@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=jean-philippe.brucker@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 162FF19BF; Fri, 11 May 2018 12:09:56 -0700 (PDT) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.210.33]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CC40E3F23C; Fri, 11 May 2018 12:09:50 -0700 (PDT) From: Jean-Philippe Brucker To: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, iommu@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org Cc: joro@8bytes.org, will.deacon@arm.com, robin.murphy@arm.com, alex.williamson@redhat.com, tn@semihalf.com, liubo95@huawei.com, thunder.leizhen@huawei.com, xieyisheng1@huawei.com, xuzaibo@huawei.com, ilias.apalodimas@linaro.org, jonathan.cameron@huawei.com, liudongdong3@huawei.com, shunyong.yang@hxt-semitech.com, nwatters@codeaurora.org, okaya@codeaurora.org, jcrouse@codeaurora.org, rfranz@cavium.com, dwmw2@infradead.org, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, ashok.raj@intel.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, robdclark@gmail.com, christian.koenig@amd.com, bharatku@xilinx.com, rgummal@xilinx.com Subject: [PATCH v2 26/40] iommu/arm-smmu-v3: Enable broadcast TLB maintenance Date: Fri, 11 May 2018 20:06:27 +0100 Message-Id: <20180511190641.23008-27-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511190641.23008-1-jean-philippe.brucker@arm.com> References: <20180511190641.23008-1-jean-philippe.brucker@arm.com> 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: X-Virus-Scanned: ClamAV using ClamSMTP The SMMUv3 can handle invalidation targeted at TLB entries with shared ASIDs. If the implementation supports broadcast TLB maintenance, enable it 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 allocate 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 280a5d9be839..073cba33ae6c 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -64,6 +64,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 @@ -523,6 +524,7 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_STALL_FORCE (1 << 13) #define ARM_SMMU_FEAT_VAX (1 << 14) #define ARM_SMMU_FEAT_E2H (1 << 15) +#define ARM_SMMU_FEAT_BTM (1 << 16) u32 features; #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) @@ -2459,11 +2461,14 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) writel_relaxed(reg, smmu->base + ARM_SMMU_CR1); /* CR2 (random crap) */ - reg = CR2_PTM | CR2_RECINVSID; + reg = CR2_RECINVSID; if (smmu->features & ARM_SMMU_FEAT_E2H) reg |= CR2_E2H; + if (!(smmu->features & ARM_SMMU_FEAT_BTM)) + reg |= CR2_PTM; + writel_relaxed(reg, smmu->base + ARM_SMMU_CR2); /* Stream table */ @@ -2564,6 +2569,7 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) { u32 reg; bool coherent = smmu->features & ARM_SMMU_FEAT_COHERENCY; + bool vhe = cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN); /* IDR0 */ reg = readl_relaxed(smmu->base + ARM_SMMU_IDR0); @@ -2613,10 +2619,19 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) if (reg & IDR0_HYP) { smmu->features |= ARM_SMMU_FEAT_HYP; - if (cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN)) + if (vhe) smmu->features |= ARM_SMMU_FEAT_E2H; } + /* + * 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 enable + * BTM in that case. + */ + if (reg & IDR0_BTM && (!vhe || reg & IDR0_HYP)) + smmu->features |= ARM_SMMU_FEAT_BTM; + /* * The coherency feature as set by FW is used in preference to the ID * register, but warn on mismatch.