Skip to contentSkip to conversation

drm/ttm: Implement and export ttm_dma_page_alloc_enabled

PATCH In review Thomas Hellstrom 4 participants 8 messages Jan 25, 2019 – Jan 30, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/ttm: Implement and export ttm_dma_page_alloc_enabled

The vmwgfx driver needs to know whether the dma page pool is enabled to determine whether to refuse loading if the dma mode logic requests coherent memory from the dma page pool.

Cc "Koenig, Christian" <[email protected]>
---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 +++++++++++
 include/drm/ttm/ttm_page_alloc.h         |  4 ++++
 2 files changed, 15 insertions(+)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +11 -0
index d594f7520b7b..adf8cc189ecc 100644
@@ -1235,4 +1235,15 @@ int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
 }
 EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
 
+/**
+ * ttm_dma_page_alloc_enabled - Is the dma page pool enabled?
+ *
+ * Returns true if the dma page pool is enabled. false otherwise.
+ */
+bool ttm_dma_page_alloc_enabled(void)
+{
+	return !!_manager;
+}
+EXPORT_SYMBOL(ttm_dma_page_alloc_enabled);
+
 #endif
include/drm/ttm/ttm_page_alloc.h +4 -0
index 4d9b019d253c..f810d389f5ad 100644
@@ -94,6 +94,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 			struct ttm_operation_ctx *ctx);
 void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
 
+bool ttm_dma_page_alloc_enabled(void);
+
 #else
 static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
 					  unsigned max_pages)
@@ -117,6 +119,8 @@ static inline void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma,
 				      struct device *dev)
 {
 }
+
+static inline bool ttm_dma_page_alloc_enabled(void) { return false; }
 #endif
 
 #endif
Signature · 6 lines
2.19.0.rc1

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

PATCH 2/2 drm/vmwgfx: Use ttm_dma_page_alloc_enabled

Instead of guessing whether TTM has the dma page allocator enabled, ask TTM.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +2 -2
index 77f422cd18ab..125a2b423847 100644
@@ -35,6 +35,7 @@
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_page_alloc.h>
 
 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
 #define VMWGFX_CHIP_SVGAII 0
@@ -594,8 +595,7 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 	if (dev_priv->map_mode == vmw_dma_map_populate && vmw_restrict_iommu)
 		dev_priv->map_mode = vmw_dma_map_bind;
 
