All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled
@ 2017-03-14 16:16 Chris Wilson
  2017-03-15  8:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Chris Wilson @ 2017-03-14 16:16 UTC (permalink / raw)
  To: intel-gfx

kasan is very good at detecting use-after-free. However, our requests
are allocated from a rcu-typesafe slab that is important for performance
but makes kasan less effective. When enabling kasan we are intentionally
looking for memory errors, disable the use of our caches to improve the
likelihood of kasan spotting a bug.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/Kconfig.debug      | 13 +++++++++++++
 drivers/gpu/drm/i915/i915_gem.c         | 11 +++++++++--
 drivers/gpu/drm/i915/i915_gem_request.c | 25 ++++++++++++++++++++-----
 drivers/gpu/drm/i915/i915_vma.c         | 15 ++++++++++++---
 4 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/Kconfig.debug b/drivers/gpu/drm/i915/Kconfig.debug
index e091809a9a9e..bd8e90e4dfb9 100644
--- a/drivers/gpu/drm/i915/Kconfig.debug
+++ b/drivers/gpu/drm/i915/Kconfig.debug
@@ -48,6 +48,19 @@ config DRM_I915_DEBUG_GEM
 
           If in doubt, say "N".
 
+config DRM_I915_DEBUG_KASAN
+        bool "Insert extra checks when using KASAN"
+        default n
+        depends on DRM_I915_WERROR
+        depends on KASAN
+        help
+	  Turns off use of kmem_caches to improve KASAN error detection,
+          and inserts extra santiy checks.
+
+          Recommended for driver developers only.
+
+          If in doubt, say "N".
+
 config DRM_I915_SW_FENCE_DEBUG_OBJECTS
         bool "Enable additional driver debugging for fence objects"
         depends on DRM_I915
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 202bb850f260..0195468531f7 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -639,13 +639,20 @@ i915_gem_phys_pwrite(struct drm_i915_gem_object *obj,
 
 void *i915_gem_object_alloc(struct drm_i915_private *dev_priv)
 {
-	return kmem_cache_zalloc(dev_priv->objects, GFP_KERNEL);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		return kzalloc(kmem_cache_size(dev_priv->objects), GFP_KERNEL);
+	else
+		return kmem_cache_zalloc(dev_priv->objects, GFP_KERNEL);
 }
 
 void i915_gem_object_free(struct drm_i915_gem_object *obj)
 {
 	struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
-	kmem_cache_free(dev_priv->objects, obj);
+
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		kfree(obj);
+	else
+		kmem_cache_free(dev_priv->objects, obj);
 }
 
 static int
diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c
index 1e1d9f2072cd..715760aa5aa1 100644
--- a/drivers/gpu/drm/i915/i915_gem_request.c
+++ b/drivers/gpu/drm/i915/i915_gem_request.c
@@ -73,7 +73,10 @@ static void i915_fence_release(struct dma_fence *fence)
 	 */
 	i915_sw_fence_fini(&req->submit);
 
-	kmem_cache_free(req->i915->requests, req);
+	if (IS_ENABLED(CONFIG_KASAN))
+		dma_fence_free(fence);
+	else
+		kmem_cache_free(req->i915->requests, req);
 }
 
 const struct dma_fence_ops i915_fence_ops = {
@@ -105,14 +108,20 @@ i915_gem_request_remove_from_client(struct drm_i915_gem_request *request)
 static struct i915_dependency *
 i915_dependency_alloc(struct drm_i915_private *i915)
 {
-	return kmem_cache_alloc(i915->dependencies, GFP_KERNEL);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		return kmalloc(kmem_cache_size(i915->dependencies), GFP_KERNEL);
+	else
+		return kmem_cache_alloc(i915->dependencies, GFP_KERNEL);
 }
 
 static void
 i915_dependency_free(struct drm_i915_private *i915,
 		     struct i915_dependency *dep)
 {
-	kmem_cache_free(i915->dependencies, dep);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		kfree(dep);
+	else
+		kmem_cache_free(i915->dependencies, dep);
 }
 
 static void
@@ -571,7 +580,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
 	 *
 	 * Do not use kmem_cache_zalloc() here!
 	 */
-	req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		req = kmalloc(sizeof(*req), GFP_KERNEL);
+	else
+		req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
 	if (!req) {
 		ret = -ENOMEM;
 		goto err_unreserve;
@@ -634,7 +646,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
 	GEM_BUG_ON(!list_empty(&req->priotree.signalers_list));
 	GEM_BUG_ON(!list_empty(&req->priotree.waiters_list));
 
-	kmem_cache_free(dev_priv->requests, req);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		kfree(req);
+	else
+		kmem_cache_free(dev_priv->requests, req);
 err_unreserve:
 	unreserve_seqno(engine);
 err_unpin:
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index 1aba47024656..684d529f6b91 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -81,7 +81,10 @@ vma_create(struct drm_i915_gem_object *obj,
 	/* The aliasing_ppgtt should never be used directly! */
 	GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->base);
 
-	vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		vma = kzalloc(kmem_cache_size(vm->i915->vmas), GFP_KERNEL);
+	else
+		vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
 	if (vma == NULL)
 		return ERR_PTR(-ENOMEM);
 
@@ -159,7 +162,10 @@ vma_create(struct drm_i915_gem_object *obj,
 	return vma;
 
 err_vma:
-	kmem_cache_free(vm->i915->vmas, vma);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		kfree(vma);
+	else
+		kmem_cache_free(vm->i915->vmas, vma);
 	return ERR_PTR(-E2BIG);
 }
 
@@ -588,7 +594,10 @@ void i915_vma_destroy(struct i915_vma *vma)
 	if (!i915_vma_is_ggtt(vma))
 		i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm));
 
