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=-12.8 required=3.0 tests=BAYES_00,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=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 98DC6C4345A for ; Thu, 23 Jul 2020 15:06:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D49B2086A for ; Thu, 23 Jul 2020 15:06:37 +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="mvhLrEgw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D49B2086A 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 E8D2E6B0026; Thu, 23 Jul 2020 11:06:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E3BCB6B0027; Thu, 23 Jul 2020 11:06:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D608B6B0028; Thu, 23 Jul 2020 11:06:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0142.hostedemail.com [216.40.44.142]) by kanga.kvack.org (Postfix) with ESMTP id C05466B0026 for ; Thu, 23 Jul 2020 11:06:36 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 7BD2ABEAB for ; Thu, 23 Jul 2020 15:06:36 +0000 (UTC) X-FDA: 77069667192.22.verse64_2b0be7326f3f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id AF1AC1803AA95 for ; Thu, 23 Jul 2020 15:06:06 +0000 (UTC) X-HE-Tag: verse64_2b0be7326f3f X-Filterd-Recvd-Size: 7767 Received: from mail-ej1-f68.google.com (mail-ej1-f68.google.com [209.85.218.68]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 23 Jul 2020 15:06:02 +0000 (UTC) Received: by mail-ej1-f68.google.com with SMTP id y10so6780716eje.1 for ; Thu, 23 Jul 2020 08:06:02 -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=S5AED+AmLuc340wZRBghHkZgD6fSHnG17Dhcvbb6LG8=; b=mvhLrEgwzR3iZucDURuIlZgKpouE3ax9X6RmoyEIoxJtpfKwhaFUyz1wyceDW/uD4V ANI1CA/B02+gizy2dXsrDVev6D5HIUj73+3SLV9QeevQaqnerDuNqQzp/o/4fKW4zUTw 6nOyVRFVtYTPloI13JUmCUVWK2zJ3GDyV078QkI9Uf2lU1Iiw9whqcq4eVhL2AZXOzoS 9sBcohXUxueKQP4XYT7gWYF1aHJCH/xhl9MwDkvrM44w1J4EGC11LxYWc8Jf7Ix+HsDX 47FqCavQPLPdjBxiiBP4Hq3P9zEB7rkZ7Z8T6vW3Oc5Oi61+iu8pM3ezm8msx0Mp/eWw EDRw== 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=S5AED+AmLuc340wZRBghHkZgD6fSHnG17Dhcvbb6LG8=; b=shTuXyRN33tFnad0Y9KxvkdPz9cgmTP7wezS7RlbW5D/lqwv/06zQbBJTLQSXJHNUV EgY80+/YBaTnWiBQ2f5Mp9HNWPnPBT0IYsCWiGkxA9L5NrfMPBfRKlNKYTiUX7dFut1x 6Euxdc0aN1I6LKnrRogsGPm0NGxhZgAZMwL2aS019PrV63EExAMCB+mcmVOHdrbtjAoH uP+kjykMueTDSXJoZeXyZky/rKZZGyrul7b9FVAcrZDt6GUgEgEELxI0NM9l4J5XfaYD 2ln5DnslejWcVECffZXFhHITu/iMhevQvFiQavauSskhw9lPwwXT8UBLHZIlxPGbLL2Q 05Ow== X-Gm-Message-State: AOAM531MDVLOm3aeinULgHIRBuHByYxlum69YvHAukpFBkbqNJDBqS2c TNHtHO/+dZaSVz7ZOB2PQc5c0A== X-Google-Smtp-Source: ABdhPJyrN8twrBRM3dxZpKdtlRVWMv5PMVBDdBZ78Mz4WMqAp4xvT88XtwgShlREF2NsMPW+hYUiWg== X-Received: by 2002:a17:906:8608:: with SMTP id o8mr2836958ejx.156.1595516761662; Thu, 23 Jul 2020 08:06:01 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id k15sm2145952eji.49.2020.07.23.08.06.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2020 08:06:00 -0700 (PDT) From: Jean-Philippe Brucker To: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org Cc: joro@8bytes.org, catalin.marinas@arm.com, will@kernel.org, robin.murphy@arm.com, baolu.lu@linux.intel.com, Jonathan.Cameron@huawei.com, jacob.jun.pan@linux.intel.com, zhangfei.gao@linaro.org, xuzaibo@huawei.com, zhengxiang9@huawei.com, fenghua.yu@intel.com, hch@infradead.org, Jean-Philippe Brucker Subject: [PATCH v9 13/13] iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops Date: Thu, 23 Jul 2020 16:57:25 +0200 Message-Id: <20200723145724.3014766-14-jean-philippe@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200723145724.3014766-1-jean-philippe@linaro.org> References: <20200723145724.3014766-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: AF1AC1803AA95 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 invalidate_range() notifier is called for any change to the address space. Perform the required ATC invalidations. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/arm-smmu-v3.h | 2 ++ drivers/iommu/arm-smmu-v3-sva.c | 16 +++++++++++++++- drivers/iommu/arm-smmu-v3.c | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.h b/drivers/iommu/arm-smmu-v3.h index 6365c81a4614..baa80498ad9f 100644 --- a/drivers/iommu/arm-smmu-v3.h +++ b/drivers/iommu/arm-smmu-v3.h @@ -694,6 +694,8 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *s= mmu_domain, int ssid, struct arm_smmu_ctx_desc *cd); void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid); bool arm_smmu_free_asid(struct arm_smmu_ctx_desc *cd); +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssi= d, + unsigned long iova, size_t size); =20 #ifdef CONFIG_ARM_SMMU_V3_SVA bool arm_smmu_sva_supported(struct arm_smmu_device *smmu); diff --git a/drivers/iommu/arm-smmu-v3-sva.c b/drivers/iommu/arm-smmu-v3-= sva.c index a77abbb7a9d7..1ed6b92b2c72 100644 --- a/drivers/iommu/arm-smmu-v3-sva.c +++ b/drivers/iommu/arm-smmu-v3-sva.c @@ -178,6 +178,16 @@ static void arm_smmu_free_shared_cd(struct arm_smmu_= ctx_desc *cd) } } =20 +static void arm_smmu_mm_invalidate_range(struct mmu_notifier *mn, + struct mm_struct *mm, + unsigned long start, unsigned long end) +{ + struct arm_smmu_mmu_notifier *smmu_mn =3D mn_to_smmu(mn); + + arm_smmu_atc_inv_domain(smmu_mn->domain, mm->pasid, start, + end - start + 1); +} + static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struc= t *mm) { struct arm_smmu_mmu_notifier *smmu_mn =3D mn_to_smmu(mn); @@ -196,6 +206,7 @@ static void arm_smmu_mm_release(struct mmu_notifier *= mn, struct mm_struct *mm) arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, &quiet_cd); =20 arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid); + arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0); =20 smmu_mn->cleared =3D true; mutex_unlock(&sva_lock); @@ -207,6 +218,7 @@ static void arm_smmu_mmu_notifier_free(struct mmu_not= ifier *mn) } =20 static struct mmu_notifier_ops arm_smmu_mmu_notifier_ops =3D { + .invalidate_range =3D arm_smmu_mm_invalidate_range, .release =3D arm_smmu_mm_release, .free_notifier =3D arm_smmu_mmu_notifier_free, }; @@ -279,8 +291,10 @@ static void arm_smmu_mmu_notifier_put(struct arm_smm= u_mmu_notifier *smmu_mn) * If we went through clear(), we've already invalidated, and no * new TLB entry can have been formed. */ - if (!smmu_mn->cleared) + if (!smmu_mn->cleared) { arm_smmu_tlb_inv_asid(smmu_domain->smmu, cd->asid); + arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0); + } =20 /* Frees smmu_mn */ mmu_notifier_put(&smmu_mn->mn); diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index ad71c07e783f..89efa9db7869 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -1515,6 +1515,20 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long io= va, size_t size, size_t inval_grain_shift =3D 12; unsigned long page_start, page_end; =20 + /* + * ATS and PASID: + * + * If substream_valid is clear, the PCIe TLP is sent without a PASID + * prefix. In that case all ATC entries within the address range are + * invalidated, including those that were requested with a PASID! There + * is no way to invalidate only entries without PASID. + * + * When using STRTAB_STE_1_S1DSS_SSID0 (reserving CD 0 for non-PASID + * traffic), translation requests without PASID create ATC entries + * without PASID, which must be invalidated with substream_valid clear. + * This has the unpleasant side-effect of invalidating all PASID-tagged + * ATC entries within the address range. + */ *cmd =3D (struct arm_smmu_cmdq_ent) { .opcode =3D CMDQ_OP_ATC_INV, .substream_valid =3D !!ssid, @@ -1573,8 +1587,8 @@ static int arm_smmu_atc_inv_master(struct arm_smmu_= master *master) return arm_smmu_cmdq_issue_sync(master->smmu); } =20 -static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, - int ssid, unsigned long iova, size_t size) +int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, int ssi= d, + unsigned long iova, size_t size) { int i; unsigned long flags; --=20 2.27.0