Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp996414pxb; Sun, 11 Apr 2021 04:17:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBW7ZSzKG9TqqEO+l2IOfS4+VyfLRnNqtRK7ce+sLWscZFzZd9grNKX5iOXQh8lh/cYfoK X-Received: by 2002:a50:ec92:: with SMTP id e18mr15466378edr.246.1618139866381; Sun, 11 Apr 2021 04:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618139866; cv=none; d=google.com; s=arc-20160816; b=EnS3jQGEnek/RO5x7ocIkjdr/z5+pk/hiBwkBnKwRpHBTxV5v7EcoxWIfAzQu3gU7W FY+FYlDGWts+QsuCNESqMlLVLOfGtqAsTC/bZpygj/pEwKI3Gk3uxj9dh7UI2C/kiGMc Kwwa+Jkchz18StgcnvulxVQZGwkBVEzHpUSgy7fvO0mLstGscc0a4l0cFRHPqFude3gt /Re/rmNaN5WPBKylqx/AzdSv6Otr+Dfk3pf7a9I4kFPT7RFLwGgy62kRQ07lCO/g6hol ceYWEI/1QNpeNd7oJbUTJTv2vsWplo9pANr8wTu/uDgSNqI0VfJ5o8zUrjhG99PELVgA ocAg== 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=nKOUQdjGGvMFd2q1Io59u7XNZkuFm/YEdxRPelfei3A=; b=oxDYjhtSbmtF8fiZhmBsXQCj0FgXiX2CyqJ1TYIexm3DZJ1Adr5QdNAZviF5E+6y9Z 9KKrczKmy4Pt3I1lHMeIQ2Qggm7ICYEtXidpHY46Goo1cw6WTyMoxhppcFu/U14YBt5v eEhX5qBvqLEB22KY1y1M4wqNgZmYvjiYEmp3XeOTI3MR9QjGXYSUa2CY9CprE4DMoQ3e 5cjiFB4GRC5AoyDPsT3/a/K3gUQ6Db6Pkag4VMmUNEAEkcqwvhOHC/pM0R/LWKXDazzw pj1yWhu82PsU+jSKh+VJ5WKB9rOpd8szI/NaPOm7kQigqFjAlBGy+uJCuXkRLEzlsTQm IMHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ImwUrxQz; 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 h17si5420979ejl.703.2021.04.11.04.17.23; Sun, 11 Apr 2021 04:17:46 -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=ImwUrxQz; 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 S235392AbhDKLPG (ORCPT + 99 others); Sun, 11 Apr 2021 07:15:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59855 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235408AbhDKLPG (ORCPT ); Sun, 11 Apr 2021 07:15:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618139689; 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=nKOUQdjGGvMFd2q1Io59u7XNZkuFm/YEdxRPelfei3A=; b=ImwUrxQzbob5GQG+aE6u0l32+yFmaDRI69QzBBwzYWWKP+9wei9Lee7ROM1DgQvKK/ux6m uMCBDNyRM8coeTmzSM9AsiaaawlaceBPifbbrgJ8arlatzuUyJaAmrRM2wSBGhepZ2v6ms FHJ59XwIpgMOsK7dm2nybq7hM0pgtQk= 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-393-ptZu9ssMPfa_XYGZfhaTpg-1; Sun, 11 Apr 2021 07:14:46 -0400 X-MC-Unique: ptZu9ssMPfa_XYGZfhaTpg-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 A5720188E3C4; Sun, 11 Apr 2021 11:14:42 +0000 (UTC) Received: from laptop.redhat.com (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5368D100164A; Sun, 11 Apr 2021 11:14:29 +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, maz@kernel.org, robin.murphy@arm.com, joro@8bytes.org, alex.williamson@redhat.com, tn@semihalf.com, zhukeqian1@huawei.com Cc: jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, wangxingang5@huawei.com, jean-philippe@linaro.org, zhangfei.gao@linaro.org, zhangfei.gao@gmail.com, vivek.gautam@arm.com, shameerali.kolothum.thodi@huawei.com, yuzenghui@huawei.com, nicoleotsuka@gmail.com, lushenming@huawei.com, vsethi@nvidia.com, chenxiang66@hisilicon.com, vdumpa@nvidia.com, jiangkunkun@huawei.com Subject: [PATCH v15 10/12] iommu/smmuv3: Enforce incompatibility between nested mode and HW MSI regions Date: Sun, 11 Apr 2021 13:12:26 +0200 Message-Id: <20210411111228.14386-11-eric.auger@redhat.com> In-Reply-To: <20210411111228.14386-1-eric.auger@redhat.com> References: <20210411111228.14386-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 Nested mode currently is not compatible with HW MSI reserved regions. Indeed MSI transactions targeting this MSI doorbells bypass the SMMU. Let's check nested mode is not attempted in such configuration. Signed-off-by: Eric Auger --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 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 c4794c21c35f..ec75219d6a52 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2472,6 +2472,23 @@ static bool arm_smmu_share_msi_domain(struct iommu_domain *domain, return share; } +static bool arm_smmu_has_hw_msi_resv_region(struct device *dev) +{ + struct iommu_resv_region *region; + bool has_msi_resv_region = false; + LIST_HEAD(resv_regions); + + iommu_get_resv_regions(dev, &resv_regions); + list_for_each_entry(region, &resv_regions, list) { + if (region->type == IOMMU_RESV_MSI) { + has_msi_resv_region = true; + break; + } + } + iommu_put_resv_regions(dev, &resv_regions); + return has_msi_resv_region; +} + static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; @@ -2532,10 +2549,12 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) /* * In nested mode we must check all devices belonging to the * domain share the same physical MSI doorbell. Otherwise nested - * stage MSI binding is not supported. + * stage MSI binding is not supported. Also nested mode is not + * compatible with MSI HW reserved regions. */ if (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED && - !arm_smmu_share_msi_domain(domain, dev)) { + (!arm_smmu_share_msi_domain(domain, dev) || + arm_smmu_has_hw_msi_resv_region(dev))) { ret = -EINVAL; goto out_unlock; } -- 2.26.3