-	/* No TTM coherent page pool? FIXME: Ask TTM instead! */
-        if (!(IS_ENABLED(CONFIG_SWIOTLB) || IS_ENABLED(CONFIG_INTEL_IOMMU)) &&
+        if (!ttm_dma_page_alloc_enabled() &&
 	    (dev_priv->map_mode == vmw_dma_alloc_coherent))
 		return -EINVAL;
 
Signature · 6 lines
2.19.0.rc1

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

Re: [PATCH 2/2] drm/vmwgfx: Use ttm_dma_page_alloc_enabled

Hi Thomas.

One little nit, and an improvment proposal (for another patch/day).

Quoted 21 lines · Thomas Hellstrom

Instead of guessing whether TTM has the dma page allocator enabled, ask TTM.

---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -0
index 77f422cd18ab..125a2b423847 100644
@@ -35,6 +35,7 @@
 #include <drm/ttm/ttm_placement.h>
 #include <drm/ttm/ttm_bo_driver.h>
 #include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_page_alloc.h>
 
 #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
 #define VMWGFX_CHIP_SVGAII 0

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_dma_select_mode(struct vmw_private *dev_priv) · line 598

Quoted 6 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -2
@@ -594,8 +595,7 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
 	if (dev_priv->map_mode == vmw_dma_map_populate && vmw_restrict_iommu)
 		dev_priv->map_mode = vmw_dma_map_bind;
 
-	/* No TTM coherent page pool? FIXME: Ask TTM instead! */
-        if (!(IS_ENABLED(CONFIG_SWIOTLB) || IS_ENABLED(CONFIG_INTEL_IOMMU)) &&
+        if (!ttm_dma_page_alloc_enabled() &&

The line uses spaces for indent, tabs?

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_dma_select_mode(struct vmw_private *dev_priv) · line 599

Quoted 1 line
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -0
 	    (dev_priv->map_mode == vmw_dma_alloc_coherent))

The code could benefit from a:
static bool is_map_coherent(const struct vmw_private *dev_priv)

{
	return dev_priv->map_mode == vmw_dma_alloc_coherent;
}

Then the above would become:

	if (!ttm_dma_page_alloc_enabled() && is_map_coherent(dev_priv))

And the other places that test for vmw_dma_alloc_coherent would be a bit simpler too.
Same goes for the other map types obviously.

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

#3 lore raw

Re: [PATCH 2/2] drm/vmwgfx: Use ttm_dma_page_alloc_enabled

Hi, Sam,

Quoted 29 lines · Sam Ravnborg

Hi Thomas.

One little nit, and an improvment proposal (for another patch/day).

Quoted 24 lines · Thomas Hellstrom

Instead of guessing whether TTM has the dma page allocator enabled, ask TTM.

---
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -0
index 77f422cd18ab..125a2b423847 100644
@@ -35,6 +35,7 @@
  #include <drm/ttm/ttm_placement.h>
  #include <drm/ttm/ttm_bo_driver.h>
  #include <drm/ttm/ttm_module.h>
+#include <drm/ttm/ttm_page_alloc.h>
 
  #define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
  #define VMWGFX_CHIP_SVGAII 0
@@ -594,8 +595,7 @@ static int vmw_dma_select_mode(struct vmw_private *dev_priv)
  	if (dev_priv->map_mode == vmw_dma_map_populate && vmw_restrict_iommu)
  		dev_priv->map_mode = vmw_dma_map_bind;
 
Quoted 4 lines

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_dma_select_mode(struct vmw_private *dev_priv) · line 598

Quoted 3 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -2
-	/* No TTM coherent page pool? FIXME: Ask TTM instead! */
-        if (!(IS_ENABLED(CONFIG_SWIOTLB) || IS_ENABLED(CONFIG_INTEL_IOMMU)) &&
+        if (!ttm_dma_page_alloc_enabled() &&

The line uses spaces for indent, tabs?

Ugh, I thought I ran this through checkpatch. Anyway that will get corrected. Thanks.

Quoted 8 lines

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c static int vmw_dma_select_mode(struct vmw_private *dev_priv) · line 599

Quoted 2 lines
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +0 -0
  	    (dev_priv->map_mode == vmw_dma_alloc_coherent))

The code could benefit from a:
static bool is_map_coherent(const struct vmw_private *dev_priv)

{
	return dev_priv->map_mode == vmw_dma_alloc_coherent;
}
Quoted 7 lines

Then the above would become:

	if (!ttm_dma_page_alloc_enabled() && is_map_coherent(dev_priv))

And the other places that test for vmw_dma_alloc_coherent would be a bit simpler too.
Same goes for the other map types obviously.

Sure. I'll add that to the backlog for consideration, although if we get to it we'll use other names because all map modes are presumed to be coherent...

Thanks,
/Thomas

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

#4 lore raw
In reply to Thomas Hellstrom

Am 25.01.19 um 14:05 schrieb Thomas Hellstrom:

Quoted 20 lines

The vmwgfx driver needs to know whether the dma page pool is enabled to determine whether to refuse loading if the dma mode logic requests coherent memory from the dma page pool.

Cc "Koenig, Christian" <[email protected]>
---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 +++++++++++
  include/drm/ttm/ttm_page_alloc.h         |  4 ++++
  2 files changed, 15 insertions(+)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -0
index d594f7520b7b..adf8cc189ecc 100644
@@ -1235,4 +1235,15 @@ int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data)
  }
  EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
 
+/**

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) · line 1248

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +10 -0
+ * ttm_dma_page_alloc_enabled - Is the dma page pool enabled?
+ *
+ * Returns true if the dma page pool is enabled. false otherwise.
+ */
+bool ttm_dma_page_alloc_enabled(void)
+{
+	return !!_manager;
+}
+EXPORT_SYMBOL(ttm_dma_page_alloc_enabled);
+

This is completely superfluous cause the manager is enabled as soon as it is compiled in.

You could just use "#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)" instead.

Christian.

Quoted 15 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +0 -0
  #endif
include/drm/ttm/ttm_page_alloc.h +2 -0
index 4d9b019d253c..f810d389f5ad 100644
@@ -94,6 +94,8 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
  			struct ttm_operation_ctx *ctx);
  void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
 
+bool ttm_dma_page_alloc_enabled(void);
+
  #else
  static inline int ttm_dma_page_alloc_init(struct ttm_mem_global *glob,
  					  unsigned max_pages)

include/drm/ttm/ttm_page_alloc.h static inline void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, · line 126

Quoted 8 lines
include/drm/ttm/ttm_page_alloc.h +2 -0
@@ -117,6 +119,8 @@ static inline void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma,
  				      struct device *dev)
  {
  }
+
+static inline bool ttm_dma_page_alloc_enabled(void) { return false; }
  #endif
 
  #endif

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

#5 lore raw

Hi,

Quoted 39 lines · Christian

Am 25.01.19 um 14:05 schrieb Thomas Hellstrom:

Quoted 23 lines

The vmwgfx driver needs to know whether the dma page pool is enabled
to determine whether to refuse loading if the dma mode logic requests coherent memory from the dma page pool.

Cc "Koenig, Christian" <[email protected]>
---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 +++++++++++
  include/drm/ttm/ttm_page_alloc.h         |  4 ++++
  2 files changed, 15 insertions(+)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -0
index d594f7520b7b..adf8cc189ecc 100644
@@ -1235,4 +1235,15 @@ int ttm_dma_page_alloc_debugfs(struct
 seq_file *m, void *data)
  }
  EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
 
+/**

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c int ttm_dma_page_alloc_debugfs(struct · line 1249

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +10 -0
+ * ttm_dma_page_alloc_enabled - Is the dma page pool enabled?
+ *
+ * Returns true if the dma page pool is enabled. false otherwise.
+ */
+bool ttm_dma_page_alloc_enabled(void)
+{
+	return !!_manager;
+}
+EXPORT_SYMBOL(ttm_dma_page_alloc_enabled);
+

