From patchwork Mon May 22 16:39:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9741043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 832F660388 for ; Mon, 22 May 2017 16:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7515028449 for ; Mon, 22 May 2017 16:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69C472871C; Mon, 22 May 2017 16:41:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E843228449 for ; Mon, 22 May 2017 16:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=2RRoReMy3+Zbrq8DTTTRWQcasZdxZ7OUHW8/wtQG+zs=; b=JiVB+uRWXV+SV7DMIus6onz4VT UH49Sh4wt2al1YSRjuMRaPbFjsYrvI4mObI6p/xtZqiuQqUkf1/3vBzd80fNdmGkC07It57+6hQaV 4R9X0b/U4GlmXO9+ZpQ5mSY9H6PAHdWLg876XuvWuk9nyhc8BtdffZ0huQDhI6M1IMKY9RhfJQsve c0myx9MXixgC/IWLjkCDT4jL1HLGQ/VB4dglpVfHtjFiLN/7LaeH/89g5w13uU7+flmEE4AZejE/i a0/S/Izw1uie8rkPpkJqhonptcM2CVHd9FwVygWNju2113KzijB7yrWZtiX5GQSSl1LmYhs6e/a9L VTeAtZ2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dCqOD-0002yS-CG; Mon, 22 May 2017 16:41:01 +0000 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dCqNe-0001kN-9l for linux-arm-kernel@lists.infradead.org; Mon, 22 May 2017 16:40:30 +0000 Received: by mail-pf0-x22b.google.com with SMTP id m17so87444242pfg.3 for ; Mon, 22 May 2017 09:40:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=stqovSzEEjTr1+ZGgR7tXCb+HaaMUfUW2zeDiteDNe8=; b=dSiuhU33gmhzddPC8zVYJQvlwolMidT1a0Iyo/ikhQNvsv/mkuzdDKisE0Pv5FRirt sinSyxWhoTyrfsSKogRlL8IYItrRhZ6U9c4IX4Z/xbY5jpTtI1dD50STIrXJX2g4rIdi jDOmDXJDaSQeqoP8+6+HXett3ck+5dXfrNH2w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=stqovSzEEjTr1+ZGgR7tXCb+HaaMUfUW2zeDiteDNe8=; b=mH8OZmovcfi0NRwBLAbL71Ix249tZ/1Rc03cI/N5cbRw093aZ6rUfNil7I7WOw/0QH 0wrFgThyt2hoFb+2tDjo5btHBd0tjbOBWOjSPGRUZgHmKbnCGRfKlOUxAFCS5AG0AjB6 hbXJGQAeJiD70U2KS2YPzc8ZEksVV+V6EO/NhXYDoq/A7M5Rdtu6MdY77cJIAa8w8bcn 72BJvBbOTmdN6ZA/hgu8/jg3TaVSAhuR5i5t2wWnR+ipq7g6HCTQMJzUQzlo2XxgJIeO 2ACXiJE3ihLlBii7b0frlKiFIkC4xxK4qtJ6g5x8QY5SYnj0XaY8stNOTmzUDzf/iZVg wknw== X-Gm-Message-State: AODbwcAs2VM6pIMC/+D4HJCI4hX2r22F6McbDKzdlkbfYAYMPqLEhJK3 ECurSCjuf/SMrUEb X-Received: by 10.84.224.66 with SMTP id a2mr29579342plt.191.1495471205334; Mon, 22 May 2017 09:40:05 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id x198sm26538853pgx.28.2017.05.22.09.40.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 May 2017 09:40:04 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH v7 3/3] IOMMU/PCI: Reserve IOVA for inbound memory for PCI masters Date: Mon, 22 May 2017 22:09:42 +0530 Message-Id: <1495471182-12490-4-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1495471182-12490-1-git-send-email-oza.oza@broadcom.com> References: <1495471182-12490-1-git-send-email-oza.oza@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170522_094026_816608_365EA6C6 X-CRM114-Status: GOOD ( 13.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, bcm-kernel-feedback-list@broadcom.com, Oza Pawandeep , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch reserves the inbound memory holes for PCI masters. ARM64 based SOCs may have scattered memory banks. For e.g as iproc based SOC has <0x00000000 0x80000000 0x0 0x80000000>, /* 2G @ 2G */ <0x00000008 0x80000000 0x3 0x80000000>, /* 14G @ 34G */ <0x00000090 0x00000000 0x4 0x00000000>, /* 16G @ 576G */ <0x000000a0 0x00000000 0x4 0x00000000>; /* 16G @ 640G */ But incoming PCI transaction addressing capability is limited by host bridge, for example if max incoming window capability is 512 GB, then 0x00000090 and 0x000000a0 will fall beyond it. To address this problem, iommu has to avoid allocating IOVA which are reserved. Which in turn does not allocate IOVA if it falls into hole. and the holes should be reserved before any of the IOVA allocations can happen. Signed-off-by: Oza Pawandeep diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 8348f366..efe3d07 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -171,16 +171,15 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) { struct pci_host_bridge *bridge; struct resource_entry *window; + struct iommu_resv_region *region; + phys_addr_t start, end; + size_t length; if (!dev_is_pci(dev)) return; bridge = pci_find_host_bridge(to_pci_dev(dev)->bus); resource_list_for_each_entry(window, &bridge->windows) { - struct iommu_resv_region *region; - phys_addr_t start; - size_t length; - if (resource_type(window->res) != IORESOURCE_MEM) continue; @@ -193,6 +192,43 @@ void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list) list_add_tail(®ion->list, list); } + + /* PCI inbound memory reservation. */ + start = length = 0; + resource_list_for_each_entry(window, &bridge->inbound_windows) { + end = window->res->start - window->offset; + + if (start > end) { + /* multiple ranges assumed sorted. */ + pr_warn("PCI: failed to reserve iovas\n"); + return; + } + + if (start != end) { + length = end - start - 1; + region = iommu_alloc_resv_region(start, length, 0, + IOMMU_RESV_RESERVED); + if (!region) + return; + + list_add_tail(®ion->list, list); + } + + start += end + length + 1; + } + /* + * the last dma-range should honour based on the + * 32/64-bit dma addresses. + */ + if ((start) && (start < DMA_BIT_MASK(sizeof(dma_addr_t) * 8))) { + length = DMA_BIT_MASK((sizeof(dma_addr_t) * 8)) - 1; + region = iommu_alloc_resv_region(start, length, 0, + IOMMU_RESV_RESERVED); + if (!region) + return; + + list_add_tail(®ion->list, list); + } } EXPORT_SYMBOL(iommu_dma_get_resv_regions);