Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp242451pxb; Wed, 18 Nov 2020 03:25:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9dJdXxDypmMAT2lj1xKo10Nqill61OUz2LK3VoaIj8gN+Bqp86KsUhpjFZSprHAu2xKi2 X-Received: by 2002:a17:906:bcf9:: with SMTP id op25mr22812341ejb.223.1605698742516; Wed, 18 Nov 2020 03:25:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605698742; cv=none; d=google.com; s=arc-20160816; b=Hs7rpjF4NeqTS/vA61pJYzBDqL5owYYumKeCAhbdgp5MeOZNNW0aAkYHSnnL2Rpn5g +zD+YVwlIEw+U29vkpqAvvPpLMdNNxcEg0TiHPZmCB1BcSby73xXFLGzdHjEtCF/S3st 2o7Jb5Y6vjPxY5Z++DqMxP/1BqTNsCOT9XS4Yt3BDREheF9DVpVVlb0rq9KJSveHqCTf 142JWgU44rggA0ImdslAo4n3nRAyzAj0jGdeMOzUFSJPc/ywHavYpXsW9Apu9HIvKgHa YelnQbkZvjPhmWrOpcXytrZ8JBqugkG2CIaa0cbO3XnObggK58AL2ZLCaNIuc+a2Gis6 CCLg== 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=hwX0AR7RVibJsIaFfohPJxvOVO8axyUCtDhnNS70RoI=; b=t357a8r3B9GuCXM2F0P7+MYvM6ew6NvzV6atcieprLAZUYnRgzQe17p4GtqKd6DJaV 6MfWQ0kVP6sORoMkeuaRt+BrmLD+4aNgqXeLgPSGj/nxGkPzLzMqstb8hggU3Zh+javk 36hMmBIgSz9QhHz/oTbSSG05d5JDDQvWoHqGCKnCl/LvjirB3Kc93Atlqr4+ZnLhjiiA sD8Uvz+rlbADfSLy7CpuaPHLgQTxR3eC4s8T+1eLvhcK4R4Swhop3Xq+9OJYt9eNiVZA UlorCEyGaNZFGrkPXKMmtQZlcTa4kvKkPNZjkZEKDi5dn2/8E37n2k5nz/AMa9StuEs7 GwxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D72W62pg; 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 c19si166875edw.66.2020.11.18.03.25.19; Wed, 18 Nov 2020 03:25:42 -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=D72W62pg; 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 S1727901AbgKRLXQ (ORCPT + 99 others); Wed, 18 Nov 2020 06:23:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45037 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727862AbgKRLXQ (ORCPT ); Wed, 18 Nov 2020 06:23:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605698594; 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=hwX0AR7RVibJsIaFfohPJxvOVO8axyUCtDhnNS70RoI=; b=D72W62pgvKEC+QwzKbwwc/PeEQ56cV7zTQe3zgfGOdnC8BhbGPt8R9aECj7XgpG8qze1K/ bFdgcrNzG6TSlEpXmIjjcA3B5mifiB7zeJaES/VJbTPEk+r45sbN7X5rAeFt9ljPABUafL A9u8rEFvZY8pHs5qk4uMKfNBe+gsFJw= 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-410-laHTFD0gPJmaWvS6ZtkZcg-1; Wed, 18 Nov 2020 06:23:12 -0500 X-MC-Unique: laHTFD0gPJmaWvS6ZtkZcg-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 70A301891E83; Wed, 18 Nov 2020 11:23:10 +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 D3B1951512; Wed, 18 Nov 2020 11:22:57 +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 08/15] iommu/smmuv3: Implement cache_invalidate Date: Wed, 18 Nov 2020 12:21:44 +0100 Message-Id: <20201118112151.25412-9-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 Implement domain-selective and page-selective IOTLB invalidations. Signed-off-by: Eric Auger --- 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 | 53 +++++++++++++++++++++ 1 file changed, 53 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 fdecc9f17b36..24124361dd3b 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2771,6 +2771,58 @@ 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_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_IOTLB) { + if (inv_info->granularity == IOMMU_INV_GRANU_PASID) { + struct iommu_inv_pasid_info *info = + &inv_info->granu.pasid_info; + + if (!(info->flags & IOMMU_INV_PASID_FLAGS_ARCHID) || + (info->flags & IOMMU_INV_PASID_FLAGS_PASID)) + return -EINVAL; + + __arm_smmu_tlb_inv_context(smmu_domain, info->archid); + + } else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) { + struct iommu_inv_addr_info *info = &inv_info->granu.addr_info; + size_t size = info->nb_granules * info->granule_size; + bool leaf = info->flags & IOMMU_INV_ADDR_FLAGS_LEAF; + + if (!(info->flags & IOMMU_INV_ADDR_FLAGS_ARCHID) || + (info->flags & IOMMU_INV_ADDR_FLAGS_PASID)) + return -EINVAL; + + __arm_smmu_tlb_inv_range(info->addr, size, + info->granule_size, leaf, + smmu_domain, info->archid); + + arm_smmu_cmdq_issue_sync(smmu); + } else { + return -EINVAL; + } + } + if (inv_info->cache & IOMMU_CACHE_INV_TYPE_PASID || + inv_info->cache & IOMMU_CACHE_INV_TYPE_DEV_IOTLB) { + return -ENOENT; + } + return 0; +} + static bool arm_smmu_dev_has_feature(struct device *dev, enum iommu_dev_features feat) { @@ -2854,6 +2906,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.21.3