Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5987008ybe; Tue, 10 Sep 2019 11:46:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrbiGJp3KkdboFR/Lv8Xjr7IwPKN8B+Yf5UmuUaauIo5/2XpdNhMRPrf+eoe5oyhnc+1ZP X-Received: by 2002:aa7:c542:: with SMTP id s2mr32743007edr.32.1568141218086; Tue, 10 Sep 2019 11:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568141218; cv=none; d=google.com; s=arc-20160816; b=wEOR8cR6v3lsNYwUzqEdQ1uGbREhctIBR/Jl387XY1WsbkebkRVh61Rrdohu7EvQtX P99e122wuMbevPAnyhpoITMEY5YxEhakW6RVgA3YJMCuKVqbMs1DABruZYt6bT1E110z Kqr1arhYcGMbWGqDpTWp3sLfEcpvv46uMQGbzx57A1MDUggVtHThrYVwIC/im4KpbZZ0 eAj6YnWuXK45Etwu+H7mDreEHM4tUZVHM4VEZFIaXUHeL+t7i23942g7BPUxf2/Odo1S 801XBFtAyoJlw8VW3UYOvrAiHexpB3xaboAV3iwCgRus5IzjF5sf/OAm4xjnxWE9n85P KqQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=11BU75FNhOET4lxxKYP41cErHn44YoXwNHE5ja5Br8M=; b=inTg6mKm9PwC/orYnhFn9oHF56/IPSimQA1Nm3pBBsUHexPpyBrTfJiFC7fN265I/2 S33AHyBC486tN4Uvgou5KPb61lKeeGiI//zsIyYa8Y16ocyIupYHfB6mw+AJvLcFhpci 7rBkoMsl2tWX2RpQehV2JsQkUwtv5RqvhBYvEFOcbAGRJzryc+aJvbzRsBHnZlxvNa4e qMHoMx4ciYjLl6cpd15LSHytRCB6k+VU+yCMctsB7iA9X7fmxLeUankbTLFJlZrO2OWJ MnMok1bPv57QDVGgbyfypgjaM3HoN7yzuIG8HGEOlBqx+uBKMCLIUYpdT9OC487bdHw/ Wb1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ICKCzJ/t"; 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 s18si8083287ejb.49.2019.09.10.11.46.33; Tue, 10 Sep 2019 11:46:58 -0700 (PDT) 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="ICKCzJ/t"; 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 S2390460AbfIJASe (ORCPT + 99 others); Mon, 9 Sep 2019 20:18:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:42672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbfIJASe (ORCPT ); Mon, 9 Sep 2019 20:18:34 -0400 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (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 993D421924; Tue, 10 Sep 2019 00:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568074713; bh=dKUKP3JPu7hVaTGP/S7YYTxBafVoENZ0MqGtavG/XfE=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=ICKCzJ/tQcgzvr4AuWWrSSWAMgo/0zHUMkF/TlGCj70+2xzfS3uf/i3xzDUbh8xmQ 1Z6ktOKxbMzN89BMGZl+7e6Jg3qHxS/ZguCel7w3EqnaqShpDKLeJnt3o/I8SLqYfH gqdTVOzVv1KrLeujtImQbq/9LKuweVBSM8lx0hkw= Date: Mon, 9 Sep 2019 17:18:32 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-T480s To: Christoph Hellwig cc: Stefano Stabellini , Konrad Rzeszutek Wilk , gross@suse.com, boris.ostrovsky@oracle.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, xen-devel@lists.xenproject.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 02/11] xen/arm: consolidate page-coherent.h In-Reply-To: <20190905113408.3104-3-hch@lst.de> Message-ID: References: <20190905113408.3104-1-hch@lst.de> <20190905113408.3104-3-hch@lst.de> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 5 Sep 2019, Christoph Hellwig wrote: > Shared the duplicate arm/arm64 code in include/xen/arm/page-coherent.h. > > Signed-off-by: Christoph Hellwig Reviewed-by: Stefano Stabellini > --- > arch/arm/include/asm/xen/page-coherent.h | 75 -------------------- > arch/arm64/include/asm/xen/page-coherent.h | 75 -------------------- > include/xen/arm/page-coherent.h | 80 ++++++++++++++++++++++ > 3 files changed, 80 insertions(+), 150 deletions(-) > > diff --git a/arch/arm/include/asm/xen/page-coherent.h b/arch/arm/include/asm/xen/page-coherent.h > index 602ac02f154c..27e984977402 100644 > --- a/arch/arm/include/asm/xen/page-coherent.h > +++ b/arch/arm/include/asm/xen/page-coherent.h > @@ -1,77 +1,2 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > -#ifndef _ASM_ARM_XEN_PAGE_COHERENT_H > -#define _ASM_ARM_XEN_PAGE_COHERENT_H > - > -#include > -#include > #include > - > -static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size, > - dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) > -{ > - return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs); > -} > - > -static inline void xen_free_coherent_pages(struct device *hwdev, size_t size, > - void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs) > -{ > - dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs); > -} > - > -static inline void xen_dma_sync_single_for_cpu(struct device *hwdev, > - dma_addr_t handle, size_t size, enum dma_data_direction dir) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - > - if (pfn_valid(pfn)) > - dma_direct_sync_single_for_cpu(hwdev, handle, size, dir); > - else > - __xen_dma_sync_single_for_cpu(hwdev, handle, size, dir); > -} > - > -static inline void xen_dma_sync_single_for_device(struct device *hwdev, > - dma_addr_t handle, size_t size, enum dma_data_direction dir) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - if (pfn_valid(pfn)) > - dma_direct_sync_single_for_device(hwdev, handle, size, dir); > - else > - __xen_dma_sync_single_for_device(hwdev, handle, size, dir); > -} > - > -static inline void xen_dma_map_page(struct device *hwdev, struct page *page, > - dma_addr_t dev_addr, unsigned long offset, size_t size, > - enum dma_data_direction dir, unsigned long attrs) > -{ > - unsigned long page_pfn = page_to_xen_pfn(page); > - unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr); > - unsigned long compound_pages = > - (1< - bool local = (page_pfn <= dev_pfn) && > - (dev_pfn - page_pfn < compound_pages); > - > - if (local) > - dma_direct_map_page(hwdev, page, offset, size, dir, attrs); > - else > - __xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs); > -} > - > -static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, > - size_t size, enum dma_data_direction dir, unsigned long attrs) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - /* > - * Dom0 is mapped 1:1, while the Linux page can be spanned accross > - * multiple Xen page, it's not possible to have a mix of local and > - * foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a > - * foreign mfn will always return false. If the page is local we can > - * safely call the native dma_ops function, otherwise we call the xen > - * specific function. > - */ > - if (pfn_valid(pfn)) > - dma_direct_unmap_page(hwdev, handle, size, dir, attrs); > - else > - __xen_dma_unmap_page(hwdev, handle, size, dir, attrs); > -} > - > -#endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */ > diff --git a/arch/arm64/include/asm/xen/page-coherent.h b/arch/arm64/include/asm/xen/page-coherent.h > index d88e56b90b93..27e984977402 100644 > --- a/arch/arm64/include/asm/xen/page-coherent.h > +++ b/arch/arm64/include/asm/xen/page-coherent.h > @@ -1,77 +1,2 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > -#ifndef _ASM_ARM64_XEN_PAGE_COHERENT_H > -#define _ASM_ARM64_XEN_PAGE_COHERENT_H > - > -#include > -#include > #include > - > -static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size, > - dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) > -{ > - return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs); > -} > - > -static inline void xen_free_coherent_pages(struct device *hwdev, size_t size, > - void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs) > -{ > - dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs); > -} > - > -static inline void xen_dma_sync_single_for_cpu(struct device *hwdev, > - dma_addr_t handle, size_t size, enum dma_data_direction dir) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - > - if (pfn_valid(pfn)) > - dma_direct_sync_single_for_cpu(hwdev, handle, size, dir); > - else > - __xen_dma_sync_single_for_cpu(hwdev, handle, size, dir); > -} > - > -static inline void xen_dma_sync_single_for_device(struct device *hwdev, > - dma_addr_t handle, size_t size, enum dma_data_direction dir) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - if (pfn_valid(pfn)) > - dma_direct_sync_single_for_device(hwdev, handle, size, dir); > - else > - __xen_dma_sync_single_for_device(hwdev, handle, size, dir); > -} > - > -static inline void xen_dma_map_page(struct device *hwdev, struct page *page, > - dma_addr_t dev_addr, unsigned long offset, size_t size, > - enum dma_data_direction dir, unsigned long attrs) > -{ > - unsigned long page_pfn = page_to_xen_pfn(page); > - unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr); > - unsigned long compound_pages = > - (1< - bool local = (page_pfn <= dev_pfn) && > - (dev_pfn - page_pfn < compound_pages); > - > - if (local) > - dma_direct_map_page(hwdev, page, offset, size, dir, attrs); > - else > - __xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs); > -} > - > -static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, > - size_t size, enum dma_data_direction dir, unsigned long attrs) > -{ > - unsigned long pfn = PFN_DOWN(handle); > - /* > - * Dom0 is mapped 1:1, while the Linux page can be spanned accross > - * multiple Xen page, it's not possible to have a mix of local and > - * foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a > - * foreign mfn will always return false. If the page is local we can > - * safely call the native dma_ops function, otherwise we call the xen > - * specific function. > - */ > - if (pfn_valid(pfn)) > - dma_direct_unmap_page(hwdev, handle, size, dir, attrs); > - else > - __xen_dma_unmap_page(hwdev, handle, size, dir, attrs); > -} > - > -#endif /* _ASM_ARM64_XEN_PAGE_COHERENT_H */ > diff --git a/include/xen/arm/page-coherent.h b/include/xen/arm/page-coherent.h > index 2ca9164a79bf..a840d6949a87 100644 > --- a/include/xen/arm/page-coherent.h > +++ b/include/xen/arm/page-coherent.h > @@ -2,6 +2,9 @@ > #ifndef _XEN_ARM_PAGE_COHERENT_H > #define _XEN_ARM_PAGE_COHERENT_H > > +#include > +#include > + > void __xen_dma_map_page(struct device *hwdev, struct page *page, > dma_addr_t dev_addr, unsigned long offset, size_t size, > enum dma_data_direction dir, unsigned long attrs); > @@ -13,4 +16,81 @@ void __xen_dma_sync_single_for_cpu(struct device *hwdev, > void __xen_dma_sync_single_for_device(struct device *hwdev, > dma_addr_t handle, size_t size, enum dma_data_direction dir); > > +static inline void *xen_alloc_coherent_pages(struct device *hwdev, size_t size, > + dma_addr_t *dma_handle, gfp_t flags, unsigned long attrs) > +{ > + return dma_direct_alloc(hwdev, size, dma_handle, flags, attrs); > +} > + > +static inline void xen_free_coherent_pages(struct device *hwdev, size_t size, > + void *cpu_addr, dma_addr_t dma_handle, unsigned long attrs) > +{ > + dma_direct_free(hwdev, size, cpu_addr, dma_handle, attrs); > +} > + > +static inline void xen_dma_sync_single_for_cpu(struct device *hwdev, > + dma_addr_t handle, size_t size, enum dma_data_direction dir) > +{ > + unsigned long pfn = PFN_DOWN(handle); > + > + if (pfn_valid(pfn)) > + dma_direct_sync_single_for_cpu(hwdev, handle, size, dir); > + else > + __xen_dma_sync_single_for_cpu(hwdev, handle, size, dir); > +} > + > +static inline void xen_dma_sync_single_for_device(struct device *hwdev, > + dma_addr_t handle, size_t size, enum dma_data_direction dir) > +{ > + unsigned long pfn = PFN_DOWN(handle); > + if (pfn_valid(pfn)) > + dma_direct_sync_single_for_device(hwdev, handle, size, dir); > + else > + __xen_dma_sync_single_for_device(hwdev, handle, size, dir); > +} > + > +static inline void xen_dma_map_page(struct device *hwdev, struct page *page, > + dma_addr_t dev_addr, unsigned long offset, size_t size, > + enum dma_data_direction dir, unsigned long attrs) > +{ > + unsigned long page_pfn = page_to_xen_pfn(page); > + unsigned long dev_pfn = XEN_PFN_DOWN(dev_addr); > + unsigned long compound_pages = > + (1< + bool local = (page_pfn <= dev_pfn) && > + (dev_pfn - page_pfn < compound_pages); > + > + /* > + * Dom0 is mapped 1:1, while the Linux page can span across > + * multiple Xen pages, it's not possible for it to contain a > + * mix of local and foreign Xen pages. So if the first xen_pfn > + * == mfn the page is local otherwise it's a foreign page > + * grant-mapped in dom0. If the page is local we can safely > + * call the native dma_ops function, otherwise we call the xen > + * specific function. > + */ > + if (local) > + dma_direct_map_page(hwdev, page, offset, size, dir, attrs); > + else > + __xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs); > +} > + > +static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, > + size_t size, enum dma_data_direction dir, unsigned long attrs) > +{ > + unsigned long pfn = PFN_DOWN(handle); > + /* > + * Dom0 is mapped 1:1, while the Linux page can be spanned accross > + * multiple Xen page, it's not possible to have a mix of local and > + * foreign Xen page. Dom0 is mapped 1:1, so calling pfn_valid on a > + * foreign mfn will always return false. If the page is local we can > + * safely call the native dma_ops function, otherwise we call the xen > + * specific function. > + */ > + if (pfn_valid(pfn)) > + dma_direct_unmap_page(hwdev, handle, size, dir, attrs); > + else > + __xen_dma_unmap_page(hwdev, handle, size, dir, attrs); > +} > + > #endif /* _XEN_ARM_PAGE_COHERENT_H */ > -- > 2.20.1 >