Skip to contentSkip to conversation

FAILED: patch "[PATCH] iommu/dma: Trace bounce buffer usage when mapping buffers" failed to apply to 5.15-stable tree

PATCH In review [email protected] 4 participants 7 messages Jan 22, 2024 – Jun 14, 2024

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x a63c357b9fd56ad5fe64616f5b22835252c6a76a
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2024012226-unmanned-marshy-5819@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..

Possible dependencies:

a63c357b9fd5 ("iommu/dma: Trace bounce buffer usage when mapping buffers") f316ba0a8814 ("dma-iommu: Check that swiotlb is active before trying to use it") a17e3026bc4d ("iommu: Move flush queue data into iommu_dma_cookie") f7f07484542f ("iommu/iova: Move flush queue code to iommu-dma") ea4d71bb5e3f ("iommu/iova: Consolidate flush queue code") 87f60cc65d24 ("iommu/vt-d: Use put_pages_list")
649ad9835a37 ("iommu/iova: Squash flush_cb abstraction") d5c383f2c98a ("iommu/iova: Squash entry_dtor abstraction") d7061627d701 ("iommu/iova: Fix race between FQ timeout and teardown") 2e727bffbe93 ("iommu/dma: Check CONFIG_SWIOTLB more broadly") 9b49bbc2c4df ("iommu/dma: Fold _swiotlb helpers into callers") ee9d4097cc14 ("iommu/dma: Skip extra sync during unmap w/swiotlb") 06e620345d54 ("iommu/dma: Fix arch_sync_dma for map")
08ae5d4a1ae9 ("iommu/dma: Fix sync_sg with swiotlb")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From a63c357b9fd56ad5fe64616f5b22835252c6a76a Mon Sep 17 00:00:00 2001
From: "Isaac J. Manjarres" <[email protected]>
Date: Fri, 8 Dec 2023 15:41:40 -0800
Subject: [PATCH] iommu/dma: Trace bounce buffer usage when mapping buffers

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
drivers/iommu/dma-iommu.c +3 -0
index 85163a83df2f..037fcf826407 100644
@@ -29,6 +29,7 @@
 #include <linux/spinlock.h>
 #include <linux/swiotlb.h>
 #include <linux/vmalloc.h>
+#include <trace/events/swiotlb.h>
 
 #include "dma-iommu.h"
 
@@ -1156,6 +1157,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
 			return DMA_MAPPING_ERROR;
 		}
 
+		trace_swiotlb_bounced(dev, phys, size);
+
 		aligned_size = iova_align(iovad, size);
 		phys = swiotlb_tbl_map_single(dev, phys, size, aligned_size,
 					      iova_mask(iovad), dir, attrs);
#1 lore raw

PATCH 1/1 iommu/dma: Trace bounce buffer usage when mapping buffers

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)
---
 drivers/iommu/dma-iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/dma-iommu.c +3 -0
index 48c6f7ff4aef..8cd63e6ccd2c 100644
@@ -25,6 +25,7 @@
 #include <linux/vmalloc.h>
 #include <linux/crash_dump.h>
 #include <linux/dma-direct.h>
+#include <trace/events/swiotlb.h>
 
 struct iommu_dma_msi_page {
 	struct list_head	list;
@@ -817,6 +818,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
 		void *padding_start;
 		size_t padding_size, aligned_size;
 
+		trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
+
 		aligned_size = iova_align(iovad, size);
 		phys = swiotlb_tbl_map_single(dev, phys, size, aligned_size,
 					      iova_mask(iovad), dir, attrs);
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
#2 lore raw

Re: [PATCH 5.15.y] iommu/dma: Trace bounce buffer usage when mapping buffers

Quoted 9 lines · Isaac J. Manjarres

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Quoted 10 lines
Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)

Now queued up, thanks.

greg k-h

#3 lore raw

Re: [PATCH 5.15.y] iommu/dma: Trace bounce buffer usage when mapping buffers

In reply to Isaac J. Manjarres
Quoted 36 lines · Isaac J. Manjarres

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)
---
 drivers/iommu/dma-iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/dma-iommu.c +1 -0
index 48c6f7ff4aef..8cd63e6ccd2c 100644
@@ -25,6 +25,7 @@
 #include <linux/vmalloc.h>
 #include <linux/crash_dump.h>
 #include <linux/dma-direct.h>
