Skip to contentSkip to conversation

drm/i915: Fix the sgt.pfn sanity check

PATCH In review Matthew Auld 4 participants 9 messages Jan 18, 2021

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

PATCH 1/3 drm/i915: Fix the sgt.pfn sanity check

From: Kui Wen <[email protected]>

For the device local-memory case, sgt.pfn will always be equal to zero, since we instead use sgt.dma. Also, for device local-memory it is perfectly valid for it to start from zero anyway, so no need to add a new check for that either.

---
 drivers/gpu/drm/i915/i915_mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_mm.c +1 -1
index 43039dc8c607..dcf6b3e5bfdf 100644
@@ -62,7 +62,7 @@ static int remap_sg(pte_t *pte, unsigned long addr, void *data)
 {
 	struct remap_pfn *r = data;
 
-	if (GEM_WARN_ON(!r->sgt.pfn))
+	if (GEM_WARN_ON(!use_dma(r->iobase) && !r->sgt.pfn))
 		return -EINVAL;
 
 	/* Special PTE are not associated with any struct page */
Signature · 6 lines
2.26.2

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

PATCH 2/3 drm/i915: prefer FORCE_WC for the blitter routines

From: CQ Tang <[email protected]>

The pool is shared and so we might find that there is a pool object with an existing mapping, but is mapped with different underlying type, which will result in -EBUSY.

---
 drivers/gpu/drm/i915/gem/i915_gem_object_blt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +2 -2
index 10cac9fac79b..c6db745900b3 100644
@@ -55,7 +55,7 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,
 	if (unlikely(err))
 		goto out_put;
 
-	cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+	cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
 	if (IS_ERR(cmd)) {
 		err = PTR_ERR(cmd);
 		goto out_unpin;
@@ -277,7 +277,7 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,
 	if (unlikely(err))
 		goto out_put;
 
-	cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+	cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
 	if (IS_ERR(cmd)) {
 		err = PTR_ERR(cmd);
 		goto out_unpin;
Signature · 6 lines
2.26.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH 3/3 drm/i915/error: Fix object page offset within a region

In reply to Matthew Auld

From: CQ Tang <[email protected]>

io_mapping_map_wc() expects the offset to be relative to the iomapping base address. Currently we just pass in the physical address for the page which only works if the region.start starts at zero.

---
 drivers/gpu/drm/i915/i915_gpu_error.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gpu_error.c +3 -1
index 8b163ee1b86d..f962693404b7 100644
@@ -1051,7 +1051,9 @@ i915_vma_coredump_create(const struct intel_gt *gt,
 		for_each_sgt_daddr(dma, iter, vma->pages) {
 			void __iomem *s;
 
-			s = io_mapping_map_wc(&mem->iomap, dma, PAGE_SIZE);
+			s = io_mapping_map_wc(&mem->iomap,
+					      dma - mem->region.start,
+					      PAGE_SIZE);
 			ret = compress_page(compress,
 					    (void __force *)s, dst,
 					    true);
Signature · 6 lines
2.26.2

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

Re: [Intel-gfx] [PATCH 2/3] drm/i915: prefer FORCE_WC for the blitter routines

In reply to Matthew Auld

Quoting Matthew Auld (2021-01-18 14:17:31)

Quoted 1 line

From: CQ Tang <[email protected]>

First patch hasn't arrive, so excuse this misplaced reply.

- if (GEM_WARN_ON(!r->sgt.pfn))
+ if (GEM_WARN_ON(!use_dma(r->iobase) && !r->sgt.pfn))
return -EINVAL;

The better check would be if (GEM_WARN_ON(!r->sgt.sgp)) return -EINVAL; -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#3 lore raw

Re: [Intel-gfx] [PATCH 2/3] drm/i915: prefer FORCE_WC for the blitter routines

In reply to Matthew Auld

Quoting Matthew Auld (2021-01-18 14:17:31)

Quoted 26 lines

From: CQ Tang <[email protected]>

The pool is shared and so we might find that there is a pool object with an existing mapping, but is mapped with different underlying type, which will result in -EBUSY.

---
 drivers/gpu/drm/i915/gem/i915_gem_object_blt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
index 10cac9fac79b..c6db745900b3 100644
@@ -55,7 +55,7 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

drivers/gpu/drm/i915/gem/i915_gem_object_blt.c struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce, · line 283

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
@@ -277,7 +277,7 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

FORCE is becoming meaningless.

In this case we pin the pages upon acquiring from the pool, which then prevents us from changing the mapping type. The purpose of which was so that we could cache the mapping between users, and here we are saying that cache is made useless. The danger is that we are now thrashing the cache, hurting ourselves with the vmap overhead.

Maybe we should move the mapping-type into the buffer-pool cache itself? -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v1 3/3
#7 lore raw

Re: [Intel-gfx] [PATCH 3/3] drm/i915/error: Fix object page offset within a region

In reply to Matthew Auld

Quoting Matthew Auld (2021-01-18 14:17:32)

Quoted 17 lines

From: CQ Tang <[email protected]>

io_mapping_map_wc() expects the offset to be relative to the iomapping base address. Currently we just pass in the physical address for the page which only works if the region.start starts at zero.

---
 drivers/gpu/drm/i915/i915_gpu_error.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/i915_gpu_error.c +0 -0
index 8b163ee1b86d..f962693404b7 100644

drivers/gpu/drm/i915/i915_gpu_error.c i915_vma_coredump_create(const struct intel_gt *gt, · line 1056

Quoted 7 lines
drivers/gpu/drm/i915/i915_gpu_error.c +3 -1
@@ -1051,7 +1051,9 @@ i915_vma_coredump_create(const struct intel_gt *gt,
                for_each_sgt_daddr(dma, iter, vma->pages) {
                        void __iomem *s;
 
-                       s = io_mapping_map_wc(&mem->iomap, dma, PAGE_SIZE);
+                       s = io_mapping_map_wc(&mem->iomap,
+                                             dma - mem->region.start,
+                                             PAGE_SIZE);

From i915_gem_object_get_pages_buddy:

sg_dma_address(sg) = mem->region.start + offset;

-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw

Re: [Intel-gfx] [PATCH 2/3] drm/i915: prefer FORCE_WC for the blitter routines

In reply to Chris Wilson
Quoted 39 lines · Chris Wilson

Quoting Matthew Auld (2021-01-18 14:17:31)

Quoted 26 lines

From: CQ Tang <[email protected]>

The pool is shared and so we might find that there is a pool object with an existing mapping, but is mapped with different underlying type, which will result in -EBUSY.

---
 drivers/gpu/drm/i915/gem/i915_gem_object_blt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
index 10cac9fac79b..c6db745900b3 100644
@@ -55,7 +55,7 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

drivers/gpu/drm/i915/gem/i915_gem_object_blt.c struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce, · line 283

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
@@ -277,7 +277,7 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

FORCE is becoming meaningless.

Quoted 7 lines

In this case we pin the pages upon acquiring from the pool, which then prevents us from changing the mapping type. The purpose of which was so that we could cache the mapping between users, and here we are saying that cache is made useless. The danger is that we are now thrashing the cache, hurting ourselves with the vmap overhead.

Maybe we should move the mapping-type into the buffer-pool cache itself?

Yeah, makes sense I think. Maybe something simple like:

drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c +9 -3
@@ -145,7 +145,8 @@ static void pool_retire(struct i915_active *ref)
 }
 
 static struct intel_gt_buffer_pool_node *
-node_create(struct intel_gt_buffer_pool *pool, size_t sz)
+node_create(struct intel_gt_buffer_pool *pool, size_t sz,
+           enum i915_map_type type)
 {
        struct intel_gt *gt = to_gt(pool);
        struct intel_gt_buffer_pool_node *node;
@@ -169,12 +170,14 @@ node_create(struct intel_gt_buffer_pool *pool, size_t sz)
 
        i915_gem_object_set_readonly(obj);
 
+       node->type = type;
        node->obj = obj;
        return node;
 }
 
 struct intel_gt_buffer_pool_node *
-intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
+intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size,
+                        enum i915_map_type type)
 {
        struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
        struct intel_gt_buffer_pool_node *node;
@@ -191,6 +194,9 @@ intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
                if (node->obj->base.size < size)
                        continue;
 
+               if (node->type != type)
+                       continue;
+
                age = READ_ONCE(node->age);
                if (!age)
                        continue;
@@ -205,7 +211,7 @@ intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
        rcu_read_unlock();
 
        if (&node->link == list) {
-               node = node_create(pool, size);
+               node = node_create(pool, size, type);
                if (IS_ERR(node))
                        return node;
        }
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.h
index 42cbac003e8a..6068f8f1762e 100644

drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.h +2 -1
@@ -15,7 +15,8 @@ struct intel_gt;
 struct i915_request;
 
 struct intel_gt_buffer_pool_node *
-intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size);
+intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size,
+                        enum i915_map_type type);
 
 static inline int
 intel_gt_buffer_pool_mark_active(struct intel_gt_buffer_pool_node *node,
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/gt/intel_gt_buffer_pool_types.h index bcf1658c9633..e8f7dba36b76 100644

drivers/gpu/drm/i915/gt/intel_gt_buffer_pool_types.h +1 -0
@@ -31,6 +31,7 @@ struct intel_gt_buffer_pool_node {
                struct rcu_head rcu;
        };
        unsigned long age;
+       enum i915_map_type type;
 };
 

Or maybe it should be split over multiple lists or something, one for each type?

Quoted 5 lines

-Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

Re: [Intel-gfx] [PATCH 2/3] drm/i915: prefer FORCE_WC for the blitter routines

Quoting Matthew Auld (2021-01-18 15:55:31)

Quoted 124 lines · Chris Wilson
Quoted 39 lines

Quoting Matthew Auld (2021-01-18 14:17:31)

Quoted 26 lines

From: CQ Tang <[email protected]>

The pool is shared and so we might find that there is a pool object with an existing mapping, but is mapped with different underlying type, which will result in -EBUSY.

---
 drivers/gpu/drm/i915/gem/i915_gem_object_blt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
index 10cac9fac79b..c6db745900b3 100644
@@ -55,7 +55,7 @@ struct i915_vma *intel_emit_vma_fill_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

drivers/gpu/drm/i915/gem/i915_gem_object_blt.c struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce, · line 283

Quoted 8 lines
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c +1 -1
@@ -277,7 +277,7 @@ struct i915_vma *intel_emit_vma_copy_blt(struct intel_context *ce,
        if (unlikely(err))
                goto out_put;
 
-       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_WC);
+       cmd = i915_gem_object_pin_map(pool->obj, I915_MAP_FORCE_WC);
        if (IS_ERR(cmd)) {
                err = PTR_ERR(cmd);
                goto out_unpin;

FORCE is becoming meaningless.

Quoted 7 lines

In this case we pin the pages upon acquiring from the pool, which then prevents us from changing the mapping type. The purpose of which was so that we could cache the mapping between users, and here we are saying that cache is made useless. The danger is that we are now thrashing the cache, hurting ourselves with the vmap overhead.

Maybe we should move the mapping-type into the buffer-pool cache itself?

Yeah, makes sense I think. Maybe something simple like:

drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.c +9 -3
@@ -145,7 +145,8 @@ static void pool_retire(struct i915_active *ref)
 }
 
 static struct intel_gt_buffer_pool_node *
-node_create(struct intel_gt_buffer_pool *pool, size_t sz)
+node_create(struct intel_gt_buffer_pool *pool, size_t sz,
+           enum i915_map_type type)
 {
        struct intel_gt *gt = to_gt(pool);
        struct intel_gt_buffer_pool_node *node;
@@ -169,12 +170,14 @@ node_create(struct intel_gt_buffer_pool *pool, size_t sz)
 
        i915_gem_object_set_readonly(obj);
 
+       node->type = type;
        node->obj = obj;
        return node;
 }
 
 struct intel_gt_buffer_pool_node *
-intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
+intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size,
+                        enum i915_map_type type)
 {
        struct intel_gt_buffer_pool *pool = &gt->buffer_pool;
        struct intel_gt_buffer_pool_node *node;
@@ -191,6 +194,9 @@ intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
                if (node->obj->base.size < size)
                        continue;
 
+               if (node->type != type)
+                       continue;
+
                age = READ_ONCE(node->age);
                if (!age)
                        continue;
@@ -205,7 +211,7 @@ intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size)
        rcu_read_unlock();
 
        if (&node->link == list) {
-               node = node_create(pool, size);
+               node = node_create(pool, size, type);
                if (IS_ERR(node))
                        return node;
        }
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool.h +2 -1
index 42cbac003e8a..6068f8f1762e 100644
@@ -15,7 +15,8 @@ struct intel_gt;
 struct i915_request;
 
 struct intel_gt_buffer_pool_node *
-intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size);
+intel_gt_get_buffer_pool(struct intel_gt *gt, size_t size,
+                        enum i915_map_type type);
 
 static inline int
 intel_gt_buffer_pool_mark_active(struct intel_gt_buffer_pool_node *node,
drivers/gpu/drm/i915/gt/intel_gt_buffer_pool_types.h +1 -0
index bcf1658c9633..e8f7dba36b76 100644
@@ -31,6 +31,7 @@ struct intel_gt_buffer_pool_node {
                struct rcu_head rcu;
        };
        unsigned long age;
+       enum i915_map_type type;
 };
 
Quoted 1 line

Or maybe it should be split over multiple lists or something, one for each type?

This looks good for a first pass. We can split the buckets by type later if we feel so inclined. At the moment, I hope our lists are short enough that we only have to skip one or two before finding a match. -Chris
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for series starting with [1/3] drm/i915: Fix the sgt.pfn sanity check (rev2)

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: series starting with [1/3] drm/i915: Fix the sgt.pfn sanity check (rev2)
URL : https://patchwork.freedesktop.org/series/85997/
State : failure

== Summary ==

Applying: drm/i915: Fix the sgt.pfn sanity check
Applying: drm/i915: prefer FORCE_WC for the blitter routines
error: git diff header lacks filename information when removing 1 leading pathname component (line 49)
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0002 drm/i915: prefer FORCE_WC for the blitter routines
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx