Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17929734ybl; Thu, 2 Jan 2020 15:02:03 -0800 (PST) X-Google-Smtp-Source: APXvYqy0bOnT7g4f6FCgC3/JOnvfT93MTqioUHXKrqik6j3LExOQYI9iuQp1WeTERtdhMeSg5Cvm X-Received: by 2002:a05:6830:114f:: with SMTP id x15mr91893290otq.291.1578006123754; Thu, 02 Jan 2020 15:02:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578006123; cv=none; d=google.com; s=arc-20160816; b=Mg7r97AlsD688BHyM4itcfLY9PaRp3WGMBvDN27cderSsLuUFRPWBC+jEwAkjsEhZ4 UhV10eO62db026XyhL6HDUmUM9mEa0PWX1EbsGHjVyPBTiVdTPxF4GHLk2BAB5Tj2Imj Xc83vb11dArWj88vJgijjI1R8Xg7FRvLO3bl512ajBBM45am2nvnEGEiio4W/jcHeZAF zO/ghXOI8sm9jTviKEK/EXlbZTyuvHB8zSDiTJaFsgI5Dt9iPmKFvHnIy5vk3M6NbYUH EZACQ01cVDkwDTcMcYPuAaMR/ldEIrXtfgj6bN5urUL20BEePV1BfOpe8Pwyce8mcQIF ZCNw== 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=6Qxd2eDKHY+j8VW6LiOA7jJuX6AJYftrxSJxGdjGxBU=; b=ClQxF2mZI/gg7FchkmSmUUInWxqWkSVQbtjrqYd4KR8/czmuO8BAZq657ZYQU43Bki 5D7X4TI1r5YhGFLK6h5zPa2/ULPNzXtCQl5cd9/3RqXeAhQnLHgHP6nQ/nS/yY9CD2de dlaDNGrQrs/kvHf9zeVYreHm9Qi7gusoZ/FVcnlxZYYFqofE0E4/53zBB2rneCTyzjbE +RlCGvboeBOjiqsKwq9q2sN3u0KkSMz+DdQmtohqEn+VdRqpC+QYcovV1+Qxx9GuFx4r G8Z9WMceSGV2cDo8OXZ+5MekeuFkNuhY8MoXpy38K435jq/U61vTWRhs2zoEnGsi2Kfp gAcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JkwOrmEz; 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 p22si29846023ota.43.2020.01.02.15.01.52; Thu, 02 Jan 2020 15:02:03 -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=JkwOrmEz; 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 S1727188AbgABWMx (ORCPT + 99 others); Thu, 2 Jan 2020 17:12:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:52264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727564AbgABWMv (ORCPT ); Thu, 2 Jan 2020 17:12:51 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 C3CD022314; Thu, 2 Jan 2020 22:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003170; bh=wxDmdhcUnbBX2CZ0XmoLV4M6pajezQlYetqQyaL8R+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkwOrmEz5BA5zCIi+kh6LPvXY7V0rZbd9B6USlyEkOYXic3Qu9898S2aSCfbamDfq c/4pDzK6FC3YrI1CyCsDGV821RJlhVdsVbVvcKrIZssS4Hfzt12rEEpZnRP51ypgTy JoqcrDKV7hvyrgD7Tp5bkRVABNB+VKuBacGekkk0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniele Alessandrelli , Alexandre Torgue , Vladimir Murzin , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.4 031/191] dma-mapping: fix handling of dma-ranges for reserved memory (again) Date: Thu, 2 Jan 2020 23:05:13 +0100 Message-Id: <20200102215833.327867167@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@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: Vladimir Murzin [ Upstream commit a445e940ea686fc60475564009821010eb213be3 ] Daniele reported that issue previously fixed in c41f9ea998f3 ("drivers: dma-coherent: Account dma_pfn_offset when used with device tree") reappear shortly after 43fc509c3efb ("dma-coherent: introduce interface for default DMA pool") where fix was accidentally dropped. Lets put fix back in place and respect dma-ranges for reserved memory. Fixes: 43fc509c3efb ("dma-coherent: introduce interface for default DMA pool") Reported-by: Daniele Alessandrelli Tested-by: Daniele Alessandrelli Tested-by: Alexandre Torgue Signed-off-by: Vladimir Murzin Signed-off-by: Christoph Hellwig Signed-off-by: Sasha Levin --- arch/arm/mm/dma-mapping-nommu.c | 2 +- include/linux/dma-mapping.h | 4 ++-- kernel/dma/coherent.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c index db9247898300..287ef898a55e 100644 --- a/arch/arm/mm/dma-mapping-nommu.c +++ b/arch/arm/mm/dma-mapping-nommu.c @@ -35,7 +35,7 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size, unsigned long attrs) { - void *ret = dma_alloc_from_global_coherent(size, dma_handle); + void *ret = dma_alloc_from_global_coherent(dev, size, dma_handle); /* * dma_alloc_from_global_coherent() may fail because: diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 0aad641d662c..4d450672b7d6 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -162,7 +162,7 @@ int dma_release_from_dev_coherent(struct device *dev, int order, void *vaddr); int dma_mmap_from_dev_coherent(struct device *dev, struct vm_area_struct *vma, void *cpu_addr, size_t size, int *ret); -void *dma_alloc_from_global_coherent(ssize_t size, dma_addr_t *dma_handle); +void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size, dma_addr_t *dma_handle); int dma_release_from_global_coherent(int order, void *vaddr); int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr, size_t size, int *ret); @@ -172,7 +172,7 @@ int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr, #define dma_release_from_dev_coherent(dev, order, vaddr) (0) #define dma_mmap_from_dev_coherent(dev, vma, vaddr, order, ret) (0) -static inline void *dma_alloc_from_global_coherent(ssize_t size, +static inline void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size, dma_addr_t *dma_handle) { return NULL; diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index 545e3869b0e3..551b0eb7028a 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -123,8 +123,9 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr, return ret; } -static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem, - ssize_t size, dma_addr_t *dma_handle) +static void *__dma_alloc_from_coherent(struct device *dev, + struct dma_coherent_mem *mem, + ssize_t size, dma_addr_t *dma_handle) { int order = get_order(size); unsigned long flags; @@ -143,7 +144,7 @@ static void *__dma_alloc_from_coherent(struct dma_coherent_mem *mem, /* * Memory was found in the coherent area. */ - *dma_handle = mem->device_base + (pageno << PAGE_SHIFT); + *dma_handle = dma_get_device_base(dev, mem) + (pageno << PAGE_SHIFT); ret = mem->virt_base + (pageno << PAGE_SHIFT); spin_unlock_irqrestore(&mem->spinlock, flags); memset(ret, 0, size); @@ -175,17 +176,18 @@ int dma_alloc_from_dev_coherent(struct device *dev, ssize_t size, if (!mem) return 0; - *ret = __dma_alloc_from_coherent(mem, size, dma_handle); + *ret = __dma_alloc_from_coherent(dev, mem, size, dma_handle); return 1; } -void *dma_alloc_from_global_coherent(ssize_t size, dma_addr_t *dma_handle) +void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size, + dma_addr_t *dma_handle) { if (!dma_coherent_default_memory) return NULL; - return __dma_alloc_from_coherent(dma_coherent_default_memory, size, - dma_handle); + return __dma_alloc_from_coherent(dev, dma_coherent_default_memory, size, + dma_handle); } static int __dma_release_from_coherent(struct dma_coherent_mem *mem, -- 2.20.1