Add support for DMA writable pages being writable by the network stack
Subsystems (27)
v2 cover Add support for DMA writable pages being writable by the network stack
The first 22 patches in the set add support for the DMA attribute DMA_ATTR_SKIP_CPU_SYNC on multiple platforms/architectures. This is needed so that we can flag the calls to dma_map/unmap_page so that we do not invalidate cache lines that do not currently belong to the device. Instead we have to take care of this in the driver via a call to sync_single_range_for_cpu prior to freeing the Rx page.
Patch 23 adds support for dma_map_page_attrs and dma_unmap_page_attrs so that we can unmap and map a page using the DMA_ATTR_SKIP_CPU_SYNC attribute.
Patch 24 adds support for freeing a page that has multiple references being held by a single caller. This way we can free page fragments that were allocated by a given driver.
The last 2 patches use these updates in the igb driver, and lay the groundwork to allow for us to reimpelement the use of build_skb.
v1: Split out changes DMA_ERROR_CODE fix for swiotlb-xen
Minor fixes based on issues found by kernel build bot Few minor changes for issues found on code review Added Acked-by for patches that were acked and not changed
v2: Added a few more Acked-by
Added swiotlb_unmap_sg to functions dropped in patch 1, dropped Acked-by Submitting patches to mm instead of net-next
---
Alexander Duyck (26):
swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
swiotlb-xen: Enforce return of DMA_ERROR_CODE in mapping function
swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC
arch/arc: Add option to skip sync on DMA mapping
arch/arm: Add option to skip sync on DMA map and unmap arch/avr32: Add option to skip sync on DMA map arch/blackfin: Add option to skip sync on DMA map
arch/c6x: Add option to skip sync on DMA map and unmap arch/frv: Add option to skip sync on DMA map
arch/hexagon: Add option to skip DMA sync as a part of mapping arch/m68k: Add option to skip DMA sync as a part of mapping arch/metag: Add option to skip DMA sync as a part of map and unmap arch/microblaze: Add option to skip DMA sync as a part of map and unmap arch/mips: Add option to skip DMA sync as a part of map and unmap arch/nios2: Add option to skip DMA sync as a part of map and unmap arch/openrisc: Add option to skip DMA sync as a part of mapping arch/parisc: Add option to skip DMA sync as a part of map and unmap arch/powerpc: Add option to skip DMA sync as a part of mapping arch/sh: Add option to skip DMA sync as a part of mapping arch/sparc: Add option to skip DMA sync as a part of map and unmap arch/tile: Add option to skip DMA sync as a part of map and unmap arch/xtensa: Add option to skip DMA sync as a part of mapping
dma: Add calls for dma_map_page_attrs and dma_unmap_page_attrs
mm: Add support for releasing multiple instances of a page
igb: Update driver to make use of DMA_ATTR_SKIP_CPU_SYNC
igb: Update code to better handle incrementing page count
arch/arc/mm/dma.c | 5 ++ arch/arm/common/dmabounce.c | 16 ++++-- arch/arm/xen/mm.c | 1 arch/avr32/mm/dma-coherent.c | 7 ++- arch/blackfin/kernel/dma-mapping.c | 8 +++ arch/c6x/kernel/dma.c | 14 ++++- arch/frv/mb93090-mb00/pci-dma-nommu.c | 14 ++++- arch/frv/mb93090-mb00/pci-dma.c | 9 +++ arch/hexagon/kernel/dma.c | 6 ++ arch/m68k/kernel/dma.c | 8 +++ arch/metag/kernel/dma.c | 16 +++++- arch/microblaze/kernel/dma.c | 10 +++- arch/mips/loongson64/common/dma-swiotlb.c | 2 - arch/mips/mm/dma-default.c | 8 ++- arch/nios2/mm/dma-mapping.c | 26 +++++++--- arch/openrisc/kernel/dma.c | 3 + arch/parisc/kernel/pci-dma.c | 20 ++++++-- arch/powerpc/kernel/dma.c | 9 +++ arch/sh/kernel/dma-nommu.c | 7 ++- arch/sparc/kernel/iommu.c | 4 +- arch/sparc/kernel/ioport.c | 4 +- arch/tile/kernel/pci-dma.c | 12 ++++- arch/x86/xen/pci-swiotlb-xen.c | 1 arch/xtensa/kernel/pci-dma.c | 7 ++- drivers/net/ethernet/intel/igb/igb.h | 7 ++- drivers/net/ethernet/intel/igb/igb_main.c | 77 +++++++++++++++++++---------- drivers/xen/swiotlb-xen.c | 27 +++++----- include/linux/dma-mapping.h | 20 +++++--- include/linux/gfp.h | 2 + include/linux/swiotlb.h | 14 ++--- include/xen/swiotlb-xen.h | 3 - lib/swiotlb.c | 64 +++++++++++------------- mm/page_alloc.c | 14 +++++ 33 files changed, 291 insertions(+), 154 deletions(-)
--
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 1/26 swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
There are no users for swiotlb_map_sg or swiotlb_unmap_sg so we might as well just drop them.
---
v2: Added swiotlb_unmap_sg to functions dropped.
include/linux/swiotlb.h | 8 -------- lib/swiotlb.c | 16 ---------------- 2 files changed, 24 deletions(-)
include/linux/swiotlb.h +0 -8
@@ -73,14 +73,6 @@ extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, unsigned long attrs);extern int -swiotlb_map_sg (struct device *hwdev,struct scatterlist *sg,int nents, -enum dma_data_direction dir); - -extern void -swiotlb_unmap_sg (struct device *hwdev,struct scatterlist *sg,int nents, -enum dma_data_direction dir); - -extern int swiotlb_map_sg_attrs (struct device *hwdev,struct scatterlist *sgl,int nelems,enum dma_data_direction dir,unsigned long attrs);
lib/swiotlb.c +0 -16
@@ -910,14 +910,6 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, }EXPORT_SYMBOL (swiotlb_map_sg_attrs); -int -swiotlb_map_sg (struct device *hwdev,struct scatterlist *sgl,int nelems, -enum dma_data_direction dir) -{ -return swiotlb_map_sg_attrs (hwdev, sgl, nelems, dir,0 ); -} -EXPORT_SYMBOL (swiotlb_map_sg); -/* * Unmap a set of streaming mode DMA translations. Again, cpu read rules * concerning calls here are the same as for swiotlb_unmap_page() above.
@@ -938,14 +930,6 @@ void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, }EXPORT_SYMBOL (swiotlb_unmap_sg_attrs); -void -swiotlb_unmap_sg (struct device *hwdev,struct scatterlist *sgl,int nelems, -enum dma_data_direction dir) -{ -return swiotlb_unmap_sg_attrs (hwdev, sgl, nelems, dir,0 ); -} -EXPORT_SYMBOL (swiotlb_unmap_sg); -/* * Make physical memory consistent for a set of streaming mode DMA translations * after a transfer.
Re: [mm PATCH v2 01/26] swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
Quoted 2 lines · Alexander Duyck
There are no users for
swiotlb_map_sgorswiotlb_unmap_sgso we might as well just drop them.
FYI, I sent the same patch already on Sep, 11 and Konrad already ACKed it:
https://lkml.org/lkml/2016/9/11/112
https://lkml.org/lkml/2016/9/16/474
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [mm PATCH v2 01/26] swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
Quoted 9 lines · Christoph Hellwig
Quoted 2 lines · Alexander Duyck
There are no users for
swiotlb_map_sgorswiotlb_unmap_sgso we might as well just drop them.FYI, I sent the same patch already on Sep, 11 and Konrad already ACKed it:
https://lkml.org/lkml/2016/9/11/112
https://lkml.org/lkml/2016/9/16/474
Somehow I thought you wanted to put them through your tree (which is why I acked them).
I can take them and also the first couple of Alexander through my tree. Or if it makes it simpler - they can go through the -mm tree?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [mm PATCH v2 01/26] swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
Quoted 5 lines · Konrad Rzeszutek Wilk
Somehow I thought you wanted to put them through your tree (which is why I acked them).
I can take them and also the first couple of Alexander through my tree. Or if it makes it simpler - they can go through the -mm tree?
I don't have a tree for it, so I kinda expected you to pick it up. But I'm also fine with you just Acking the version from Alex and having him funnel it through whatever tree he wants to get his patches in through.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
RE: [mm PATCH v2 01/26] swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
Quoted 14 lines
-----Original Message-----
From: Christoph Hellwig [mailto:[email protected]]
Sent: Thursday, November 3, 2016 7:46 AM
To: Konrad Rzeszutek Wilk <[email protected]>
Cc: Christoph Hellwig <[email protected]>; Duyck, Alexander H <[email protected]>; [email protected]; akpm@linux- foundation.org; [email protected]; [email protected]
Subject: Re: [mm PATCH v2 01/26] swiotlb: Drop unused functionsswiotlb_map_sgandswiotlb_unmap_sgQuoted 3 lines · Konrad Rzeszutek Wilk
Somehow I thought you wanted to put them through your tree (which is why I acked them).
Quoted 6 lines
Quoted 2 lines
I can take them and also the first couple of Alexander through my tree. Or if it makes it simpler - they can go through the -mm tree?
I don't have a tree for it, so I kinda expected you to pick it up. But I'm also fine with you just Acking the version from Alex and having him funnel it through whatever tree he wants to get his patches in through.
For the first 3 patches in my series I am fine with them being pulled into the swiotlb tree. So if you want to pull Christoph's two patches, and then drop my duplicate patch and instead pull the next 2 I could submit a v3 of my series without the swiotlb patches in it.
At this point I have redone my series so that I technically don't have anything with a hard dependency on the DMA_ATTR_SKIP_CPU_SYNC actually doing anything yet. My plan is to get this all into Linus's tree first via whatever tree I can get these patches pulled into and once I have all that I will start updating drivers in net-next.
Thanks.
- Alex
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 2/26 swiotlb-xen: Enforce return of DMA_ERROR_CODE in mapping function
In reply to Alexander DuyckThe mapping function should always return DMA_ERROR_CODE when a mapping has failed as this is what the DMA API expects when a DMA error has occurred. The current function for mapping a page in Xen was returning either DMA_ERROR_CODE or 0 depending on where it failed.
On x86 DMA_ERROR_CODE is 0, but on other architectures such as ARM it is ~0. We need to make sure we return the same error value if either the mapping failed or the device is not capable of accessing the mapping.
If we are returning DMA_ERROR_CODE as our error value we can drop the function for checking the error code as the default is to compare the return value against DMA_ERROR_CODE if no function is defined.
---
v1: Added this patch which was part of an earlier patch.
arch/arm/xen/mm.c | 1 - arch/x86/xen/pci-swiotlb-xen.c | 1 - drivers/xen/swiotlb-xen.c | 18 ++++++------------ include/xen/swiotlb-xen.h | 3 --- 4 files changed, 6 insertions(+), 17 deletions(-)
arch/arm/xen/mm.c +0 -1
@@ -186,7 +186,6 @@ void xen_destroy_contiguous_region(phys_addr_t pstart, unsigned int order)EXPORT_SYMBOL (xen_dma_ops);static struct dma_map_ops xen_swiotlb_dma_ops = { - .mapping_error = xen_swiotlb_dma_mapping_error, .alloc = xen_swiotlb_alloc_coherent, .free = xen_swiotlb_free_coherent, .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
arch/x86/xen/pci-swiotlb-xen.c +0 -1
@@ -19,7 +19,6 @@int xen_swiotlb__read_mostly ;static struct dma_map_ops xen_swiotlb_dma_ops = { - .mapping_error = xen_swiotlb_dma_mapping_error, .alloc = xen_swiotlb_alloc_coherent, .free = xen_swiotlb_free_coherent, .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
drivers/xen/swiotlb-xen.c +6 -12
@@ -416,11 +416,12 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,/* * Ensure that the address returned is DMA'ble */ -if (!dma_capable (dev, dev_addr, size)) { -swiotlb_tbl_unmap_single (dev, map, size, dir); - dev_addr =0 ; - } -return dev_addr; +if (dma_capable (dev, dev_addr, size)) +return dev_addr; + +swiotlb_tbl_unmap_single (dev, map, size, dir); + +return DMA_ERROR_CODE ; }EXPORT_SYMBOL_GPL (xen_swiotlb_map_page);
@@ -648,13 +649,6 @@ void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, }EXPORT_SYMBOL_GPL (xen_swiotlb_sync_sg_for_device); -int -xen_swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr) -{ -return !dma_addr; -} -EXPORT_SYMBOL_GPL (xen_swiotlb_dma_mapping_error); -/* * Return whether the given device DMA address mask can be supported * properly. For example, if your device can only drive the low 24-bits
include/xen/swiotlb-xen.h +0 -3
@@ -51,9 +51,6 @@ extern void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, int nelems, enum dma_data_direction dir);extern int -xen_swiotlb_dma_mapping_error (struct device *hwdev,dma_addr_t dma_addr); - -extern int xen_swiotlb_dma_supported (struct device *hwdev,u64 mask); extern int
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 3/26 swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC
In reply to Alexander DuyckAs a first step to making DMA_ATTR_SKIP_CPU_SYNC apply to architectures beyond just ARM I need to make it so that the swiotlb will respect the flag. In order to do that I also need to update the swiotlb-xen since it heavily makes use of the functionality.
---
v1: Found different fix for avoiding lines longer than 80 characters
Dropped code that moved section to a label at end of function. Split out mapping error fix to separate patch.
drivers/xen/swiotlb-xen.c | 11 +++++++--- include/linux/swiotlb.h | 6 ++++-- lib/swiotlb.c | 48 +++++++++++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 25 deletions(-)
drivers/xen/swiotlb-xen.c +7 -4
@@ -405,7 +405,8 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,*/ trace_swiotlb_bounced (dev, dev_addr, size, swiotlb_force); - map =swiotlb_tbl_map_single (dev, start_dma_addr, phys, size, dir); + map =swiotlb_tbl_map_single (dev, start_dma_addr, phys, size, dir, + attrs);if (map ==SWIOTLB_MAP_ERROR )return DMA_ERROR_CODE ;
@@ -419,7 +420,8 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,if (dma_capable (dev, dev_addr, size))return dev_addr; -swiotlb_tbl_unmap_single (dev, map, size, dir); +swiotlb_tbl_unmap_single (dev, map, size, dir, + attrs |DMA_ATTR_SKIP_CPU_SYNC );return DMA_ERROR_CODE ; }
@@ -445,7 +447,7 @@ static void xen_unmap_single(struct device *hwdev, dma_addr_t dev_addr,/* NOTE: We use dev_addr here, not paddr! */ if (is_xen_swiotlb_buffer (dev_addr)) { -swiotlb_tbl_unmap_single (hwdev, paddr, size, dir); +swiotlb_tbl_unmap_single (hwdev, paddr, size, dir, attrs);return ; }
@@ -558,11 +560,12 @@ void xen_swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, start_dma_addr,sg_phys (sg), sg->length, - dir); + dir, attrs);if (map ==SWIOTLB_MAP_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_attrs (hwdev, sgl, i, dir, attrs);sg_dma_len (sgl) =0 ;
include/linux/swiotlb.h +4 -2
@@ -44,11 +44,13 @@ enum dma_sync_target {extern phys_addr_t swiotlb_tbl_map_single (struct device *hwdev,dma_addr_t tbl_dma_addr,phys_addr_t phys,size_t size, -enum dma_data_direction dir); +enum dma_data_direction dir, +unsigned long attrs);extern void swiotlb_tbl_unmap_single (struct device *hwdev,phys_addr_t tlb_addr, -size_t size,enum dma_data_direction dir); +size_t size,enum dma_data_direction dir, +unsigned long attrs); extern void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,
lib/swiotlb.c +29 -19
142 lines not on this page · raw message
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [mm PATCH v2 03/26] swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC
.. snip..
Quoted 19 lines
lib/swiotlb.c +3
-1@@ -561,6 +565,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,* First, sync the memory before unmapping the entry */ if (orig_addr !=INVALID_PHYS_ADDR && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC ) && ((dir ==DMA_FROM_DEVICE ) || (dir ==DMA_BIDIRECTIONAL )))swiotlb_bounce (orig_addr, tlb_addr, size,DMA_FROM_DEVICE );@@ -654,7 +659,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,* GFP_DMA memory; fall back on map_single(), which * will grab memory from the lowest available address range. */ -phys_addr_t paddr =map_single (hwdev,0 , size,DMA_FROM_DEVICE ); +phys_addr_t paddr =map_single (hwdev,0 , size, +DMA_FROM_DEVICE ,0 );if (paddr ==SWIOTLB_MAP_ERROR ) goto err_warn;
lib/swiotlb.c void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, · line 679
Quoted 6 lines
lib/swiotlb.c +2
-1@@ -669,7 +675,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,/* DMA_TO_DEVICE to avoid memcpy in unmap_single */ swiotlb_tbl_unmap_single (hwdev, paddr, - size,DMA_TO_DEVICE ); + size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC );
This I believe is redundant. That is swiotlb_tbl_unmap_single only does an bounce if the dir is DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
I added /* optional. */
lib/swiotlb.c void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, · line 709
Quoted 9 lines
lib/swiotlb.c +1
-1goto err_warn; } }@@ -699,7 +706,7 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,free_pages ((unsigned long )vaddr,get_order (size)); else /* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single */ -swiotlb_tbl_unmap_single (hwdev ,paddr ,size ,DMA_TO_DEVICE ); + swiotlb_tbl_unmap_single(hwdev, paddr, size, DMA_TO_DEVICE, 0);
.. but here you choose to put 0? I changed that to DMA_ATTR_SKIP_CPU_SYNC and expanded the comment above.
Time to test the patches.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [mm PATCH v2 03/26] swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC
Quoted 30 lines · Konrad Rzeszutek Wilk
.. snip..
Quoted 19 lines
lib/swiotlb.c +3
-1@@ -561,6 +565,7 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr,* First, sync the memory before unmapping the entry */ if (orig_addr !=INVALID_PHYS_ADDR && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC ) && ((dir ==DMA_FROM_DEVICE ) || (dir ==DMA_BIDIRECTIONAL )))swiotlb_bounce (orig_addr, tlb_addr, size,DMA_FROM_DEVICE );@@ -654,7 +659,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,* GFP_DMA memory; fall back on map_single(), which * will grab memory from the lowest available address range. */ -phys_addr_t paddr =map_single (hwdev,0 , size,DMA_FROM_DEVICE ); +phys_addr_t paddr =map_single (hwdev,0 , size, +DMA_FROM_DEVICE ,0 );if (paddr ==SWIOTLB_MAP_ERROR ) goto err_warn;lib/swiotlb.c void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, · line 679
Quoted 6 lines
lib/swiotlb.c +2
-1@@ -669,7 +675,8 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,/* DMA_TO_DEVICE to avoid memcpy in unmap_single */ swiotlb_tbl_unmap_single (hwdev, paddr, - size,DMA_TO_DEVICE ); + size,DMA_TO_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC );This I believe is redundant. That is
swiotlb_tbl_unmap_singleonly does an bounce if the dir isDMA_FROM_DEVICEorDMA_BIDIRECTIONAL.
Quoted 1 line
I added /* optional. */
You are probably right. I don't need to add the DMA_ATTR_SKIP_CPU_SYNC here.
Quoted 13 lines
lib/swiotlb.c void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, · line 709
Quoted 9 lines
lib/swiotlb.c +1
-1goto err_warn; } }@@ -699,7 +706,7 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr,free_pages ((unsigned long )vaddr,get_order (size)); else /* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single */ -swiotlb_tbl_unmap_single (hwdev ,paddr ,size ,DMA_TO_DEVICE ); + swiotlb_tbl_unmap_single(hwdev, paddr, size, DMA_TO_DEVICE, 0);.. but here you choose to put 0? I changed that to
DMA_ATTR_SKIP_CPU_SYNCand expanded the comment above.
Quoted 1 line
Time to test the patches.
I think I had probably realized the fact that I didn't need it above and so just used 0 here. I can clean this up and resubmit if you want.
Do you want me to just split this patch set up so that I submit the swiotlb patches to you and leave the rest of the patches for the mm tree?
Thanks.
- Alex
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 4/26 arch/arc: Add option to skip sync on DMA mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it later via a sync_for_cpu or sync_for_device call.
--- arch/arc/mm/dma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arc/mm/dma.c +4 -1
@@ -133,7 +133,10 @@ static dma_addr_t arc_dma_map_page(struct device *dev, struct page *page, unsigned long attrs) {phys_addr_t paddr =page_to_phys (page) + offset; -_dma_cache_sync (paddr, size, dir); + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +_dma_cache_sync (paddr, size, dir); +return plat_phys_to_dma (dev, paddr); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 5/26 arch/arm: Add option to skip sync on DMA map and unmap
In reply to Alexander DuyckThe use of DMA_ATTR_SKIP_CPU_SYNC was not consistent across all of the DMA APIs in the arch/arm folder. This change is meant to correct that so that we get consistent behavior.
--- arch/arm/common/dmabounce.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
arch/arm/common/dmabounce.c +10 -6
@@ -243,7 +243,8 @@ static int needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size) }static inline dma_addr_t map_single (struct device *dev,void *ptr,size_t size, -enum dma_data_direction dir) +enum dma_data_direction dir, +unsigned long attrs) {struct dmabounce_device_info *device_info = dev->archdata.dmabounce;struct safe_buffer *buf;
@@ -262,7 +263,8 @@ static inline dma_addr_t map_single(struct device *dev, void *ptr, size_t size, __func__, buf->ptr,virt_to_dma (dev, buf->ptr), buf->safe, buf->safe_dma_addr); -if (dir ==DMA_TO_DEVICE || dir ==DMA_BIDIRECTIONAL ) { +if ((dir ==DMA_TO_DEVICE || dir ==DMA_BIDIRECTIONAL ) && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) {dev_dbg (dev,"%s: copy unsafe %p to safe %p, size %d\n" , __func__, ptr, buf->safe, size);memcpy (buf->safe, ptr, size);
@@ -272,7 +274,8 @@ static inline dma_addr_t map_single(struct device *dev, void *ptr, size_t size, }static inline void unmap_single (struct device *dev,struct safe_buffer *buf, -size_t size,enum dma_data_direction dir) +size_t size,enum dma_data_direction dir, +unsigned long attrs) {BUG_ON (buf->size != size);BUG_ON (buf->direction != dir);
@@ -283,7 +286,8 @@ static inline void unmap_single(struct device *dev, struct safe_buffer *buf,DO_STATS (dev->archdata.dmabounce->bounce_count++); -if (dir ==DMA_FROM_DEVICE || dir ==DMA_BIDIRECTIONAL ) { +if ((dir ==DMA_FROM_DEVICE || dir ==DMA_BIDIRECTIONAL ) && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) {void *ptr = buf->ptr; dev_dbg(dev, "%s: copy back safe %p to unsafe %p size %d\n",
@@ -334,7 +338,7 @@ static dma_addr_t dmabounce_map_page(struct device *dev, struct page *page,return DMA_ERROR_CODE ; } -return map_single (dev,page_address (page) + offset, size, dir); +return map_single (dev,page_address (page) + offset, size, dir, attrs); }/*
@@ -357,7 +361,7 @@ static void dmabounce_unmap_page(struct device *dev, dma_addr_t dma_addr, size_treturn ; } -unmap_single (dev, buf, size, dir); +unmap_single (dev, buf, size, dir, attrs); } static int __dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
PATCH v2 6/26 arch/avr32: Add option to skip sync on DMA map
In reply to Alexander DuyckThe use of DMA_ATTR_SKIP_CPU_SYNC was not consistent across all of the DMA APIs in the arch/arm folder. This change is meant to correct that so that we get consistent behavior.
--- arch/avr32/mm/dma-coherent.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/avr32/mm/dma-coherent.c +6 -1
@@ -146,7 +146,8 @@ static dma_addr_t avr32_dma_map_page(struct device *dev, struct page *page, {void *cpu_addr =page_address (page) + offset; -dma_cache_sync (dev, cpu_addr, size, direction); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_cache_sync (dev, cpu_addr, size, direction);return virt_to_bus (cpu_addr); }
@@ -162,6 +163,10 @@ static int avr32_dma_map_sg(struct device *dev, struct scatterlist *sglist, sg->dma_address =page_to_bus (sg_page (sg)) + sg->offset; virt =sg_virt (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +dma_cache_sync (dev, virt, sg->length, direction); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 7/26 arch/blackfin: Add option to skip sync on DMA map
In reply to Alexander DuyckThe use of DMA_ATTR_SKIP_CPU_SYNC was not consistent across all of the DMA APIs in the arch/arm folder. This change is meant to correct that so that we get consistent behavior.
--- arch/blackfin/kernel/dma-mapping.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/blackfin/kernel/dma-mapping.c +7 -1
@@ -118,6 +118,10 @@ static int bfin_dma_map_sg(struct device *dev, struct scatterlist *sg_list,for_each_sg (sg_list, sg, nents, i) { sg->dma_address = (dma_addr_t )sg_virt (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +__dma_sync (sg_dma_address (sg),sg_dma_len (sg), direction); }
@@ -143,7 +147,9 @@ static dma_addr_t bfin_dma_map_page(struct device *dev, struct page *page, {dma_addr_t handle = (dma_addr_t)(page_address (page) + offset); -_dma_sync (handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +_dma_sync (handle, size, dir); +return handle; }
PATCH v2 8/26 arch/c6x: Add option to skip sync on DMA map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it later via a sync_for_cpu or sync_for_device call.
--- arch/c6x/kernel/dma.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
arch/c6x/kernel/dma.c +10 -4
@@ -42,14 +42,17 @@ static dma_addr_t c6x_dma_map_page(struct device *dev, struct page *page, {dma_addr_t handle =virt_to_phys (page_address (page) + offset); -c6x_dma_sync (handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +c6x_dma_sync (handle, size, dir); +return handle; }static void c6x_dma_unmap_page (struct device *dev,dma_addr_t handle,size_t size,enum dma_data_direction dir,unsigned long attrs) { -c6x_dma_sync (handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +c6x_dma_sync (handle, size, dir); } static int c6x_dma_map_sg(struct device *dev, struct scatterlist *sglist,
@@ -60,7 +63,8 @@ static int c6x_dma_map_sg(struct device *dev, struct scatterlist *sglist,for_each_sg (sglist, sg, nents, i) { sg->dma_address =sg_phys (sg); -c6x_dma_sync (sg->dma_address, sg->length, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +c6x_dma_sync (sg->dma_address, sg->length, dir); }return nents;
@@ -72,9 +76,11 @@ static void c6x_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,struct scatterlist *sg;int i; +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return ; +for_each_sg (sglist, sg, nents, i)c6x_dma_sync (sg_dma_address (sg), sg->length, dir); - } static void c6x_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 9/26 arch/frv: Add option to skip sync on DMA map
In reply to Alexander DuyckThe use of DMA_ATTR_SKIP_CPU_SYNC was not consistent across all of the DMA APIs in the arch/arm folder. This change is meant to correct that so that we get consistent behavior.
--- arch/frv/mb93090-mb00/pci-dma-nommu.c | 14 ++++++++++---- arch/frv/mb93090-mb00/pci-dma.c | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-)
arch/frv/mb93090-mb00/pci-dma-nommu.c +10 -4
@@ -109,16 +109,19 @@ static int frv_dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction, unsigned long attrs) { - int i; struct scatterlist *sg; +int i; + +BUG_ON (direction ==DMA_NONE ); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return nents;for_each_sg (sglist, sg, nents, i) {frv_cache_wback_inv (sg_dma_address (sg),sg_dma_address (sg) +sg_dma_len (sg)); } -BUG_ON (direction ==DMA_NONE ); -return nents; }
@@ -127,7 +130,10 @@ static dma_addr_t frv_dma_map_page(struct device *dev, struct page *page, enum dma_data_direction direction, unsigned long attrs) { BUG_ON(direction == DMA_NONE); -flush_dcache_page (page); + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +flush_dcache_page (page); +return (dma_addr_t )page_to_phys (page) + offset; }
arch/frv/mb93090-mb00/pci-dma.c +7 -2
@@ -40,13 +40,16 @@ static int frv_dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents, enum dma_data_direction direction, unsigned long attrs) { + struct scatterlist *sg;unsigned long dampr2;void *vaddr;int i; -struct scatterlist *sg;BUG_ON (direction ==DMA_NONE ); +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return nents; + dampr2 =__get_DAMPR (2 );for_each_sg (sglist, sg, nents, i) {
@@ -70,7 +73,9 @@ static dma_addr_t frv_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction direction, unsigned long attrs) { -flush_dcache_page (page ); + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + flush_dcache_page(page); +return (dma_addr_t )page_to_phys (page) + offset; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 10/26 arch/hexagon: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it later via a sync_for_cpu or sync_for_device call.
--- arch/hexagon/kernel/dma.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/hexagon/kernel/dma.c +5 -1
@@ -119,6 +119,9 @@ static int hexagon_map_sg(struct device *hwdev, struct scatterlist *sg, s->dma_length = s->length; +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +flush_dcache_range (dma_addr_to_virt (s->dma_address),dma_addr_to_virt (s->dma_address + s->length)); }
@@ -180,7 +183,8 @@ static dma_addr_t hexagon_map_page(struct device *dev, struct page *page,if (!check_addr ("map_single" , dev, bus, size))return bad_dma_address; -dma_sync (dma_addr_to_virt (bus), size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_sync (dma_addr_to_virt (bus), size, dir);return bus; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 11/26 arch/m68k: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it later via a sync_for_cpu or sync_for_device call.
--- arch/m68k/kernel/dma.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/m68k/kernel/dma.c +7 -1
@@ -134,7 +134,9 @@ static dma_addr_t m68k_dma_map_page(struct device *dev, struct page *page, {dma_addr_t handle =page_to_phys (page) + offset; -dma_sync_single_for_device (dev, handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_sync_single_for_device (dev, handle, size, dir); +return handle; }
@@ -146,6 +148,10 @@ static int m68k_dma_map_sg(struct device *dev, struct scatterlist *sglist,for_each_sg (sglist, sg, nents, i) { sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +dma_sync_single_for_device (dev, sg->dma_address, sg->length, dir); }
PATCH v2 11/26 arch/m68k: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it later via a sync_for_cpu or sync_for_device call.
--- arch/m68k/kernel/dma.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/m68k/kernel/dma.c +7 -1
@@ -134,7 +134,9 @@ static dma_addr_t m68k_dma_map_page(struct device *dev, struct page *page, {dma_addr_t handle =page_to_phys (page) + offset; -dma_sync_single_for_device (dev, handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_sync_single_for_device (dev, handle, size, dir); +return handle; }
@@ -146,6 +148,10 @@ static int m68k_dma_map_sg(struct device *dev, struct scatterlist *sglist,for_each_sg (sglist, sg, nents, i) { sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +dma_sync_single_for_device (dev, sg->dma_address, sg->length, dir); }
PATCH v2 12/26 arch/metag: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/metag/kernel/dma.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
arch/metag/kernel/dma.c +13 -3
@@ -484,8 +484,9 @@ static dma_addr_t metag_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction direction, unsigned long attrs) { - dma_sync_for_device((void *)(page_to_phys(page) + offset), size, - direction); + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + dma_sync_for_device((void *)(page_to_phys(page) + offset), + size, direction);return page_to_phys (page) + offset; }
@@ -493,7 +494,8 @@ static void metag_dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, enum dma_data_direction direction, unsigned long attrs) { -dma_sync_for_cpu (phys_to_virt (dma_address ),size ,direction ); + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + dma_sync_for_cpu(phys_to_virt(dma_address), size, direction); } static int metag_dma_map_sg(struct device *dev, struct scatterlist *sglist,
@@ -507,6 +509,10 @@ static int metag_dma_map_sg(struct device *dev, struct scatterlist *sglist,BUG_ON (!sg_page (sg)); sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +dma_sync_for_device (sg_virt (sg), sg->length, direction); }
@@ -525,6 +531,10 @@ static void metag_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,BUG_ON (!sg_page (sg)); sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +dma_sync_for_cpu (sg_virt (sg), sg->length, direction); } }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 13/26 arch/microblaze: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/microblaze/kernel/dma.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
arch/microblaze/kernel/dma.c +8 -2
@@ -61,6 +61,10 @@ static int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl,/* FIXME this part of code is untested */ for_each_sg (sgl, sg, nents, i) { sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +__dma_sync (page_to_phys (sg_page (sg)) + sg->offset, sg->length, direction); }
@@ -80,7 +84,8 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev, enum dma_data_direction direction, unsigned long attrs) { - __dma_sync(page_to_phys(page) + offset, size, direction); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_sync (page_to_phys (page) + offset, size, direction);return page_to_phys (page) + offset; }
@@ -95,7 +100,8 @@ static inline void dma_direct_unmap_page(struct device *dev,* phys_to_virt is here because in __dma_sync_page is __virt_to_phys and * dma_address is physical address */ -__dma_sync (dma_address, size, direction); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_sync (dma_address, size, direction); } static inline void
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 14/26 arch/mips: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/mips/loongson64/common/dma-swiotlb.c | 2 +- arch/mips/mm/dma-default.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-)
arch/mips/loongson64/common/dma-swiotlb.c +1 -1
@@ -61,7 +61,7 @@ static int loongson_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction dir, unsigned long attrs) { - int r = swiotlb_map_sg_attrs(dev, sg, nents, dir, 0); + int r = swiotlb_map_sg_attrs(dev, sg, nents, dir, attrs);mb ();return r;
arch/mips/mm/dma-default.c +5 -3
@@ -293,7 +293,7 @@ static inline void __dma_sync(struct page *page,static void mips_dma_unmap_page (struct device *dev,dma_addr_t dma_addr,size_t size,enum dma_data_direction direction,unsigned long attrs) { -if (cpu_needs_post_dma_flush (dev)) +if (cpu_needs_post_dma_flush (dev) && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))__dma_sync (dma_addr_to_page (dev, dma_addr), dma_addr & ~PAGE_MASK , size, direction);plat_post_dma_flush (dev);
@@ -307,7 +307,8 @@ static int mips_dma_map_sg(struct device *dev, struct scatterlist *sglist,struct scatterlist *sg;for_each_sg (sglist, sg, nents, i) { -if (!plat_device_is_coherent (dev)) +if (!plat_device_is_coherent (dev) && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))__dma_sync (sg_page (sg), sg->offset, sg->length, direction);#ifdef CONFIG_NEED_SG_DMA_LENGTH
@@ -324,7 +325,7 @@ static dma_addr_t mips_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction direction, unsigned long attrs) { - if (!plat_device_is_coherent(dev)) + if (!plat_device_is_coherent(dev) && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) __dma_sync(page, offset, size, direction);return plat_map_dma_mem_page (dev, page) + offset;
@@ -339,6 +340,7 @@ static void mips_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,for_each_sg (sglist, sg, nhwentries, i) {if (!plat_device_is_coherent (dev) && + !(attrs &DMA_ATTR_SKIP_CPU_SYNC ) && direction !=DMA_TO_DEVICE )__dma_sync (sg_page (sg), sg->offset, sg->length, direction);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 15/26 arch/nios2: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/nios2/mm/dma-mapping.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
arch/nios2/mm/dma-mapping.c +18 -8
@@ -98,13 +98,17 @@ static int nios2_dma_map_sg(struct device *dev, struct scatterlist *sg,int i;for_each_sg (sg, sg, nents, i) { -void *addr; +void *addr =sg_virt (sg); - addr =sg_virt (sg); -if (addr) { -__dma_sync_for_device (addr, sg->length, direction); - sg->dma_address =sg_phys (sg); - } +if (!addr) +continue ; + + sg->dma_address =sg_phys (sg); + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; + +__dma_sync_for_device (addr, sg->length, direction); }return nents;
@@ -117,7 +121,9 @@ static dma_addr_t nios2_dma_map_page(struct device *dev, struct page *page, {void *addr =page_address (page) + offset; -__dma_sync_for_device (addr, size, direction); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_sync_for_device (addr, size, direction); +return page_to_phys (page) + offset; }
@@ -125,7 +131,8 @@ static void nios2_dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size, enum dma_data_direction direction, unsigned long attrs) { -__dma_sync_for_cpu (phys_to_virt (dma_address ),size ,direction ); + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + __dma_sync_for_cpu(phys_to_virt(dma_address), size, direction); } static void nios2_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
@@ -138,6 +145,9 @@ static void nios2_dma_unmap_sg(struct device *dev, struct scatterlist *sg,if (direction ==DMA_TO_DEVICE )return ; +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return ; +for_each_sg (sg, sg, nhwentries, i) { addr =sg_virt (sg);if (addr)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 16/26 arch/openrisc: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/openrisc/kernel/dma.c | 3 +++ 1 file changed, 3 insertions(+)
arch/openrisc/kernel/dma.c +3 -0
@@ -141,6 +141,9 @@unsigned long cl;dma_addr_t addr =page_to_phys (page) + offset; +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return addr; +switch (dir) {case DMA_TO_DEVICE :/* Flush the dcache for the requested range */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 17/26 arch/parisc: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/parisc/kernel/pci-dma.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
arch/parisc/kernel/pci-dma.c +15 -5
@@ -459,7 +459,9 @@ static dma_addr_t pa11_dma_map_page(struct device *dev, struct page *page,void *addr =page_address (page) + offset;BUG_ON (direction ==DMA_NONE ); -flush_kernel_dcache_range ((unsigned long ) addr, size); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +flush_kernel_dcache_range ((unsigned long ) addr, size); +return virt_to_phys (addr); }
@@ -469,8 +471,11 @@ static void pa11_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, {BUG_ON (direction ==DMA_NONE ); +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return ; +if (direction ==DMA_TO_DEVICE ) -return ; +return ;/* * For PCI_DMA_FROMDEVICE this flush is not necessary for the
@@ -479,7 +484,6 @@ static void pa11_dma_unmap_page(struct device *dev, dma_addr_t dma_handle,*/ flush_kernel_dcache_range ((unsigned long )phys_to_virt (dma_handle), size); -return ; } static int pa11_dma_map_sg(struct device *dev, struct scatterlist *sglist,
@@ -496,6 +500,10 @@ static int pa11_dma_map_sg(struct device *dev, struct scatterlist *sglist,sg_dma_address (sg) = (dma_addr_t )virt_to_phys (vaddr);sg_dma_len (sg) = sg->length; + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +flush_kernel_dcache_range (vaddr, sg->length); }return nents;
@@ -510,14 +518,16 @@ static void pa11_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,BUG_ON (direction ==DMA_NONE ); +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return ; +if (direction ==DMA_TO_DEVICE ) -return ; +return ;/* once we do combining we'll need to use phys_to_virt(sg_dma_address(sglist)) */ for_each_sg (sglist, sg, nents, i)flush_kernel_vmap_range (sg_virt (sg), sg->length); -return ; } static void pa11_dma_sync_single_for_cpu(struct device *dev,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 18/26 arch/powerpc: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/powerpc/kernel/dma.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/powerpc/kernel/dma.c +8 -1
@@ -203,6 +203,10 @@ static int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl,for_each_sg (sgl, sg, nents, i) { sg->dma_address =sg_phys (sg) +get_dma_offset (dev); sg->dma_length = sg->length; + +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +__dma_sync_page (sg_page (sg), sg->offset, sg->length, direction); }
@@ -235,7 +239,10 @@ static inline dma_addr_t dma_direct_map_page(struct device *dev, unsigned long attrs) {BUG_ON (dir ==DMA_NONE ); -__dma_sync_page (page, offset, size, dir); + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_sync_page (page, offset, size, dir); +return page_to_phys (page) + offset +get_dma_offset (dev); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [mm PATCH v2 18/26] arch/powerpc: Add option to skip DMA sync as a part of mapping
Quoted 4 lines · Alexander Duyck
This change allows us to pass
DMA_ATTR_SKIP_CPU_SYNCwhich allows us to avoid invoking cache line invalidation if the driver will just handle it via async_for_cpuorsync_for_devicecall.
Quoted 8 lines
Cc Benjamin Herrenschmidt <[email protected]>Cc Paul Mackerras <[email protected]>Cc Michael Ellerman <[email protected]>Signed-off-by Alexander Duyck <[email protected]>--- arch/powerpc/kernel/dma.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
LGTM.
cheers
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 19/26 arch/sh: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/sh/kernel/dma-nommu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/sh/kernel/dma-nommu.c +5 -2
@@ -18,7 +18,9 @@ static dma_addr_t nommu_map_page(struct device *dev, struct page *page,dma_addr_t addr =page_to_phys (page) + offset;WARN_ON (size =0 ); -dma_cache_sync (dev,page_address (page) + offset, size, dir); + +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_cache_sync (dev,page_address (page) + offset, size, dir);return addr; }
@@ -35,7 +37,8 @@ static int nommu_map_sg(struct device *dev, struct scatterlist *sg,for_each_sg (sg, s, nents, i) {BUG_ON (!sg_page (s)); -dma_cache_sync (dev,sg_virt (s), s->length, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +dma_cache_sync (dev,sg_virt (s), s->length, dir); s->dma_address =sg_phys (s); s->dma_length = s->length;
PATCH v2 20/26 arch/sparc: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/sparc/kernel/iommu.c | 4 ++-- arch/sparc/kernel/ioport.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
arch/sparc/kernel/iommu.c +2 -2
@@ -415,7 +415,7 @@ static void dma_4u_unmap_page(struct device *dev, dma_addr_t bus_addr, ctx = (iopte_val (*base) &IOPTE_CONTEXT ) >>47UL ;/* Step 1: Kick data out of streaming buffers if necessary. */ -if (strbuf->strbuf_enabled) +if (strbuf->strbuf_enabled && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))strbuf_flush (strbuf, iommu, bus_addr, ctx, npages, direction);
@@ -640,7 +640,7 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist, base = iommu->page_table + entry; dma_handle &=IO_PAGE_MASK ; -if (strbuf->strbuf_enabled) +if (strbuf->strbuf_enabled && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))strbuf_flush (strbuf, iommu, dma_handle, ctx, npages, direction);
arch/sparc/kernel/ioport.c +2 -2
@@ -527,7 +527,7 @@ static dma_addr_t pci32_map_page(struct device *dev, struct page *page,static void pci32_unmap_page (struct device *dev,dma_addr_t ba,size_t size,enum dma_data_direction dir,unsigned long attrs) { -if (dir !=PCI_DMA_TODEVICE ) +if (dir !=PCI_DMA_TODEVICE && !(attrs &DMA_ATTR_SKIP_CPU_SYNC ))dma_make_coherent (ba,PAGE_ALIGN (size)); }
@@ -572,7 +572,7 @@ static void pci32_unmap_sg(struct device *dev, struct scatterlist *sgl,struct scatterlist *sg;int n; -if (dir !=PCI_DMA_TODEVICE ) { +if (dir !=PCI_DMA_TODEVICE && !(attrs &DMA_ATTR_SKIP_CPU_SYNC )) {for_each_sg (sgl, sg, nents, n) {dma_make_coherent (sg_phys (sg),PAGE_ALIGN (sg->length)); }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 21/26 arch/tile: Add option to skip DMA sync as a part of map and unmap
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/tile/kernel/pci-dma.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/tile/kernel/pci-dma.c +10 -2
@@ -213,10 +213,12 @@ static int tile_dma_map_sg(struct device *dev, struct scatterlist *sglist,for_each_sg (sglist, sg, nents, i) { sg->dma_address =sg_phys (sg); -__dma_prep_pa_range (sg->dma_address, sg->length, direction);#ifdef CONFIG_NEED_SG_DMA_LENGTH sg->dma_length = sg->length;#endif +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ; +__dma_prep_pa_range (sg->dma_address, sg->length, direction); }return nents;
@@ -232,6 +234,8 @@ static void tile_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,BUG_ON (!valid_dma_direction (direction));for_each_sg (sglist, sg, nents, i) { sg->dma_address =sg_phys (sg); +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +continue ;__dma_complete_pa_range (sg->dma_address, sg->length, direction); }
@@ -245,7 +249,8 @@ static dma_addr_t tile_dma_map_page(struct device *dev, struct page *page,BUG_ON (!valid_dma_direction (direction));BUG_ON (offset + size >PAGE_SIZE ); -__dma_prep_page (page, offset, size, direction); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +__dma_prep_page (page, offset, size, direction);return page_to_pa (page) + offset; }
@@ -256,6 +261,9 @@ static void tile_dma_unmap_page(struct device *dev, dma_addr_t dma_address, {BUG_ON (!valid_dma_direction (direction)); +if (attrs &DMA_ATTR_SKIP_CPU_SYNC ) +return ; +__dma_complete_page (pfn_to_page (PFN_DOWN (dma_address)), dma_address & (PAGE_SIZE -1 ), size, direction); }
PATCH v2 22/26 arch/xtensa: Add option to skip DMA sync as a part of mapping
In reply to Alexander DuyckThis change allows us to pass DMA_ATTR_SKIP_CPU_SYNC which allows us to avoid invoking cache line invalidation if the driver will just handle it via a sync_for_cpu or sync_for_device call.
--- arch/xtensa/kernel/pci-dma.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
arch/xtensa/kernel/pci-dma.c +5 -2
@@ -189,7 +189,9 @@ static dma_addr_t xtensa_map_page(struct device *dev, struct page *page, {dma_addr_t dma_handle =page_to_phys (page) + offset; -xtensa_sync_single_for_device (dev, dma_handle, size, dir); +if (!(attrs &DMA_ATTR_SKIP_CPU_SYNC )) +xtensa_sync_single_for_device (dev, dma_handle, size, dir); +return dma_handle; }
@@ -197,7 +199,8 @@ static void xtensa_unmap_page(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction dir, unsigned long attrs) { -xtensa_sync_single_for_cpu (dev ,dma_handle ,size ,dir ); + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) + xtensa_sync_single_for_cpu(dev, dma_handle, size, dir); } static int xtensa_map_sg(struct device *dev, struct scatterlist *sg,
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 23/26 dma: Add calls for dma_map_page_attrs and dma_unmap_page_attrs
In reply to Alexander DuyckAdd support for mapping and unmapping a page with attributes. The primary use for this is currently to allow for us to pass the DMA_ATTR_SKIP_CPU_SYNC attribute when mapping and unmapping a page. On some architectures such as ARM the synchronization has significant overhead and if we are already taking care of the sync_for_cpu and sync_for_device from the driver there isn't much need to handle this in the map/unmap calls as well.
--- include/linux/dma-mapping.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
include/linux/dma-mapping.h +13 -7
@@ -243,29 +243,33 @@ static inline void dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sg ops->unmap_sg (dev, sg, nents, dir, attrs); } -static inline dma_addr_t dma_map_page (struct device *dev,struct page *page, -size_t offset,size_t size, -enum dma_data_direction dir) +static inline dma_addr_t dma_map_page_attrs (struct device *dev, +struct page *page, +size_t offset,size_t size, +enum dma_data_direction dir, +unsigned long attrs) {struct dma_map_ops *ops =get_dma_ops (dev);dma_addr_t addr;kmemcheck_mark_initialized (page_address (page) + offset, size);BUG_ON (!valid_dma_direction (dir)); - addr = ops->map_page (dev, page, offset, size, dir,0 ); + addr = ops->map_page (dev, page, offset, size, dir, attrs);debug_dma_map_page (dev, page, offset, size, dir, addr, false);return addr; } -static inline void dma_unmap_page (struct device *dev,dma_addr_t addr, -size_t size,enum dma_data_direction dir) +static inline void dma_unmap_page_attrs (struct device *dev, +dma_addr_t addr,size_t size, +enum dma_data_direction dir, +unsigned long attrs) {struct dma_map_ops *ops =get_dma_ops (dev);BUG_ON (!valid_dma_direction (dir));if (ops->unmap_page) - ops->unmap_page (dev, addr, size, dir,0 ); + ops->unmap_page (dev, addr, size, dir, attrs);debug_dma_unmap_page (dev, addr, size, dir, false); }
@@ -385,6 +389,8 @@ static inline void dma_sync_single_range_for_device(struct device *dev,#define dma_unmap_single (d, a, s, r) dma_unmap_single_attrs(d, a, s, r, 0)#define dma_map_sg (d, s, n, r) dma_map_sg_attrs(d, s, n, r, 0)#define dma_unmap_sg (d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, 0) +#define dma_map_page (d, p, o, s, r) dma_map_page_attrs(d, p, o, s, r, 0) +#define dma_unmap_page (d, a, s, r) dma_unmap_page_attrs(d, a, s, r, 0)extern int dma_common_mmap (struct device *dev,struct vm_area_struct *vma,void *cpu_addr,dma_addr_t dma_addr,size_t size);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 24/26 mm: Add support for releasing multiple instances of a page
In reply to Alexander DuyckThis patch adds a function that allows us to batch free a page that has multiple references outstanding. Specifically this function can be used to drop a page being used in the page frag alloc cache. With this drivers can make use of functionality similar to the page frag alloc cache without having to do any workarounds for the fact that there is no function that frees multiple references.
--- include/linux/gfp.h | 2 ++ mm/page_alloc.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
include/linux/gfp.h +2 -0
@@ -506,6 +506,8 @@ extern struct page *alloc_pages_vma(gfp_t gfp_mask, int order,extern void free_hot_cold_page_list (struct list_head *list,bool cold);struct page_frag_cache ; +extern void __page_frag_drain (struct page *page,unsigned int order, +unsigned int count);extern void *__alloc_page_frag (struct page_frag_cache *nc,unsigned int fragsz,gfp_t gfp_mask);extern void __free_page_frag (void *addr);
mm/page_alloc.c +14 -0
@@ -3938,6 +3938,20 @@ static struct page *__page_frag_refill(struct page_frag_cache *nc,return page; } +void __page_frag_drain (struct page *page,unsigned int order, +unsigned int count) +{ +VM_BUG_ON_PAGE (page_ref_count (page) ==0 , page); + +if (page_ref_sub_and_test (page, count)) { +if (order ==0 ) +free_hot_cold_page (page, false); +else +__free_pages_ok (page, order); + } +} +EXPORT_SYMBOL (__page_frag_drain); +void *__alloc_page_frag (struct page_frag_cache *nc,unsigned int fragsz,gfp_t gfp_mask) {
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 25/26 igb: Update driver to make use of DMA_ATTR_SKIP_CPU_SYNC
In reply to Alexander DuyckThe ARM architecture provides a mechanism for deferring cache line invalidation in the case of map/unmap. This patch makes use of this mechanism to avoid unnecessary synchronization.
A secondary effect of this change is that the portion of the page that has been synchronized for use by the CPU should be writable and could be passed up the stack (at least on ARM).
The last bit that occurred to me is that on architectures where the sync_for_cpu call invalidates cache lines we were prefetching and then invalidating the first 128 bytes of the packet. To avoid that I have moved the sync up to before we perform the prefetch and allocate the skbuff so that we can actually make use of it.
--- drivers/net/ethernet/intel/igb/igb_main.c | 53 ++++++++++++++++++----------- 1 file changed, 33 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +33 -20
@@ -3947,10 +3947,21 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring)if (!buffer_info->page)continue ; -dma_unmap_page (rx_ring->dev, - buffer_info->dma, -PAGE_SIZE , -DMA_FROM_DEVICE ); +/* Invalidate cache lines that may have been written to by +* device so that we avoid corrupting memory. +*/ +dma_sync_single_range_for_cpu (rx_ring->dev, + buffer_info->dma, + buffer_info->page_offset, +IGB_RX_BUFSZ , +DMA_FROM_DEVICE ); + +/* free resources associated with mapping */ +dma_unmap_page_attrs (rx_ring->dev, + buffer_info->dma, +PAGE_SIZE , +DMA_FROM_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC );__free_page (buffer_info->page); buffer_info->page =NULL ;
@@ -6808,12 +6819,6 @@ static void igb_reuse_rx_page(struct igb_ring *rx_ring,/* transfer page from old buffer to new buffer */ *new_buff = *old_buff; - -/* sync the buffer for use by the device */ -dma_sync_single_range_for_device (rx_ring->dev, old_buff->dma, - old_buff->page_offset, -IGB_RX_BUFSZ , -DMA_FROM_DEVICE ); }static inline bool igb_page_is_reserved (struct page *page)
@@ -6934,6 +6939,13 @@ static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring, page = rx_buffer->page;prefetchw (page); +/* we are reusing so sync this buffer for CPU use */ +dma_sync_single_range_for_cpu (rx_ring->dev, + rx_buffer->dma, + rx_buffer->page_offset, + size, +DMA_FROM_DEVICE ); +if (likely (!skb)) {void *page_addr =page_address (page) + rx_buffer->page_offset;
@@ -6958,21 +6970,15 @@ static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,prefetchw (skb->data); } -/* we are reusing so sync this buffer for CPU use */ -dma_sync_single_range_for_cpu (rx_ring->dev, - rx_buffer->dma, - rx_buffer->page_offset, - size, -DMA_FROM_DEVICE ); -/* pull page into skb */ if (igb_add_rx_frag (rx_ring, rx_buffer, size, rx_desc, skb)) {/* hand second half of page back to the ring */ igb_reuse_rx_page (rx_ring, rx_buffer); }else {/* we are not reusing the buffer so unmap it */ -dma_unmap_page (rx_ring->dev, rx_buffer->dma, -PAGE_SIZE ,DMA_FROM_DEVICE ); +dma_unmap_page_attrs (rx_ring->dev, rx_buffer->dma, +PAGE_SIZE ,DMA_FROM_DEVICE , +DMA_ATTR_SKIP_CPU_SYNC ); }/* clear contents of rx_buffer */
@@ -7230,7 +7236,8 @@ static bool igb_alloc_mapped_page(struct igb_ring *rx_ring, }/* map page for use */ - dma =dma_map_page (rx_ring->dev, page,0 ,PAGE_SIZE ,DMA_FROM_DEVICE ); + dma =dma_map_page_attrs (rx_ring->dev, page,0 ,PAGE_SIZE , +DMA_FROM_DEVICE ,DMA_ATTR_SKIP_CPU_SYNC );/* if mapping failed free memory back to system since * there isn't much point in holding memory we can't use
@@ -7271,6 +7278,12 @@ void igb_alloc_rx_buffers(struct igb_ring *rx_ring, u16 cleaned_count)if (!igb_alloc_mapped_page (rx_ring, bi))break ; +/* sync the buffer for use by the device */ +dma_sync_single_range_for_device (rx_ring->dev, bi->dma, + bi->page_offset, +IGB_RX_BUFSZ , +DMA_FROM_DEVICE ); +/* Refresh the desc even if buffer_addrs didn't change * because each write-back erases this info. */
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v2 26/26 igb: Update code to better handle incrementing page count
In reply to Alexander DuyckThis patch updates the driver code so that we do bulk updates of the page reference count instead of just incrementing it by one reference at a time. The advantage to doing this is that we cut down on atomic operations and this in turn should give us a slight improvement in cycles per packet. In addition if we eventually move this over to using build_skb the gains will be more noticeable.
--- drivers/net/ethernet/intel/igb/igb.h | 7 ++++++- drivers/net/ethernet/intel/igb/igb_main.c | 24 +++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/igb/igb.h +6 -1
@@ -210,7 +210,12 @@ struct igb_tx_buffer {struct igb_rx_buffer {dma_addr_t dma;struct page *page; -unsigned int page_offset; +#if (BITS_PER_LONG >32 ) || (PAGE_SIZE >=65536 ) +__u32 page_offset; +#else +__u16 page_offset; +#endif +__u16 pagecnt_bias; };struct igb_tx_queue_stats {
drivers/net/ethernet/intel/igb/igb_main.c +17 -7
@@ -3962,7 +3962,8 @@ static void igb_clean_rx_ring(struct igb_ring *rx_ring)PAGE_SIZE ,DMA_FROM_DEVICE , DMA_ATTR_SKIP_CPU_SYNC); -__free_page (buffer_info->page); +__page_frag_drain (buffer_info->page,0 , + buffer_info->pagecnt_bias); buffer_info->page =NULL ; }
@@ -6830,13 +6831,15 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer, struct page *page, unsigned int truesize) { +unsigned int pagecnt_bias = rx_buffer->pagecnt_bias--; +/* avoid re-using remote pages */ if (unlikely (igb_page_is_reserved (page)))return false;#if (PAGE_SIZE <8192 )/* if we are only owner of page we can reuse it */ -if (unlikely (page_count (page) !=1 )) +if (unlikely (page_ref_count (page) != pagecnt_bias))return false;/* flip page offset to other buffer */
@@ -6849,10 +6852,14 @@ static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,return false;#endif -/* Even if we own the page, we are not allowed to use atomic_set() -* This would break get_page_unless_zero() users. +/* If we have drained the page fragment pool we need to update +* the pagecnt_bias and page count so that we fully restock the +* number of references the driver holds. */ -page_ref_inc (page); +if (unlikely (pagecnt_bias ==1 )) { +page_ref_add (page,USHRT_MAX ); + rx_buffer->pagecnt_bias =USHRT_MAX ; + }return true; }
@@ -6904,7 +6911,6 @@ static bool igb_add_rx_frag(struct igb_ring *rx_ring,return true;/* this page cannot be reused so discard it */ -__free_page (page);return false; }
@@ -6975,10 +6981,13 @@ static struct sk_buff *igb_fetch_rx_buffer(struct igb_ring *rx_ring,/* hand second half of page back to the ring */ igb_reuse_rx_page (rx_ring, rx_buffer); }else { -/* we are not reusing the buffer so unmap it */ +/* We are not reusing the buffer so unmap it and free +* any references we are holding to it +*/ dma_unmap_page_attrs (rx_ring->dev, rx_buffer->dma,PAGE_SIZE ,DMA_FROM_DEVICE ,DMA_ATTR_SKIP_CPU_SYNC ); +__page_frag_drain (page,0 , rx_buffer->pagecnt_bias); }/* clear contents of rx_buffer */
@@ -7252,6 +7261,7 @@ static bool igb_alloc_mapped_page(struct igb_ring *rx_ring, bi->dma = dma; bi->page = page; bi->page_offset =0 ; + bi->pagecnt_bias =1 ;return true; }
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>