-	kmem_cache_free(to_i915(vma->obj->base.dev)->vmas, vma);
+	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
+		kfree(vma);
+	else
+		kmem_cache_free(to_i915(vma->obj->base.dev)->vmas, vma);
 }
 
 void i915_vma_close(struct i915_vma *vma)
-- 
2.11.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* ✗ Fi.CI.BAT: failure for drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-14 16:16 [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled Chris Wilson
@ 2017-03-15  8:31 ` Patchwork
  2017-03-15  8:43 ` ✓ Fi.CI.BAT: success " Patchwork
  2017-03-15  9:46 ` [PATCH] " Mika Kuoppala
  2 siblings, 0 replies; 7+ messages in thread
From: Patchwork @ 2017-03-15  8:31 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: Disable kmem_caches when KASAN is enabled
URL   : https://patchwork.freedesktop.org/series/21231/
State : failure

== Summary ==

Series 21231v1 drm/i915: Disable kmem_caches when KASAN is enabled
https://patchwork.freedesktop.org/api/1.0/series/21231/revisions/1/mbox/

Test gem_exec_flush:
        Subgroup basic-uc-pro-default:
                pass       -> INCOMPLETE (fi-skl-6700hq) fdo#100130
                pass       -> INCOMPLETE (fi-skl-6770hq) fdo#100130
                pass       -> INCOMPLETE (fi-skl-6700k) fdo#100130
        Subgroup basic-uc-ro-default:
                pass       -> INCOMPLETE (fi-skl-6260u)
Test kms_cursor_legacy:
        Subgroup basic-busy-flip-before-cursor-atomic:
                fail       -> PASS       (fi-snb-2520m)

fdo#100130 https://bugs.freedesktop.org/show_bug.cgi?id=100130

fi-bdw-5557u     total:278  pass:267  dwarn:0   dfail:0   fail:0   skip:11  time: 450s
fi-bsw-n3050     total:278  pass:239  dwarn:0   dfail:0   fail:0   skip:39  time: 537s
fi-bxt-j4205     total:278  pass:259  dwarn:0   dfail:0   fail:0   skip:19  time: 497s
fi-bxt-t5700     total:278  pass:258  dwarn:0   dfail:0   fail:0   skip:20  time: 555s
fi-byt-j1900     total:278  pass:251  dwarn:0   dfail:0   fail:0   skip:27  time: 503s
fi-byt-n2820     total:278  pass:247  dwarn:0   dfail:0   fail:0   skip:31  time: 500s
fi-ilk-650       total:278  pass:228  dwarn:0   dfail:0   fail:0   skip:50  time: 436s
fi-ivb-3770      total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  time: 480s
fi-skl-6260u     total:55   pass:53   dwarn:0   dfail:0   fail:0   skip:1   time: 0s
fi-skl-6700hq    total:53   pass:45   dwarn:0   dfail:0   fail:0   skip:7   time: 0s
fi-skl-6700k     total:53   pass:45   dwarn:0   dfail:0   fail:0   skip:7   time: 0s
fi-skl-6770hq    total:53   pass:51   dwarn:0   dfail:0   fail:0   skip:1   time: 0s
fi-snb-2520m     total:278  pass:250  dwarn:0   dfail:0   fail:0   skip:28  time: 544s
fi-snb-2600      total:278  pass:249  dwarn:0   dfail:0   fail:0   skip:29  time: 415s

c641417b70c6b78efca29ae732d7cbf5716ac6d5 drm-tip: 2017y-03m-14d-16h-04m-56s UTC integration manifest
4edc033 drm/i915: Disable kmem_caches when KASAN is enabled

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_4168/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* ✓ Fi.CI.BAT: success for drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-14 16:16 [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled Chris Wilson
  2017-03-15  8:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
@ 2017-03-15  8:43 ` Patchwork
  2017-03-15  9:46 ` [PATCH] " Mika Kuoppala
  2 siblings, 0 replies; 7+ messages in thread
From: Patchwork @ 2017-03-15  8:43 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

== Series Details ==

Series: drm/i915: Disable kmem_caches when KASAN is enabled
URL   : https://patchwork.freedesktop.org/series/21231/
State : success

== Summary ==

Series 21231v1 drm/i915: Disable kmem_caches when KASAN is enabled
https://patchwork.freedesktop.org/api/1.0/series/21231/revisions/1/mbox/

Test gem_exec_flush:
        Subgroup basic-uc-pro-default:
                pass       -> INCOMPLETE (fi-skl-6700k) fdo#100130
                pass       -> INCOMPLETE (fi-skl-6770hq) fdo#100130
                pass       -> INCOMPLETE (fi-skl-6700hq) fdo#100130
        Subgroup basic-uc-ro-default:
                pass       -> INCOMPLETE (fi-skl-6260u) fdo#100130
Test kms_cursor_legacy:
        Subgroup basic-busy-flip-before-cursor-atomic:
                fail       -> PASS       (fi-snb-2520m)

fdo#100130 https://bugs.freedesktop.org/show_bug.cgi?id=100130

fi-bdw-5557u     total:278  pass:267  dwarn:0   dfail:0   fail:0   skip:11  time: 450s
fi-bsw-n3050     total:278  pass:239  dwarn:0   dfail:0   fail:0   skip:39  time: 537s
fi-bxt-j4205     total:278  pass:259  dwarn:0   dfail:0   fail:0   skip:19  time: 497s
fi-bxt-t5700     total:278  pass:258  dwarn:0   dfail:0   fail:0   skip:20  time: 555s
fi-byt-j1900     total:278  pass:251  dwarn:0   dfail:0   fail:0   skip:27  time: 503s
fi-byt-n2820     total:278  pass:247  dwarn:0   dfail:0   fail:0   skip:31  time: 500s
fi-ilk-650       total:278  pass:228  dwarn:0   dfail:0   fail:0   skip:50  time: 436s
fi-ivb-3770      total:278  pass:260  dwarn:0   dfail:0   fail:0   skip:18  time: 480s
fi-skl-6260u     total:55   pass:53   dwarn:0   dfail:0   fail:0   skip:1   time: 0s
fi-skl-6700hq    total:53   pass:45   dwarn:0   dfail:0   fail:0   skip:7   time: 0s
fi-skl-6700k     total:53   pass:45   dwarn:0   dfail:0   fail:0   skip:7   time: 0s
fi-skl-6770hq    total:53   pass:51   dwarn:0   dfail:0   fail:0   skip:1   time: 0s
fi-snb-2520m     total:278  pass:250  dwarn:0   dfail:0   fail:0   skip:28  time: 544s
fi-snb-2600      total:278  pass:249  dwarn:0   dfail:0   fail:0   skip:29  time: 415s

c641417b70c6b78efca29ae732d7cbf5716ac6d5 drm-tip: 2017y-03m-14d-16h-04m-56s UTC integration manifest
4edc033 drm/i915: Disable kmem_caches when KASAN is enabled

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_4168/
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-14 16:16 [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled Chris Wilson
  2017-03-15  8:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
  2017-03-15  8:43 ` ✓ Fi.CI.BAT: success " Patchwork
@ 2017-03-15  9:46 ` Mika Kuoppala
  2017-03-15  9:54   ` Chris Wilson
  2 siblings, 1 reply; 7+ messages in thread
From: Mika Kuoppala @ 2017-03-15  9:46 UTC (permalink / raw)
  To: Chris Wilson, intel-gfx

Chris Wilson <chris@chris-wilson.co.uk> writes:

> kasan is very good at detecting use-after-free. However, our requests
> are allocated from a rcu-typesafe slab that is important for performance
> but makes kasan less effective. When enabling kasan we are intentionally
> looking for memory errors, disable the use of our caches to improve the
> likelihood of kasan spotting a bug.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  drivers/gpu/drm/i915/Kconfig.debug      | 13 +++++++++++++
>  drivers/gpu/drm/i915/i915_gem.c         | 11 +++++++++--
>  drivers/gpu/drm/i915/i915_gem_request.c | 25 ++++++++++++++++++++-----
>  drivers/gpu/drm/i915/i915_vma.c         | 15 ++++++++++++---
>  4 files changed, 54 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/Kconfig.debug b/drivers/gpu/drm/i915/Kconfig.debug
> index e091809a9a9e..bd8e90e4dfb9 100644
> --- a/drivers/gpu/drm/i915/Kconfig.debug
> +++ b/drivers/gpu/drm/i915/Kconfig.debug
> @@ -48,6 +48,19 @@ config DRM_I915_DEBUG_GEM
>  
>            If in doubt, say "N".
>  
> +config DRM_I915_DEBUG_KASAN
> +        bool "Insert extra checks when using KASAN"
> +        default n
> +        depends on DRM_I915_WERROR
> +        depends on KASAN
> +        help
> +	  Turns off use of kmem_caches to improve KASAN error detection,
> +          and inserts extra santiy checks.

s/santiy/sanity.

Would i915.kmem_cache=0/1 be too costly?

The name could also be DEBUG_NO_KMEM_CACHE
-Mika

> +
> +          Recommended for driver developers only.
> +
> +          If in doubt, say "N".
> +
>  config DRM_I915_SW_FENCE_DEBUG_OBJECTS
>          bool "Enable additional driver debugging for fence objects"
>          depends on DRM_I915
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index 202bb850f260..0195468531f7 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -639,13 +639,20 @@ i915_gem_phys_pwrite(struct drm_i915_gem_object *obj,
>  
>  void *i915_gem_object_alloc(struct drm_i915_private *dev_priv)
>  {
> -	return kmem_cache_zalloc(dev_priv->objects, GFP_KERNEL);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		return kzalloc(kmem_cache_size(dev_priv->objects), GFP_KERNEL);
> +	else
> +		return kmem_cache_zalloc(dev_priv->objects, GFP_KERNEL);
>  }
>  
>  void i915_gem_object_free(struct drm_i915_gem_object *obj)
>  {
>  	struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
> -	kmem_cache_free(dev_priv->objects, obj);
> +
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		kfree(obj);
> +	else
> +		kmem_cache_free(dev_priv->objects, obj);
>  }
>  
>  static int
> diff --git a/drivers/gpu/drm/i915/i915_gem_request.c b/drivers/gpu/drm/i915/i915_gem_request.c
> index 1e1d9f2072cd..715760aa5aa1 100644
> --- a/drivers/gpu/drm/i915/i915_gem_request.c
> +++ b/drivers/gpu/drm/i915/i915_gem_request.c
> @@ -73,7 +73,10 @@ static void i915_fence_release(struct dma_fence *fence)
>  	 */
>  	i915_sw_fence_fini(&req->submit);
>  
> -	kmem_cache_free(req->i915->requests, req);
> +	if (IS_ENABLED(CONFIG_KASAN))
> +		dma_fence_free(fence);
> +	else
> +		kmem_cache_free(req->i915->requests, req);
>  }
>  
>  const struct dma_fence_ops i915_fence_ops = {
> @@ -105,14 +108,20 @@ i915_gem_request_remove_from_client(struct drm_i915_gem_request *request)
>  static struct i915_dependency *
>  i915_dependency_alloc(struct drm_i915_private *i915)
>  {
> -	return kmem_cache_alloc(i915->dependencies, GFP_KERNEL);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		return kmalloc(kmem_cache_size(i915->dependencies), GFP_KERNEL);
> +	else
> +		return kmem_cache_alloc(i915->dependencies, GFP_KERNEL);
>  }
>  
>  static void
>  i915_dependency_free(struct drm_i915_private *i915,
>  		     struct i915_dependency *dep)
>  {
> -	kmem_cache_free(i915->dependencies, dep);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		kfree(dep);
> +	else
> +		kmem_cache_free(i915->dependencies, dep);
>  }
>  
>  static void
> @@ -571,7 +580,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
>  	 *
>  	 * Do not use kmem_cache_zalloc() here!
>  	 */
> -	req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		req = kmalloc(sizeof(*req), GFP_KERNEL);
> +	else
> +		req = kmem_cache_alloc(dev_priv->requests, GFP_KERNEL);
>  	if (!req) {
>  		ret = -ENOMEM;
>  		goto err_unreserve;
> @@ -634,7 +646,10 @@ i915_gem_request_alloc(struct intel_engine_cs *engine,
>  	GEM_BUG_ON(!list_empty(&req->priotree.signalers_list));
>  	GEM_BUG_ON(!list_empty(&req->priotree.waiters_list));
>  
> -	kmem_cache_free(dev_priv->requests, req);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		kfree(req);
> +	else
> +		kmem_cache_free(dev_priv->requests, req);
>  err_unreserve:
>  	unreserve_seqno(engine);
>  err_unpin:
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index 1aba47024656..684d529f6b91 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -81,7 +81,10 @@ vma_create(struct drm_i915_gem_object *obj,
>  	/* The aliasing_ppgtt should never be used directly! */
>  	GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->base);
>  
> -	vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		vma = kzalloc(kmem_cache_size(vm->i915->vmas), GFP_KERNEL);
> +	else
> +		vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL);
>  	if (vma == NULL)
>  		return ERR_PTR(-ENOMEM);
>  
> @@ -159,7 +162,10 @@ vma_create(struct drm_i915_gem_object *obj,
>  	return vma;
>  
>  err_vma:
> -	kmem_cache_free(vm->i915->vmas, vma);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		kfree(vma);
> +	else
> +		kmem_cache_free(vm->i915->vmas, vma);
>  	return ERR_PTR(-E2BIG);
>  }
>  
> @@ -588,7 +594,10 @@ void i915_vma_destroy(struct i915_vma *vma)
>  	if (!i915_vma_is_ggtt(vma))
>  		i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm));
>  
> -	kmem_cache_free(to_i915(vma->obj->base.dev)->vmas, vma);
> +	if (IS_ENABLED(CONFIG_DRM_I915_KASAN))
> +		kfree(vma);
> +	else
> +		kmem_cache_free(to_i915(vma->obj->base.dev)->vmas, vma);
>  }
>  
>  void i915_vma_close(struct i915_vma *vma)
> -- 
> 2.11.0
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-15  9:46 ` [PATCH] " Mika Kuoppala
@ 2017-03-15  9:54   ` Chris Wilson
  2017-03-15 11:14     ` Mika Kuoppala
  0 siblings, 1 reply; 7+ messages in thread
From: Chris Wilson @ 2017-03-15  9:54 UTC (permalink / raw)
  To: Mika Kuoppala; +Cc: intel-gfx

On Wed, Mar 15, 2017 at 11:46:24AM +0200, Mika Kuoppala wrote:
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> 
> > kasan is very good at detecting use-after-free. However, our requests
> > are allocated from a rcu-typesafe slab that is important for performance
> > but makes kasan less effective. When enabling kasan we are intentionally
> > looking for memory errors, disable the use of our caches to improve the
> > likelihood of kasan spotting a bug.
> >
> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> > ---
> >  drivers/gpu/drm/i915/Kconfig.debug      | 13 +++++++++++++
> >  drivers/gpu/drm/i915/i915_gem.c         | 11 +++++++++--
> >  drivers/gpu/drm/i915/i915_gem_request.c | 25 ++++++++++++++++++++-----
> >  drivers/gpu/drm/i915/i915_vma.c         | 15 ++++++++++++---
> >  4 files changed, 54 insertions(+), 10 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/Kconfig.debug b/drivers/gpu/drm/i915/Kconfig.debug
> > index e091809a9a9e..bd8e90e4dfb9 100644
> > --- a/drivers/gpu/drm/i915/Kconfig.debug
> > +++ b/drivers/gpu/drm/i915/Kconfig.debug
> > @@ -48,6 +48,19 @@ config DRM_I915_DEBUG_GEM
> >  
> >            If in doubt, say "N".
> >  
> > +config DRM_I915_DEBUG_KASAN
> > +        bool "Insert extra checks when using KASAN"
> > +        default n
> > +        depends on DRM_I915_WERROR
> > +        depends on KASAN
> > +        help
> > +	  Turns off use of kmem_caches to improve KASAN error detection,
> > +          and inserts extra santiy checks.
> 
> s/santiy/sanity.
> 
> Would i915.kmem_cache=0/1 be too costly?

More of the principle. Having module options means somebody will enable
it. Hiding it away underneath a bevy of expert config options makes it
much less likely. CI basically have to do two runs for each option -- if
we are using kasan, we want improved coverage, but we also need to test
that the default configuration works. It's probably best just to teach
kmem_cache itself to behave differently if it helps. I was just thinking
fine-grained swapping of behaviour would be benificial.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-15  9:54   ` Chris Wilson
@ 2017-03-15 11:14     ` Mika Kuoppala
  2017-03-15 11:21       ` Chris Wilson
  0 siblings, 1 reply; 7+ messages in thread
