Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp242376pxb; Wed, 18 Nov 2020 03:25:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhnZI4L+Vq0YCjF3p5ShZt21CpPugS1GG9sWUo4vTOeKFwm352/uin8S8evpS3yKXLj9Ka X-Received: by 2002:a05:6402:114b:: with SMTP id g11mr25920584edw.228.1605698733741; Wed, 18 Nov 2020 03:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605698733; cv=none; d=google.com; s=arc-20160816; b=cb5BCuxGnsbDh9IOMLaLPzPtnOL4ofsC0qKBYMk9h9X2RYCDxKljGpmhyjDnjPqCyW wxrgPrHOBdXDgKGN2z2XS6xnhxJ01Fn905A82tO61eaGAb+VKzv1uRGCciqua171SHO5 asOEhXTAtD1qKjtxQzCHEZYlvMMo3RImpCEi/C5BV9kBRDPwMxFB8/U8jYvpQmxNDVIS JicTnbuPNAIRUqYxru+mZz9f8ZOa/6FTV0PXPrfdQnF16d+cfcC/w3oZyHWkCX+IJbA+ KykuqylIl2KqLGshjPy+JpheIBA4AXlNHaFAm+ZMLkF3QRivsyUsczrzv+NdxTboTlwh A6lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qnUjJ97DJwtxIYzbchtIblFBVD2ckX7sYbjAKmnKixA=; b=zAAd7Zwt83UcIZ7yZQZDjssA64WXuQFGWZ5PvAYJVs4WllLClkKsXRlmEX8IXvT9KO 3ep94Duj3i58omGmDAHyyHh/ltrvegl3tPITWeQ7mD7UVp3+VRWZv6gntVpBoLkL7gfi 25eEdwbOoSMVyua8IBTzblZi1PAvmq1A5fsrvQwjwaVlk4qmIdDONvE9ZRfewMX0k62k ncDzp3W6w3aaVKCjiTNwW3tr+ds//Vw+1nLnjgQ2Kh3SbP4Nd3T6KBt1p7SxlknnFuN+ zr6sKEAlLrjoDYtuA5Jre5flZAzmWBVdo9uHnkkQPXesXm9SUs5ipKFD6tMD9VmhvfaJ FPAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hROqwIn1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si11872639ejb.468.2020.11.18.03.25.11; Wed, 18 Nov 2020 03:25:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hROqwIn1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727889AbgKRLXH (ORCPT + 99 others); Wed, 18 Nov 2020 06:23:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25667 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbgKRLXE (ORCPT ); Wed, 18 Nov 2020 06:23:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605698583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qnUjJ97DJwtxIYzbchtIblFBVD2ckX7sYbjAKmnKixA=; b=hROqwIn1XkD1fzHYibB4CGpLf3jvRN0Qg/Me4pWpI75GlgQqW+oWmUwphWOQC0/z4AeEg0 SnwH78pWZk5ErPRhCCHS61o6gYuXWHQbAawCyfQ2ccuj64/526XETEq2iV9LyNOFjMJm33 axPg3Htpf6cvdIrNsSA/As1RLb3VQGA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-B-FK26WGOg6Aq1J214rPtw-1; Wed, 18 Nov 2020 06:22:59 -0500 X-MC-Unique: B-FK26WGOg6Aq1J214rPtw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C8AE8A8F01; Wed, 18 Nov 2020 11:22:57 +0000 (UTC) Received: from laptop.redhat.com (ovpn-115-104.ams2.redhat.com [10.36.115.104]) by smtp.corp.redhat.com (Postfix) with ESMTP id E435F51512; Wed, 18 Nov 2020 11:22:52 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, joro@8bytes.org, maz@kernel.org, robin.murphy@arm.com, alex.williamson@redhat.com Cc: jean-philippe@linaro.org, zhangfei.gao@linaro.org, zhangfei.gao@gmail.com, vivek.gautam@arm.com, shameerali.kolothum.thodi@huawei.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, tn@semihalf.com, nicoleotsuka@gmail.com, yuzenghui@huawei.com Subject: [PATCH v13 07/15] iommu/smmuv3: Allow stage 1 invalidation with unmanaged ASIDs Date: Wed, 18 Nov 2020 12:21:43 +0100 Message-Id: <20201118112151.25412-8-eric.auger@redhat.com> In-Reply-To: <20201118112151.25412-1-eric.auger@redhat.com> References: <20201118112151.25412-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With nested stage support, soon we will need to invalidate S1 contexts and ranges tagged with an unmanaged asid, this latter being managed by the guest. So let's introduce 2 helpers that allow to invalidate with externally managed ASIDs Signed-off-by: Eric Auger --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 35 +++++++++++++++++---- 1 file changed, 29 insertions(+), 6 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 805acdc18a3a..fdecc9f17b36 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1697,9 +1697,9 @@ static int arm_smmu_atc_inv_domain(struct arm_smmu_domain *smmu_domain, } /* IO_PGTABLE API */ -static void arm_smmu_tlb_inv_context(void *cookie) +static void __arm_smmu_tlb_inv_context(struct arm_smmu_domain *smmu_domain, + int ext_asid) { - struct arm_smmu_domain *smmu_domain = cookie; struct arm_smmu_device *smmu = smmu_domain->smmu; struct arm_smmu_cmdq_ent cmd; @@ -1710,7 +1710,11 @@ static void arm_smmu_tlb_inv_context(void *cookie) * insertion to guarantee those are observed before the TLBI. Do be * careful, 007. */ - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + if (ext_asid >= 0) { /* guest stage 1 invalidation */ + cmd.opcode = CMDQ_OP_TLBI_NH_ASID; + cmd.tlbi.asid = ext_asid; + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; + } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { arm_smmu_tlb_inv_asid(smmu, smmu_domain->s1_cfg.cd.asid); } else { cmd.opcode = CMDQ_OP_TLBI_S12_VMALL; @@ -1721,9 +1725,17 @@ 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, +static void arm_smmu_tlb_inv_context(void *cookie) +{ + struct arm_smmu_domain *smmu_domain = cookie; + + __arm_smmu_tlb_inv_context(smmu_domain, -1); +} + +static void __arm_smmu_tlb_inv_range(unsigned long iova, size_t size, size_t granule, bool leaf, - struct arm_smmu_domain *smmu_domain) + struct arm_smmu_domain *smmu_domain, + int ext_asid) { struct arm_smmu_device *smmu = smmu_domain->smmu; unsigned long start = iova, end = iova + size, num_pages = 0, tg = 0; @@ -1738,7 +1750,11 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, if (!size) return; - if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) { + if (ext_asid >= 0) { /* guest stage 1 invalidation */ + cmd.opcode = CMDQ_OP_TLBI_NH_VA; + cmd.tlbi.asid = ext_asid; + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; + } else 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 { @@ -1798,6 +1814,13 @@ static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, arm_smmu_atc_inv_domain(smmu_domain, 0, start, size); } +static void arm_smmu_tlb_inv_range(unsigned long iova, size_t size, + size_t granule, bool leaf, + struct arm_smmu_domain *smmu_domain) +{ + __arm_smmu_tlb_inv_range(iova, size, granule, leaf, smmu_domain, -1); +} + static void arm_smmu_tlb_inv_page_nosync(struct iommu_iotlb_gather *gather, unsigned long iova, size_t granule, void *cookie) -- 2.21.3