Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3707660ybv; Mon, 10 Feb 2020 05:05:15 -0800 (PST) X-Google-Smtp-Source: APXvYqz2kkgARrcywXQBdNCckL+CDV4dothl48YhpKTn4voeNsNm6vdXoGNn+tSrDw0nPZ+8VOzE X-Received: by 2002:aca:e106:: with SMTP id y6mr750965oig.131.1581339914597; Mon, 10 Feb 2020 05:05:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581339914; cv=none; d=google.com; s=arc-20160816; b=AAnrEZMHu+X3/ff+Nl47fFcORgztf6A+OhCBJfq/AXS7LydjFJt8xqJuaJjaI0AefF 6SwM+3VW/HhtaK0lmPV2nYXaFe2JKQzIwzWMygyKxKWKPUuXS3lyXdHwnzPZvdxbMbPO 7gCV+SpAw1LLakoreAXM7aU80pfBSSPmrYJV0nSoIHOX9wpHnTrUfpzdpazBqjFXSyZg uC83OHAsziUkjtP9EG53Cp7hVVftLhIyLBZ38oeJoa2KAhOqLscmpSsygpzi+P6Cfr9L gVNuKMySuGBPCAFIYZQCJ6FQfo6r+sK9BhuCwET81oINpPW3GVqqw+xTGPziVbYvHfa0 293w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R4YUQye2ZkXVr6umIsWQfTzJ1o9yI2UB/0jOVrurwOo=; b=sYD7BIlW3LGH1e+WlHLiVubN2q70kpZhLvpoaun04yTzQJP3n9A/3DpOU2MbqEj4FM MFI3yCdPpFnd/++9THMsbq4N/XXSIGEZPZhvxmdyouMpd8Fad2lNaAvKZESAv/5Gy7ln INeGftEhMo7JZlfzem7IBpMDorCWwQMbf6kkdygUN62DQiW33tgpE4fkCw/IsBMZyMky ObZmE1nyOqXPWI5C1xQ+IKi6rX8jCU3Ih0wvslZ+bENSY/EFy678bHtiabZrTGfA/K0V 1+oISouv8n1xkqE0uVSopVVRyo4nyF6cVz3FxVi84Iad5XYPS3pmI9XRAE/U+o4X0HvC 298g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q4CncrEx; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si182707otk.126.2020.02.10.05.05.01; Mon, 10 Feb 2020 05:05:14 -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=q4CncrEx; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729856AbgBJNDp (ORCPT + 99 others); Mon, 10 Feb 2020 08:03:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:40240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729711AbgBJMkV (ORCPT ); Mon, 10 Feb 2020 07:40:21 -0500 Received: from localhost (unknown [209.37.97.194]) (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 CDFA821739; Mon, 10 Feb 2020 12:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581338420; bh=8ZdGH4cViKER73J86CwWEW5+ohT/R9M7TtH64Uwyo78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q4CncrExImbTniJ1PXkEJFrLQaGDMa8YxtOa4QyaFC0brQ/Inw3sOc66P/jxc8C4I NrGZbyAvxyM6rwWpEI7F0G7+22Tfrvv/KO5pgGifYjqyZADF5tVhB2AJtqmasM6dYc ZekzxeXsniAFBB+VYH9tCY74ttax6W2oi6GpsjEA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chen-Yu Tsai , Christoph Hellwig , Russell King , Robin Murphy , Andrew Morton , Linus Torvalds Subject: [PATCH 5.5 139/367] ARM: dma-api: fix max_pfn off-by-one error in __dma_supported() Date: Mon, 10 Feb 2020 04:30:52 -0800 Message-Id: <20200210122437.679718067@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200210122423.695146547@linuxfoundation.org> References: <20200210122423.695146547@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 commit f3cc4e1d44a813a0685f2e558b78ace3db559722 upstream. 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. Link: http://lkml.kernel.org/r/20191224030239.5656-1-wens@kernel.org 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") Signed-off-by: Chen-Yu Tsai Reviewed-by: Christoph Hellwig Cc: Russell King Cc: Robin Murphy Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/arm/mm/dma-mapping.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- 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