From patchwork Thu Dec 29 20:45:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikita Yushchenko X-Patchwork-Id: 9491407 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 340A562AB8 for ; Thu, 29 Dec 2016 20:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2342F1FFD6 for ; Thu, 29 Dec 2016 20:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1788522BF1; Thu, 29 Dec 2016 20:47:27 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD2371FFD6 for ; Thu, 29 Dec 2016 20:47:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cMha3-0000Md-D6; Thu, 29 Dec 2016 20:45:43 +0000 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1cMhZx-0000Fu-HB for linux-arm-kernel@lists.infradead.org; Thu, 29 Dec 2016 20:45:39 +0000 Received: by mail-lf0-x22a.google.com with SMTP id c13so227345798lfg.0 for ; Thu, 29 Dec 2016 12:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cogentembedded-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=5n0nViJRUk5iFvdAi+XB+HT+MP1Tc7Q8E47VVOZI0aw=; b=RGYcPQMN1Rk/bKa99iOwZfyZ37MPcMq6hLH8V82D0Mt77AIvrmS2tikHDku66vox90 nG1d5+IiKB44Z2vFCM6XTAt2C7FVyrSYWyEvdyP7LRxLmfINd87dndu/B2uabicLCiwt h9ixwuxyAIkrmF7+R00MrZLlqkX7CV+RN84gbVDElMEEX8GVnQTffDJmhErK9s/6tIBn A06wdWTcsjKCyYx3jb+9p/YXDqNK9pArU2XiUUmzmUD3ZutqTqsv4SZu/GF2vpthdPba MHMnMz5DreJKtD73VzgBxtzWP4YmFWsaL+M/LZ96ZuONa5/7EVvzUpj/QEA8IuRCZwfo NuLA== 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; bh=5n0nViJRUk5iFvdAi+XB+HT+MP1Tc7Q8E47VVOZI0aw=; b=giTLyCelzCLUM5a/Zjd/SS5sz+M/OqVibWR755usoZsCmfkuJE113o/GLf0RXRv95k cJuPMB8+a54DGgXG8X3tXGvX/z5s6jsVe8TPG6xQS9+553CkaaSZTW1c3obBTz+edEbS S/aO6s/TXq5Q74rWsHSlcz4s05vH4w2fPkMw6vu4UzGiTtLCjGAIFg5hex+qp5g7NVJw 78kUqWQ/buy8/y0jBM+zRIjIPFAYM0BSyenNwwWsZ2D2ljE6cL7LbIHGnl74rX1L6bbW aMPKctciPuzDlM3Ov2OpQlv78FsblwVe9bpx5a3iXg5TG7AMF+fv88bQuc0BZewUUw/I 4QQQ== X-Gm-Message-State: AIkVDXJUNnKt6/qlmx0SJu4hPjGvlGlWbcy5SG/s8B5XypMmhtJMN5UY2B0qqS4ECbtrPA== X-Received: by 10.25.79.21 with SMTP id d21mr12422394lfb.49.1483044314541; Thu, 29 Dec 2016 12:45:14 -0800 (PST) Received: from hugenb.home (nikaet.starlink.ru. [94.141.168.29]) by smtp.gmail.com with ESMTPSA id d2sm3338104lfe.13.2016.12.29.12.45.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Dec 2016 12:45:12 -0800 (PST) From: Nikita Yushchenko To: Catalin Marinas , Will Deacon , Arnd Bergmann , linux-arm-kernel@lists.infradead.org, Simon Horman , Bjorn Helgaas , linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH 1/2] arm64: dma_mapping: allow PCI host driver to limit DMA mask Date: Thu, 29 Dec 2016 23:45:03 +0300 Message-Id: <1483044304-2085-1-git-send-email-nikita.yoush@cogentembedded.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161229_124537_843955_8B7C1B97 X-CRM114-Status: GOOD ( 13.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nikita Yushchenko , artemi.ivanov@cogentembedded.com, linux-kernel@vger.kernel.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 It is possible that PCI device supports 64-bit DMA addressing, and thus it's driver sets device's dma_mask to DMA_BIT_MASK(64), however PCI host bridge has limitations on inbound transactions addressing. Example of such setup is NVME SSD device connected to RCAR PCIe controller. Previously there was attempt to handle this via bus notifier: after driver is attached to PCI device, bridge driver gets notifier callback, and resets dma_mask from there. However, this is racy: PCI device driver could already allocate buffers and/or start i/o in probe routine. In NVME case, i/o is started in workqueue context, and this race gives "sometimes works, sometimes not" effect. Proper solution should make driver's dma_set_mask() call to fail if host bridge can't support mask being set. This patch makes __swiotlb_dma_supported() to check mask being set for PCI device against dma_mask of struct device corresponding to PCI host bridge (one with name "pciXXXX:YY"), if that dma_mask is set. This is the least destructive approach: currently dma_mask of that device object is not used anyhow, thus all existing setups will work as before, and modification is required only in actually affected components - driver of particular PCI host bridge, and dma_map_ops of particular platform. Signed-off-by: Nikita Yushchenko --- arch/arm64/mm/dma-mapping.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 290a84f..49645277 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -347,6 +348,16 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, static int __swiotlb_dma_supported(struct device *hwdev, u64 mask) { +#ifdef CONFIG_PCI + if (dev_is_pci(hwdev)) { + struct pci_dev *pdev = to_pci_dev(hwdev); + struct pci_host_bridge *br = pci_find_host_bridge(pdev->bus); + + if (br->dev.dma_mask && (*br->dev.dma_mask) && + (mask & (*br->dev.dma_mask)) != mask) + return 0; + } +#endif if (swiotlb) return swiotlb_dma_supported(hwdev, mask); return 1;