+#include <trace/events/swiotlb.h>
 
 struct iommu_dma_msi_page {
 	struct list_head	list;

drivers/iommu/dma-iommu.c static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, · line 822

Quoted 5 lines
drivers/iommu/dma-iommu.c +2 -0
@@ -817,6 +818,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
 		void *padding_start;
 		size_t padding_size, aligned_size;
 
+		trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
+

Hi, this backported patch trying to access swiotlb_force variable is causing a build conflict where CONFIG_SWIOTLB is not enabled.

In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
enum swiotlb_force swiotlb_force),
^
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'

#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
kernel/drivers/iommu/dma-iommu.c:865:42: error: argument type 'enum SWIOTLB_NO_FORCE' is incomplete
                                       trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
                                                                              ^~~~~~~~~~~~~
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^~~~~~~~~~~~~~~~
kernel/include/trace/events/swiotlb.h:15:9: note: forward declaration of 'enum SWIOTLB_NO_FORCE'
enum swiotlb_force swiotlb_force),
     ^

kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force' #define swiotlb_force SWIOTLB_NO_FORCE

--------------------------------------------------------------------------------------------------------------------------------------------------

I have a simple proposed fix which can resolve this compile time conflict when CONFIG_SWIOTLB is disabled.

include/trace/events/swiotlb.h +4 -0
@@ -7,6 +7,7 @@
 
 #include <linux/tracepoint.h>
 
+#ifdef CONFIG_SWIOTLB
 TRACE_EVENT(swiotlb_bounced,
 
        TP_PROTO(struct device *dev,
@@ -43,6 +44,9 @@ TRACE_EVENT(swiotlb_bounced,
                        { SWIOTLB_FORCE,        "FORCE" },
                        { SWIOTLB_NO_FORCE,     "NO_FORCE" }))
 );
+#else
+#define trace_swiotlb_bounced(dev, phys, size, swiotlb_force)
+#endif /* CONFIG_SWIOTLB */
 
 #endif /*  _TRACE_SWIOTLB_H */
 

Thanks & regards,
Bibek

Quoted 6 lines
drivers/iommu/dma-iommu.c +0 -0
 		aligned_size = iova_align(iovad, size);
 		phys = swiotlb_tbl_map_single(dev, phys, size, aligned_size,
 					      iova_mask(iovad), dir, attrs);
Signature · 1 line
2.43.0.429.g432eaa2c6b-goog
#4 lore raw

Re: [PATCH 5.15.y] iommu/dma: Trace bounce buffer usage when mapping buffers

Quoted 96 lines · Bibek Kumar Patro
Quoted 36 lines · Isaac J. Manjarres

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)
---
 drivers/iommu/dma-iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/dma-iommu.c +1 -0
index 48c6f7ff4aef..8cd63e6ccd2c 100644
@@ -25,6 +25,7 @@
 #include <linux/vmalloc.h>
 #include <linux/crash_dump.h>
 #include <linux/dma-direct.h>
+#include <trace/events/swiotlb.h>
 
 struct iommu_dma_msi_page {
 	struct list_head	list;

drivers/iommu/dma-iommu.c static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, · line 822

Quoted 5 lines
drivers/iommu/dma-iommu.c +2 -0
@@ -817,6 +818,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
 		void *padding_start;
 		size_t padding_size, aligned_size;
 
+		trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
+

Hi, this backported patch trying to access swiotlb_force variable is causing a build conflict where CONFIG_SWIOTLB is not enabled.

In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
enum swiotlb_force swiotlb_force),
^
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'

#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^
kernel/drivers/iommu/dma-iommu.c:865:42: error: argument type 'enum SWIOTLB_NO_FORCE' is incomplete
                                       trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
                                                                              ^~~~~~~~~~~~~
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                      ^~~~~~~~~~~~~~~~
kernel/include/trace/events/swiotlb.h:15:9: note: forward declaration of 'enum SWIOTLB_NO_FORCE'
enum swiotlb_force swiotlb_force),
     ^

kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force' #define swiotlb_force SWIOTLB_NO_FORCE

--------------------------------------------------------------------------------------------------------------------------------------------------

I have a simple proposed fix which can resolve this compile time conflict when CONFIG_SWIOTLB is disabled.

