Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2988963pxb; Mon, 16 Nov 2020 02:47:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZSTPpAKbhEtPswFd6VsxI6N9MxUtmG7AJq2PeXepUSwINcyuDlChtntugHNYo68lSlqXl X-Received: by 2002:a05:6402:3064:: with SMTP id bs4mr15489390edb.258.1605523657454; Mon, 16 Nov 2020 02:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605523657; cv=none; d=google.com; s=arc-20160816; b=g9Pid2ZZ33/jV9blKr6pqOLcJNTv5xx+HZoVAsfUXXCo0xDm3gJuyL/iHSDVBvaI4t nQT1LTlOWADWmTptYWAAlNWEtNfJ+1lVSa9QCnk+rMg3tmv1PYAjAIvW2amltRB4Zci0 E3izOs/yqUrzU5hgJmIS4RNKjQchM0uDLajnvuJwHMlyIFuc1kcWT4SDf23LJGbhgeId jJ5fD/tMo/RjswQqepWN84v+rxL3dTlj+n2IebqcHBDmDYFEzoRWO0RRsnJF/WnFUbjE wL5jVUsHvH5Noem1P53jlvAizlD41ffJ9sLMydj9NAgHX3WW065wB3+psBlKmMX/GXVS aFzw== 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=LxvNRDy9SuWnb+59b3eyzpbcV50DXwqGzvQKc9IpdYI=; b=uhPUJLZxEXFjaitw7y75CjVhIVAZAG9EnMQgMQkjLnVQ5I0/xfipw3f7OaoilB19U/ JprsZN0LwFfF5xaaB1n26WOn4UwS09EaDGSpqChdH8LkECjtTMgaoOrdeBijFhiDcH96 IwT1F/QmGM8KFX0bi9rf9azAxXYuuA7Es5WqQOWAD62fskADzNSmIiNCFuTiBKQFcQLA U+RZWTF0o4DncLkjtQhs+mpdUGLCid7ZSysBUj1mtR+Muk/rLCg49jkejyb7e9sZ5lUW ASfxZpcZP1OHl9BsaHe8j7GaZ0Cskmfm308IPHaidtUGIzpnqOWL2NKo3GaXgiuKWb8Z e/tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="HQdd7/X7"; 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 l23si14145902ejb.488.2020.11.16.02.47.14; Mon, 16 Nov 2020 02:47:37 -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="HQdd7/X7"; 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 S1729391AbgKPKo2 (ORCPT + 99 others); Mon, 16 Nov 2020 05:44:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46737 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729381AbgKPKo1 (ORCPT ); Mon, 16 Nov 2020 05:44:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605523466; 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=LxvNRDy9SuWnb+59b3eyzpbcV50DXwqGzvQKc9IpdYI=; b=HQdd7/X7sWoojT2ms/n1TRFD0lZklGzgG8nVI5JGYuYtOWJ3EbAaathXptlU2dHrujkygE mihFzHJ0UnWcpftJtYVEGE46JVCd4QW6JhU4mP6gVHubxmppu0DrVI4G/+DMIv+w5VLp2M Sp25ZUUa0uagolXTw7Ok62jaTlILjPg= 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-211-qEHzefDeMhe_mBDcSDL2gw-1; Mon, 16 Nov 2020 05:44:22 -0500 X-MC-Unique: qEHzefDeMhe_mBDcSDL2gw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 809D5186841F; Mon, 16 Nov 2020 10:44:19 +0000 (UTC) Received: from laptop.redhat.com (ovpn-113-230.ams2.redhat.com [10.36.113.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 407E35C5FE; Mon, 16 Nov 2020 10:44:15 +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 Cc: jean-philippe@linaro.org, zhangfei.gao@linaro.org, zhangfei.gao@gmail.com, vivek.gautam@arm.com, shameerali.kolothum.thodi@huawei.com, alex.williamson@redhat.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, tn@semihalf.com, nicoleotsuka@gmail.com Subject: [PATCH v12 08/15] iommu/smmuv3: Implement cache_invalidate Date: Mon, 16 Nov 2020 11:43:09 +0100 Message-Id: <20201116104316.31816-9-eric.auger@redhat.com> In-Reply-To: <20201116104316.31816-1-eric.auger@redhat.com> References: <20201116104316.31816-1-eric.auger@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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 73f7a56101dd..4b796693d697 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2774,6 +2774,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) { @@ -2857,6 +2909,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