Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp882002pxb; Wed, 27 Oct 2021 14:23:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuRjJ6V6/xdhlZFCiylDe80MxxdfPn6iuVZjIFN3scIcbxBmv/8DPg1EYarD4E+GSW0omR X-Received: by 2002:a05:6402:40f:: with SMTP id q15mr397250edv.333.1635369831987; Wed, 27 Oct 2021 14:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369831; cv=none; d=google.com; s=arc-20160816; b=0PZ3bT+TDEsAwMTsPQKH0nmpW8CSnW8LchvD5IV/th+tF8zGKxeh/iI+nVUVh10m7p E+urxVXOtLU7ArCOHI4R5LL0LL4thVFtsRqrsnPYfjCkUCVwj/VktYlc/RKRJsFDak0s 0z2l0eiSjmXD40eNYCQbzr/YX0D1+3RKBdmWCw6I/qu8cUWdAVsPsBfjP/BAFr0kKCmw BUlA/kJWKPGgiXei4Zx6JdcNtmVkItG7fxSieScLrOivGVsMrnN8GQM9CcRIA5rTfLno +r5rLq87Qf+DB4ppzAOTmLrNtmcTDEILZLibZ3VtJ8Q0ixF3AOZj6uWfKoOpfUEST4QU 4EBA== 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=fmDFJfLNPrVWdqUbXfKL9SAwAMM9d1ycI/NAMCsnAJY=; b=j0Gcy1U8/Od17SZkA1w8YUOymReDlrWhPEMBGV1w93whDExrLT3j/cq5k9x0ThQuTX xmgznpnYYdAEAOTi8lLTSos02yZnWcXLjUgNu/fvut4l4aIE/PqNF7SuAA/4LFAFcu2g L2YCGuGON9M25n5PLrmCqZPjGPhWHxaHfkv/yo8K8ODtxC71pHL1eWq76rL9oKNFVs0l 5a/2k/7GbXjbsE6E24JVDcLl+Isa8gwymdKASF0NhqkKGJlTmQvsjE9k8cjcvu5Ee/j8 wCdlAFxn3PpTWzuP4XxtzY5PXcow1G2YkHOmzwpk2GUr2NszKxsaX2X8w6Q6VE0wODIg X6zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HE1Cs535; 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 s4si1422368ejn.134.2021.10.27.14.23.28; Wed, 27 Oct 2021 14:23:51 -0700 (PDT) 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=HE1Cs535; 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 S239752AbhJ0Ks6 (ORCPT + 97 others); Wed, 27 Oct 2021 06:48:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39471 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241540AbhJ0Ks5 (ORCPT ); Wed, 27 Oct 2021 06:48:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635331591; 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=fmDFJfLNPrVWdqUbXfKL9SAwAMM9d1ycI/NAMCsnAJY=; b=HE1Cs535tJxDcV9mE8lPAV76rDiWERkVpWPfJXLbsnQ6epw+yiL0Ph9JqaiMiyOGK44Xu8 1BS+OrJseap7PET74ZurLw5/a95Qunzk2yO783+CX4mO0MpnVgQiPPbfpupMwsIKe0wV9/ XIHkXqboJzlCh2ye2c+aZ8cv/6IC2X4= 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-419-80buNhwjNfO9fKzOU1bivg-1; Wed, 27 Oct 2021 06:46:28 -0400 X-MC-Unique: 80buNhwjNfO9fKzOU1bivg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5644F1006AA6; Wed, 27 Oct 2021 10:46:24 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.154]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE4D0100E809; Wed, 27 Oct 2021 10:46:13 +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, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, jean-philippe@linaro.org, zhukeqian1@huawei.com Cc: alex.williamson@redhat.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, kevin.tian@intel.com, ashok.raj@intel.com, maz@kernel.org, peter.maydell@linaro.org, vivek.gautam@arm.com, shameerali.kolothum.thodi@huawei.com, wangxingang5@huawei.com, jiangkunkun@huawei.com, yuzenghui@huawei.com, nicoleotsuka@gmail.com, chenxiang66@hisilicon.com, sumitg@nvidia.com, nicolinc@nvidia.com, vdumpa@nvidia.com, zhangfei.gao@linaro.org, zhangfei.gao@gmail.com, lushenming@huawei.com, vsethi@nvidia.com Subject: [RFC v16 7/9] iommu/smmuv3: Implement cache_invalidate Date: Wed, 27 Oct 2021 12:44:26 +0200 Message-Id: <20211027104428.1059740-8-eric.auger@redhat.com> In-Reply-To: <20211027104428.1059740-1-eric.auger@redhat.com> References: <20211027104428.1059740-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement domain-selective, pasid selective and page-selective IOTLB invalidations. Signed-off-by: Eric Auger --- v15 -> v16: - make sure the range is set (RIL guest) and check the granule size is supported by the physical IOMMU - use cmd_with_sync v14 -> v15: - remove the redundant arm_smmu_cmdq_issue_sync(smmu) in IOMMU_INV_GRANU_ADDR case (Zenghui) - if RIL is not supported by the host, make sure the granule_size that is passed by the userspace is supported or fix it (Chenxiang) v13 -> v14: - Add domain invalidation - do global inval when asid is not provided with addr granularity v7 -> v8: - ASID based invalidation using iommu_inv_pasid_info - check ARCHID/PASID flags in addr based invalidation - use __arm_smmu_tlb_inv_context and __arm_smmu_tlb_inv_range_nosync v6 -> v7 - check the uapi version v3 -> v4: - adapt to changes in the uapi - add support for leaf parameter - do not use arm_smmu_tlb_inv_range_nosync or arm_smmu_tlb_inv_context anymore v2 -> v3: - replace __arm_smmu_tlb_sync by arm_smmu_cmdq_issue_sync v1 -> v2: - properly pass the asid --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) 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 d5e722105624..e84a7c3e8730 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2923,6 +2923,87 @@ static void arm_smmu_detach_pasid_table(struct iommu_domain *domain) mutex_unlock(&smmu_domain->init_mutex); } +static int +arm_smmu_cache_invalidate(struct iommu_domain *domain, struct device *dev, + struct iommu_cache_invalidate_info *inv_info) +{ + struct arm_smmu_cmdq_ent cmd = {.opcode = CMDQ_OP_TLBI_NSNH_ALL}; + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct arm_smmu_device *smmu = smmu_domain->smmu; + + if (smmu_domain->stage != ARM_SMMU_DOMAIN_NESTED) + return -EINVAL; + + if (!smmu) + return -EINVAL; + + if (inv_info->version != IOMMU_CACHE_INVALIDATE_INFO_VERSION_1) + return -EINVAL; + + if (inv_info->cache & IOMMU_CACHE_INV_TYPE_PASID || + inv_info->cache & IOMMU_CACHE_INV_TYPE_DEV_IOTLB) { + return -ENOENT; + } + + if (!(inv_info->cache & IOMMU_CACHE_INV_TYPE_IOTLB)) + return -EINVAL; + + /* IOTLB invalidation */ + + switch (inv_info->granularity) { + case IOMMU_INV_GRANU_PASID: + { + struct iommu_inv_pasid_info *info = + &inv_info->granu.pasid_info; + + if (info->flags & IOMMU_INV_ADDR_FLAGS_PASID) + return -ENOENT; + if (!(info->flags & IOMMU_INV_PASID_FLAGS_ARCHID)) + return -EINVAL; + + __arm_smmu_tlb_inv_context(smmu_domain, info->archid); + return 0; + } + case IOMMU_INV_GRANU_ADDR: + { + struct iommu_inv_addr_info *info = &inv_info->granu.addr_info; + uint64_t granule_size = info->granule_size; + uint64_t size = info->nb_granules * info->granule_size; + bool leaf = info->flags & IOMMU_INV_ADDR_FLAGS_LEAF; + int tg; + + if (info->flags & IOMMU_INV_ADDR_FLAGS_PASID) + return -ENOENT; + + if (!(info->flags & IOMMU_INV_ADDR_FLAGS_ARCHID)) + break; + + tg = __ffs(granule_size); + if (!granule_size || granule_size & ~(1ULL << tg) || + !(granule_size & smmu->pgsize_bitmap)) + return -EINVAL; + + /* range invalidation must be used */ + if (!size) + return -EINVAL; + + arm_smmu_tlb_inv_range_domain(info->addr, size, + granule_size, leaf, + info->archid, smmu_domain); + return 0; + } + case IOMMU_INV_GRANU_DOMAIN: + break; + default: + return -EINVAL; + } + + /* Global S1 invalidation */ + cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid; + arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd); + return 0; +} + static bool arm_smmu_dev_has_feature(struct device *dev, enum iommu_dev_features feat) { @@ -3022,6 +3103,7 @@ static struct iommu_ops arm_smmu_ops = { .put_resv_regions = generic_iommu_put_resv_regions, .attach_pasid_table = arm_smmu_attach_pasid_table, .detach_pasid_table = arm_smmu_detach_pasid_table, + .cache_invalidate = arm_smmu_cache_invalidate, .dev_has_feat = arm_smmu_dev_has_feature, .dev_feat_enabled = arm_smmu_dev_feature_enabled, .dev_enable_feat = arm_smmu_dev_enable_feature, -- 2.26.3