From patchwork Mon Jul 23 22:16:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 10541207 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83DE091E for ; Mon, 23 Jul 2018 22:16:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71AC328536 for ; Mon, 23 Jul 2018 22:16:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65BD92855D; Mon, 23 Jul 2018 22:16:21 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 C4BEE28536 for ; Mon, 23 Jul 2018 22:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388131AbeGWXTi (ORCPT ); Mon, 23 Jul 2018 19:19:38 -0400 Received: from foss.arm.com ([217.140.101.70]:39948 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388077AbeGWXTi (ORCPT ); Mon, 23 Jul 2018 19:19:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 389D180D; Mon, 23 Jul 2018 15:16:19 -0700 (PDT) Received: from e110467-lin.cambridge.arm.com (e110467-lin.Emea.Arm.com [10.4.12.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 019F83F5D0; Mon, 23 Jul 2018 15:16:16 -0700 (PDT) From: Robin Murphy To: hch@lst.de, m.szyprowski@samsung.com Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, x86@kernel.org, lorenzo.pieralisi@arm.com, hanjun.guo@linaro.org, sudeep.holla@arm.com, joro@8bytes.org, robh+dt@kernel.org, frowand.list@gmail.com, gregkh@linuxfoundation.org Subject: [PATCH v2 0/7] Stop losing firmware-set DMA masks Date: Mon, 23 Jul 2018 23:16:05 +0100 Message-Id: X-Mailer: git-send-email 2.17.1.dirty Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Whilst the common firmware code invoked by dma_configure() initialises devices' DMA masks according to limitations described by the respective properties ("dma-ranges" for OF and _DMA/IORT for ACPI), the nature of the dma_set_mask() API leads to that information getting lost when well-behaved drivers probe and set a 64-bit mask, since in general there's no way to tell the difference between a firmware-described mask (which should be respected) and whatever default may have come from the bus code (which should be replaced outright). This can break DMA on systems with certain IOMMU topologies (e.g. [1]) where the IOMMU driver only knows its maximum supported address size, not how many of those address bits might actually be wired up between any of its input interfaces and the associated DMA master devices. Similarly, some PCIe root complexes only have a 32-bit native interface on their host bridge, which leads to the same DMA-address-truncation problem in systems with a larger physical memory map and RAM above 4GB (e.g. [2]). These patches attempt to deal with this in the simplest way possible by generalising the specific quirk for 32-bit bridges into an arbitrary mask which can then also be plumbed into the firmware code. In the interest of being minimally invasive, I've only included a point fix for the IOMMU issue as seen on arm64 - there may be further tweaks needed in DMA ops (e.g. in arch/arm/ and other OF users) to catch all possible incarnations of this problem, but at least any that I'm not fixing here have always been broken. It is also noteworthy that of_dma_get_range() has never worked properly for the way PCI host bridges are passed into of_dma_configure() - I'll be working on further patches to sort that out once this part is done. Changes since v1 (RFC): - Pull in patch #1 (previously sent separately) to avoid conflicts - Fix up comment and silly build-breaking typo in patch #2 - Add patches #6 and #7 since fiddling with coherent masks no longer serves a reasonable purpose Robin. [1] http://lists.infradead.org/pipermail/linux-arm-kernel/2018-May/580804.html [2] http://lists.infradead.org/pipermail/linux-arm-kernel/2016-December/474443.html Robin Murphy (7): ACPI/IORT: Support address size limit for root complexes dma-mapping: Generalise dma_32bit_limit flag ACPI/IORT: Set bus DMA mask as appropriate of/device: Set bus DMA mask as appropriate iommu/dma: Respect bus DMA limit for IOVAs ACPI/IORT: Don't set default coherent DMA mask OF: Don't set default coherent DMA mask arch/x86/kernel/pci-dma.c | 2 +- drivers/acpi/arm64/iort.c | 50 ++++++++++++++++++++++++++++----------- drivers/iommu/dma-iommu.c | 3 +++ drivers/of/device.c | 21 ++++++++-------- include/linux/device.h | 6 ++--- kernel/dma/direct.c | 6 ++--- 6 files changed, 57 insertions(+), 31 deletions(-) Acked-by: Will Deacon Acked-by: Ard Biesheuvel