This is completely superfluous cause the manager is enabled as soon as
it is compiled in.

Quoted 5 lines

You could just use "#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)" instead.

Christian.

Yes, that's what was done before in vmgwfx, but it's very fragile and based on assumptions about what various parts of TTM does and doesn't do. Chances are somebody would modify the enablement and forget to modify this function.

But of course I can change it if you think that'd be better.

/Thomas

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

#6 lore raw
Quoted 49 lines · Thomas Hellström

Hi,

Quoted 40 lines · Christian

Am 25.01.19 um 14:05 schrieb Thomas Hellstrom:

Quoted 28 lines

The vmwgfx driver needs to know whether the dma page pool is enabled
to determine whether to refuse loading if the dma mode logic requests coherent memory from the dma page pool.

Cc "Koenig, Christian" <[email protected]>
---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 +++++++++++
  include/drm/ttm/ttm_page_alloc.h         |  4 ++++
  2 files changed, 15 insertions(+)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -0
index d594f7520b7b..adf8cc189ecc 100644
@@ -1235,4 +1235,15 @@ int ttm_dma_page_alloc_debugfs(struct
 seq_file *m, void *data)
  }
  EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
 
+/**
+ * ttm_dma_page_alloc_enabled - Is the dma page pool enabled?
+ *
+ * Returns true if the dma page pool is enabled. false

otherwise.
+ */

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) · line 1248

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6 -0
+bool ttm_dma_page_alloc_enabled(void)
+{
+	return !!_manager;
+}
+EXPORT_SYMBOL(ttm_dma_page_alloc_enabled);
+

This is completely superfluous cause the manager is enabled as soon as
it is compiled in.

Quoted 5 lines

You could just use "#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)" instead.

Christian.

Quoted 9 lines

Yes, that's what was done before in vmgwfx, but it's very fragile and based on assumptions about what various parts of TTM does and doesn't do. Chances are somebody would modify the enablement and forget to modify this function.

But of course I can change it if you think that'd be better.

/Thomas

What about

static inline bool ttm_dma_page_alloc_enabled(void)

{
	return (IS_ENABLED(CONFIG_INTEL_IOMMU) ||

IS_ENABLED(CONFIG_SWIOTLB)) && _manager;
}

to avoid that layering violation?

/Thomas

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

#7 lore raw

Am 28.01.19 um 15:21 schrieb Thomas Hellstrom:

Quoted 59 lines · Thomas Hellström
Quoted 47 lines

Hi,

Quoted 39 lines · Christian

Am 25.01.19 um 14:05 schrieb Thomas Hellstrom:

Quoted 28 lines

The vmwgfx driver needs to know whether the dma page pool is enabled
to determine whether to refuse loading if the dma mode logic requests coherent memory from the dma page pool.

Cc "Koenig, Christian" <[email protected]>
---
   drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 11 +++++++++++
   include/drm/ttm/ttm_page_alloc.h         |  4 ++++
   2 files changed, 15 insertions(+)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +4 -0
index d594f7520b7b..adf8cc189ecc 100644
@@ -1235,4 +1235,15 @@ int ttm_dma_page_alloc_debugfs(struct
 seq_file *m, void *data)
   }
   EXPORT_SYMBOL_GPL(ttm_dma_page_alloc_debugfs);
 
+/**
+ * ttm_dma_page_alloc_enabled - Is the dma page pool enabled?
+ *
+ * Returns true if the dma page pool is enabled. false

otherwise.
+ */

drivers/gpu/drm/ttm/ttm_page_alloc_dma.c int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data) · line 1248

Quoted 6 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +6 -0
+bool ttm_dma_page_alloc_enabled(void)
+{
+	return !!_manager;
+}
+EXPORT_SYMBOL(ttm_dma_page_alloc_enabled);
+

This is completely superfluous cause the manager is enabled as soon as
it is compiled in.

Quoted 5 lines

You could just use "#if defined(CONFIG_SWIOTLB) || defined(CONFIG_INTEL_IOMMU)" instead.

Christian.

Quoted 9 lines

Yes, that's what was done before in vmgwfx, but it's very fragile and based on assumptions about what various parts of TTM does and doesn't do. Chances are somebody would modify the enablement and forget to modify this function.

But of course I can change it if you think that'd be better.

/Thomas

What about

Quoted 7 lines

static inline bool ttm_dma_page_alloc_enabled(void)

{
	return (IS_ENABLED(CONFIG_INTEL_IOMMU) ||

IS_ENABLED(CONFIG_SWIOTLB)) && _manager;
}

to avoid that layering violation?

If you drop the "&& _manager" check and move it into the header then that should work.

But we could as well really clean it up and add a hidden CONFIG_DRM_TTM_DMA_PAGE_ALLOC and remove all the references to CONFIG_INTEL_IOMMU and CONFIG_SWIOTLB from the code.

Christian.

Quoted 3 lines

/Thomas

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