Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2989053pxb; Mon, 16 Nov 2020 02:47:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyZOTxZOHgNSbyCyaUKmXIzZUoPx9KCSB3gllIjKBa7dP1ACAog7HB776Rw2xk971lcmwP5 X-Received: by 2002:a50:cfcd:: with SMTP id i13mr14864482edk.275.1605523669598; Mon, 16 Nov 2020 02:47:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605523669; cv=none; d=google.com; s=arc-20160816; b=A2GoYUfqdWD2T+PBbrTgp+iL0mn67id1ydEd+4iO+SPnPPWBod6Z2AJO3+BjXnMOSP FE9GnWB26+p96xIKGn+XftkN2iNRX9t8Uz40PI6rKdoeCfKHUc5dAAR4rfO+jNs3K7DH nFUbxsF9YT/llOWSjp40nGKIsQ6MWK3sx4zPwh3CUcuRRfVCFJtH0bdq5RtOGnrDTkef TvuJgTQFyLlWrKguIPuC6uhoPdzphWst+5esXW/vf368o0aM9VYlisA7RJnqdSkzRGRp QKRL7QD84tmwzolXmYEsQsX7B5l8mlz+hAcuhHYWgC3klhLuZ1FPRk0EbhixEfFxn2+y c9fg== 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=ixObt33SQSUhhgCf7x9vgSjSIHO8K8bOkoUiwoCuGlw=; b=HFRb75LnEtNuFC3IKiD2XDEfdKpGZTnBHwr/VgRIXpJcTsiw+zKOp6IiiW8xIt1DFH tcBf2z8ZS8GPpfp/6qe3ITUdrm83zIkh5/++lCOSP1RqEXp9PgUQ0puzoOuoh6HWMskm 0tmRutWbGPxUue3Vm9/ipcrnARbyiJ7tBenK5F82fHO129T07DfVwdU4kHntA8Tq9nBa 9mDJTgwN2MghTfQ2vkheULmgCCe0cMxkGfK5D+h2jo2Mw0og0AmEroLDQs4NtM0AxPVN tefFWPAVFqsD84rWAuTKAcYvovMyPY2I2UUmHlBjbrlAxal4nWyhBrmOCr34eqnZXL2J gxdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AXvTdRbq; 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 t18si11288713edy.95.2020.11.16.02.47.26; Mon, 16 Nov 2020 02:47:49 -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=AXvTdRbq; 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 S1729429AbgKPKon (ORCPT + 99 others); Mon, 16 Nov 2020 05:44:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51166 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729396AbgKPKom (ORCPT ); Mon, 16 Nov 2020 05:44:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605523480; 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=ixObt33SQSUhhgCf7x9vgSjSIHO8K8bOkoUiwoCuGlw=; b=AXvTdRbqWNfcjCh/LXJAX5UnYbX8Es9ddOtFbzAYsW15oSfGtwvFFqGFyIXyoPAGqPQ8dy iu1Wj4N0VUINXoj5IEN/3bf/Y9RGFZXib3zfackpaMJF9sO1hXB318SUj7a6ckHbmBz9hw IS+7gDVmu7uLbEuBCJN/f+lnaGjRGdw= 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-408-mz_oryH9MlGDsSlXZntuNw-1; Mon, 16 Nov 2020 05:44:37 -0500 X-MC-Unique: mz_oryH9MlGDsSlXZntuNw-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 AB2F6186DD2B; Mon, 16 Nov 2020 10:44:34 +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 750995C5AF; Mon, 16 Nov 2020 10:44:30 +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 10/15] iommu/smmuv3: Nested mode single MSI doorbell per domain enforcement Date: Mon, 16 Nov 2020 11:43:11 +0100 Message-Id: <20201116104316.31816-11-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 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 4b796693d697..de03ac111f76 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