[Intel-gfx] [PATCH v9 34/70] drm/i915: Add ww locking around vm_access()

Daniel Vetter daniel at ffwll.ch
Wed Mar 24 16:21:55 UTC 2021


On Tue, Mar 23, 2021 at 04:50:23PM +0100, Maarten Lankhorst wrote:
> i915_gem_object_pin_map potentially needs a ww context, so ensure we
> have one we can revoke.
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
> Reviewed-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>

We shouldn't hand-roll our own vm_access callback, generic_access_phys
should be used here instead.

I've applied this, but can you pls do a follow up patch here?

Thanks, Daniel

> ---
>  drivers/gpu/drm/i915/gem/i915_gem_mman.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_mman.c b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> index 163208a6260d..2561a2f1e54f 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_mman.c
> @@ -421,7 +421,9 @@ vm_access(struct vm_area_struct *area, unsigned long addr,
>  {
>  	struct i915_mmap_offset *mmo = area->vm_private_data;
>  	struct drm_i915_gem_object *obj = mmo->obj;
> +	struct i915_gem_ww_ctx ww;
>  	void *vaddr;
> +	int err = 0;
>  
>  	if (i915_gem_object_is_readonly(obj) && write)
>  		return -EACCES;
> @@ -430,10 +432,18 @@ vm_access(struct vm_area_struct *area, unsigned long addr,
>  	if (addr >= obj->base.size)
>  		return -EINVAL;
>  
> +	i915_gem_ww_ctx_init(&ww, true);
> +retry:
> +	err = i915_gem_object_lock(obj, &ww);
> +	if (err)
> +		goto out;
> +
>  	/* As this is primarily for debugging, let's focus on simplicity */
>  	vaddr = i915_gem_object_pin_map(obj, I915_MAP_FORCE_WC);
> -	if (IS_ERR(vaddr))
> -		return PTR_ERR(vaddr);
> +	if (IS_ERR(vaddr)) {
> +		err = PTR_ERR(vaddr);
> +		goto out;
> +	}
>  
>  	if (write) {
>  		memcpy(vaddr + addr, buf, len);
> @@ -443,6 +453,16 @@ vm_access(struct vm_area_struct *area, unsigned long addr,
>  	}
>  
>  	i915_gem_object_unpin_map(obj);
> +out:
> +	if (err == -EDEADLK) {
> +		err = i915_gem_ww_ctx_backoff(&ww);
> +		if (!err)
> +			goto retry;
> +	}
> +	i915_gem_ww_ctx_fini(&ww);
> +
> +	if (err)
> +		return err;
>  
>  	return len;
>  }
> -- 
> 2.31.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the Intel-gfx mailing list