From patchwork Fri Jan 22 11:52:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 12039113 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 41C78C433E6 for ; Fri, 22 Jan 2021 11:58:10 +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 06ABC22C9F for ; Fri, 22 Jan 2021 11:58:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06ABC22C9F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org 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:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: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:List-Owner; bh=2qtjEnQ7dRH6pnkDzWl9cL1/4J1vpo7jTqZL0DIUKqA=; b=fSVpQS1WQSyq5Gk6RXTavv/Il t2YKJvV/1nCHTVfgLaij12EYrcdm8GcYMIefryQge7VL2nrVMJe8nc4HB697Esa+MpZyLIyrZc4LV toYQZ7pK9hl6r9nY5b3ma1y5bLDB4AR5n+EX3RYVhIjzPG7jv81SfnhWBSEIftO01GMvnNwe5OZUN HK9Jow3Z7J7bhEfoBnSg03HygDRQET91Z5K+zBWXhUsmH3rPy88dYYaXj8XNQFwogOBfgHjO3b9MT M7tcLWwt3da7MO/lZ5Bbe0D+O446/jR5eYJkoJehBVlWFzm5XQb5qlMc+/wT2NQHcmB22mLvl8jv3 SjUsmVgsQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2v3R-0003Us-L5; Fri, 22 Jan 2021 11:56:41 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2v3G-0003RA-CI for linux-arm-kernel@lists.infradead.org; Fri, 22 Jan 2021 11:56:31 +0000 Received: by mail-wr1-x42d.google.com with SMTP id 7so4836370wrz.0 for ; Fri, 22 Jan 2021 03:56:30 -0800 (PST) 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=owZkjSFOA0fuCp5k3fuGX+G2Hp6YSx1juCTT9XbA4kE=; b=Yfotiij4PbT44jIwb874ov94q9TaJDIr5uPZmkTQVPdRZWtdCst/v6l+xeo4jnWBMu MlaCnH3+Gxgv079JfZb4MTr/GSo8Yb9GWJYxYabZzRq52FufOyZVmHwxraQ/KzVJ92lb BtuQ/4V+F0ZHuIlCOhmXQGEvbOZyseb/36c95qb0YJ6y1KeUIKROkvjCPixnXwpQqx4k XTx2C6Z8u+pi8+F6APbGGv8P6Q2D+kfR50/YNse42JxmWoVZqPDnR5zq5I8Ei6fFB6Tt ZA5MiHUhwp1eHSEglPQgJIcmJ13JceHsZtcZ1y6nJnnvnG+hHOHBwirNFms2VxXD/BHt IwWg== 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=owZkjSFOA0fuCp5k3fuGX+G2Hp6YSx1juCTT9XbA4kE=; b=faZ++WQbHAV6nAkf7OFPYia/N0b14eV7jW08rkKElmF7hCbrQ4/wsWoQDbiGu/F4ZP wt2sfk+375KBSYm/oPhSPfOnI23ZYxPjLcZgIyeFXJKXrqgCmMeHJGZvXcPdGrrxwIZn /UacQHXOkq2uXGweVfdBjWN9mKa8bUAP9RzzyRAgik5mIYWQExhw7JQfzdPDKgZ5QNhC zVPYsVng7nD9kzj1PIMAoyolqWA/17x0D13JdG1NvvVCgzbAwTI6dtX2gdNVX7A60sbs UEw5icbBBnWyqRRawfNuJBwbC+YkHjA1RyHrDUSpikYLXquIfXGy6FYQsYIZkWY99Dgr 6sBg== X-Gm-Message-State: AOAM533gY0TQGj6V6tc8Z6isj+vSrfrGb8aHjyua8NEeYBjnflBb6pu5 PT/KI8s7O3QxOER5/cWTJCB5Cg== X-Google-Smtp-Source: ABdhPJxmWG1lTuXpvqqZl1ip4r8FU//sAdGE7mIr6uOeJ1+qwBEyt54qF3kDGQgJMOB/K5vmESCGbg== X-Received: by 2002:adf:fd10:: with SMTP id e16mr3952999wrr.376.1611316589591; Fri, 22 Jan 2021 03:56:29 -0800 (PST) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id s25sm13293901wrs.49.2021.01.22.03.56.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 03:56:29 -0800 (PST) From: Jean-Philippe Brucker To: will@kernel.org, robin.murphy@arm.com, joro@8bytes.org Subject: [PATCH 2/3] iommu/arm-smmu-v3: Make BTM optional for SVA Date: Fri, 22 Jan 2021 12:52:57 +0100 Message-Id: <20210122115257.2502526-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122115257.2502526-1-jean-philippe@linaro.org> References: <20210122115257.2502526-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210122_065630_440802_27EF7FBC X-CRM114-Status: GOOD ( 15.47 ) 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: Jean-Philippe Brucker , vivek.gautam@arm.com, eric.auger@redhat.com, iommu@lists.linux-foundation.org, Jonathan.Cameron@huawei.com, zhangfei.gao@linaro.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When BTM isn't supported by the SMMU, send invalidations on the command queue. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 14 +++++++++++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index a6536c2b32d0..652d03ad8ae6 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -743,6 +743,9 @@ extern struct arm_smmu_ctx_desc quiet_cd; int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid, struct arm_smmu_ctx_desc *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); +void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, + size_t granule, bool leaf, + struct arm_smmu_domain *smmu_domain); bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssid, unsigned long iova, size_t size); diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c index 642ce2c225b5..ad8cf62a8f83 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c @@ -16,6 +16,7 @@ struct arm_smmu_mmu_notifier { struct mmu_notifier mn; struct arm_smmu_ctx_desc *cd; bool cleared; + bool tlb_inv_command; refcount_t refs; struct list_head list; struct arm_smmu_domain *domain; @@ -182,9 +183,13 @@ static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, unsigned long start, unsigned long end) { struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn); + struct arm_smmu_domain *smmu_domain = smmu_mn->domain; + size_t size = end - start + 1; - arm_smmu_atc_inv_domain(smmu_mn->domain, mm->pasid, start, - end - start + 1); + if (smmu_mn->tlb_inv_command) + arm_smmu_tlb_inv_range_asid(start, size, smmu_mn->cd->asid, + PAGE_SIZE, false, smmu_domain); + arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, start, size); } static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm) @@ -253,6 +258,9 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain, smmu_mn->domain = smmu_domain; smmu_mn->mn.ops = &arm_smmu_mmu_notifier_ops; + if (!(smmu_domain->smmu->features & ARM_SMMU_FEAT_BTM)) + smmu_mn->tlb_inv_command = true; + ret = mmu_notifier_register(&smmu_mn->mn, mm); if (ret) { kfree(smmu_mn); @@ -404,7 +412,7 @@ bool arm_smmu_sva_supported(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; + u32 feat_mask = ARM_SMMU_FEAT_COHERENCY; if (vabits_actual == 52) feat_mask |= ARM_SMMU_FEAT_VAX; 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 a27b074d5c0c..db545834493b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2018,6 +2018,20 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, arm_smmu_atc_inv_domain(smmu_domain, 0, iova, size); } +void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid, + size_t granule, bool leaf, + struct arm_smmu_domain *smmu_domain) +{ + struct arm_smmu_cmdq_ent cmd = { + .opcode = CMDQ_OP_TLBI_NH_VA, + .tlbi = { + .asid = asid, + .leaf = leaf, + }, + }; + arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); +} + static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, unsigned long iova, size_t granule, void *cookie)