Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp243847pxb; Wed, 18 Nov 2020 03:28:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4sGq6O6WOX+Vm3l9q2eDb9AVXIrMZyOsuiJ6TslrRKrnXzBfZUlG2YubaKrsBmZJFetVw X-Received: by 2002:aa7:d717:: with SMTP id t23mr24840566edq.286.1605698889298; Wed, 18 Nov 2020 03:28:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605698889; cv=none; d=google.com; s=arc-20160816; b=Y1YEPrrL6pb7cnekjNofKCLftXg9vFVzq9vLlu1d0If5r4KPPxOFKA7Mh40xtxWb3p B4CTNfiMN/i9Jt3SCK7k94AuRtxD3vSr78LBzHcN0lfjGfrHfxx25cRlycEz2nF8YJGU RJlhw/CcnwHMOmIyIVheKfXHnISZo441YuC/EsN9NHYw2T7XLct0J4Oq5PwyAoWYD54L WTMk6yGHsjy2kqlv2dKZLJ1yR80TARPfU+dJqEziD+Q17jHlUN2Jz40rAHWET/CIHMQ7 9wUh3ws8XRjZ3Woe+zYZZnx3r6TpWENSNoHLMO6Glyz/u0CiD2JPlBUecjcdQ4kuMeeB Nhew== 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=uaQwiNSGqfR1biFLXiHmn4AIozeQd6xlUFw6nx9Ywig=; b=IW/V1PvUqUzjyQyopl4hJgShTmc1MznsHXLKxI3r8HyLNX2SIS55IIiUuAqJBOHQzH Xah6v5sP3/U+N65tcrdD5pRhbJ1jv4DWYor5lgGtujbQmG7gmYZtimQhs55t4JR6LMEf wRXc3a5p3SZBnFN4Yo/O0nJmH0uI/vLyZnVm6Lg4rC04jPzGMO03T2G7ZwSL5UJBwIeD v5goZYffm6R5ZQvks2r7yUh0EboDs69oOVwXHYQrZmZOfeQXwN9Fp8cX/XhPchRP/5KF nQmBUrc3KH74ZGoC7ELbxCc4mHEsHhsuHfAM8ungi8UMIzxaEmOeE9bwlve2AfagPIN+ Pp7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Nd+eoudh; 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 ce9si14952519ejb.713.2020.11.18.03.27.46; Wed, 18 Nov 2020 03:28:09 -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=Nd+eoudh; 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 S1727934AbgKRLX1 (ORCPT + 99 others); Wed, 18 Nov 2020 06:23:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24476 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727926AbgKRLX0 (ORCPT ); Wed, 18 Nov 2020 06:23:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605698605; 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=uaQwiNSGqfR1biFLXiHmn4AIozeQd6xlUFw6nx9Ywig=; b=Nd+eoudhxIat2X+WYK+MnCvSP0HS2sHK4EhA98QK3fwn6eXbNLyP6phrsN9yWxniBRZfh6 c1yiy7tgDyRbXHDHW392bD49z8rfOiKsLxXhXo6aEaVSbG9Hv1VxSsk/gCjIoq2q2XZqOw wyUanv40gLjdmUA3z9TBdCu/P4kysMM= 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-197-Tj9zjH77PgiXeVgtm-8Tjw-1; Wed, 18 Nov 2020 06:23:23 -0500 X-MC-Unique: Tj9zjH77PgiXeVgtm-8Tjw-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 7654A64092; Wed, 18 Nov 2020 11:23:20 +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 BDA075B4A0; Wed, 18 Nov 2020 11:23: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, 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 10/15] iommu/smmuv3: Nested mode single MSI doorbell per domain enforcement Date: Wed, 18 Nov 2020 12:21:46 +0100 Message-Id: <20201118112151.25412-11-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 In nested mode we enforce the rule that all devices belonging to the same iommu_domain share the same msi_domain. Indeed if there were several physical MSI doorbells being used within a single iommu_domain, it becomes really difficult to resolve the nested stage mapping translating into the correct physical doorbell. So let's forbid this situation. Signed-off-by: Eric Auger --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 41 +++++++++++++++++++++ 1 file changed, 41 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 24124361dd3b..5a05c2074c8a 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2265,6 +2265,37 @@ static void arm_smmu_detach_dev(struct arm_smmu_master *master) arm_smmu_install_ste_for_dev(master); } +static bool arm_smmu_share_msi_domain(struct iommu_domain *domain, + struct device *dev) +{ + struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain); + struct irq_domain *irqd = dev_get_msi_domain(dev); + struct arm_smmu_master *master; + unsigned long flags; + bool share = false; + + if (!irqd) + return true; + + spin_lock_irqsave(&smmu_domain->devices_lock, flags); + list_for_each_entry(master, &smmu_domain->devices, domain_head) { + struct irq_domain *d = dev_get_msi_domain(master->dev); + + if (!d) + continue; + if (irqd != d) { + dev_info(dev, "Nested mode forbids to attach devices " + "using different physical MSI doorbells " + "to the same iommu_domain"); + goto unlock; + } + } + share = true; +unlock: + spin_unlock_irqrestore(&smmu_domain->devices_lock, flags); + return share; +} + static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) { int ret = 0; @@ -2316,6 +2347,16 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) ret = -EINVAL; goto out_unlock; } + /* + * 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. + */ + if (smmu_domain->stage == ARM_SMMU_DOMAIN_NESTED && + !arm_smmu_share_msi_domain(domain, dev)) { + ret = -EINVAL; + goto out_unlock; + } master->domain = smmu_domain; -- 2.21.3