include/trace/events/swiotlb.h +1 -0
@@ -7,6 +7,7 @@
 
 #include <linux/tracepoint.h>
 
+#ifdef CONFIG_SWIOTLB
 TRACE_EVENT(swiotlb_bounced,
 
        TP_PROTO(struct device *dev,

include/trace/events/swiotlb.h TRACE_EVENT(swiotlb_bounced, · line 52

Quoted 9 lines
include/trace/events/swiotlb.h +3 -0
@@ -43,6 +44,9 @@ TRACE_EVENT(swiotlb_bounced,
                        { SWIOTLB_FORCE,        "FORCE" },
                        { SWIOTLB_NO_FORCE,     "NO_FORCE" }))
 );
+#else
+#define trace_swiotlb_bounced(dev, phys, size, swiotlb_force)
+#endif /* CONFIG_SWIOTLB */
 
 #endif /*  _TRACE_SWIOTLB_H */
 

Why not just take whatever change upstream fixes this instead of a one-off change?

thanks

greg k-h

#5 lore raw

Re: [PATCH 5.15.y] iommu/dma: Trace bounce buffer usage when mapping buffers

Quoted 103 lines · Greg KH
Quoted 102 lines · Bibek Kumar Patro
Quoted 36 lines · Isaac J. Manjarres

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)
---
  drivers/iommu/dma-iommu.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/iommu/dma-iommu.c +1 -0
index 48c6f7ff4aef..8cd63e6ccd2c 100644
@@ -25,6 +25,7 @@
  #include <linux/vmalloc.h>
  #include <linux/crash_dump.h>
  #include <linux/dma-direct.h>
+#include <trace/events/swiotlb.h>
 
  struct iommu_dma_msi_page {
  	struct list_head	list;

drivers/iommu/dma-iommu.c static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, · line 822

Quoted 5 lines
drivers/iommu/dma-iommu.c +2 -0
@@ -817,6 +818,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
  		void *padding_start;
  		size_t padding_size, aligned_size;
 
+		trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
+

Hi, this backported patch trying to access swiotlb_force variable is causing a build conflict where CONFIG_SWIOTLB is not enabled.

In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
enum swiotlb_force swiotlb_force),
^
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'

#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
kernel/drivers/iommu/dma-iommu.c:865:42: error: argument type 'enum SWIOTLB_NO_FORCE' is incomplete
                                        trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
                                                                               ^~~~~~~~~~~~~
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^~~~~~~~~~~~~~~~
kernel/include/trace/events/swiotlb.h:15:9: note: forward declaration of 'enum SWIOTLB_NO_FORCE'
enum swiotlb_force swiotlb_force),
      ^

kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force' #define swiotlb_force SWIOTLB_NO_FORCE

--------------------------------------------------------------------------------------------------------------------------------------------------

I have a simple proposed fix which can resolve this compile time conflict when CONFIG_SWIOTLB is disabled.

include/trace/events/swiotlb.h +4 -0
@@ -7,6 +7,7 @@
 
  #include <linux/tracepoint.h>
 
+#ifdef CONFIG_SWIOTLB
  TRACE_EVENT(swiotlb_bounced,
 
         TP_PROTO(struct device *dev,
@@ -43,6 +44,9 @@ TRACE_EVENT(swiotlb_bounced,
                         { SWIOTLB_FORCE,        "FORCE" },
                         { SWIOTLB_NO_FORCE,     "NO_FORCE" }))
  );
+#else
+#define trace_swiotlb_bounced(dev, phys, size, swiotlb_force)
+#endif /* CONFIG_SWIOTLB */
 
Quoted 7 lines

