Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp995738pxb; Sun, 11 Apr 2021 04:16:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLJRBiK1CAuNvgbQszXa5Pv+vnE2KIqaU19p3NYjm2hdSuaxQKfsncwbNvG85OzuG55OW8 X-Received: by 2002:a17:906:d8a9:: with SMTP id qc9mr2894827ejb.37.1618139788720; Sun, 11 Apr 2021 04:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618139788; cv=none; d=google.com; s=arc-20160816; b=Xa34LcUuJyxw3J57BAKGqXOFLTtdxGhh2QgPhFv44Z9N6IvXZvSiK+8HgqHDpmjKId 0M8O3RmgWWmX8cUSgB8KN+7Yx9hywBkQSy0e6FwvQwwxIgfOqa10Ec1qKalEqhvM3esi QgBpch6Lp6t/2H4JOldUPo3Bmv/12TTITRs1ZG4GNlC50Isgd7s8Hpml3/1xOslT9+ig wOpE6ooZrS2bU1PEdqZeT7VY72dY5xjDhcMNenbWmN0TR+BlS6De287fjcnFIk2cfcSs VBxASa4fKZvP6oy4cpJT/vXLHeEcZuVRvrkbyNxETZ8k4a/NXYDnoYKyHuMPG0aIRkHf VzPA== 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=iSh4yAXP/Do32L4Y2Fyt9q3avNaxTzgVS+iaVmFuxCA=; b=oe5P1ZAeop30Ixx3WtjNgO8ajvJEId8jWRww4YREMjkv3uezn/TfSIKFhpuxJZ+gAe UgyUZe8YAPRtsxi19S0sPgD/1slxDQtp7WyAudLiR5kHh3/oyWr9OwIiTt9jKlBzx2s7 JCDjr+ZZFsA+ZykWQQjmmBjM4+Kc2a1Uw6/pw9tUpH/D4LwWg3N4Uojslc4yRfy/ADR8 mr795W89Ey8Bo7lbm153hw7XBLFScgHkhuXX/o+T+xI9Vd71fsBjHZkszd9W84QDyuYJ oMIyoYM2yP2ZjR49FgDv09KsrBW0EDZGlEQoLfUcQxKJgxPlED0BoMgnzscVaIlpaeE8 +q6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IaFrUFUo; 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 t22si5735825edd.558.2021.04.11.04.16.06; Sun, 11 Apr 2021 04:16:28 -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=IaFrUFUo; 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 S235525AbhDKLOx (ORCPT + 99 others); Sun, 11 Apr 2021 07:14:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60963 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235509AbhDKLOv (ORCPT ); Sun, 11 Apr 2021 07:14:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618139674; 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=iSh4yAXP/Do32L4Y2Fyt9q3avNaxTzgVS+iaVmFuxCA=; b=IaFrUFUo1qZYWMl5+yj9T7ZrFfhEqbikSDUMBdxuGCwfUORFW4EsaCKZh27jsbrRH/72dI MWY9EQdnbaBRHmKUKx0KOmdxCghp3ehiF5BTNA7UP02FwPAUcwhTdKvld3XMG4RIP34ilT /OdalHN53Ysi5JRH6ChSEsO/J35EwO0= 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-380-G11BQGGtOiKBlXzGbVBwNA-1; Sun, 11 Apr 2021 07:14:31 -0400 X-MC-Unique: G11BQGGtOiKBlXzGbVBwNA-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 BA0021823DCB; Sun, 11 Apr 2021 11:14:28 +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 E1020100164A; Sun, 11 Apr 2021 11:14:19 +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 09/12] iommu/smmuv3: Nested mode single MSI doorbell per domain enforcement Date: Sun, 11 Apr 2021 13:12:25 +0200 Message-Id: <20210411111228.14386-10-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 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 bfc112cc0d38..c4794c21c35f 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2441,6 +2441,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; @@ -2498,6 +2529,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.26.3