From patchwork Fri May 11 19:06:28 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: 10395017 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 CBAC26053A for ; Fri, 11 May 2018 19:10:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC15528F8B for ; Fri, 11 May 2018 19:10:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B053D28F95; Fri, 11 May 2018 19:10:18 +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=unavailable 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 4B31B28F8E for ; Fri, 11 May 2018 19:10:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2523D6B06B8; Fri, 11 May 2018 15:10:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1D6CC6B06BA; Fri, 11 May 2018 15:10:16 -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 EFB176B06BB; Fri, 11 May 2018 15:10:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f71.google.com (mail-oi0-f71.google.com [209.85.218.71]) by kanga.kvack.org (Postfix) with ESMTP id B96236B06B8 for ; Fri, 11 May 2018 15:10:15 -0400 (EDT) Received: by mail-oi0-f71.google.com with SMTP id 8-v6so3428842oip.22 for ; Fri, 11 May 2018 12:10:15 -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=Dg9Ss+K7sS+Ykd4dsuKoE25AaYXdbncFrfKKBz7DGi8=; b=pWUoYIYYiazZzzjMwgpRFXOXGgq31cN6SF0To45BaA8YF7BNgQsJ3ccH1AqhmZXloW kEooA6t2UQteNHX77DRa5Q/MJzez9i1jSJzEO8YsYmqIX+2ULmNSujK55hawMBNYx0VQ Xw/ucyWz85rgVRaTSKxPbO7+msOVBmsSNILANVhubcUBuW9jqRSNx7W2FszxalYYnemr 1pi1O/kmXNuUTlW5xZy6OVOJR5c183yxEGLSI3cGH9qBtrtc29gmFJPIXimvckH3lxLg /p66u1K5SNx/nWsJ71ekMe4VX1P71VsitD0qWa7H+X3Qxm7P4BBSji+PZ0QO5jq6rh4+ Na6w== 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: ALKqPwdj2X1tv4k4BT2qdaDz8i5XkkHJVkVJlVQIHGs/QcXsbuYkOQQ+ LR8/1ZhBX+2ro2gpsEUTbDqWkvtNDhpE1uP8ed9jgNtH/9Crw6/3ACHb+cpdqVHE77/ZF0f036h yDJXb1o0uth/hcfvmfnqsuY2NL+8AJTKmpnAVRfGn4iF6tQYxM51oRZOonAxlh6o6PA== X-Received: by 2002:a9d:29b5:: with SMTP id n50-v6mr5063223otb.136.1526065814146; Fri, 11 May 2018 12:10:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoP7/oV3D5hRI45Qef46ULTLIm3uANTUhM+B/6NgrXf7qe84L34IVbzWgfJcy8PJu/WL6nR X-Received: by 2002:a9d:29b5:: with SMTP id n50-v6mr5062678otb.136.1526065802260; Fri, 11 May 2018 12:10:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526065802; cv=none; d=google.com; s=arc-20160816; b=MpHUeXcNea2qUy1D5op4wZFXi10wz2uEu6upWkzexjeK/T1JR06+/6U5XCoAzJHv6e G8mZ1/3M+Il//S7TM3oyIYrjaWYGJmn9e61psPaBz/oHI2s6WNguRS5oWZ19PPDMu+U1 aP06gF/DMbyszTRkk3Yy2Im7gjVu4O74mAd+66DaEnCilg00fQqVK8HHDQpVPVEv6lwc inJcONF3/Qg+pHbJzM5TIkOw4q51QJvA7UHTtf2k1/Csp7Sp496hpHMYX6azT9hoWCJY Xac0wUsWypMNmiFgMRluSTDoAAqgjPNnP6TUpXUtbzHz47T3/NN1J9oaaGZ7il4dv10P 6toQ== 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=Dg9Ss+K7sS+Ykd4dsuKoE25AaYXdbncFrfKKBz7DGi8=; b=atolcTa9k4p0KqJekf/aTXF9JTExE6fykxRMAfwDY76yUMcmU7/gouiaaDo1bZVrHd TZfSdx+EImyEOvDq17jZgUhY0RXCVyg075m1ZCvb2snr7kgVEr/ZeuYN9Vwpsf61uZUX lUfZxjOgKwF5kI78nBnm3d60E7AgnbTUyHYRjVYOFwdIdTMAQkgs69dxXrvB88LlgB2S 42f9w/xRRnsFyI7oRr6gbjb+cmD7FD/hcwzczn3qzBQKvfcmucH+hgNWHQRKM+NZQJxd 83cQCuGsFEEpMZTNPD1QutLuArRtysOjCPAM65sJpdk0HtPbDrcWXSlX5Pt1AGsRpkG2 5m8A== 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 c26-v6si1275706otf.390.2018.05.11.12.10.01 for ; Fri, 11 May 2018 12:10:02 -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 916C41993; Fri, 11 May 2018 12:10:01 -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 533E43F23C; Fri, 11 May 2018 12:09:56 -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 27/40] iommu/arm-smmu-v3: Add SVA feature checking Date: Fri, 11 May 2018 20:06:28 +0100 Message-Id: <20180511190641.23008-28-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 Aggregate all sanity-checks for sharing CPU page tables with the SMMU under a single ARM_SMMU_FEAT_SVA bit. For PCIe SVA, users also need to check FEAT_ATS and FEAT_PRI. For platform SVM, they will most likely have to check FEAT_STALLS. Signed-off-by: Jean-Philippe Brucker --- v1->v2: Add 52-bit PA cap and debug message --- drivers/iommu/arm-smmu-v3.c | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 073cba33ae6c..2716e4a4d3f7 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -525,6 +525,7 @@ struct arm_smmu_device { #define ARM_SMMU_FEAT_VAX (1 << 14) #define ARM_SMMU_FEAT_E2H (1 << 15) #define ARM_SMMU_FEAT_BTM (1 << 16) +#define ARM_SMMU_FEAT_SVA (1 << 17) u32 features; #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) @@ -2565,6 +2566,74 @@ static int arm_smmu_device_reset(struct arm_smmu_device *smmu, bool bypass) return 0; } +static bool arm_smmu_supports_sva(struct arm_smmu_device *smmu) +{ + unsigned long reg, fld; + unsigned long oas; + unsigned long asid_bits; + + u32 feat_mask = ARM_SMMU_FEAT_BTM | ARM_SMMU_FEAT_COHERENCY; + + if ((smmu->features & feat_mask) != feat_mask) + return false; + + if (!(smmu->pgsize_bitmap & PAGE_SIZE)) + return false; + + /* + * Get the smallest PA size of all CPUs (sanitized by cpufeature). We're + * not even pretending to support AArch32 here. + */ + reg = read_sanitised_ftr_reg(SYS_ID_AA64MMFR0_EL1); + fld = cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR0_PARANGE_SHIFT); + switch (fld) { + case 0x0: + oas = 32; + break; + case 0x1: + oas = 36; + break; + case 0x2: + oas = 40; + break; + case 0x3: + oas = 42; + break; + case 0x4: + oas = 44; + break; + case 0x5: + oas = 48; + break; + case 0x6: + oas = 52; + break; + default: + return false; + } + + /* abort if MMU outputs addresses greater than what we support. */ + if (smmu->oas < oas) + return false; + + /* We can support bigger ASIDs than the CPU, but not smaller */ + fld = cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR0_ASID_SHIFT); + asid_bits = fld ? 16 : 8; + if (smmu->asid_bits < asid_bits) + return false; + + /* + * See max_pinned_asids in arch/arm64/mm/context.c. The following is + * generally the maximum number of bindable processes. + */ + if (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) + asid_bits--; + dev_dbg(smmu->dev, "%d shared contexts\n", (1 << asid_bits) - + num_possible_cpus() - 2); + + return true; +} + static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) { u32 reg; @@ -2766,6 +2835,9 @@ static int arm_smmu_device_hw_probe(struct arm_smmu_device *smmu) smmu->ias = max(smmu->ias, smmu->oas); + if (arm_smmu_supports_sva(smmu)) + smmu->features |= ARM_SMMU_FEAT_SVA; + dev_info(smmu->dev, "ias %lu-bit, oas %lu-bit (features 0x%08x)\n", smmu->ias, smmu->oas, smmu->features); return 0;