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: 9741035 X-Patchwork-Delegate: bhelgaas@google.com 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 A1DE4603F1 for ; Mon, 22 May 2017 16:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94D6328449 for ; Mon, 22 May 2017 16:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 888D62854F; Mon, 22 May 2017 16:40:13 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A6702854F for ; Mon, 22 May 2017 16:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934761AbdEVQkI (ORCPT ); Mon, 22 May 2017 12:40:08 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:34329 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935966AbdEVQkG (ORCPT ); Mon, 22 May 2017 12:40:06 -0400 Received: by mail-pf0-f176.google.com with SMTP id 9so87426329pfj.1 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=ouG0g/gLlJcU7H8Cpt/JPZ+b0euKbO0MqnibrHnrZME2lyJCcUht6k3crJcfJYqPxd +zwE2w2DWYtHDeEsKNwv9cDbNfGvivoKSdhPWRFuMjwJtecZe5kXUNs77ZDZr0tyqcJz 6uSlPuavCMkUbwI0akgTSifNbOinzdXl0vnqNXZxFYGGbYVY1uWGFgiKJxp8Gqfd1ySa NnFuH67/bnVJwDFLsKwVD+YJljmTQIblrsBOKQdoWkk5DadWgXD7sNDj5GoEXsXH7Fu3 VkbeaRsEg8D0eWnoUsQ7sBFb+Sh8xc1pSNomksSFukHAIUnVgzIW0OLT46bPj7KT7EVn CXhw== X-Gm-Message-State: AODbwcCg4fXSPL+eqdMMTzl3C5dm6VlRfhvpXf9kZEmntb1q35pRVCmi WAIoKDt5U0Q20i/i 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 Cc: iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Oza Pawandeep , Oza Pawandeep 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> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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);