Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1143447pxv; Fri, 16 Jul 2021 02:37:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZlQuKVoO/ov/wCq66yMETNfUDgWNIrI/8KtQUnyfCgLax4ztsIvS0AqjanrkEzIV9BwOV X-Received: by 2002:a17:906:aaca:: with SMTP id kt10mr10827188ejb.127.1626428242485; Fri, 16 Jul 2021 02:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626428242; cv=none; d=google.com; s=arc-20160816; b=YInU1hotT6fcRd/ugBo/Nmb96u0+a7WtZ5XSfNi2tfToCCSsnfFSuJMKjqxYHU2IBv JEb8LUD3HjaHpK9cf0bS25fiIvaqsAyTE7cmYdSNpyx48gkgwUIdCIvgVV41E64IyF3L Tib3T9AqlnKL2puJAbhXBxFsp779dzkJr06cbYOcSUE/Q4RkGtHPTReWc1eoyLhv/oVD +3CAhLGy4byAJIgiCiquJlXrAE8WovG0Be2qDwFTZJUSziaBaQA8HQRC2Yw9B8i1KWmV fJVdhVfbigd7JGf4g3B7KVsUo39diwCOHvAl9LlrMXwTy2uqWiM/SXtwwAOqnc6mqdtG IbpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=qIefwmN2SgBb06ZnIfBEapzCL18du9l7qwSFKhfJ1pY=; b=llAxGiLW2LpEo9vwjKu2Yj3GJrWZ0BZQDIRuvSL3EpNDlT+IVVn9cIcyef+xzsAP3g T/GEj+0iVqld2NilT3rVS6zSxfX3dP0pX8ztXGYIa7lF+IxwKi1EIo5Ib1rMGKKaicRj H3wisAsc3x6WfEMh6H/3x7z5JPNLQJAODE8AMefJQH9mQxVQAlZbQcWaJIBjMreC+Oon Amw0hd98j8pfU5CTKbCVAxzGOb+nWg51+xSlfJObU39o56RVK4LTInZI4of55QBbsP4b CyL9uSyjHOudJZAI6zWsxJxN0yzyOnolbQhtABF0ktMreYzMtPsRCNk1zjxIrmPWCsi6 NbQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b21si10115409edw.395.2021.07.16.02.36.56; Fri, 16 Jul 2021 02:37:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbhGPJiv (ORCPT + 99 others); Fri, 16 Jul 2021 05:38:51 -0400 Received: from verein.lst.de ([213.95.11.211]:42582 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229833AbhGPJiu (ORCPT ); Fri, 16 Jul 2021 05:38:50 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 2D76067373; Fri, 16 Jul 2021 11:35:52 +0200 (CEST) Date: Fri, 16 Jul 2021 11:35:51 +0200 From: Christoph Hellwig To: Roman Skakun Cc: Christoph Hellwig , Boris Ostrovsky , Konrad Rzeszutek Wilk , Juergen Gross , Stefano Stabellini , xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Oleksandr Tyshchenko , Oleksandr Andrushchenko , Volodymyr Babchuk , Andrii Anisov , Roman Skakun Subject: Re: [PATCH v2] dma-mapping: use vmalloc_to_page for vmalloc addresses Message-ID: <20210716093551.GA17981@lst.de> References: <20210715170011.GA17324@lst.de> <20210716083934.154992-1-rm.skakun@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210716083934.154992-1-rm.skakun@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Technically this looks good. But given that exposing a helper that does either vmalloc_to_page or virt_to_page is one of the never ending MM discussions I don't want to get into that discussion and just keep it local in the DMA code. Are you fine with me applying this version? --- From 40ac971eab89330d6153e7721e88acd2d98833f9 Mon Sep 17 00:00:00 2001 From: Roman Skakun Date: Fri, 16 Jul 2021 11:39:34 +0300 Subject: dma-mapping: handle vmalloc addresses in dma_common_{mmap,get_sgtable} xen-swiotlb can use vmalloc backed addresses for dma coherent allocations and uses the common helpers. Properly handle them to unbreak Xen on ARM platforms. Fixes: 1b65c4e5a9af ("swiotlb-xen: use xen_alloc/free_coherent_pages") Signed-off-by: Roman Skakun Reviewed-by: Andrii Anisov [hch: split the patch, renamed the helpers] Signed-off-by: Christoph Hellwig --- kernel/dma/ops_helpers.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/dma/ops_helpers.c b/kernel/dma/ops_helpers.c index 910ae69cae77..af4a6ef48ce0 100644 --- a/kernel/dma/ops_helpers.c +++ b/kernel/dma/ops_helpers.c @@ -5,6 +5,13 @@ */ #include +static struct page *dma_common_vaddr_to_page(void *cpu_addr) +{ + if (is_vmalloc_addr(cpu_addr)) + return vmalloc_to_page(cpu_addr); + return virt_to_page(cpu_addr); +} + /* * Create scatter-list for the already allocated DMA buffer. */ @@ -12,7 +19,7 @@ int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, void *cpu_addr, dma_addr_t dma_addr, size_t size, unsigned long attrs) { - struct page *page = virt_to_page(cpu_addr); + struct page *page = dma_common_vaddr_to_page(cpu_addr); int ret; ret = sg_alloc_table(sgt, 1, GFP_KERNEL); @@ -32,6 +39,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, unsigned long user_count = vma_pages(vma); unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; unsigned long off = vma->vm_pgoff; + struct page *page = dma_common_vaddr_to_page(cpu_addr); int ret = -ENXIO; vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); @@ -43,7 +51,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, return -ENXIO; return remap_pfn_range(vma, vma->vm_start, - page_to_pfn(virt_to_page(cpu_addr)) + vma->vm_pgoff, + page_to_pfn(page) + vma->vm_pgoff, user_count << PAGE_SHIFT, vma->vm_page_prot); #else return -ENXIO; -- 2.30.2