Commit 7867d709 authored by Chris Wilson's avatar Chris Wilson

drm/i915/gem: Distinguish each object type

Separate each object class into a separate lock type to avoid lockdep
cross-contamination between paths (i.e. userptr!).
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: default avatarMatthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191022144501.26486-1-chris@chris-wilson.co.uk
parent a201b00e
...@@ -256,6 +256,7 @@ static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = { ...@@ -256,6 +256,7 @@ static const struct drm_i915_gem_object_ops i915_gem_object_dmabuf_ops = {
struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
struct dma_buf *dma_buf) struct dma_buf *dma_buf)
{ {
static struct lock_class_key lock_class;
struct dma_buf_attachment *attach; struct dma_buf_attachment *attach;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
int ret; int ret;
...@@ -287,7 +288,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, ...@@ -287,7 +288,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev,
} }
drm_gem_private_object_init(dev, &obj->base, dma_buf->size); drm_gem_private_object_init(dev, &obj->base, dma_buf->size);
i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops); i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops, &lock_class);
obj->base.import_attach = attach; obj->base.import_attach = attach;
obj->base.resv = dma_buf->resv; obj->base.resv = dma_buf->resv;
......
...@@ -164,6 +164,7 @@ struct drm_i915_gem_object * ...@@ -164,6 +164,7 @@ struct drm_i915_gem_object *
i915_gem_object_create_internal(struct drm_i915_private *i915, i915_gem_object_create_internal(struct drm_i915_private *i915,
phys_addr_t size) phys_addr_t size)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
unsigned int cache_level; unsigned int cache_level;
...@@ -178,7 +179,7 @@ i915_gem_object_create_internal(struct drm_i915_private *i915, ...@@ -178,7 +179,7 @@ i915_gem_object_create_internal(struct drm_i915_private *i915,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
drm_gem_private_object_init(&i915->drm, &obj->base, size); drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &i915_gem_object_internal_ops); i915_gem_object_init(obj, &i915_gem_object_internal_ops, &lock_class);
/* /*
* Mark the object as volatile, such that the pages are marked as * Mark the object as volatile, such that the pages are marked as
......
...@@ -47,9 +47,10 @@ void i915_gem_object_free(struct drm_i915_gem_object *obj) ...@@ -47,9 +47,10 @@ void i915_gem_object_free(struct drm_i915_gem_object *obj)
} }
void i915_gem_object_init(struct drm_i915_gem_object *obj, void i915_gem_object_init(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_object_ops *ops) const struct drm_i915_gem_object_ops *ops,
struct lock_class_key *key)
{ {
mutex_init(&obj->mm.lock); __mutex_init(&obj->mm.lock, "obj->mm.lock", key);
spin_lock_init(&obj->vma.lock); spin_lock_init(&obj->vma.lock);
INIT_LIST_HEAD(&obj->vma.list); INIT_LIST_HEAD(&obj->vma.list);
......
...@@ -23,7 +23,8 @@ struct drm_i915_gem_object *i915_gem_object_alloc(void); ...@@ -23,7 +23,8 @@ struct drm_i915_gem_object *i915_gem_object_alloc(void);
void i915_gem_object_free(struct drm_i915_gem_object *obj); void i915_gem_object_free(struct drm_i915_gem_object *obj);
void i915_gem_object_init(struct drm_i915_gem_object *obj, void i915_gem_object_init(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_object_ops *ops); const struct drm_i915_gem_object_ops *ops,
struct lock_class_key *key);
struct drm_i915_gem_object * struct drm_i915_gem_object *
i915_gem_object_create_shmem(struct drm_i915_private *i915, i915_gem_object_create_shmem(struct drm_i915_private *i915,
resource_size_t size); resource_size_t size);
......
...@@ -465,6 +465,7 @@ create_shmem(struct intel_memory_region *mem, ...@@ -465,6 +465,7 @@ create_shmem(struct intel_memory_region *mem,
resource_size_t size, resource_size_t size,
unsigned int flags) unsigned int flags)
{ {
static struct lock_class_key lock_class;
struct drm_i915_private *i915 = mem->i915; struct drm_i915_private *i915 = mem->i915;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct address_space *mapping; struct address_space *mapping;
...@@ -491,7 +492,7 @@ create_shmem(struct intel_memory_region *mem, ...@@ -491,7 +492,7 @@ create_shmem(struct intel_memory_region *mem,
mapping_set_gfp_mask(mapping, mask); mapping_set_gfp_mask(mapping, mask);
GEM_BUG_ON(!(mapping_gfp_mask(mapping) & __GFP_RECLAIM)); GEM_BUG_ON(!(mapping_gfp_mask(mapping) & __GFP_RECLAIM));
i915_gem_object_init(obj, &i915_gem_shmem_ops); i915_gem_object_init(obj, &i915_gem_shmem_ops, &lock_class);
obj->write_domain = I915_GEM_DOMAIN_CPU; obj->write_domain = I915_GEM_DOMAIN_CPU;
obj->read_domains = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU;
......
...@@ -556,6 +556,7 @@ __i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, ...@@ -556,6 +556,7 @@ __i915_gem_object_create_stolen(struct drm_i915_private *dev_priv,
struct drm_mm_node *stolen, struct drm_mm_node *stolen,
struct intel_memory_region *mem) struct intel_memory_region *mem)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
unsigned int cache_level; unsigned int cache_level;
int err = -ENOMEM; int err = -ENOMEM;
...@@ -565,7 +566,7 @@ __i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, ...@@ -565,7 +566,7 @@ __i915_gem_object_create_stolen(struct drm_i915_private *dev_priv,
goto err; goto err;
drm_gem_private_object_init(&dev_priv->drm, &obj->base, stolen->size); drm_gem_private_object_init(&dev_priv->drm, &obj->base, stolen->size);
i915_gem_object_init(obj, &i915_gem_object_stolen_ops); i915_gem_object_init(obj, &i915_gem_object_stolen_ops, &lock_class);
obj->stolen = stolen; obj->stolen = stolen;
obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT; obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
......
...@@ -725,6 +725,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev, ...@@ -725,6 +725,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
void *data, void *data,
struct drm_file *file) struct drm_file *file)
{ {
static struct lock_class_key lock_class;
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct drm_i915_gem_userptr *args = data; struct drm_i915_gem_userptr *args = data;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
...@@ -769,7 +770,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev, ...@@ -769,7 +770,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
return -ENOMEM; return -ENOMEM;
drm_gem_private_object_init(dev, &obj->base, args->user_size); drm_gem_private_object_init(dev, &obj->base, args->user_size);
i915_gem_object_init(obj, &i915_gem_userptr_ops); i915_gem_object_init(obj, &i915_gem_userptr_ops, &lock_class);
obj->read_domains = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU;
obj->write_domain = I915_GEM_DOMAIN_CPU; obj->write_domain = I915_GEM_DOMAIN_CPU;
i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC); i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
......
...@@ -96,6 +96,7 @@ huge_gem_object(struct drm_i915_private *i915, ...@@ -96,6 +96,7 @@ huge_gem_object(struct drm_i915_private *i915,
phys_addr_t phys_size, phys_addr_t phys_size,
dma_addr_t dma_size) dma_addr_t dma_size)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
unsigned int cache_level; unsigned int cache_level;
...@@ -111,7 +112,7 @@ huge_gem_object(struct drm_i915_private *i915, ...@@ -111,7 +112,7 @@ huge_gem_object(struct drm_i915_private *i915,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
drm_gem_private_object_init(&i915->drm, &obj->base, dma_size); drm_gem_private_object_init(&i915->drm, &obj->base, dma_size);
i915_gem_object_init(obj, &huge_ops); i915_gem_object_init(obj, &huge_ops, &lock_class);
obj->read_domains = I915_GEM_DOMAIN_CPU; obj->read_domains = I915_GEM_DOMAIN_CPU;
obj->write_domain = I915_GEM_DOMAIN_CPU; obj->write_domain = I915_GEM_DOMAIN_CPU;
......
...@@ -149,6 +149,7 @@ huge_pages_object(struct drm_i915_private *i915, ...@@ -149,6 +149,7 @@ huge_pages_object(struct drm_i915_private *i915,
u64 size, u64 size,
unsigned int page_mask) unsigned int page_mask)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
GEM_BUG_ON(!size); GEM_BUG_ON(!size);
...@@ -165,7 +166,7 @@ huge_pages_object(struct drm_i915_private *i915, ...@@ -165,7 +166,7 @@ huge_pages_object(struct drm_i915_private *i915,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
drm_gem_private_object_init(&i915->drm, &obj->base, size); drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &huge_page_ops); i915_gem_object_init(obj, &huge_page_ops, &lock_class);
i915_gem_object_set_volatile(obj); i915_gem_object_set_volatile(obj);
...@@ -295,6 +296,7 @@ static const struct drm_i915_gem_object_ops fake_ops_single = { ...@@ -295,6 +296,7 @@ static const struct drm_i915_gem_object_ops fake_ops_single = {
static struct drm_i915_gem_object * static struct drm_i915_gem_object *
fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single) fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
GEM_BUG_ON(!size); GEM_BUG_ON(!size);
...@@ -313,9 +315,9 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single) ...@@ -313,9 +315,9 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single)
drm_gem_private_object_init(&i915->drm, &obj->base, size); drm_gem_private_object_init(&i915->drm, &obj->base, size);
if (single) if (single)
i915_gem_object_init(obj, &fake_ops_single); i915_gem_object_init(obj, &fake_ops_single, &lock_class);
else else
i915_gem_object_init(obj, &fake_ops); i915_gem_object_init(obj, &fake_ops, &lock_class);
i915_gem_object_set_volatile(obj); i915_gem_object_set_volatile(obj);
......
...@@ -152,6 +152,7 @@ static const struct drm_i915_gem_object_ops intel_vgpu_gem_ops = { ...@@ -152,6 +152,7 @@ static const struct drm_i915_gem_object_ops intel_vgpu_gem_ops = {
static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev, static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,
struct intel_vgpu_fb_info *info) struct intel_vgpu_fb_info *info)
{ {
static struct lock_class_key lock_class;
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
...@@ -161,7 +162,7 @@ static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev, ...@@ -161,7 +162,7 @@ static struct drm_i915_gem_object *vgpu_create_gem(struct drm_device *dev,
drm_gem_private_object_init(dev, &obj->base, drm_gem_private_object_init(dev, &obj->base,
roundup(info->size, PAGE_SIZE)); roundup(info->size, PAGE_SIZE));
i915_gem_object_init(obj, &intel_vgpu_gem_ops); i915_gem_object_init(obj, &intel_vgpu_gem_ops, &lock_class);
obj->read_domains = I915_GEM_DOMAIN_GTT; obj->read_domains = I915_GEM_DOMAIN_GTT;
obj->write_domain = 0; obj->write_domain = 0;
......
...@@ -104,6 +104,7 @@ static const struct drm_i915_gem_object_ops fake_ops = { ...@@ -104,6 +104,7 @@ static const struct drm_i915_gem_object_ops fake_ops = {
static struct drm_i915_gem_object * static struct drm_i915_gem_object *
fake_dma_object(struct drm_i915_private *i915, u64 size) fake_dma_object(struct drm_i915_private *i915, u64 size)
{ {
static struct lock_class_key lock_class;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
GEM_BUG_ON(!size); GEM_BUG_ON(!size);
...@@ -117,7 +118,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size) ...@@ -117,7 +118,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size)
goto err; goto err;
drm_gem_private_object_init(&i915->drm, &obj->base, size); drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &fake_ops); i915_gem_object_init(obj, &fake_ops, &lock_class);
i915_gem_object_set_volatile(obj); i915_gem_object_set_volatile(obj);
......
...@@ -19,6 +19,7 @@ mock_object_create(struct intel_memory_region *mem, ...@@ -19,6 +19,7 @@ mock_object_create(struct intel_memory_region *mem,
resource_size_t size, resource_size_t size,
unsigned int flags) unsigned int flags)
{ {
static struct lock_class_key lock_class;
struct drm_i915_private *i915 = mem->i915; struct drm_i915_private *i915 = mem->i915;
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
...@@ -30,7 +31,7 @@ mock_object_create(struct intel_memory_region *mem, ...@@ -30,7 +31,7 @@ mock_object_create(struct intel_memory_region *mem,
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
drm_gem_private_object_init(&i915->drm, &obj->base, size); drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &mock_region_obj_ops); i915_gem_object_init(obj, &mock_region_obj_ops, &lock_class);
obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT; obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment