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=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 CFB8DC433DB for ; Fri, 22 Jan 2021 13:58:27 +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 902B8239D1 for ; Fri, 22 Jan 2021 13:58:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 902B8239D1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com 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-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ZEBAaPjKsbT/4IOx3ojnX0/GART5VzLoAlbzcQfWVBw=; b=Jj7VEK3u6NxBqeMbi5BMcbmit jkDzHYmenkzyGV+nMBDXLir2OupwEFUIuKUiEmQ0criibe2OAldtKNGBT6Hpadl/evHxtEaGlT1Rf +yoEeLTXsaleeAS7CGQGUblhKP2aULwUTW7xN8jEMro40pvW7oj7hNQcyLxVeyYRM/hGr7rBKQHO9 7pl9ZJSBXOr21UKoL2ojfhI5SptIZAae0NXN06nm/KUATWw0bnmL0ZOzuqp9scj3rusaXKHW4ZBdR IFBY0hTOvt2tesC3H3URo+UIlAdM7fPj9OLbd+c/wBxieF74es7lEJnKf6LQ4agK442s98oh0h2FM n0rtAi/gA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2wvl-0001hc-B1; Fri, 22 Jan 2021 13:56:53 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2wvi-0001hF-JB for linux-arm-kernel@lists.infradead.org; Fri, 22 Jan 2021 13:56:51 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9179811B3; Fri, 22 Jan 2021 05:56:49 -0800 (PST) Received: from [10.57.39.58] (unknown [10.57.39.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABC403F66E; Fri, 22 Jan 2021 05:56:47 -0800 (PST) Subject: Re: [PATCH 1/3] iommu/arm-smmu-v3: Split arm_smmu_tlb_inv_range() To: Jean-Philippe Brucker , will@kernel.org, joro@8bytes.org References: <20210122115257.2502526-1-jean-philippe@linaro.org> <20210122115257.2502526-2-jean-philippe@linaro.org> From: Robin Murphy Message-ID: <4a4cee75-2ebb-6de8-05c3-2973b08d5428@arm.com> Date: Fri, 22 Jan 2021 13:56:47 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210122115257.2502526-2-jean-philippe@linaro.org> Content-Language: en-GB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210122_085650_730438_3D369C55 X-CRM114-Status: GOOD ( 24.57 ) 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: 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2021-01-22 11:52, Jean-Philippe Brucker wrote: > Extract some of the cmd initialization and the ATC invalidation from > arm_smmu_tlb_inv_range(), to allow an MMU notifier to invalidate a VA > range by ASID. > > Signed-off-by: Jean-Philippe Brucker > --- > drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 62 ++++++++++++--------- > 1 file changed, 35 insertions(+), 27 deletions(-) > > 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 740a3d487591..a27b074d5c0c 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > @@ -1934,40 +1934,27 @@ static void arm_smmu_tlb_inv_context(void *cookie) > arm_smmu_atc_inv_domain(smmu_domain, 0, 0, 0); > } > > -static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, > - size_t granule, bool leaf, > +static void arm_smmu_tlb_inv_range(struct arm_smmu_cmdq_ent *cmd, > + unsigned long iova, size_t size, > + size_t granule, > struct arm_smmu_domain *smmu_domain) To keep with the specific low-level helper vibe, maybe we should just pass the pgsize_bitmap directly, since I think that's all we're using the domain for now. Robin. > { > struct arm_smmu_device *smmu = smmu_domain->smmu; > - unsigned long start = iova, end = iova + size, num_pages = 0, tg = 0; > + unsigned long end = iova + size, num_pages = 0, tg = 0; > size_t inv_range = granule; > struct arm_smmu_cmdq_batch cmds = {}; > - struct arm_smmu_cmdq_ent cmd = { > - .tlbi = { > - .leaf = leaf, > - }, > - }; > - > if (!size) > return; > > - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { > - cmd.opcode = CMDQ_OP_TLBI_NH_VA; > - cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid; > - } else { > - cmd.opcode = CMDQ_OP_TLBI_S2_IPA; > - cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; > - } > - > if (smmu->features & ARM_SMMU_FEAT_RANGE_INV) { > /* Get the leaf page size */ > tg = __ffs(smmu_domain->domain.pgsize_bitmap); > > /* Convert page size of 12,14,16 (log2) to 1,2,3 */ > - cmd.tlbi.tg = (tg - 10) / 2; > + cmd->tlbi.tg = (tg - 10) / 2; > > /* Determine what level the granule is at */ > - cmd.tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3)); > + cmd->tlbi.ttl = 4 - ((ilog2(granule) - 3) / (tg - 3)); > > num_pages = size >> tg; > } > @@ -1985,11 +1972,11 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, > > /* Determine the power of 2 multiple number of pages */ > scale = __ffs(num_pages); > - cmd.tlbi.scale = scale; > + cmd->tlbi.scale = scale; > > /* Determine how many chunks of 2^scale size we have */ > num = (num_pages >> scale) & CMDQ_TLBI_RANGE_NUM_MAX; > - cmd.tlbi.num = num - 1; > + cmd->tlbi.num = num - 1; > > /* range is num * 2^scale * pgsize */ > inv_range = num << (scale + tg); > @@ -1998,17 +1985,37 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, > num_pages -= num << scale; > } > > - cmd.tlbi.addr = iova; > - arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd); > + cmd->tlbi.addr = iova; > + arm_smmu_cmdq_batch_add(smmu, &cmds, cmd); > iova += inv_range; > } > arm_smmu_cmdq_batch_submit(smmu, &cmds); > +} > + > +static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size, > + size_t granule, bool leaf, > + struct arm_smmu_domain *smmu_domain) > +{ > + struct arm_smmu_cmdq_ent cmd = { > + .tlbi = { > + .leaf = leaf, > + }, > + }; > + > + if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { > + cmd.opcode = CMDQ_OP_TLBI_NH_VA; > + cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid; > + } else { > + cmd.opcode = CMDQ_OP_TLBI_S2_IPA; > + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; > + } > + arm_smmu_tlb_inv_range(&cmd, iova, size, granule, smmu_domain); > > /* > * Unfortunately, this can't be leaf-only since we may have > * zapped an entire table. > */ > - arm_smmu_atc_inv_domain(smmu_domain, 0, start, size); > + arm_smmu_atc_inv_domain(smmu_domain, 0, iova, size); > } > > static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, > @@ -2024,7 +2031,7 @@ static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, > static void arm_smmu_tlb_inv_walk(unsigned long iova, size_t size, > size_t granule, void *cookie) > { > - arm_smmu_tlb_inv_range(iova, size, granule, false, cookie); > + arm_smmu_tlb_inv_range_domain(iova, size, granule, false, cookie); > } > > static const struct iommu_flush_ops arm_smmu_flush_ops = { > @@ -2622,8 +2629,9 @@ static void arm_smmu_iotlb_sync(struct iommu_domain *domain, > { > struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); > > - arm_smmu_tlb_inv_range(gather->start, gather->end - gather->start, > - gather->pgsize, true, smmu_domain); > + arm_smmu_tlb_inv_range_domain(gather->start, > + gather->end - gather->start, > + gather->pgsize, true, smmu_domain); > } > > static phys_addr_t > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel