* a few xen swiotlb cleanups @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Hi all, below are a couple of cleanups for swiotlb-xen.c. They were done in preparation of eventually using the dma-noncoherent.h cache flushing hooks, but that final goal will need some major work to the arm32 code first. Until then I think these patches might be better in mainline than in my local tree so that they don't bitrot. ^ permalink raw reply [flat|nested] 40+ messages in thread
* [Xen-devel] a few xen swiotlb cleanups @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Hi all, below are a couple of cleanups for swiotlb-xen.c. They were done in preparation of eventually using the dma-noncoherent.h cache flushing hooks, but that final goal will need some major work to the arm32 code first. Until then I think these patches might be better in mainline than in my local tree so that they don't bitrot. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* a few xen swiotlb cleanups @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Hi all, below are a couple of cleanups for swiotlb-xen.c. They were done in preparation of eventually using the dma-noncoherent.h cache flushing hooks, but that final goal will need some major work to the arm32 code first. Until then I think these patches might be better in mainline than in my local tree so that they don't bitrot. _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 1/4] swiotlb-xen: make instances match their method names 2019-04-11 7:19 ` Christoph Hellwig (?) (?) @ 2019-04-11 7:19 ` Christoph Hellwig -1 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Just drop two pointless _attrs prefixes to make the code a little more grep-able. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..d4bc3aabd44d 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, * concerning calls here are the same as for swiotlb_unmap_page() above. */ static void -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, * same here. */ static int -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, /* Don't panic here, we expect map_sg users to do proper error handling. */ attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, - attrs); + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); sg_dma_len(sgl) = 0; return 0; } @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { .sync_single_for_device = xen_swiotlb_sync_single_for_device, .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, - .map_sg = xen_swiotlb_map_sg_attrs, - .unmap_sg = xen_swiotlb_unmap_sg_attrs, + .map_sg = xen_swiotlb_map_sg, + .unmap_sg = xen_swiotlb_unmap_sg, .map_page = xen_swiotlb_map_page, .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
[parent not found: <20190411072000.4306-1-hch-jcswGhMUV9g@public.gmane.org>]
* [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Just drop two pointless _attrs prefixes to make the code a little more grep-able. Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> --- drivers/xen/swiotlb-xen.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..d4bc3aabd44d 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, * concerning calls here are the same as for swiotlb_unmap_page() above. */ static void -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, * same here. */ static int -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, /* Don't panic here, we expect map_sg users to do proper error handling. */ attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, - attrs); + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); sg_dma_len(sgl) = 0; return 0; } @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { .sync_single_for_device = xen_swiotlb_sync_single_for_device, .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, - .map_sg = xen_swiotlb_map_sg_attrs, - .unmap_sg = xen_swiotlb_unmap_sg_attrs, + .map_sg = xen_swiotlb_map_sg, + .unmap_sg = xen_swiotlb_unmap_sg, .map_page = xen_swiotlb_map_page, .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, -- 2.20.1 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [Xen-devel] [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Just drop two pointless _attrs prefixes to make the code a little more grep-able. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..d4bc3aabd44d 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, * concerning calls here are the same as for swiotlb_unmap_page() above. */ static void -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, * same here. */ static int -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, /* Don't panic here, we expect map_sg users to do proper error handling. */ attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, - attrs); + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); sg_dma_len(sgl) = 0; return 0; } @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { .sync_single_for_device = xen_swiotlb_sync_single_for_device, .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, - .map_sg = xen_swiotlb_map_sg_attrs, - .unmap_sg = xen_swiotlb_unmap_sg_attrs, + .map_sg = xen_swiotlb_map_sg, + .unmap_sg = xen_swiotlb_unmap_sg, .map_page = xen_swiotlb_map_page, .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Just drop two pointless _attrs prefixes to make the code a little more grep-able. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 877baf2a94f4..d4bc3aabd44d 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, * concerning calls here are the same as for swiotlb_unmap_page() above. */ static void -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, * same here. */ static int -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - unsigned long attrs) +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, + enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; int i; @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, /* Don't panic here, we expect map_sg users to do proper error handling. */ attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, - attrs); + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); sg_dma_len(sgl) = 0; return 0; } @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { .sync_single_for_device = xen_swiotlb_sync_single_for_device, .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, - .map_sg = xen_swiotlb_map_sg_attrs, - .unmap_sg = xen_swiotlb_unmap_sg_attrs, + .map_sg = xen_swiotlb_map_sg, + .unmap_sg = xen_swiotlb_unmap_sg, .map_page = xen_swiotlb_map_page, .unmap_page = xen_swiotlb_unmap_page, .dma_supported = xen_swiotlb_dma_supported, -- 2.20.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH 1/4] swiotlb-xen: make instances match their method names 2019-04-11 7:19 ` Christoph Hellwig (?) (?) @ 2019-04-15 22:55 ` Stefano Stabellini -1 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Just drop two pointless _attrs prefixes to make the code a little > more grep-able. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 877baf2a94f4..d4bc3aabd44d 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > * concerning calls here are the same as for swiotlb_unmap_page() above. > */ > static void > -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > * same here. > */ > static int > -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > /* Don't panic here, we expect map_sg users > to do proper error handling. */ > attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, > - attrs); > + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > sg_dma_len(sgl) = 0; > return 0; > } > @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { > .sync_single_for_device = xen_swiotlb_sync_single_for_device, > .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, > .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, > - .map_sg = xen_swiotlb_map_sg_attrs, > - .unmap_sg = xen_swiotlb_unmap_sg_attrs, > + .map_sg = xen_swiotlb_map_sg, > + .unmap_sg = xen_swiotlb_unmap_sg, > .map_page = xen_swiotlb_map_page, > .unmap_page = xen_swiotlb_unmap_page, > .dma_supported = xen_swiotlb_dma_supported, > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
[parent not found: <20190411072000.4306-2-hch-jcswGhMUV9g@public.gmane.org>]
* Re: [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Just drop two pointless _attrs prefixes to make the code a little > more grep-able. > > Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> Reviewed-by: Stefano Stabellini <sstabellini-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > --- > drivers/xen/swiotlb-xen.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 877baf2a94f4..d4bc3aabd44d 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > * concerning calls here are the same as for swiotlb_unmap_page() above. > */ > static void > -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > * same here. > */ > static int > -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > /* Don't panic here, we expect map_sg users > to do proper error handling. */ > attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, > - attrs); > + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > sg_dma_len(sgl) = 0; > return 0; > } > @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { > .sync_single_for_device = xen_swiotlb_sync_single_for_device, > .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, > .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, > - .map_sg = xen_swiotlb_map_sg_attrs, > - .unmap_sg = xen_swiotlb_unmap_sg_attrs, > + .map_sg = xen_swiotlb_map_sg, > + .unmap_sg = xen_swiotlb_unmap_sg, > .map_page = xen_swiotlb_map_page, > .unmap_page = xen_swiotlb_unmap_page, > .dma_supported = xen_swiotlb_dma_supported, > -- > 2.20.1 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [Xen-devel] [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Just drop two pointless _attrs prefixes to make the code a little > more grep-able. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 877baf2a94f4..d4bc3aabd44d 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > * concerning calls here are the same as for swiotlb_unmap_page() above. > */ > static void > -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > * same here. > */ > static int > -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > /* Don't panic here, we expect map_sg users > to do proper error handling. */ > attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, > - attrs); > + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > sg_dma_len(sgl) = 0; > return 0; > } > @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { > .sync_single_for_device = xen_swiotlb_sync_single_for_device, > .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, > .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, > - .map_sg = xen_swiotlb_map_sg_attrs, > - .unmap_sg = xen_swiotlb_unmap_sg_attrs, > + .map_sg = xen_swiotlb_map_sg, > + .unmap_sg = xen_swiotlb_unmap_sg, > .map_page = xen_swiotlb_map_page, > .unmap_page = xen_swiotlb_unmap_page, > .dma_supported = xen_swiotlb_dma_supported, > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 1/4] swiotlb-xen: make instances match their method names @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Just drop two pointless _attrs prefixes to make the code a little > more grep-able. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 877baf2a94f4..d4bc3aabd44d 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -504,9 +504,8 @@ xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > * concerning calls here are the same as for swiotlb_unmap_page() above. > */ > static void > -xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -535,9 +534,8 @@ xen_swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > * same here. > */ > static int > -xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - unsigned long attrs) > +xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > + enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > int i; > @@ -562,8 +560,7 @@ xen_swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, > /* Don't panic here, we expect map_sg users > to do proper error handling. */ > attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, > - attrs); > + xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > sg_dma_len(sgl) = 0; > return 0; > } > @@ -690,8 +687,8 @@ const struct dma_map_ops xen_swiotlb_dma_ops = { > .sync_single_for_device = xen_swiotlb_sync_single_for_device, > .sync_sg_for_cpu = xen_swiotlb_sync_sg_for_cpu, > .sync_sg_for_device = xen_swiotlb_sync_sg_for_device, > - .map_sg = xen_swiotlb_map_sg_attrs, > - .unmap_sg = xen_swiotlb_unmap_sg_attrs, > + .map_sg = xen_swiotlb_map_sg, > + .unmap_sg = xen_swiotlb_unmap_sg, > .map_page = xen_swiotlb_map_page, > .unmap_page = xen_swiotlb_unmap_page, > .dma_supported = xen_swiotlb_dma_supported, > -- > 2.20.1 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA We can simply loop over the segments and map them, removing lots of duplicate code. Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> --- drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index d4bc3aabd44d..97a55c225593 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, } -/* - * Map a set of buffers described by scatterlist in streaming mode for DMA. - * This is the scatter-gather version of the above xen_swiotlb_map_page - * interface. Here the scatter gather list elements are each tagged with the - * appropriate dma address and length. They are obtained via - * sg_dma_{address,length}(SG). - * - * NOTE: An implementation may be able to use a smaller number of - * DMA address/length pairs than there are SG table elements. - * (for example via virtual mapping capabilities) - * The routine returns the number of addr/length pairs actually - * used, at most nents. - * - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the - * same here. - */ static int -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, BUG_ON(dir == DMA_NONE); for_each_sg(sgl, sg, nelems, i) { - phys_addr_t paddr = sg_phys(sg); - dma_addr_t dev_addr = xen_phys_to_bus(paddr); - - if (swiotlb_force == SWIOTLB_FORCE || - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || - !dma_capable(hwdev, dev_addr, sg->length) || - range_straddles_page_boundary(paddr, sg->length)) { - phys_addr_t map = swiotlb_tbl_map_single(hwdev, - start_dma_addr, - sg_phys(sg), - sg->length, - dir, attrs); - if (map == DMA_MAPPING_ERROR) { - dev_warn(hwdev, "swiotlb buffer is full\n"); - /* Don't panic here, we expect map_sg users - to do proper error handling. */ - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); - sg_dma_len(sgl) = 0; - return 0; - } - dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, - map & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } else { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), - dev_addr, - paddr & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), + sg->offset, sg->length, dir, attrs); + if (sg->dma_address == DMA_MAPPING_ERROR) + goto out_unmap; sg_dma_len(sg) = sg->length; } + return nelems; +out_unmap: + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); + sg_dma_len(sgl) = 0; + return 0; } /* -- 2.20.1 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [Xen-devel] [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu We can simply loop over the segments and map them, removing lots of duplicate code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index d4bc3aabd44d..97a55c225593 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, } -/* - * Map a set of buffers described by scatterlist in streaming mode for DMA. - * This is the scatter-gather version of the above xen_swiotlb_map_page - * interface. Here the scatter gather list elements are each tagged with the - * appropriate dma address and length. They are obtained via - * sg_dma_{address,length}(SG). - * - * NOTE: An implementation may be able to use a smaller number of - * DMA address/length pairs than there are SG table elements. - * (for example via virtual mapping capabilities) - * The routine returns the number of addr/length pairs actually - * used, at most nents. - * - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the - * same here. - */ static int -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, BUG_ON(dir == DMA_NONE); for_each_sg(sgl, sg, nelems, i) { - phys_addr_t paddr = sg_phys(sg); - dma_addr_t dev_addr = xen_phys_to_bus(paddr); - - if (swiotlb_force == SWIOTLB_FORCE || - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || - !dma_capable(hwdev, dev_addr, sg->length) || - range_straddles_page_boundary(paddr, sg->length)) { - phys_addr_t map = swiotlb_tbl_map_single(hwdev, - start_dma_addr, - sg_phys(sg), - sg->length, - dir, attrs); - if (map == DMA_MAPPING_ERROR) { - dev_warn(hwdev, "swiotlb buffer is full\n"); - /* Don't panic here, we expect map_sg users - to do proper error handling. */ - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); - sg_dma_len(sgl) = 0; - return 0; - } - dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, - map & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } else { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), - dev_addr, - paddr & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), + sg->offset, sg->length, dir, attrs); + if (sg->dma_address == DMA_MAPPING_ERROR) + goto out_unmap; sg_dma_len(sg) = sg->length; } + return nelems; +out_unmap: + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); + sg_dma_len(sgl) = 0; + return 0; } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu We can simply loop over the segments and map them, removing lots of duplicate code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index d4bc3aabd44d..97a55c225593 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, } -/* - * Map a set of buffers described by scatterlist in streaming mode for DMA. - * This is the scatter-gather version of the above xen_swiotlb_map_page - * interface. Here the scatter gather list elements are each tagged with the - * appropriate dma address and length. They are obtained via - * sg_dma_{address,length}(SG). - * - * NOTE: An implementation may be able to use a smaller number of - * DMA address/length pairs than there are SG table elements. - * (for example via virtual mapping capabilities) - * The routine returns the number of addr/length pairs actually - * used, at most nents. - * - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the - * same here. - */ static int -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, BUG_ON(dir == DMA_NONE); for_each_sg(sgl, sg, nelems, i) { - phys_addr_t paddr = sg_phys(sg); - dma_addr_t dev_addr = xen_phys_to_bus(paddr); - - if (swiotlb_force == SWIOTLB_FORCE || - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || - !dma_capable(hwdev, dev_addr, sg->length) || - range_straddles_page_boundary(paddr, sg->length)) { - phys_addr_t map = swiotlb_tbl_map_single(hwdev, - start_dma_addr, - sg_phys(sg), - sg->length, - dir, attrs); - if (map == DMA_MAPPING_ERROR) { - dev_warn(hwdev, "swiotlb buffer is full\n"); - /* Don't panic here, we expect map_sg users - to do proper error handling. */ - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); - sg_dma_len(sgl) = 0; - return 0; - } - dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, - map & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } else { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), - dev_addr, - paddr & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), + sg->offset, sg->length, dir, attrs); + if (sg->dma_address == DMA_MAPPING_ERROR) + goto out_unmap; sg_dma_len(sg) = sg->length; } + return nelems; +out_unmap: + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); + sg_dma_len(sgl) = 0; + return 0; } /* -- 2.20.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply related [flat|nested] 40+ messages in thread
[parent not found: <20190411072000.4306-3-hch-jcswGhMUV9g@public.gmane.org>]
* Re: [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > We can simply loop over the segments and map them, removing lots of > duplicate code. Right, the only difference is the additional dma_capable check which is good to have. Reviewed-by: Stefano Stabellini <sstabellini-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> > --- > drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- > 1 file changed, 10 insertions(+), 58 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index d4bc3aabd44d..97a55c225593 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > > } > > -/* > - * Map a set of buffers described by scatterlist in streaming mode for DMA. > - * This is the scatter-gather version of the above xen_swiotlb_map_page > - * interface. Here the scatter gather list elements are each tagged with the > - * appropriate dma address and length. They are obtained via > - * sg_dma_{address,length}(SG). > - * > - * NOTE: An implementation may be able to use a smaller number of > - * DMA address/length pairs than there are SG table elements. > - * (for example via virtual mapping capabilities) > - * The routine returns the number of addr/length pairs actually > - * used, at most nents. > - * > - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the > - * same here. > - */ > static int > -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > BUG_ON(dir == DMA_NONE); > > for_each_sg(sgl, sg, nelems, i) { > - phys_addr_t paddr = sg_phys(sg); > - dma_addr_t dev_addr = xen_phys_to_bus(paddr); > - > - if (swiotlb_force == SWIOTLB_FORCE || > - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || > - !dma_capable(hwdev, dev_addr, sg->length) || > - range_straddles_page_boundary(paddr, sg->length)) { > - phys_addr_t map = swiotlb_tbl_map_single(hwdev, > - start_dma_addr, > - sg_phys(sg), > - sg->length, > - dir, attrs); > - if (map == DMA_MAPPING_ERROR) { > - dev_warn(hwdev, "swiotlb buffer is full\n"); > - /* Don't panic here, we expect map_sg users > - to do proper error handling. */ > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > - sg_dma_len(sgl) = 0; > - return 0; > - } > - dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, > - map & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } else { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), > - dev_addr, > - paddr & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } > + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), > + sg->offset, sg->length, dir, attrs); > + if (sg->dma_address == DMA_MAPPING_ERROR) > + goto out_unmap; > sg_dma_len(sg) = sg->length; > } > + > return nelems; > +out_unmap: > + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > + sg_dma_len(sgl) = 0; > + return 0; > } > > /* > -- > 2.20.1 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [Xen-devel] [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > We can simply loop over the segments and map them, removing lots of > duplicate code. Right, the only difference is the additional dma_capable check which is good to have. Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- > 1 file changed, 10 insertions(+), 58 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index d4bc3aabd44d..97a55c225593 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > > } > > -/* > - * Map a set of buffers described by scatterlist in streaming mode for DMA. > - * This is the scatter-gather version of the above xen_swiotlb_map_page > - * interface. Here the scatter gather list elements are each tagged with the > - * appropriate dma address and length. They are obtained via > - * sg_dma_{address,length}(SG). > - * > - * NOTE: An implementation may be able to use a smaller number of > - * DMA address/length pairs than there are SG table elements. > - * (for example via virtual mapping capabilities) > - * The routine returns the number of addr/length pairs actually > - * used, at most nents. > - * > - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the > - * same here. > - */ > static int > -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > BUG_ON(dir == DMA_NONE); > > for_each_sg(sgl, sg, nelems, i) { > - phys_addr_t paddr = sg_phys(sg); > - dma_addr_t dev_addr = xen_phys_to_bus(paddr); > - > - if (swiotlb_force == SWIOTLB_FORCE || > - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || > - !dma_capable(hwdev, dev_addr, sg->length) || > - range_straddles_page_boundary(paddr, sg->length)) { > - phys_addr_t map = swiotlb_tbl_map_single(hwdev, > - start_dma_addr, > - sg_phys(sg), > - sg->length, > - dir, attrs); > - if (map == DMA_MAPPING_ERROR) { > - dev_warn(hwdev, "swiotlb buffer is full\n"); > - /* Don't panic here, we expect map_sg users > - to do proper error handling. */ > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > - sg_dma_len(sgl) = 0; > - return 0; > - } > - dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, > - map & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } else { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), > - dev_addr, > - paddr & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } > + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), > + sg->offset, sg->length, dir, attrs); > + if (sg->dma_address == DMA_MAPPING_ERROR) > + goto out_unmap; > sg_dma_len(sg) = sg->length; > } > + > return nelems; > +out_unmap: > + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > + sg_dma_len(sgl) = 0; > + return 0; > } > > /* > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > We can simply loop over the segments and map them, removing lots of > duplicate code. Right, the only difference is the additional dma_capable check which is good to have. Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- > 1 file changed, 10 insertions(+), 58 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index d4bc3aabd44d..97a55c225593 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > > } > > -/* > - * Map a set of buffers described by scatterlist in streaming mode for DMA. > - * This is the scatter-gather version of the above xen_swiotlb_map_page > - * interface. Here the scatter gather list elements are each tagged with the > - * appropriate dma address and length. They are obtained via > - * sg_dma_{address,length}(SG). > - * > - * NOTE: An implementation may be able to use a smaller number of > - * DMA address/length pairs than there are SG table elements. > - * (for example via virtual mapping capabilities) > - * The routine returns the number of addr/length pairs actually > - * used, at most nents. > - * > - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the > - * same here. > - */ > static int > -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > BUG_ON(dir == DMA_NONE); > > for_each_sg(sgl, sg, nelems, i) { > - phys_addr_t paddr = sg_phys(sg); > - dma_addr_t dev_addr = xen_phys_to_bus(paddr); > - > - if (swiotlb_force == SWIOTLB_FORCE || > - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || > - !dma_capable(hwdev, dev_addr, sg->length) || > - range_straddles_page_boundary(paddr, sg->length)) { > - phys_addr_t map = swiotlb_tbl_map_single(hwdev, > - start_dma_addr, > - sg_phys(sg), > - sg->length, > - dir, attrs); > - if (map == DMA_MAPPING_ERROR) { > - dev_warn(hwdev, "swiotlb buffer is full\n"); > - /* Don't panic here, we expect map_sg users > - to do proper error handling. */ > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > - sg_dma_len(sgl) = 0; > - return 0; > - } > - dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, > - map & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } else { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), > - dev_addr, > - paddr & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } > + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), > + sg->offset, sg->length, dir, attrs); > + if (sg->dma_address == DMA_MAPPING_ERROR) > + goto out_unmap; > sg_dma_len(sg) = sg->length; > } > + > return nelems; > +out_unmap: > + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > + sg_dma_len(sgl) = 0; > + return 0; > } > > /* > -- > 2.20.1 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg 2019-04-11 7:19 ` Christoph Hellwig ` (2 preceding siblings ...) (?) @ 2019-04-15 22:55 ` Stefano Stabellini -1 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > We can simply loop over the segments and map them, removing lots of > duplicate code. Right, the only difference is the additional dma_capable check which is good to have. Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > Signed-off-by: Christoph Hellwig <hch@lst.de> > --- > drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- > 1 file changed, 10 insertions(+), 58 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index d4bc3aabd44d..97a55c225593 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > > } > > -/* > - * Map a set of buffers described by scatterlist in streaming mode for DMA. > - * This is the scatter-gather version of the above xen_swiotlb_map_page > - * interface. Here the scatter gather list elements are each tagged with the > - * appropriate dma address and length. They are obtained via > - * sg_dma_{address,length}(SG). > - * > - * NOTE: An implementation may be able to use a smaller number of > - * DMA address/length pairs than there are SG table elements. > - * (for example via virtual mapping capabilities) > - * The routine returns the number of addr/length pairs actually > - * used, at most nents. > - * > - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the > - * same here. > - */ > static int > -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > enum dma_data_direction dir, unsigned long attrs) > { > struct scatterlist *sg; > @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, > BUG_ON(dir == DMA_NONE); > > for_each_sg(sgl, sg, nelems, i) { > - phys_addr_t paddr = sg_phys(sg); > - dma_addr_t dev_addr = xen_phys_to_bus(paddr); > - > - if (swiotlb_force == SWIOTLB_FORCE || > - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || > - !dma_capable(hwdev, dev_addr, sg->length) || > - range_straddles_page_boundary(paddr, sg->length)) { > - phys_addr_t map = swiotlb_tbl_map_single(hwdev, > - start_dma_addr, > - sg_phys(sg), > - sg->length, > - dir, attrs); > - if (map == DMA_MAPPING_ERROR) { > - dev_warn(hwdev, "swiotlb buffer is full\n"); > - /* Don't panic here, we expect map_sg users > - to do proper error handling. */ > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); > - sg_dma_len(sgl) = 0; > - return 0; > - } > - dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, > - map & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } else { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), > - dev_addr, > - paddr & ~PAGE_MASK, > - sg->length, > - dir, > - attrs); > - sg->dma_address = dev_addr; > - } > + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), > + sg->offset, sg->length, dir, attrs); > + if (sg->dma_address == DMA_MAPPING_ERROR) > + goto out_unmap; > sg_dma_len(sg) = sg->length; > } > + > return nelems; > +out_unmap: > + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); > + sg_dma_len(sgl) = 0; > + return 0; > } > > /* > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Get rid of the grand multiplexer and implement the sync_single_for_cpu and sync_single_for_device methods directly, and then loop over them for the scatterlist based variants. Note that this also loses a few comments related to highlevel DMA API concepts, which have nothing to do with the swiotlb-xen implementation details. Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> --- drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 97a55c225593..9a951504dc12 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, xen_unmap_single(hwdev, dev_addr, size, dir, attrs); } -/* - * Make physical memory consistent for a single streaming mode DMA translation - * after a transfer. - * - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer - * using the cpu, yet do not wish to teardown the dma mapping, you must - * call this function before doing so. At the next point you give the dma - * address back to the card, you must first perform a - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer - */ static void -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - phys_addr_t paddr = xen_bus_to_phys(dev_addr); + phys_addr_t paddr = xen_bus_to_phys(dma_addr); - BUG_ON(dir == DMA_NONE); - - if (target == SYNC_FOR_CPU) - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); - /* NOTE: We use dev_addr here, not paddr! */ - if (is_xen_swiotlb_buffer(dev_addr)) - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); - - if (target == SYNC_FOR_DEVICE) - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); } -void -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) +static void +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); -} + phys_addr_t paddr = xen_bus_to_phys(dma_addr); -void -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) -{ - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); + + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); } /* @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, return 0; } -/* - * Make physical memory consistent for a set of streaming mode DMA translations - * after a transfer. - * - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules - * and usage. - */ static void -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, + int nelems, enum dma_data_direction dir) { struct scatterlist *sg; int i; - for_each_sg(sgl, sg, nelems, i) - xen_swiotlb_sync_single(hwdev, sg->dma_address, - sg_dma_len(sg), dir, target); -} - -static void -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir) -{ - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, + sg->length, dir); + } } static void -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir) { - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, + sg->length, dir); + } } /* -- 2.20.1 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [Xen-devel] [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Get rid of the grand multiplexer and implement the sync_single_for_cpu and sync_single_for_device methods directly, and then loop over them for the scatterlist based variants. Note that this also loses a few comments related to highlevel DMA API concepts, which have nothing to do with the swiotlb-xen implementation details. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 97a55c225593..9a951504dc12 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, xen_unmap_single(hwdev, dev_addr, size, dir, attrs); } -/* - * Make physical memory consistent for a single streaming mode DMA translation - * after a transfer. - * - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer - * using the cpu, yet do not wish to teardown the dma mapping, you must - * call this function before doing so. At the next point you give the dma - * address back to the card, you must first perform a - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer - */ static void -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - phys_addr_t paddr = xen_bus_to_phys(dev_addr); + phys_addr_t paddr = xen_bus_to_phys(dma_addr); - BUG_ON(dir == DMA_NONE); - - if (target == SYNC_FOR_CPU) - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); - /* NOTE: We use dev_addr here, not paddr! */ - if (is_xen_swiotlb_buffer(dev_addr)) - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); - - if (target == SYNC_FOR_DEVICE) - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); } -void -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) +static void +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); -} + phys_addr_t paddr = xen_bus_to_phys(dma_addr); -void -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) -{ - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); + + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); } /* @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, return 0; } -/* - * Make physical memory consistent for a set of streaming mode DMA translations - * after a transfer. - * - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules - * and usage. - */ static void -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, + int nelems, enum dma_data_direction dir) { struct scatterlist *sg; int i; - for_each_sg(sgl, sg, nelems, i) - xen_swiotlb_sync_single(hwdev, sg->dma_address, - sg_dma_len(sg), dir, target); -} - -static void -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir) -{ - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, + sg->length, dir); + } } static void -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir) { - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, + sg->length, dir); + } } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-11 7:19 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Get rid of the grand multiplexer and implement the sync_single_for_cpu and sync_single_for_device methods directly, and then loop over them for the scatterlist based variants. Note that this also loses a few comments related to highlevel DMA API concepts, which have nothing to do with the swiotlb-xen implementation details. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 97a55c225593..9a951504dc12 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, xen_unmap_single(hwdev, dev_addr, size, dir, attrs); } -/* - * Make physical memory consistent for a single streaming mode DMA translation - * after a transfer. - * - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer - * using the cpu, yet do not wish to teardown the dma mapping, you must - * call this function before doing so. At the next point you give the dma - * address back to the card, you must first perform a - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer - */ static void -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - phys_addr_t paddr = xen_bus_to_phys(dev_addr); + phys_addr_t paddr = xen_bus_to_phys(dma_addr); - BUG_ON(dir == DMA_NONE); - - if (target == SYNC_FOR_CPU) - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); - /* NOTE: We use dev_addr here, not paddr! */ - if (is_xen_swiotlb_buffer(dev_addr)) - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); - - if (target == SYNC_FOR_DEVICE) - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); } -void -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) +static void +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); -} + phys_addr_t paddr = xen_bus_to_phys(dma_addr); -void -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) -{ - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); + + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); } /* @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, return 0; } -/* - * Make physical memory consistent for a set of streaming mode DMA translations - * after a transfer. - * - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules - * and usage. - */ static void -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, + int nelems, enum dma_data_direction dir) { struct scatterlist *sg; int i; - for_each_sg(sgl, sg, nelems, i) - xen_swiotlb_sync_single(hwdev, sg->dma_address, - sg_dma_len(sg), dir, target); -} - -static void -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir) -{ - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, + sg->length, dir); + } } static void -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir) { - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, + sg->length, dir); + } } /* -- 2.20.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations 2019-04-11 7:19 ` Christoph Hellwig (?) (?) @ 2019-04-15 22:55 ` Stefano Stabellini -1 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Get rid of the grand multiplexer and implement the sync_single_for_cpu > and sync_single_for_device methods directly, and then loop over them > for the scatterlist based variants. > > Note that this also loses a few comments related to highlevel DMA API > concepts, which have nothing to do with the swiotlb-xen implementation > details. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- > 1 file changed, 28 insertions(+), 56 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 97a55c225593..9a951504dc12 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, > xen_unmap_single(hwdev, dev_addr, size, dir, attrs); > } > > -/* > - * Make physical memory consistent for a single streaming mode DMA translation > - * after a transfer. > - * > - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer > - * using the cpu, yet do not wish to teardown the dma mapping, you must > - * call this function before doing so. At the next point you give the dma > - * address back to the card, you must first perform a > - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer > - */ > static void > -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - phys_addr_t paddr = xen_bus_to_phys(dev_addr); > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > - BUG_ON(dir == DMA_NONE); > - > - if (target == SYNC_FOR_CPU) > - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); > + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); > > - /* NOTE: We use dev_addr here, not paddr! */ > - if (is_xen_swiotlb_buffer(dev_addr)) > - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); > - > - if (target == SYNC_FOR_DEVICE) > - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); > } > > -void > -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > +static void > +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); > -} > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > -void > -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); > + > + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); > } > > /* > @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > return 0; > } > > -/* > - * Make physical memory consistent for a set of streaming mode DMA translations > - * after a transfer. > - * > - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules > - * and usage. > - */ > static void > -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, > + int nelems, enum dma_data_direction dir) > { > struct scatterlist *sg; > int i; > > - for_each_sg(sgl, sg, nelems, i) > - xen_swiotlb_sync_single(hwdev, sg->dma_address, > - sg_dma_len(sg), dir, target); > -} > - > -static void > -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, > - int nelems, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, > + sg->length, dir); > + } > } > > static void > -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, > +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, > int nelems, enum dma_data_direction dir) > { > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); > + struct scatterlist *sg; > + int i; > + > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, > + sg->length, dir); > + } > } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
[parent not found: <20190411072000.4306-4-hch-jcswGhMUV9g@public.gmane.org>]
* Re: [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Get rid of the grand multiplexer and implement the sync_single_for_cpu > and sync_single_for_device methods directly, and then loop over them > for the scatterlist based variants. > > Note that this also loses a few comments related to highlevel DMA API > concepts, which have nothing to do with the swiotlb-xen implementation > details. > > Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> Reviewed-by: Stefano Stabellini <sstabellini-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > --- > drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- > 1 file changed, 28 insertions(+), 56 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 97a55c225593..9a951504dc12 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, > xen_unmap_single(hwdev, dev_addr, size, dir, attrs); > } > > -/* > - * Make physical memory consistent for a single streaming mode DMA translation > - * after a transfer. > - * > - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer > - * using the cpu, yet do not wish to teardown the dma mapping, you must > - * call this function before doing so. At the next point you give the dma > - * address back to the card, you must first perform a > - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer > - */ > static void > -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - phys_addr_t paddr = xen_bus_to_phys(dev_addr); > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > - BUG_ON(dir == DMA_NONE); > - > - if (target == SYNC_FOR_CPU) > - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); > + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); > > - /* NOTE: We use dev_addr here, not paddr! */ > - if (is_xen_swiotlb_buffer(dev_addr)) > - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); > - > - if (target == SYNC_FOR_DEVICE) > - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); > } > > -void > -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > +static void > +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); > -} > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > -void > -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); > + > + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); > } > > /* > @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > return 0; > } > > -/* > - * Make physical memory consistent for a set of streaming mode DMA translations > - * after a transfer. > - * > - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules > - * and usage. > - */ > static void > -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, > + int nelems, enum dma_data_direction dir) > { > struct scatterlist *sg; > int i; > > - for_each_sg(sgl, sg, nelems, i) > - xen_swiotlb_sync_single(hwdev, sg->dma_address, > - sg_dma_len(sg), dir, target); > -} > - > -static void > -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, > - int nelems, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, > + sg->length, dir); > + } > } > > static void > -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, > +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, > int nelems, enum dma_data_direction dir) > { > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); > + struct scatterlist *sg; > + int i; > + > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, > + sg->length, dir); > + } > } ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [Xen-devel] [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Get rid of the grand multiplexer and implement the sync_single_for_cpu > and sync_single_for_device methods directly, and then loop over them > for the scatterlist based variants. > > Note that this also loses a few comments related to highlevel DMA API > concepts, which have nothing to do with the swiotlb-xen implementation > details. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- > 1 file changed, 28 insertions(+), 56 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 97a55c225593..9a951504dc12 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, > xen_unmap_single(hwdev, dev_addr, size, dir, attrs); > } > > -/* > - * Make physical memory consistent for a single streaming mode DMA translation > - * after a transfer. > - * > - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer > - * using the cpu, yet do not wish to teardown the dma mapping, you must > - * call this function before doing so. At the next point you give the dma > - * address back to the card, you must first perform a > - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer > - */ > static void > -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - phys_addr_t paddr = xen_bus_to_phys(dev_addr); > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > - BUG_ON(dir == DMA_NONE); > - > - if (target == SYNC_FOR_CPU) > - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); > + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); > > - /* NOTE: We use dev_addr here, not paddr! */ > - if (is_xen_swiotlb_buffer(dev_addr)) > - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); > - > - if (target == SYNC_FOR_DEVICE) > - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); > } > > -void > -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > +static void > +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); > -} > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > -void > -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); > + > + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); > } > > /* > @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > return 0; > } > > -/* > - * Make physical memory consistent for a set of streaming mode DMA translations > - * after a transfer. > - * > - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules > - * and usage. > - */ > static void > -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, > + int nelems, enum dma_data_direction dir) > { > struct scatterlist *sg; > int i; > > - for_each_sg(sgl, sg, nelems, i) > - xen_swiotlb_sync_single(hwdev, sg->dma_address, > - sg_dma_len(sg), dir, target); > -} > - > -static void > -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, > - int nelems, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, > + sg->length, dir); > + } > } > > static void > -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, > +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, > int nelems, enum dma_data_direction dir) > { > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); > + struct scatterlist *sg; > + int i; > + > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, > + sg->length, dir); > + } > } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations @ 2019-04-15 22:55 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Get rid of the grand multiplexer and implement the sync_single_for_cpu > and sync_single_for_device methods directly, and then loop over them > for the scatterlist based variants. > > Note that this also loses a few comments related to highlevel DMA API > concepts, which have nothing to do with the swiotlb-xen implementation > details. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- > 1 file changed, 28 insertions(+), 56 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 97a55c225593..9a951504dc12 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, > xen_unmap_single(hwdev, dev_addr, size, dir, attrs); > } > > -/* > - * Make physical memory consistent for a single streaming mode DMA translation > - * after a transfer. > - * > - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer > - * using the cpu, yet do not wish to teardown the dma mapping, you must > - * call this function before doing so. At the next point you give the dma > - * address back to the card, you must first perform a > - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer > - */ > static void > -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - phys_addr_t paddr = xen_bus_to_phys(dev_addr); > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > - BUG_ON(dir == DMA_NONE); > - > - if (target == SYNC_FOR_CPU) > - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); > + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); > > - /* NOTE: We use dev_addr here, not paddr! */ > - if (is_xen_swiotlb_buffer(dev_addr)) > - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); > - > - if (target == SYNC_FOR_DEVICE) > - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); > } > > -void > -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > +static void > +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, > + size_t size, enum dma_data_direction dir) > { > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); > -} > + phys_addr_t paddr = xen_bus_to_phys(dma_addr); > > -void > -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, > - size_t size, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); > + if (is_xen_swiotlb_buffer(dma_addr)) > + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); > + > + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); > } > > /* > @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, > return 0; > } > > -/* > - * Make physical memory consistent for a set of streaming mode DMA translations > - * after a transfer. > - * > - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules > - * and usage. > - */ > static void > -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, > - int nelems, enum dma_data_direction dir, > - enum dma_sync_target target) > +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, > + int nelems, enum dma_data_direction dir) > { > struct scatterlist *sg; > int i; > > - for_each_sg(sgl, sg, nelems, i) > - xen_swiotlb_sync_single(hwdev, sg->dma_address, > - sg_dma_len(sg), dir, target); > -} > - > -static void > -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, > - int nelems, enum dma_data_direction dir) > -{ > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, > + sg->length, dir); > + } > } > > static void > -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, > +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, > int nelems, enum dma_data_direction dir) > { > - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); > + struct scatterlist *sg; > + int i; > + > + for_each_sg(sgl, sg, nelems, i) { > + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, > + sg->length, dir); > + } > } _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-11 7:20 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:20 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA Refactor the code a bit to make further changes easier. Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> --- drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 9a951504dc12..5dcb06fe9667 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, if (dma_capable(dev, dev_addr, size) && !range_straddles_page_boundary(phys, size) && !xen_arch_need_swiotlb(dev, phys, dev_addr) && - (swiotlb_force != SWIOTLB_FORCE)) { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); - return dev_addr; - } + swiotlb_force != SWIOTLB_FORCE) + goto done; /* * Oh well, have to allocate and map a bounce buffer. @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, return DMA_MAPPING_ERROR; dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, map & ~PAGE_MASK, size, dir, attrs); /* * Ensure that the address returned is DMA'ble */ - if (dma_capable(dev, dev_addr, size)) - return dev_addr; - - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); + if (unlikely(!dma_capable(dev, dev_addr, size))) { + swiotlb_tbl_unmap_single(dev, map, size, dir, + attrs | DMA_ATTR_SKIP_CPU_SYNC); + return DMA_MAPPING_ERROR; + } - return DMA_MAPPING_ERROR; + page = pfn_to_page(map >> PAGE_SHIFT); + offset = map & ~PAGE_MASK; +done: + /* + * we are not interested in the dma_addr returned by xen_dma_map_page, + * only in the potential cache flushes executed by the function. + */ + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); + return dev_addr; } /* -- 2.20.1 ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [Xen-devel] [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-11 7:20 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:20 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Refactor the code a bit to make further changes easier. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 9a951504dc12..5dcb06fe9667 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, if (dma_capable(dev, dev_addr, size) && !range_straddles_page_boundary(phys, size) && !xen_arch_need_swiotlb(dev, phys, dev_addr) && - (swiotlb_force != SWIOTLB_FORCE)) { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); - return dev_addr; - } + swiotlb_force != SWIOTLB_FORCE) + goto done; /* * Oh well, have to allocate and map a bounce buffer. @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, return DMA_MAPPING_ERROR; dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, map & ~PAGE_MASK, size, dir, attrs); /* * Ensure that the address returned is DMA'ble */ - if (dma_capable(dev, dev_addr, size)) - return dev_addr; - - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); + if (unlikely(!dma_capable(dev, dev_addr, size))) { + swiotlb_tbl_unmap_single(dev, map, size, dir, + attrs | DMA_ATTR_SKIP_CPU_SYNC); + return DMA_MAPPING_ERROR; + } - return DMA_MAPPING_ERROR; + page = pfn_to_page(map >> PAGE_SHIFT); + offset = map & ~PAGE_MASK; +done: + /* + * we are not interested in the dma_addr returned by xen_dma_map_page, + * only in the potential cache flushes executed by the function. + */ + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); + return dev_addr; } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-11 7:20 ` Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:20 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Refactor the code a bit to make further changes easier. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 9a951504dc12..5dcb06fe9667 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, if (dma_capable(dev, dev_addr, size) && !range_straddles_page_boundary(phys, size) && !xen_arch_need_swiotlb(dev, phys, dev_addr) && - (swiotlb_force != SWIOTLB_FORCE)) { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); - return dev_addr; - } + swiotlb_force != SWIOTLB_FORCE) + goto done; /* * Oh well, have to allocate and map a bounce buffer. @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, return DMA_MAPPING_ERROR; dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, map & ~PAGE_MASK, size, dir, attrs); /* * Ensure that the address returned is DMA'ble */ - if (dma_capable(dev, dev_addr, size)) - return dev_addr; - - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); + if (unlikely(!dma_capable(dev, dev_addr, size))) { + swiotlb_tbl_unmap_single(dev, map, size, dir, + attrs | DMA_ATTR_SKIP_CPU_SYNC); + return DMA_MAPPING_ERROR; + } - return DMA_MAPPING_ERROR; + page = pfn_to_page(map >> PAGE_SHIFT); + offset = map & ~PAGE_MASK; +done: + /* + * we are not interested in the dma_addr returned by xen_dma_map_page, + * only in the potential cache flushes executed by the function. + */ + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); + return dev_addr; } /* -- 2.20.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply related [flat|nested] 40+ messages in thread
[parent not found: <20190411072000.4306-5-hch-jcswGhMUV9g@public.gmane.org>]
* Re: [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-15 22:56 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:56 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Refactor the code a bit to make further changes easier. > > Signed-off-by: Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org> Reviewed-by: Stefano Stabellini <sstabellini-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > --- > drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 9a951504dc12..5dcb06fe9667 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > if (dma_capable(dev, dev_addr, size) && > !range_straddles_page_boundary(phys, size) && > !xen_arch_need_swiotlb(dev, phys, dev_addr) && > - (swiotlb_force != SWIOTLB_FORCE)) { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > - return dev_addr; > - } > + swiotlb_force != SWIOTLB_FORCE) > + goto done; > > /* > * Oh well, have to allocate and map a bounce buffer. > @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > return DMA_MAPPING_ERROR; > > dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, map & ~PAGE_MASK, size, dir, attrs); > > /* > * Ensure that the address returned is DMA'ble > */ > - if (dma_capable(dev, dev_addr, size)) > - return dev_addr; > - > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); > + if (unlikely(!dma_capable(dev, dev_addr, size))) { > + swiotlb_tbl_unmap_single(dev, map, size, dir, > + attrs | DMA_ATTR_SKIP_CPU_SYNC); > + return DMA_MAPPING_ERROR; > + } > > - return DMA_MAPPING_ERROR; > + page = pfn_to_page(map >> PAGE_SHIFT); > + offset = map & ~PAGE_MASK; > +done: > + /* > + * we are not interested in the dma_addr returned by xen_dma_map_page, > + * only in the potential cache flushes executed by the function. > + */ > + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > + return dev_addr; > } > > /* > -- > 2.20.1 > ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [Xen-devel] [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-15 22:56 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:56 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Refactor the code a bit to make further changes easier. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 9a951504dc12..5dcb06fe9667 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > if (dma_capable(dev, dev_addr, size) && > !range_straddles_page_boundary(phys, size) && > !xen_arch_need_swiotlb(dev, phys, dev_addr) && > - (swiotlb_force != SWIOTLB_FORCE)) { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > - return dev_addr; > - } > + swiotlb_force != SWIOTLB_FORCE) > + goto done; > > /* > * Oh well, have to allocate and map a bounce buffer. > @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > return DMA_MAPPING_ERROR; > > dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, map & ~PAGE_MASK, size, dir, attrs); > > /* > * Ensure that the address returned is DMA'ble > */ > - if (dma_capable(dev, dev_addr, size)) > - return dev_addr; > - > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); > + if (unlikely(!dma_capable(dev, dev_addr, size))) { > + swiotlb_tbl_unmap_single(dev, map, size, dir, > + attrs | DMA_ATTR_SKIP_CPU_SYNC); > + return DMA_MAPPING_ERROR; > + } > > - return DMA_MAPPING_ERROR; > + page = pfn_to_page(map >> PAGE_SHIFT); > + offset = map & ~PAGE_MASK; > +done: > + /* > + * we are not interested in the dma_addr returned by xen_dma_map_page, > + * only in the potential cache flushes executed by the function. > + */ > + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > + return dev_addr; > } > > /* > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page @ 2019-04-15 22:56 ` Stefano Stabellini 0 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:56 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Refactor the code a bit to make further changes easier. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 9a951504dc12..5dcb06fe9667 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > if (dma_capable(dev, dev_addr, size) && > !range_straddles_page_boundary(phys, size) && > !xen_arch_need_swiotlb(dev, phys, dev_addr) && > - (swiotlb_force != SWIOTLB_FORCE)) { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > - return dev_addr; > - } > + swiotlb_force != SWIOTLB_FORCE) > + goto done; > > /* > * Oh well, have to allocate and map a bounce buffer. > @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > return DMA_MAPPING_ERROR; > > dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, map & ~PAGE_MASK, size, dir, attrs); > > /* > * Ensure that the address returned is DMA'ble > */ > - if (dma_capable(dev, dev_addr, size)) > - return dev_addr; > - > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); > + if (unlikely(!dma_capable(dev, dev_addr, size))) { > + swiotlb_tbl_unmap_single(dev, map, size, dir, > + attrs | DMA_ATTR_SKIP_CPU_SYNC); > + return DMA_MAPPING_ERROR; > + } > > - return DMA_MAPPING_ERROR; > + page = pfn_to_page(map >> PAGE_SHIFT); > + offset = map & ~PAGE_MASK; > +done: > + /* > + * we are not interested in the dma_addr returned by xen_dma_map_page, > + * only in the potential cache flushes executed by the function. > + */ > + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > + return dev_addr; > } > > /* > -- > 2.20.1 > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page 2019-04-11 7:20 ` Christoph Hellwig ` (2 preceding siblings ...) (?) @ 2019-04-15 22:56 ` Stefano Stabellini -1 siblings, 0 replies; 40+ messages in thread From: Stefano Stabellini @ 2019-04-15 22:56 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, Stefano Stabellini, Konrad Rzeszutek Wilk, iommu, xen-devel, Boris Ostrovsky On Thu, 11 Apr 2019, Christoph Hellwig wrote: > Refactor the code a bit to make further changes easier. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> > --- > drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c > index 9a951504dc12..5dcb06fe9667 100644 > --- a/drivers/xen/swiotlb-xen.c > +++ b/drivers/xen/swiotlb-xen.c > @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > if (dma_capable(dev, dev_addr, size) && > !range_straddles_page_boundary(phys, size) && > !xen_arch_need_swiotlb(dev, phys, dev_addr) && > - (swiotlb_force != SWIOTLB_FORCE)) { > - /* we are not interested in the dma_addr returned by > - * xen_dma_map_page, only in the potential cache flushes executed > - * by the function. */ > - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > - return dev_addr; > - } > + swiotlb_force != SWIOTLB_FORCE) > + goto done; > > /* > * Oh well, have to allocate and map a bounce buffer. > @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, > return DMA_MAPPING_ERROR; > > dev_addr = xen_phys_to_bus(map); > - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), > - dev_addr, map & ~PAGE_MASK, size, dir, attrs); > > /* > * Ensure that the address returned is DMA'ble > */ > - if (dma_capable(dev, dev_addr, size)) > - return dev_addr; > - > - attrs |= DMA_ATTR_SKIP_CPU_SYNC; > - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); > + if (unlikely(!dma_capable(dev, dev_addr, size))) { > + swiotlb_tbl_unmap_single(dev, map, size, dir, > + attrs | DMA_ATTR_SKIP_CPU_SYNC); > + return DMA_MAPPING_ERROR; > + } > > - return DMA_MAPPING_ERROR; > + page = pfn_to_page(map >> PAGE_SHIFT); > + offset = map & ~PAGE_MASK; > +done: > + /* > + * we are not interested in the dma_addr returned by xen_dma_map_page, > + * only in the potential cache flushes executed by the function. > + */ > + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); > + return dev_addr; > } > > /* > -- > 2.20.1 > _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: a few xen swiotlb cleanups @ 2019-04-25 18:55 ` Konrad Rzeszutek Wilk 0 siblings, 0 replies; 40+ messages in thread From: Konrad Rzeszutek Wilk @ 2019-04-25 18:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b, Boris Ostrovsky, Stefano Stabellini, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA On Thu, Apr 11, 2019 at 09:19:56AM +0200, Christoph Hellwig wrote: > Hi all, I will slurp these up.. right after I test them for correctness. > > below are a couple of cleanups for swiotlb-xen.c. They were done in > preparation of eventually using the dma-noncoherent.h cache flushing > hooks, but that final goal will need some major work to the arm32 code > first. Until then I think these patches might be better in mainline > than in my local tree so that they don't bitrot. ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: [Xen-devel] a few xen swiotlb cleanups @ 2019-04-25 18:55 ` Konrad Rzeszutek Wilk 0 siblings, 0 replies; 40+ messages in thread From: Konrad Rzeszutek Wilk @ 2019-04-25 18:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, xen-devel, Boris Ostrovsky, Stefano Stabellini, iommu On Thu, Apr 11, 2019 at 09:19:56AM +0200, Christoph Hellwig wrote: > Hi all, I will slurp these up.. right after I test them for correctness. > > below are a couple of cleanups for swiotlb-xen.c. They were done in > preparation of eventually using the dma-noncoherent.h cache flushing > hooks, but that final goal will need some major work to the arm32 code > first. Until then I think these patches might be better in mainline > than in my local tree so that they don't bitrot. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* Re: a few xen swiotlb cleanups @ 2019-04-25 18:55 ` Konrad Rzeszutek Wilk 0 siblings, 0 replies; 40+ messages in thread From: Konrad Rzeszutek Wilk @ 2019-04-25 18:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, xen-devel, Boris Ostrovsky, Stefano Stabellini, iommu On Thu, Apr 11, 2019 at 09:19:56AM +0200, Christoph Hellwig wrote: > Hi all, I will slurp these up.. right after I test them for correctness. > > below are a couple of cleanups for swiotlb-xen.c. They were done in > preparation of eventually using the dma-noncoherent.h cache flushing > hooks, but that final goal will need some major work to the arm32 code > first. Until then I think these patches might be better in mainline > than in my local tree so that they don't bitrot. _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu ^ permalink raw reply [flat|nested] 40+ messages in thread
* [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg 2019-04-11 7:19 ` Christoph Hellwig ` (3 preceding siblings ...) (?) @ 2019-04-11 7:19 ` Christoph Hellwig -1 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu We can simply loop over the segments and map them, removing lots of duplicate code. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 68 ++++++--------------------------------- 1 file changed, 10 insertions(+), 58 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index d4bc3aabd44d..97a55c225593 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -517,24 +517,8 @@ xen_swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, } -/* - * Map a set of buffers described by scatterlist in streaming mode for DMA. - * This is the scatter-gather version of the above xen_swiotlb_map_page - * interface. Here the scatter gather list elements are each tagged with the - * appropriate dma address and length. They are obtained via - * sg_dma_{address,length}(SG). - * - * NOTE: An implementation may be able to use a smaller number of - * DMA address/length pairs than there are SG table elements. - * (for example via virtual mapping capabilities) - * The routine returns the number of addr/length pairs actually - * used, at most nents. - * - * Device ownership issues as mentioned above for xen_swiotlb_map_page are the - * same here. - */ static int -xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, +xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir, unsigned long attrs) { struct scatterlist *sg; @@ -543,50 +527,18 @@ xen_swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, BUG_ON(dir == DMA_NONE); for_each_sg(sgl, sg, nelems, i) { - phys_addr_t paddr = sg_phys(sg); - dma_addr_t dev_addr = xen_phys_to_bus(paddr); - - if (swiotlb_force == SWIOTLB_FORCE || - xen_arch_need_swiotlb(hwdev, paddr, dev_addr) || - !dma_capable(hwdev, dev_addr, sg->length) || - range_straddles_page_boundary(paddr, sg->length)) { - phys_addr_t map = swiotlb_tbl_map_single(hwdev, - start_dma_addr, - sg_phys(sg), - sg->length, - dir, attrs); - if (map == DMA_MAPPING_ERROR) { - dev_warn(hwdev, "swiotlb buffer is full\n"); - /* Don't panic here, we expect map_sg users - to do proper error handling. */ - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - xen_swiotlb_unmap_sg(hwdev, sgl, i, dir, attrs); - sg_dma_len(sgl) = 0; - return 0; - } - dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(hwdev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, - map & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } else { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(hwdev, pfn_to_page(paddr >> PAGE_SHIFT), - dev_addr, - paddr & ~PAGE_MASK, - sg->length, - dir, - attrs); - sg->dma_address = dev_addr; - } + sg->dma_address = xen_swiotlb_map_page(dev, sg_page(sg), + sg->offset, sg->length, dir, attrs); + if (sg->dma_address == DMA_MAPPING_ERROR) + goto out_unmap; sg_dma_len(sg) = sg->length; } + return nelems; +out_unmap: + xen_swiotlb_unmap_sg(dev, sgl, i, dir, attrs | DMA_ATTR_SKIP_CPU_SYNC); + sg_dma_len(sgl) = 0; + return 0; } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations 2019-04-11 7:19 ` Christoph Hellwig ` (4 preceding siblings ...) (?) @ 2019-04-11 7:19 ` Christoph Hellwig -1 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Get rid of the grand multiplexer and implement the sync_single_for_cpu and sync_single_for_device methods directly, and then loop over them for the scatterlist based variants. Note that this also loses a few comments related to highlevel DMA API concepts, which have nothing to do with the swiotlb-xen implementation details. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 84 +++++++++++++-------------------------- 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 97a55c225593..9a951504dc12 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -455,48 +455,28 @@ static void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, xen_unmap_single(hwdev, dev_addr, size, dir, attrs); } -/* - * Make physical memory consistent for a single streaming mode DMA translation - * after a transfer. - * - * If you perform a xen_swiotlb_map_page() but wish to interrogate the buffer - * using the cpu, yet do not wish to teardown the dma mapping, you must - * call this function before doing so. At the next point you give the dma - * address back to the card, you must first perform a - * xen_swiotlb_dma_sync_for_device, and then the device again owns the buffer - */ static void -xen_swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_single_for_cpu(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - phys_addr_t paddr = xen_bus_to_phys(dev_addr); + phys_addr_t paddr = xen_bus_to_phys(dma_addr); - BUG_ON(dir == DMA_NONE); - - if (target == SYNC_FOR_CPU) - xen_dma_sync_single_for_cpu(hwdev, dev_addr, size, dir); + xen_dma_sync_single_for_cpu(dev, dma_addr, size, dir); - /* NOTE: We use dev_addr here, not paddr! */ - if (is_xen_swiotlb_buffer(dev_addr)) - swiotlb_tbl_sync_single(hwdev, paddr, size, dir, target); - - if (target == SYNC_FOR_DEVICE) - xen_dma_sync_single_for_device(hwdev, dev_addr, size, dir); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_CPU); } -void -xen_swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) +static void +xen_swiotlb_sync_single_for_device(struct device *dev, dma_addr_t dma_addr, + size_t size, enum dma_data_direction dir) { - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU); -} + phys_addr_t paddr = xen_bus_to_phys(dma_addr); -void -xen_swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr, - size_t size, enum dma_data_direction dir) -{ - xen_swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE); + if (is_xen_swiotlb_buffer(dma_addr)) + swiotlb_tbl_sync_single(dev, paddr, size, dir, SYNC_FOR_DEVICE); + + xen_dma_sync_single_for_device(dev, dma_addr, size, dir); } /* @@ -541,38 +521,30 @@ xen_swiotlb_map_sg(struct device *dev, struct scatterlist *sgl, int nelems, return 0; } -/* - * Make physical memory consistent for a set of streaming mode DMA translations - * after a transfer. - * - * The same as swiotlb_sync_single_* but for a scatter-gather list, same rules - * and usage. - */ static void -xen_swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl, - int nelems, enum dma_data_direction dir, - enum dma_sync_target target) +xen_swiotlb_sync_sg_for_cpu(struct device *dev, struct scatterlist *sgl, + int nelems, enum dma_data_direction dir) { struct scatterlist *sg; int i; - for_each_sg(sgl, sg, nelems, i) - xen_swiotlb_sync_single(hwdev, sg->dma_address, - sg_dma_len(sg), dir, target); -} - -static void -xen_swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg, - int nelems, enum dma_data_direction dir) -{ - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU); + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_cpu(dev, sg->dma_address, + sg->length, dir); + } } static void -xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg, +xen_swiotlb_sync_sg_for_device(struct device *dev, struct scatterlist *sgl, int nelems, enum dma_data_direction dir) { - xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); + struct scatterlist *sg; + int i; + + for_each_sg(sgl, sg, nelems, i) { + xen_swiotlb_sync_single_for_device(dev, sg->dma_address, + sg->length, dir); + } } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page 2019-04-11 7:19 ` Christoph Hellwig ` (5 preceding siblings ...) (?) @ 2019-04-11 7:20 ` Christoph Hellwig -1 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:20 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Refactor the code a bit to make further changes easier. Signed-off-by: Christoph Hellwig <hch@lst.de> --- drivers/xen/swiotlb-xen.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 9a951504dc12..5dcb06fe9667 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -391,13 +391,8 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, if (dma_capable(dev, dev_addr, size) && !range_straddles_page_boundary(phys, size) && !xen_arch_need_swiotlb(dev, phys, dev_addr) && - (swiotlb_force != SWIOTLB_FORCE)) { - /* we are not interested in the dma_addr returned by - * xen_dma_map_page, only in the potential cache flushes executed - * by the function. */ - xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); - return dev_addr; - } + swiotlb_force != SWIOTLB_FORCE) + goto done; /* * Oh well, have to allocate and map a bounce buffer. @@ -410,19 +405,25 @@ static dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page, return DMA_MAPPING_ERROR; dev_addr = xen_phys_to_bus(map); - xen_dma_map_page(dev, pfn_to_page(map >> PAGE_SHIFT), - dev_addr, map & ~PAGE_MASK, size, dir, attrs); /* * Ensure that the address returned is DMA'ble */ - if (dma_capable(dev, dev_addr, size)) - return dev_addr; - - attrs |= DMA_ATTR_SKIP_CPU_SYNC; - swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); + if (unlikely(!dma_capable(dev, dev_addr, size))) { + swiotlb_tbl_unmap_single(dev, map, size, dir, + attrs | DMA_ATTR_SKIP_CPU_SYNC); + return DMA_MAPPING_ERROR; + } - return DMA_MAPPING_ERROR; + page = pfn_to_page(map >> PAGE_SHIFT); + offset = map & ~PAGE_MASK; +done: + /* + * we are not interested in the dma_addr returned by xen_dma_map_page, + * only in the potential cache flushes executed by the function. + */ + xen_dma_map_page(dev, page, dev_addr, offset, size, dir, attrs); + return dev_addr; } /* -- 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply related [flat|nested] 40+ messages in thread
* Re: a few xen swiotlb cleanups 2019-04-11 7:19 ` Christoph Hellwig ` (6 preceding siblings ...) (?) @ 2019-04-25 18:55 ` Konrad Rzeszutek Wilk -1 siblings, 0 replies; 40+ messages in thread From: Konrad Rzeszutek Wilk @ 2019-04-25 18:55 UTC (permalink / raw) To: Christoph Hellwig Cc: Juergen Gross, xen-devel, Boris Ostrovsky, Stefano Stabellini, iommu On Thu, Apr 11, 2019 at 09:19:56AM +0200, Christoph Hellwig wrote: > Hi all, I will slurp these up.. right after I test them for correctness. > > below are a couple of cleanups for swiotlb-xen.c. They were done in > preparation of eventually using the dma-noncoherent.h cache flushing > hooks, but that final goal will need some major work to the arm32 code > first. Until then I think these patches might be better in mainline > than in my local tree so that they don't bitrot. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
* a few xen swiotlb cleanups @ 2019-04-11 7:19 Christoph Hellwig 0 siblings, 0 replies; 40+ messages in thread From: Christoph Hellwig @ 2019-04-11 7:19 UTC (permalink / raw) To: Konrad Rzeszutek Wilk, Boris Ostrovsky, Juergen Gross, Stefano Stabellini Cc: xen-devel, iommu Hi all, below are a couple of cleanups for swiotlb-xen.c. They were done in preparation of eventually using the dma-noncoherent.h cache flushing hooks, but that final goal will need some major work to the arm32 code first. Until then I think these patches might be better in mainline than in my local tree so that they don't bitrot. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel ^ permalink raw reply [flat|nested] 40+ messages in thread
end of thread, other threads:[~2019-04-25 18:57 UTC | newest]
Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-11 7:19 a few xen swiotlb cleanups Christoph Hellwig
2019-04-11 7:19 ` [Xen-devel] " Christoph Hellwig
2019-04-11 7:19 ` Christoph Hellwig
2019-04-11 7:19 ` [PATCH 1/4] swiotlb-xen: make instances match their method names Christoph Hellwig
[not found] ` <20190411072000.4306-1-hch-jcswGhMUV9g@public.gmane.org>
2019-04-11 7:19 ` Christoph Hellwig
2019-04-11 7:19 ` [Xen-devel] " Christoph Hellwig
2019-04-11 7:19 ` Christoph Hellwig
2019-04-15 22:55 ` Stefano Stabellini
[not found] ` <20190411072000.4306-2-hch-jcswGhMUV9g@public.gmane.org>
2019-04-15 22:55 ` Stefano Stabellini
2019-04-15 22:55 ` [Xen-devel] " Stefano Stabellini
2019-04-15 22:55 ` Stefano Stabellini
2019-04-11 7:19 ` [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg Christoph Hellwig
2019-04-11 7:19 ` [Xen-devel] " Christoph Hellwig
2019-04-11 7:19 ` Christoph Hellwig
[not found] ` <20190411072000.4306-3-hch-jcswGhMUV9g@public.gmane.org>
2019-04-15 22:55 ` Stefano Stabellini
2019-04-15 22:55 ` [Xen-devel] " Stefano Stabellini
2019-04-15 22:55 ` Stefano Stabellini
2019-04-15 22:55 ` Stefano Stabellini
2019-04-11 7:19 ` [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations Christoph Hellwig
2019-04-11 7:19 ` [Xen-devel] " Christoph Hellwig
2019-04-11 7:19 ` Christoph Hellwig
2019-04-15 22:55 ` Stefano Stabellini
[not found] ` <20190411072000.4306-4-hch-jcswGhMUV9g@public.gmane.org>
2019-04-15 22:55 ` Stefano Stabellini
2019-04-15 22:55 ` [Xen-devel] " Stefano Stabellini
2019-04-15 22:55 ` Stefano Stabellini
2019-04-11 7:20 ` [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page Christoph Hellwig
2019-04-11 7:20 ` [Xen-devel] " Christoph Hellwig
2019-04-11 7:20 ` Christoph Hellwig
[not found] ` <20190411072000.4306-5-hch-jcswGhMUV9g@public.gmane.org>
2019-04-15 22:56 ` Stefano Stabellini
2019-04-15 22:56 ` [Xen-devel] " Stefano Stabellini
2019-04-15 22:56 ` Stefano Stabellini
2019-04-15 22:56 ` Stefano Stabellini
2019-04-25 18:55 ` a few xen swiotlb cleanups Konrad Rzeszutek Wilk
2019-04-25 18:55 ` [Xen-devel] " Konrad Rzeszutek Wilk
2019-04-25 18:55 ` Konrad Rzeszutek Wilk
2019-04-11 7:19 ` [PATCH 2/4] swiotlb-xen: use ->map_page to implement ->map_sg Christoph Hellwig
2019-04-11 7:19 ` [PATCH 3/4] swiotlb-xen: simplify the DMA sync method implementations Christoph Hellwig
2019-04-11 7:20 ` [PATCH 4/4] swiotlb-xen: ensure we have a single callsite for xen_dma_map_page Christoph Hellwig
2019-04-25 18:55 ` a few xen swiotlb cleanups Konrad Rzeszutek Wilk
-- strict thread matches above, loose matches on Subject: below --
2019-04-11 7:19 Christoph Hellwig
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.