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 50F49C433E4 for ; Thu, 18 Jun 2020 15:53:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 105B6208B8 for ; Thu, 18 Jun 2020 15:53:15 +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="DYibauvJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 105B6208B8 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 DD9648D0040; Thu, 18 Jun 2020 11:52:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D87F38D0018; Thu, 18 Jun 2020 11:52:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9D9F8D0040; Thu, 18 Jun 2020 11:52:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id B32938D0018 for ; Thu, 18 Jun 2020 11:52:53 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7C562180AD807 for ; Thu, 18 Jun 2020 15:52:53 +0000 (UTC) X-FDA: 76942775826.28.death61_250f88826e11 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 5B56F6124 for ; Thu, 18 Jun 2020 15:52:53 +0000 (UTC) X-HE-Tag: death61_250f88826e11 X-Filterd-Recvd-Size: 7207 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Thu, 18 Jun 2020 15:52:52 +0000 (UTC) Received: by mail-ej1-f65.google.com with SMTP id dr13so6951661ejc.3 for ; Thu, 18 Jun 2020 08:52:52 -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=K0sD9muywK0nbycZHdsqSBZ4T+dLVPNn3EX5mSicmkA=; b=DYibauvJ2nimmPQCzKZsqFWxsw1cJOa83Q8lBOizOX8qC2sph7xBeWfJVDLqHcPsZT jUpy1d/5G5neFk7+aPYKN3NiWZz2OD8ek+65tg6OyKTdhesLhyiouRddaM9PTbG2zSM0 vNbXEBv/Zfu7Xpa9afY1wlNWbf7NYURm9ezvJnPuhwmG6QXxlemJYFcE9cyW4NEcWZin j2SQ+U1tQkwf6J+OWfDQA3p4lIuVm/Opa2zG6+W+u6svNiCqSklKXaS1QWT1/RMzMNp0 SPJ6ObCtmIf61+7zubUKVxAmdcChrBc908ruLceXol1cTPgQeBcB+yXy6tuW8+XaC7gk FL3w== 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=K0sD9muywK0nbycZHdsqSBZ4T+dLVPNn3EX5mSicmkA=; b=evZeCeR4jrw/x9kiShztw9TtlE70IIuvGyqrcBDbI75bLh1FgpPxGvf4tcYCKyVvy8 o+aHFP1stD/JBA8CKP7kX2KO8Y3GkZxW0kZylwc8wgqvrB/O5iW9pBNxYVhllS5WAQHs tBmlnbZmiiGf7kyK/Qeh8qUvUXIX7PXVgWIZFvKMwGSl32qclROB0oD4O//nKyf/fT8E fq2y+xm3xRSQat7bILICqwjotqd8jlqfIb4ST6zOYXT0QOSB8RX8h/Gut27vMUeMbAN5 9czVrHWoXiuug3+66vohCLTRAurx/4zJFqMZNKmyc2vRyWyB9aI4of0DQxzLTIK/9yyZ 54kg== X-Gm-Message-State: AOAM532SKr0MxnOTw2/p+cXNwgXprb8r8q2DFsfUaB7y3FbH/TWAHQqR W+O+rG57Czss2emuvBImjD+CLw== X-Google-Smtp-Source: ABdhPJyPJTA3MoAcCwZxTHDutpdNm45kp002C6I1TJUitRaZbiXuqClT8u8iuWaKBu95Oo1397Yh/g== X-Received: by 2002:a17:906:ae85:: with SMTP id md5mr4476555ejb.213.1592495571768; Thu, 18 Jun 2020 08:52:51 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id 63sm2402267edy.8.2020.06.18.08.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 08:52:51 -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 v8 12/12] iommu/arm-smmu-v3: Hook up ATC invalidation to mm ops Date: Thu, 18 Jun 2020 17:51:25 +0200 Message-Id: <20200618155125.1548969-13-jean-philippe@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200618155125.1548969-1-jean-philippe@linaro.org> References: <20200618155125.1548969-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5B56F6124 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index af551f3c78a78..972c061399fc9 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2378,6 +2378,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, @@ -2421,12 +2435,12 @@ arm_smmu_atc_inv_to_cmd(int ssid, unsigned long i= ova, size_t size, cmd->atc.size =3D log2_span; } =20 -static int arm_smmu_atc_inv_master(struct arm_smmu_master *master) +static int arm_smmu_atc_inv_master(struct arm_smmu_master *master, int s= sid) { int i; struct arm_smmu_cmdq_ent cmd; =20 - arm_smmu_atc_inv_to_cmd(0, 0, 0, &cmd); + arm_smmu_atc_inv_to_cmd(ssid, 0, 0, &cmd); =20 for (i =3D 0; i < master->num_sids; i++) { cmd.atc.sid =3D master->sids[i]; @@ -2955,7 +2969,7 @@ static void arm_smmu_disable_ats(struct arm_smmu_ma= ster *master) * ATC invalidation via the SMMU. */ wmb(); - arm_smmu_atc_inv_master(master); + arm_smmu_atc_inv_master(master, 0); atomic_dec(&smmu_domain->nr_ats_masters); } =20 @@ -3152,6 +3166,16 @@ arm_smmu_iova_to_phys(struct iommu_domain *domain,= dma_addr_t iova) return ops->iova_to_phys(ops, iova); } =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); @@ -3170,6 +3194,7 @@ static void arm_smmu_mm_release(struct mmu_notifier= *mn, struct mm_struct *mm) arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, &invalid_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); @@ -3181,6 +3206,7 @@ static void arm_smmu_mmu_notifier_free(struct mmu_n= otifier *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, }; @@ -3257,8 +3283,10 @@ static void arm_smmu_mmu_notifier_put(struct arm_s= mmu_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); --=20 2.27.0