From: Mika Kuoppala @ 2017-03-15 11:14 UTC (permalink / raw)
  To: Chris Wilson; +Cc: intel-gfx

Chris Wilson <chris@chris-wilson.co.uk> writes:

> On Wed, Mar 15, 2017 at 11:46:24AM +0200, Mika Kuoppala wrote:
>> Chris Wilson <chris@chris-wilson.co.uk> writes:
>> 
>> > kasan is very good at detecting use-after-free. However, our requests
>> > are allocated from a rcu-typesafe slab that is important for performance
>> > but makes kasan less effective. When enabling kasan we are intentionally
>> > looking for memory errors, disable the use of our caches to improve the
>> > likelihood of kasan spotting a bug.
>> >

I didn't notice anything except the typo in the desc. Until
someone makes a kmem_cache kasan aware, this patch would
be useful if and when someone does kasan runs with our driver.

The name could be DEBUG_KMEM_CACHE_DISABLE. It is more logical
wrt to content of the patch. However perhaps the current name
is more practical.

Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>


>> > Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
>> > ---
>> >  drivers/gpu/drm/i915/Kconfig.debug      | 13 +++++++++++++
>> >  drivers/gpu/drm/i915/i915_gem.c         | 11 +++++++++--
>> >  drivers/gpu/drm/i915/i915_gem_request.c | 25 ++++++++++++++++++++-----
>> >  drivers/gpu/drm/i915/i915_vma.c         | 15 ++++++++++++---
>> >  4 files changed, 54 insertions(+), 10 deletions(-)
>> >
>> > diff --git a/drivers/gpu/drm/i915/Kconfig.debug b/drivers/gpu/drm/i915/Kconfig.debug
>> > index e091809a9a9e..bd8e90e4dfb9 100644
>> > --- a/drivers/gpu/drm/i915/Kconfig.debug
>> > +++ b/drivers/gpu/drm/i915/Kconfig.debug
>> > @@ -48,6 +48,19 @@ config DRM_I915_DEBUG_GEM
>> >  
>> >            If in doubt, say "N".
>> >  
>> > +config DRM_I915_DEBUG_KASAN
>> > +        bool "Insert extra checks when using KASAN"
>> > +        default n
>> > +        depends on DRM_I915_WERROR
>> > +        depends on KASAN
>> > +        help
>> > +	  Turns off use of kmem_caches to improve KASAN error detection,
>> > +          and inserts extra santiy checks.
>> 
>> s/santiy/sanity.
>> 
>> Would i915.kmem_cache=0/1 be too costly?
>
> More of the principle. Having module options means somebody will enable
> it. Hiding it away underneath a bevy of expert config options makes it
> much less likely. CI basically have to do two runs for each option -- if
> we are using kasan, we want improved coverage, but we also need to test
> that the default configuration works. It's probably best just to teach
> kmem_cache itself to behave differently if it helps. I was just thinking
> fine-grained swapping of behaviour would be benificial.
> -Chris
>
> -- 
> Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled
  2017-03-15 11:14     ` Mika Kuoppala
@ 2017-03-15 11:21       ` Chris Wilson
  0 siblings, 0 replies; 7+ messages in thread
