Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp5985260ybe; Tue, 10 Sep 2019 11:45:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRP18R30uyhbCIHOney6UDcw0N5ktbjbo7oeigGT9GKSG3xUeWPnWT8yNofDb5LZrb0lDa X-Received: by 2002:a17:906:5813:: with SMTP id m19mr5801501ejq.246.1568141119325; Tue, 10 Sep 2019 11:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568141119; cv=none; d=google.com; s=arc-20160816; b=NBwr43KiXLYYT4Y/Vx/oP1on2oc+ruJEIPN3zqzrPf1ymA2TjaE2QdjRZ8F/QsJw+9 Kv1bBIzbcXqKr4ulSQoSfy6UwhKCDgk9Kb0tsgFfQG7Hki5/dHoKIfdEt+cC+ntYQNic GW9iUsRb1aGaOXnEfo1UAPyoNe8at8ClYX3jnVPmvvns7z1okYWwsR3GscBnym4evUOL YoM0LItMUMxKqRXKxWctByo630E6lY4iYaos1KP9wgEybUEJxU0+6GlXYT+kUIvBaCLi whuZ178bqPtWtXMIyTTtdkJST1SGS8QAj6Es+WDEm4QgROdx+1et4Wer6ouSbp2iK6ZF 4u3g== 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=KbvLiV4lWEy4bdeM67PIPh90TfqErKpdV0b2wi3tmZI=; b=0MaQa393vqtR0pU+M/JQmxCaWaXf29zLEq88cZwOx/jG0Xm3JryCBw+MWr71hOgrMq JeJ34jzP8rb+1MLcWPDRHNBMI1lYZ8Wzd8uPRK+DlQK1Xh0BP1w9QgaM6tE9+ACArhWS O0DsR5E5kmps1FmnbVxJr9BofcN1WHzCjVupczzkQbYPFg5t4D2lXkz3PtGikE4nX9gE I+jsz2U5r9sROKcO0R4VLjrHjwExTNtJZzNbzBOaiILb8OWK9XZWQc82MjzPvAqPMcVP gBE06G0+ORGrPBGspdmeZzJO8F3zBaj+elTlm287ZYa4B7Pkx9bcdfPqCTC5On1h2mqS 9kbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jDdg6bjk; 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 w11si1839009edi.442.2019.09.10.11.44.55; Tue, 10 Sep 2019 11:45:19 -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=jDdg6bjk; 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 S1732218AbfIJASb (ORCPT + 99 others); Mon, 9 Sep 2019 20:18:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:42604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727351AbfIJASa (ORCPT ); Mon, 9 Sep 2019 20:18:30 -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 C351C21670; Tue, 10 Sep 2019 00:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1568074709; bh=YgqPgucJuky5FcSp0vrxNvRL/Fngfl3HUuoywRnLxy0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=jDdg6bjkfqRkN2qiY8xoU/nMdM+W40s+tBS17TmDrDcR3MECdp1nBG0NCqvoH4YvV BhBFaNaLjghh08U+HyVFYhOT2bdGVC30dg4Fe3ALVyp/kGUA3+wG2mX1tAtaVHNUem LmajRzth9Ln8b9KkbWlaJjYNjxw9p2XvDczARe2k= Date: Mon, 9 Sep 2019 17:18:27 -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 01/11] xen/arm: use dma-noncoherent.h calls for xen-swiotlb cache maintainance In-Reply-To: <20190905113408.3104-2-hch@lst.de> Message-ID: References: <20190905113408.3104-1-hch@lst.de> <20190905113408.3104-2-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: > Copy the arm64 code that uses the dma-direct/swiotlb helpers for DMA > on-coherent devices. > > Signed-off-by: Christoph Hellwig This is much better and much more readable. Reviewed-by: Stefano Stabellini > --- > arch/arm/include/asm/device.h | 3 - > arch/arm/include/asm/xen/page-coherent.h | 72 +++++++++--------------- > arch/arm/mm/dma-mapping.c | 8 +-- > drivers/xen/swiotlb-xen.c | 20 ------- > 4 files changed, 28 insertions(+), 75 deletions(-) > > diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h > index f6955b55c544..c675bc0d5aa8 100644 > --- a/arch/arm/include/asm/device.h > +++ b/arch/arm/include/asm/device.h > @@ -14,9 +14,6 @@ struct dev_archdata { > #endif > #ifdef CONFIG_ARM_DMA_USE_IOMMU > struct dma_iommu_mapping *mapping; > -#endif > -#ifdef CONFIG_XEN > - const struct dma_map_ops *dev_dma_ops; > #endif > unsigned int dma_coherent:1; > unsigned int dma_ops_setup:1; > diff --git a/arch/arm/include/asm/xen/page-coherent.h b/arch/arm/include/asm/xen/page-coherent.h > index 2c403e7c782d..602ac02f154c 100644 > --- a/arch/arm/include/asm/xen/page-coherent.h > +++ b/arch/arm/include/asm/xen/page-coherent.h > @@ -6,23 +6,37 @@ > #include > #include > > -static inline const struct dma_map_ops *xen_get_dma_ops(struct device *dev) > -{ > - if (dev && dev->archdata.dev_dma_ops) > - return dev->archdata.dev_dma_ops; > - return get_arch_dma_ops(NULL); > -} > - > 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 xen_get_dma_ops(hwdev)->alloc(hwdev, size, dma_handle, flags, 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) > { > - xen_get_dma_ops(hwdev)->free(hwdev, size, cpu_addr, dma_handle, 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, > @@ -36,17 +50,8 @@ static inline void xen_dma_map_page(struct device *hwdev, struct page *page, > 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) > - xen_get_dma_ops(hwdev)->map_page(hwdev, page, offset, size, dir, attrs); > + dma_direct_map_page(hwdev, page, offset, size, dir, attrs); > else > __xen_dma_map_page(hwdev, page, dev_addr, offset, size, dir, attrs); > } > @@ -63,33 +68,10 @@ static inline void xen_dma_unmap_page(struct device *hwdev, dma_addr_t handle, > * safely call the native dma_ops function, otherwise we call the xen > * specific function. > */ > - if (pfn_valid(pfn)) { > - if (xen_get_dma_ops(hwdev)->unmap_page) > - xen_get_dma_ops(hwdev)->unmap_page(hwdev, handle, size, dir, attrs); > - } else > + if (pfn_valid(pfn)) > + dma_direct_unmap_page(hwdev, handle, size, dir, attrs); > + else > __xen_dma_unmap_page(hwdev, handle, size, dir, 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)) { > - if (xen_get_dma_ops(hwdev)->sync_single_for_cpu) > - xen_get_dma_ops(hwdev)->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)) { > - if (xen_get_dma_ops(hwdev)->sync_single_for_device) > - xen_get_dma_ops(hwdev)->sync_single_for_device(hwdev, handle, size, dir); > - } else > - __xen_dma_sync_single_for_device(hwdev, handle, size, dir); > -} > - > #endif /* _ASM_ARM_XEN_PAGE_COHERENT_H */ > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c > index d42557ee69c2..738097396445 100644 > --- a/arch/arm/mm/dma-mapping.c > +++ b/arch/arm/mm/dma-mapping.c > @@ -1132,10 +1132,6 @@ static const struct dma_map_ops *arm_get_dma_map_ops(bool coherent) > * 32-bit DMA. > * Use the generic dma-direct / swiotlb ops code in that case, as that > * handles bounce buffering for us. > - * > - * Note: this checks CONFIG_ARM_LPAE instead of CONFIG_SWIOTLB as the > - * latter is also selected by the Xen code, but that code for now relies > - * on non-NULL dev_dma_ops. To be cleaned up later. > */ > if (IS_ENABLED(CONFIG_ARM_LPAE)) > return NULL; > @@ -2363,10 +2359,8 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, > set_dma_ops(dev, dma_ops); > > #ifdef CONFIG_XEN > - if (xen_initial_domain()) { > - dev->archdata.dev_dma_ops = dev->dma_ops; > + if (xen_initial_domain()) > dev->dma_ops = xen_dma_ops; > - } > #endif > dev->archdata.dma_ops_setup = true; > } > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index ae1df496bf38..eee86cc7046b 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -557,11 +557,6 @@ xen_swiotlb_dma_mmap(struct device *dev, struct vm_area_struct *vma, > void *cpu_addr, dma_addr_t dma_addr, size_t size, > unsigned long attrs) > { > -#ifdef CONFIG_ARM > - if (xen_get_dma_ops(dev)->mmap) > - return xen_get_dma_ops(dev)->mmap(dev, vma, cpu_addr, > - dma_addr, size, attrs); > -#endif > return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size, attrs); > } > > @@ -574,21 +569,6 @@ xen_swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, > void *cpu_addr, dma_addr_t handle, size_t size, > unsigned long attrs) > { > -#ifdef CONFIG_ARM > - if (xen_get_dma_ops(dev)->get_sgtable) { > -#if 0 > - /* > - * This check verifies that the page belongs to the current domain and > - * is not one mapped from another domain. > - * This check is for debug only, and should not go to production build > - */ > - unsigned long bfn = PHYS_PFN(dma_to_phys(dev, handle)); > - BUG_ON (!page_is_ram(bfn)); > -#endif > - return xen_get_dma_ops(dev)->get_sgtable(dev, sgt, cpu_addr, > - handle, size, attrs); > - } > -#endif > return dma_common_get_sgtable(dev, sgt, cpu_addr, handle, size, attrs); > } > > -- > 2.20.1 >