include/trace/events/swiotlb.h TRACE_EVENT(swiotlb_bounced, · line 52

Quoted 3 lines
include/trace/events/swiotlb.h +0 -0
  #endif /*  _TRACE_SWIOTLB_H */
 

Why not just take whatever change upstream fixes this instead of a one-off change?

I am currently checking the history on swiotlb_force and how it's removed in latest kernel versions. If those changes are applicable on this stable branch can we explore backporting those instead of this one- off change ?

Thanks & regards,
Bibek

Quoted 3 lines

thanks

greg k-h

#6 lore raw

Re: [PATCH 5.15.y] iommu/dma: Trace bounce buffer usage when mapping buffers

Quoted 112 lines · Bibek Kumar Patro
Quoted 101 lines · Greg KH
Quoted 100 lines · Bibek Kumar Patro
Quoted 35 lines · Isaac J. Manjarres

When commit 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers") was introduced, it did not add the logic for tracing the bounce buffer usage from iommu_dma_map_page().

All of the users of swiotlb_tbl_map_single() trace their bounce buffer usage, except iommu_dma_map_page(). This makes it difficult to track SWIOTLB usage from that function. Thus, trace bounce buffer usage from iommu_dma_map_page().

Fixes 82612d66d51d ("iommu: Allow the dma-iommu api to use bounce buffers")
Cc [email protected] # v5.15+
Cc Tom Murphy <[email protected]>
Cc Lu Baolu <[email protected]>
Cc Saravana Kannan <[email protected]>
(cherry picked from commit a63c357b9fd56ad5fe64616f5b22835252c6a76a)
---
  drivers/iommu/dma-iommu.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/iommu/dma-iommu.c +1 -0
index 48c6f7ff4aef..8cd63e6ccd2c 100644
@@ -25,6 +25,7 @@
  #include <linux/vmalloc.h>
  #include <linux/crash_dump.h>
  #include <linux/dma-direct.h>
+#include <trace/events/swiotlb.h>
  struct iommu_dma_msi_page {
  	struct list_head	list;

drivers/iommu/dma-iommu.c static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, · line 821

Quoted 4 lines
drivers/iommu/dma-iommu.c +2 -0
@@ -817,6 +818,8 @@ static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
  		void *padding_start;
  		size_t padding_size, aligned_size;
+		trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
+

Hi, this backported patch trying to access swiotlb_force variable is causing a build conflict where CONFIG_SWIOTLB is not enabled.

In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
enum swiotlb_force swiotlb_force),
^
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'

#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
In file included from kernel/drivers/iommu/dma-iommu.c:28:
kernel/include/trace/events/swiotlb.h:15:9: error: declaration of 'enum SWIOTLB_NO_FORCE' will not be visible outside of this function [-Werror,-Wvisibility]
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^
kernel/drivers/iommu/dma-iommu.c:865:42: error: argument type 'enum SWIOTLB_NO_FORCE' is incomplete
                                        trace_swiotlb_bounced(dev, phys, size, swiotlb_force);
                                                                               ^~~~~~~~~~~~~
kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force'
#define swiotlb_force SWIOTLB_NO_FORCE
                       ^~~~~~~~~~~~~~~~
kernel/include/trace/events/swiotlb.h:15:9: note: forward declaration of 'enum SWIOTLB_NO_FORCE'
enum swiotlb_force swiotlb_force),
      ^

kernel/include/linux/swiotlb.h:143:23: note: expanded from macro 'swiotlb_force' #define swiotlb_force SWIOTLB_NO_FORCE

--------------------------------------------------------------------------------------------------------------------------------------------------

I have a simple proposed fix which can resolve this compile time conflict when CONFIG_SWIOTLB is disabled.

include/trace/events/swiotlb.h +4 -0
@@ -7,6 +7,7 @@
 
  #include <linux/tracepoint.h>
 
+#ifdef CONFIG_SWIOTLB
  TRACE_EVENT(swiotlb_bounced,
 
         TP_PROTO(struct device *dev,
@@ -43,6 +44,9 @@ TRACE_EVENT(swiotlb_bounced,
                         { SWIOTLB_FORCE,        "FORCE" },
                         { SWIOTLB_NO_FORCE,     "NO_FORCE" }))
  );
+#else
+#define trace_swiotlb_bounced(dev, phys, size, swiotlb_force)
+#endif /* CONFIG_SWIOTLB */
 
Quoted 7 lines

include/trace/events/swiotlb.h TRACE_EVENT(swiotlb_bounced, · line 52

Quoted 3 lines
include/trace/events/swiotlb.h +0 -0
  #endif /*  _TRACE_SWIOTLB_H */
 

Why not just take whatever change upstream fixes this instead of a one-off change?

Quoted 4 lines

I am currently checking the history on swiotlb_force and how it's removed in latest kernel versions. If those changes are applicable on this stable branch can we explore backporting those instead of this one- off change ?

Please backport what is in the tree already.