From: Chris Wilson @ 2017-03-15 11:21 UTC (permalink / raw)
  To: Mika Kuoppala; +Cc: intel-gfx

On Wed, Mar 15, 2017 at 01:14:50PM +0200, Mika Kuoppala wrote:
> Chris Wilson <chris@chris-wilson.co.uk> writes:
> 
> > On Wed, Mar 15, 2017 at 11:46:24AM +0200, Mika Kuoppala wrote:
> >> Chris Wilson <chris@chris-wilson.co.uk> writes:
> >> 
> >> > kasan is very good at detecting use-after-free. However, our requests
> >> > are allocated from a rcu-typesafe slab that is important for performance
> >> > but makes kasan less effective. When enabling kasan we are intentionally
> >> > looking for memory errors, disable the use of our caches to improve the
> >> > likelihood of kasan spotting a bug.
> >> >
> 
> I didn't notice anything except the typo in the desc. Until
> someone makes a kmem_cache kasan aware, this patch would
> be useful if and when someone does kasan runs with our driver.
> 
> The name could be DEBUG_KMEM_CACHE_DISABLE. It is more logical
> wrt to content of the patch. However perhaps the current name
> is more practical.

I was contemplating the possibility of sticking other tests under here
if kasan (or memdebug in general) has some more debugging aides.
 
> Reviewed-by: Mika Kuoppala <mika.kuoppala@intel.com>

I'm sitting on the fence for this atm, until kasan is enabled in the CI
farm and then we can decide what is the best approach.
-Chris

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-03-15 11:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-14 16:16 [PATCH] drm/i915: Disable kmem_caches when KASAN is enabled Chris Wilson
2017-03-15  8:31 ` ✗ Fi.CI.BAT: failure for " Patchwork
2017-03-15  8:43 ` ✓ Fi.CI.BAT: success " Patchwork
2017-03-15  9:46 ` [PATCH] " Mika Kuoppala
2017-03-15  9:54   ` Chris Wilson
2017-03-15 11:14     ` Mika Kuoppala
2017-03-15 11:21       ` Chris Wilson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.