Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2100097ybl; Thu, 30 Jan 2020 11:21:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwFJd2vT1DWc+US7u+GxjT3LeTJPFKuIZ3qBG+exuci66Yf02ynl8/aPFP6AytvQtnsoIwz X-Received: by 2002:aca:ab51:: with SMTP id u78mr3977619oie.21.1580412075384; Thu, 30 Jan 2020 11:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580412075; cv=none; d=google.com; s=arc-20160816; b=myAN3SDdtX6ruWDq8/dPCU1uSCvXpItK/sskIIQl2GE1GCTegdksyJJKcw7a+QiPMB BKnoMgp+qEEK/s4C7m9U5LFvFtEpUbWq4Iitfrg7wFJ2sWFTBIEDOUi7+ZHcKu0o3LfI VFE0ZWe8ukP7chCEYKwLptS4Vk4UdovKvDOEN+zHcwuZ8cfIqg++eAOn+2d/Z3+eGWp0 TcQYcwu5OgimKhveB7uQSznl5R/7yUfoKE/5KttkuVaRJk4yb08zX1drXaGskbTaGFie hfSKcZfaJ55ZyCx8wHnfmKg3q0ANQF9r6amW1LQIplg2i7rqTcuMI9mwwluBlZkx7TSf W8Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5Fcx9CY10Jcy2t6rapZ6EEo18J5Lh+ZNOhC8Fo6zVUI=; b=al2SA8vzfRLTy1dsPUf+YkZQvTUUKGUL0IL4Y2/lTq6DVEjUypSJEH21EtuXcReqIa 6JShCjk6yjF5VtUynZvAIMswEihWDsyetNFJiZz5UMbqQOauS5ZYZupKj2xXjxoHC6sv zdDs9zYT0D+aGpq3e/7sYlCDyGJZPQ7uN6fRl42kyt5EupLcH2btL3XyzBSHw4MeT/VO wfaXAoFjYPfQaQUrSuZC9nuyPcBIL7aGO3opcBIC7R2VkKPN8OrG7D38QklZFixzzRaC KpqFYI9FhXcRxLh2jM8y6yZrfdA+7xPUqItGiJwxtK8cjKv8K37COJwZO6h/yG6fKRk8 DomQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KEQux95+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m67si3025401oib.117.2020.01.30.11.21.03; Thu, 30 Jan 2020 11:21:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KEQux95+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731531AbgA3SsT (ORCPT + 99 others); Thu, 30 Jan 2020 13:48:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:59114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731516AbgA3SsP (ORCPT ); Thu, 30 Jan 2020 13:48:15 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 368CB2082E; Thu, 30 Jan 2020 18:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580410094; bh=+CXCHPZFxuFAhYwU84P3dabbs1o76IT9JCxq49576m8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KEQux95+G8qz4XcWNKsAeMIYbOD1bO5EZDKWzo7+KN/u+oZ0x/Pcl3ocVOYvN4JzZ peKWlpQPTbJ8UZRg7QWgMRvpEsP7ntxAb82ElIWajwFLpHC1ZCdVlKvDt3nixC3v6g D5SwMjQ0ztuD19W8kxTNwAje8+7tGaE7jp0lu7vY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Logan Gunthorpe , Joerg Roedel , Sasha Levin Subject: [PATCH 4.19 43/55] iommu/amd: Support multiple PCI DMA aliases in IRQ Remapping Date: Thu, 30 Jan 2020 19:39:24 +0100 Message-Id: <20200130183616.368600456@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200130183608.563083888@linuxfoundation.org> References: <20200130183608.563083888@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Logan Gunthorpe [ Upstream commit 3c124435e8dd516df4b2fc983f4415386fd6edae ] Non-Transparent Bridge (NTB) devices (among others) may have many DMA aliases seeing the hardware will send requests with different device ids depending on their origin across the bridged hardware. See commit ad281ecf1c7d ("PCI: Add DMA alias quirk for Microsemi Switchtec NTB") for more information on this. The AMD IOMMU IRQ remapping functionality ignores all PCI aliases for IRQs so if devices send an interrupt from one of their aliases they will be blocked on AMD hardware with the IOMMU enabled. To fix this, ensure IRQ remapping is enabled for all aliases with MSI interrupts. This is analogous to the functionality added to the Intel IRQ remapping code in commit 3f0c625c6ae7 ("iommu/vt-d: Allow interrupts from the entire bus for aliased devices") Signed-off-by: Logan Gunthorpe Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/amd_iommu.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index bea19aa337587..0783f44e9afe5 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3709,7 +3709,20 @@ static void set_remap_table_entry(struct amd_iommu *iommu, u16 devid, iommu_flush_dte(iommu, devid); } -static struct irq_remap_table *alloc_irq_table(u16 devid) +static int set_remap_table_entry_alias(struct pci_dev *pdev, u16 alias, + void *data) +{ + struct irq_remap_table *table = data; + + irq_lookup_table[alias] = table; + set_dte_irq_entry(alias, table); + + iommu_flush_dte(amd_iommu_rlookup_table[alias], alias); + + return 0; +} + +static struct irq_remap_table *alloc_irq_table(u16 devid, struct pci_dev *pdev) { struct irq_remap_table *table = NULL; struct irq_remap_table *new_table = NULL; @@ -3755,7 +3768,12 @@ static struct irq_remap_table *alloc_irq_table(u16 devid) table = new_table; new_table = NULL; - set_remap_table_entry(iommu, devid, table); + if (pdev) + pci_for_each_dma_alias(pdev, set_remap_table_entry_alias, + table); + else + set_remap_table_entry(iommu, devid, table); + if (devid != alias) set_remap_table_entry(iommu, alias, table); @@ -3772,7 +3790,8 @@ out_unlock: return table; } -static int alloc_irq_index(u16 devid, int count, bool align) +static int alloc_irq_index(u16 devid, int count, bool align, + struct pci_dev *pdev) { struct irq_remap_table *table; int index, c, alignment = 1; @@ -3782,7 +3801,7 @@ static int alloc_irq_index(u16 devid, int count, bool align) if (!iommu) return -ENODEV; - table = alloc_irq_table(devid); + table = alloc_irq_table(devid, pdev); if (!table) return -ENODEV; @@ -4215,7 +4234,7 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq, struct irq_remap_table *table; struct amd_iommu *iommu; - table = alloc_irq_table(devid); + table = alloc_irq_table(devid, NULL); if (table) { if (!table->min_index) { /* @@ -4232,11 +4251,15 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq, } else { index = -ENOMEM; } - } else { + } else if (info->type == X86_IRQ_ALLOC_TYPE_MSI || + info->type == X86_IRQ_ALLOC_TYPE_MSIX) { bool align = (info->type == X86_IRQ_ALLOC_TYPE_MSI); - index = alloc_irq_index(devid, nr_irqs, align); + index = alloc_irq_index(devid, nr_irqs, align, info->msi_dev); + } else { + index = alloc_irq_index(devid, nr_irqs, false, NULL); } + if (index < 0) { pr_warn("Failed to allocate IRTE\n"); ret = index; -- 2.20.1