Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7131415ybl; Mon, 23 Dec 2019 19:03:41 -0800 (PST) X-Google-Smtp-Source: APXvYqx3hCEhZu/nJWbFgshMlulvhKJqx0a/2sNa6XiUy8nN69lO7RHG7+wRisn0uwB185BNGPhz X-Received: by 2002:a9d:1d02:: with SMTP id m2mr33753206otm.45.1577156621865; Mon, 23 Dec 2019 19:03:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577156621; cv=none; d=google.com; s=arc-20160816; b=btAeS2MKfisT+0yci6rvBYdrdYA0ch6gdGKBnenX8r4df0A1NPHsUk89d+d+5iJXiC S16j18jnJih4baoE3wEgolNwm46H34kiMXQ0z6IzniHpXSDMxdL1QFbWxV8d9G3cAnqP /eZ5hZiaWmJfCmdguMQ4zbZghrJkqX91bv8pf0kJtWSDuUI4Zgub3jUcE0/e1NfoD6/g YESK5pgWbvyEjaAEISoDDq8xNAaF4Gtv9oifakEIhIiz52LgW6hhl1xmu/t5R/QRaNWr uYsxyRI0D+0QVy1vx0DUyOtsrw7ByN3oO2O3cxkzCggyn4O6Gst47jWvDlfyFhfIj6EB JaEA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=OMaUyK9UREBURuH+mkmrDfQLcmarV8MAGQGpFxwMWJw=; b=wG1O55rxi7sQKYDmwAYGqorx6Y7xBPasApDxhRdhd64AdEiDCp+hxxu72YsAxHrmYf 2sM5wmO1N/IvQUeTpg8GHQld1zAKIFFnAfV7JYiJEA0R+QF7bwMk86CIHXACY+PD11uI I/jnTVwb+CKKKbjEtKF9rWYvnjfdh4xJvcJxbOblwgiLl+QUVny0vwYuB5tpTprSsxwE CA9ynsc6EdZaZBN05cBPm/U7SfDixSlymLGLiyA/R5zwCXTAKhAWEkhev/9FvKVL2zda exAWovhVhW9qu67/eN4mpOFRZ2GJoUZEZAUgXuY6hjLmN9n86uXBazRQT6TlgJ0oy1gh rgXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KIw6j9qg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16si11205780otp.316.2019.12.23.19.03.29; Mon, 23 Dec 2019 19:03:41 -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=KIw6j9qg; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726878AbfLXDCw (ORCPT + 99 others); Mon, 23 Dec 2019 22:02:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:59770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726747AbfLXDCv (ORCPT ); Mon, 23 Dec 2019 22:02:51 -0500 Received: from wens.tw (mirror2.csie.ntu.edu.tw [140.112.30.76]) (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 36B24206B7; Tue, 24 Dec 2019 03:02:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577156571; bh=4dZHptUocDTk3SMP2Sv3sZ8BavU3pNtaSpQenIapHsM=; h=From:To:Cc:Subject:Date:From; b=KIw6j9qg7Ahaw+bH3ikbPbfqAcxtMxiS2GED2BhbCiix+4T5HZu6btbxvQT/mZA7K aJSd0SXB1C804B6pCGWWIrPoCNlYbzOZneiNYO5b9p29TD9RRVUkMDmA6MKRQTcer6 AtEV6BvJQUzoyo3P5v/Fr7Ru0qThqqQ4CL8ZdQQg= Received: by wens.tw (Postfix, from userid 1000) id E77AF5FC87; Tue, 24 Dec 2019 11:02:47 +0800 (CST) From: Chen-Yu Tsai To: Russell King , Christoph Hellwig , Andrew Morton Cc: Chen-Yu Tsai , Robin Murphy , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH RESEND v2] ARM: dma-api: fix max_pfn off-by-one error in __dma_supported() Date: Tue, 24 Dec 2019 11:02:39 +0800 Message-Id: <20191224030239.5656-1-wens@kernel.org> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen-Yu Tsai max_pfn, as set in arch/arm/mm/init.c: static void __init find_limits(unsigned long *min, unsigned long *max_low, unsigned long *max_high) { *max_low = PFN_DOWN(memblock_get_current_limit()); *min = PFN_UP(memblock_start_of_DRAM()); *max_high = PFN_DOWN(memblock_end_of_DRAM()); } with memblock_end_of_DRAM() pointing to the next byte after DRAM. As such, max_pfn points to the PFN after the end of DRAM. Thus when using max_pfn to check DMA masks, we should subtract one when checking DMA ranges against it. Commit 8bf1268f48ad ("ARM: dma-api: fix off-by-one error in __dma_supported()") fixed the same issue, but missed this spot. This issue was found while working on the sun4i-csi v4l2 driver on the Allwinner R40 SoC. On Allwinner SoCs, DRAM is offset at 0x40000000, and we are starting to use of_dma_configure() with the "dma-ranges" property in the device tree to have the DMA API handle the offset. In this particular instance, dma-ranges was set to the same range as the actual available (2 GiB) DRAM. The following error appeared when the driver attempted to allocate a buffer: sun4i-csi 1c09000.csi: Coherent DMA mask 0x7fffffff (pfn 0x40000-0xc0000) covers a smaller range of system memory than the DMA zone pfn 0x0-0xc0001 sun4i-csi 1c09000.csi: dma_alloc_coherent of size 307200 failed Fixing the off-by-one error makes things work. Fixes: 11a5aa32562e ("ARM: dma-mapping: check DMA mask against available memory") Fixes: 9f28cde0bc64 ("ARM: another fix for the DMA mapping checks") Fixes: ab746573c405 ("ARM: dma-mapping: allow larger DMA mask than supported") Cc: Signed-off-by: Chen-Yu Tsai --- It's been close to two weeks since I sent this. I wasn't sure if I reached the right maintainers, so I'm resending this to more people. Changes since v1: - correct max_pfn offset in the correct place. --- arch/arm/mm/dma-mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index e822af0d9219..9414d72f664b 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -221,7 +221,7 @@ EXPORT_SYMBOL(arm_coherent_dma_ops); static int __dma_supported(struct device *dev, u64 mask, bool warn) { - unsigned long max_dma_pfn = min(max_pfn, arm_dma_pfn_limit); + unsigned long max_dma_pfn = min(max_pfn - 1, arm_dma_pfn_limit); /* * Translate the device's DMA mask to a PFN limit. This -- 2.24.1