Skip to contentSkip to conversation

swiotlb: Fix inversed DMA_ATTR_NO_WARN test

PATCH Applied Michel Dänzer 4 participants 11 messages May 1, 2018 – May 25, 2018 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swiotlb: Fix inversed DMA_ATTR_NO_WARN test

From: Michel Dänzer <[email protected]>

The result was printing the warning only when we were explicitly asked not to.

Fixes 0176adb004065d6815a8e67946752df4cd947c5b "swiotlb: refactor

coherent buffer allocation"

---
 lib/swiotlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/swiotlb.c +1 -1
index c43ec2271469..e9ac21540628 100644
@@ -750,7 +750,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle,
 	swiotlb_tbl_unmap_single(dev, phys_addr, size, DMA_TO_DEVICE,
 			DMA_ATTR_SKIP_CPU_SYNC);
 out_warn:
-	if ((attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
+	if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
 		dev_warn(dev,
 			"swiotlb: coherent allocation failed, size=%zu\n",
 			size);
Signature · 6 lines
2.17.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw

Am 01.05.2018 um 15:24 schrieb Michel Dänzer:

Quoted 9 lines

From: Michel Dänzer <[email protected]>

The result was printing the warning only when we were explicitly asked not to.

Fixes 0176adb004065d6815a8e67946752df4cd947c5b "swiotlb: refactor

coherent buffer allocation"

Good catch, looked at the code multiple times and haven't seen that myself :)

Christian.

Quoted 9 lines
---
  lib/swiotlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/swiotlb.c +0 -0
index c43ec2271469..e9ac21540628 100644

lib/swiotlb.c swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle, · line 756

Quoted 8 lines
lib/swiotlb.c +1 -1
@@ -750,7 +750,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size, dma_addr_t *dma_handle,
  	swiotlb_tbl_unmap_single(dev, phys_addr, size, DMA_TO_DEVICE,
  			DMA_ATTR_SKIP_CPU_SYNC);
  out_warn:
-	if ((attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
+	if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
  		dev_warn(dev,
  			"swiotlb: coherent allocation failed, size=%zu\n",
  			size);

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#2 lore raw
Quoted 13 lines · Christian König

Am 01.05.2018 um 15:24 schrieb Michel Dänzer:

Quoted 10 lines

From: Michel Dänzer <[email protected]>

The result was printing the warning only when we were explicitly asked not to.

Fixes 0176adb004065d6815a8e67946752df4cd947c5b "swiotlb: refactor

coherent buffer allocation"

Quoted 4 lines

Good catch, looked at the code multiple times and haven't seen that myself :)

Other dma-api backends like cma just shut up when __GFP_NOWARN is passed. And afaiui Christoph Hellwig has plans to nuke the DMA_ATTR stuff (or at least clean it up) - should we just remove DMA_ATTR_NO_WARN and instead only look at __GFP_NOWARN?

For context the CMA patch:

commit ef4650144e76ae361fe4b8c9a0afcd53074cd520

Author: Boris Brezillon <[email protected]>
Date:   Fri Oct 13 15:58:01 2017 -0700

mm/cma.c: take __GFP_NOWARN into account in cma_alloc()

Or maybe we should at least enforce that both or none are set, for consistency for now?

Cheers, Daniel

Quoted 27 lines

Christian.

Quoted 17 lines
---
  lib/swiotlb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/swiotlb.c +1 -1
index c43ec2271469..e9ac21540628 100644
@@ -750,7 +750,7 @@ swiotlb_alloc_buffer(struct device *dev, size_t size,
 dma_addr_t *dma_handle,
        swiotlb_tbl_unmap_single(dev, phys_addr, size, DMA_TO_DEVICE,
                        DMA_ATTR_SKIP_CPU_SYNC);
  out_warn:
-       if ((attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
+       if (!(attrs & DMA_ATTR_NO_WARN) && printk_ratelimit()) {
                dev_warn(dev,
                        "swiotlb: coherent allocation failed, size=%zu\n",
Quoted 1 line
                        size);

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw
Quoted 4 lines · Daniel Vetter

Other dma-api backends like cma just shut up when __GFP_NOWARN is passed. And afaiui Christoph Hellwig has plans to nuke the DMA_ATTR stuff (or at least clean it up) - should we just remove DMA_ATTR_NO_WARN and instead only look at __GFP_NOWARN?

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

Quoted 2 lines

Or maybe we should at least enforce that both or none are set, for consistency for now?

The interface should be DMA_ATTR_NO_WARN. __GFP_NOWARN in this context was never documented, and just slipped in.

#4 lore raw
Quoted 10 lines · Christoph Hellwig
Quoted 4 lines · Daniel Vetter

Other dma-api backends like cma just shut up when __GFP_NOWARN is passed. And afaiui Christoph Hellwig has plans to nuke the DMA_ATTR stuff (or at least clean it up) - should we just remove DMA_ATTR_NO_WARN and instead only look at __GFP_NOWARN?

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Signature · 2 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
#5 lore raw
Quoted 8 lines · Michel Dänzer
Quoted 4 lines

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Well, that is exactly what I don't want drivers to do - same for __GFP_COMP in some drm code. This very much assumes the page allocator is used to back dma allocations, which very often it actually isn't, and any use of magic gfp flags creates a tight coupling of consumers with a specific implementation.

In general I can't think of a good reason not to actually use GFP_TRANSHUGE_LIGHT by default in the dma allocator unless DMA_ATTR_ALLOC_SINGLE_PAGES is set. Can you prepare a patch for that?

#6 lore raw
Quoted 16 lines · Christoph Hellwig
Quoted 8 lines · Michel Dänzer
Quoted 4 lines

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Well, that is exactly what I don't want drivers to do - same for __GFP_COMP in some drm code. This very much assumes the page allocator is used to back dma allocations, which very often it actually isn't, and any use of magic gfp flags creates a tight coupling of consumers with a specific implementation.

Quoted 3 lines

In general I can't think of a good reason not to actually use GFP_TRANSHUGE_LIGHT by default in the dma allocator unless DMA_ATTR_ALLOC_SINGLE_PAGES is set. Can you prepare a patch for that?

I'm afraid I'll have to leave that to somebody else.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Am 02.05.2018 um 18:59 schrieb Michel Dänzer:

Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Michel Dänzer
Quoted 7 lines
Quoted 4 lines

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Well, that is exactly what I don't want drivers to do - same for __GFP_COMP in some drm code. This very much assumes the page allocator is used to back dma allocations, which very often it actually isn't, and any use of magic gfp flags creates a tight coupling of consumers with a specific implementation.

Quoted 4 lines
Quoted 3 lines

In general I can't think of a good reason not to actually use GFP_TRANSHUGE_LIGHT by default in the dma allocator unless DMA_ATTR_ALLOC_SINGLE_PAGES is set. Can you prepare a patch for that?

I'm afraid I'll have to leave that to somebody else.

Coming back to this topic once more, sorry for the delay but busy as usual :)

What exactly do you mean with "dma allocator" here? The TTM allocator using the dma_alloc_coherent calls? Or the swiotlb implementation of the calls?

Christian.

#8 lore raw
Quoted 19 lines · Christian König

Am 02.05.2018 um 18:59 schrieb Michel Dänzer:

Quoted 18 lines · Christoph Hellwig
Quoted 17 lines · Michel Dänzer
Quoted 7 lines
Quoted 4 lines

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Well, that is exactly what I don't want drivers to do - same for __GFP_COMP in some drm code. This very much assumes the page allocator is used to back dma allocations, which very often it actually isn't, and any use of magic gfp flags creates a tight coupling of consumers with a specific implementation.

In general I can't think of a good reason not to actually use GFP_TRANSHUGE_LIGHT by default in the dma allocator unless DMA_ATTR_ALLOC_SINGLE_PAGES is set. Can you prepare a patch for that?

Quoted 7 lines
Quoted 1 line

I'm afraid I'll have to leave that to somebody else.

Coming back to this topic once more, sorry for the delay but busy as usual :)

What exactly do you mean with "dma allocator" here? The TTM allocator using the dma_alloc_coherent calls? Or the swiotlb implementation of the calls?

dma allocatr in this case: backends for dma_alloc_coherent/ dma_alloc_attrs. Most importantly dma_direct_alloc.

But while we're at it I can't actually see any GFP_TRANSHUGE_LIGHT usage in TTM, just plain old GFP_TRANSHUGE.

#9 lore raw
Quoted 25 lines · Christoph Hellwig
Quoted 24 lines · Christian König

Am 02.05.2018 um 18:59 schrieb Michel Dänzer:

Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Michel Dänzer
Quoted 7 lines
Quoted 4 lines

No. __GFP_NOWARN (and gfp_t flags in general) are the wrong interface for dma allocations and just cause problems. I actually plan to get rid of the gfp_t argument in dma_alloc_attrs sooner, and only allow either GFP_KERNEL or GFP_DMA passed in dma_alloc_coherent.

How about GFP_TRANSHUGE_LIGHT? TTM uses that to opportunistically allocate huge pages (GFP_TRANSHUGE can result in unacceptably long delays with memory pressure).

Well, that is exactly what I don't want drivers to do - same for __GFP_COMP in some drm code. This very much assumes the page allocator is used to back dma allocations, which very often it actually isn't, and any use of magic gfp flags creates a tight coupling of consumers with a specific implementation.

Quoted 4 lines
Quoted 3 lines

In general I can't think of a good reason not to actually use GFP_TRANSHUGE_LIGHT by default in the dma allocator unless DMA_ATTR_ALLOC_SINGLE_PAGES is set. Can you prepare a patch for that?

I'm afraid I'll have to leave that to somebody else.

Coming back to this topic once more, sorry for the delay but busy as usual :)

Quoted 8 lines
Quoted 2 lines

What exactly do you mean with "dma allocator" here? The TTM allocator using the dma_alloc_coherent calls? Or the swiotlb implementation of the calls?

dma allocatr in this case: backends for dma_alloc_coherent/ dma_alloc_attrs. Most importantly dma_direct_alloc.

But while we're at it I can't actually see any GFP_TRANSHUGE_LIGHT usage in TTM, just plain old GFP_TRANSHUGE.

See
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=da291320baec914f0bb4e65a9dccb86bd6c728f2
.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel