Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2989151pxb; Mon, 16 Nov 2020 02:48:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJO8n5un8ToopLocdHJ9Y0AI+t+kwUFTYFWyFnrtCpZyo6VmTDCTaWM/uhxP/HxtBQ49oI X-Received: by 2002:a17:906:5c43:: with SMTP id c3mr15134130ejr.390.1605523682155; Mon, 16 Nov 2020 02:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605523682; cv=none; d=google.com; s=arc-20160816; b=sIre1o+mFPfnwjX92s9d2mVma2kKXxM1KMvFASYHj9+D13cofHpDzbaEbOdSMcGbF6 TNorvAbClKVJMgz7gQ6mXmKQNIC+B07cWH4paaOm51OW91u4cWRHYmMScV2xJ2wAf+fQ QoQD0SweszhvNjxMzTJqRPtyym1NJYNUMRDdHa6mmqpftPcI4MtumaIrkLnP2CO+e00T eaOQ2SoKS2sUGkWxg5+hj88uGMALDjXrIEsVh6VuPAAAjc6wPqCe1C/7WJ5HgsPPy5Vx 7L0qpX0Iumn0/J/BbYPgKKYjWZHCz00UnG0YLCnfutHZ/gCSqYlTzkvWYCu6I5IrBUVM szuQ== 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=7UhhE+wBoYEM6RGgx1gdxGhDxtIZ6tg0it6OX0kL9i4=; b=CZdmjRZf0T55xF28f00mOGWsAkrYxpcGctm1F+VS0SQdMvf+A7lQOGB+e+uLBVLOKP FRkmjQKhHrluu7Gd4dvzQezVcSOYIllR+XfrvVM6X9Vu0uMIj4wZGfCF77Zw6d9Bgfu9 u795KoQf+DJ0DvnkukRtHJaKiSkhmUSEQm7n4IDZpZv2zrUqzrefnidCoZlxnkgO1yXk oV4l8MWQaP3i8iNfGoCknywJt0NN+YEUawa1P5t/cL7GkpPS9+YxR+tf6PnrQONzQfX3 FtJ8n3nTBtrN0GLlRvs/LVslyH8HOVEPsnFtswdWPe41gfXioF77IUkyzIlh9HiAX3D5 3aHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=glFjeL8S; 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 n10si11174323edv.118.2020.11.16.02.47.39; Mon, 16 Nov 2020 02:48:02 -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=glFjeL8S; 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 S1729446AbgKPKos (ORCPT + 99 others); Mon, 16 Nov 2020 05:44:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23063 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729436AbgKPKos (ORCPT ); Mon, 16 Nov 2020 05:44:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605523486; 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=7UhhE+wBoYEM6RGgx1gdxGhDxtIZ6tg0it6OX0kL9i4=; b=glFjeL8So2b6FtjCEXSWzbUZF2zUsiJhtXCpEDENN1wZtiTwhrQXJ1146CbWjsoMHcc25n IVGtSI75EHHSoDYQHUnP7YJj9ZP31hD0reWg1hsmuZfX+uKnBfxKk1z/KcDlsMZ8Zz/2kC xRt5j8/mdWADF23f+1+fr+nKuhs0Gu4= 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-167-ZiQMDX2vNi-NL0GxiTic3w-1; Mon, 16 Nov 2020 05:44:43 -0500 X-MC-Unique: ZiQMDX2vNi-NL0GxiTic3w-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 76B6C1084C8D; Mon, 16 Nov 2020 10:44:39 +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 0E06B5C5FE; Mon, 16 Nov 2020 10:44:34 +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 11/15] iommu/smmuv3: Enforce incompatibility between nested mode and HW MSI regions Date: Mon, 16 Nov 2020 11:43:12 +0100 Message-Id: <20201116104316.31816-12-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 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 de03ac111f76..0c5ab4005f76 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2296,6 +2296,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; @@ -2350,10 +2367,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.21.3