[PATCH 3/6] mutable shrinkable
Matthew Auld
matthew.auld at intel.com
Fri Aug 20 17:49:53 UTC 2021
---
drivers/gpu/drm/i915/gem/i915_gem_internal.c | 3 +--
drivers/gpu/drm/i915/gem/i915_gem_object.c | 19 +++++++++++++++++++
drivers/gpu/drm/i915/gem/i915_gem_object.h | 6 +-----
.../gpu/drm/i915/gem/i915_gem_object_types.h | 6 +++---
drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 3 +--
drivers/gpu/drm/i915/gem/i915_gem_userptr.c | 5 ++---
.../gpu/drm/i915/gem/selftests/huge_pages.c | 7 +++----
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c | 2 +-
8 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_internal.c b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
index 13b217f75055..87270f54d6e5 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_internal.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_internal.c
@@ -138,7 +138,6 @@ static void i915_gem_object_put_pages_internal(struct drm_i915_gem_object *obj,
static const struct drm_i915_gem_object_ops i915_gem_object_internal_ops = {
.name = "i915_gem_object_internal",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = i915_gem_object_get_pages_internal,
.put_pages = i915_gem_object_put_pages_internal,
};
@@ -178,7 +177,7 @@ i915_gem_object_create_internal(struct drm_i915_private *i915,
drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &i915_gem_object_internal_ops, &lock_class, 0);
- obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE;
+ obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_SHRINKABLE;
/*
* Mark the object as volatile, such that the pages are marked as
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.c b/drivers/gpu/drm/i915/gem/i915_gem_object.c
index 6fb9afb65034..d6b75ada9ef4 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.c
@@ -509,6 +509,25 @@ bool i915_gem_object_has_iomem(const struct drm_i915_gem_object *obj)
return obj->mem_flags & I915_BO_FLAG_IOMEM;
}
+/**
+ * i915_gem_object_is_shrinkable - Whether the object is shrinkable
+ * @obj: The object to query.
+ *
+ * This function should only be called while the object is locked or pinned,
+ * otherwise the page backing may change under the caller.
+ *
+ * Return: True if shrinkable, false otherwise.
+ */
+bool i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
+{
+#ifdef CONFIG_LOCKDEP
+ if (IS_DGFX(to_i915(obj->base.dev)) &&
+ i915_gem_object_evictable((void __force *)obj))
+ assert_object_held_shared(obj);
+#endif
+ return obj->mem_flags & I915_BO_FLAG_SHRINKABLE;
+}
+
/**
* i915_gem_object_can_migrate - Whether an object likely can be migrated
*
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object.h b/drivers/gpu/drm/i915/gem/i915_gem_object.h
index 48112b9d76df..2d915f0ed84c 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object.h
@@ -280,11 +280,7 @@ bool i915_gem_object_has_struct_page(const struct drm_i915_gem_object *obj);
bool i915_gem_object_has_iomem(const struct drm_i915_gem_object *obj);
-static inline bool
-i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj)
-{
- return i915_gem_object_type_has(obj, I915_GEM_OBJECT_IS_SHRINKABLE);
-}
+bool i915_gem_object_is_shrinkable(const struct drm_i915_gem_object *obj);
static inline bool
i915_gem_object_is_proxy(const struct drm_i915_gem_object *obj)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
index 041b2b3e77eb..57275c75be5d 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
@@ -34,9 +34,8 @@ struct i915_lut_handle {
struct drm_i915_gem_object_ops {
unsigned int flags;
-#define I915_GEM_OBJECT_IS_SHRINKABLE BIT(1)
-#define I915_GEM_OBJECT_IS_PROXY BIT(2)
-#define I915_GEM_OBJECT_NO_MMAP BIT(3)
+#define I915_GEM_OBJECT_IS_PROXY BIT(1)
+#define I915_GEM_OBJECT_NO_MMAP BIT(2)
/* Interface between the GEM object and its backing storage.
* get_pages() is called once prior to the use of the associated set
@@ -309,6 +308,7 @@ struct drm_i915_gem_object {
unsigned int mem_flags;
#define I915_BO_FLAG_STRUCT_PAGE BIT(0) /* Object backed by struct pages */
#define I915_BO_FLAG_IOMEM BIT(1) /* Object backed by IO memory */
+#define I915_BO_FLAG_SHRINKABLE BIT(2)
/**
* @cache_level: The desired GTT caching level.
*
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
index ab02309f0752..093fa2fa815c 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c
@@ -503,7 +503,6 @@ static void shmem_release(struct drm_i915_gem_object *obj)
const struct drm_i915_gem_object_ops i915_gem_shmem_ops = {
.name = "i915_gem_object_shmem",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = shmem_get_pages,
.put_pages = shmem_put_pages,
@@ -566,7 +565,7 @@ static int shmem_object_init(struct intel_memory_region *mem,
GEM_BUG_ON(!(mapping_gfp_mask(mapping) & __GFP_RECLAIM));
i915_gem_object_init(obj, &i915_gem_shmem_ops, &lock_class, 0);
- obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE;
+ obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_SHRINKABLE;
obj->write_domain = I915_GEM_DOMAIN_CPU;
obj->read_domains = I915_GEM_DOMAIN_CPU;
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
index 468a7a617fbf..6ff4f96db857 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_userptr.c
@@ -409,8 +409,7 @@ i915_gem_userptr_pread(struct drm_i915_gem_object *obj,
static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
.name = "i915_gem_object_userptr",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE |
- I915_GEM_OBJECT_NO_MMAP |
+ .flags = I915_GEM_OBJECT_NO_MMAP |
I915_GEM_OBJECT_IS_PROXY,
.get_pages = i915_gem_userptr_get_pages,
.put_pages = i915_gem_userptr_put_pages,
@@ -550,7 +549,7 @@ i915_gem_userptr_ioctl(struct drm_device *dev,
drm_gem_private_object_init(dev, &obj->base, args->user_size);
i915_gem_object_init(obj, &i915_gem_userptr_ops, &lock_class, 0);
- obj->mem_flags = I915_BO_FLAG_STRUCT_PAGE;
+ obj->mem_flags = I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_SHRINKABLE;
obj->read_domains = I915_GEM_DOMAIN_CPU;
obj->write_domain = I915_GEM_DOMAIN_CPU;
i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
diff --git a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c
index a094f3ce1a90..e519dc7c99b7 100644
--- a/drivers/gpu/drm/i915/gem/selftests/huge_pages.c
+++ b/drivers/gpu/drm/i915/gem/selftests/huge_pages.c
@@ -140,7 +140,6 @@ static void put_huge_pages(struct drm_i915_gem_object *obj,
static const struct drm_i915_gem_object_ops huge_page_ops = {
.name = "huge-gem",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = get_huge_pages,
.put_pages = put_huge_pages,
};
@@ -168,7 +167,7 @@ huge_pages_object(struct drm_i915_private *i915,
drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &huge_page_ops, &lock_class, 0);
- obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE;
+ obj->mem_flags |= I915_BO_FLAG_STRUCT_PAGE | I915_BO_FLAG_SHRINKABLE;
i915_gem_object_set_volatile(obj);
obj->write_domain = I915_GEM_DOMAIN_CPU;
@@ -284,14 +283,12 @@ static void fake_put_huge_pages(struct drm_i915_gem_object *obj,
static const struct drm_i915_gem_object_ops fake_ops = {
.name = "fake-gem",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = fake_get_huge_pages,
.put_pages = fake_put_huge_pages,
};
static const struct drm_i915_gem_object_ops fake_ops_single = {
.name = "fake-gem",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = fake_get_huge_pages_single,
.put_pages = fake_put_huge_pages,
};
@@ -322,6 +319,8 @@ fake_huge_pages_object(struct drm_i915_private *i915, u64 size, bool single)
else
i915_gem_object_init(obj, &fake_ops, &lock_class, 0);
+ obj->mem_flags |= I915_BO_FLAG_SHRINKABLE;
+
i915_gem_object_set_volatile(obj);
obj->write_domain = I915_GEM_DOMAIN_CPU;
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
index f843a5040706..982affeb5c14 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
@@ -99,7 +99,6 @@ static void fake_put_pages(struct drm_i915_gem_object *obj,
static const struct drm_i915_gem_object_ops fake_ops = {
.name = "fake-gem",
- .flags = I915_GEM_OBJECT_IS_SHRINKABLE,
.get_pages = fake_get_pages,
.put_pages = fake_put_pages,
};
@@ -122,6 +121,7 @@ fake_dma_object(struct drm_i915_private *i915, u64 size)
drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &fake_ops, &lock_class, 0);
+ obj->mem_flags |= I915_BO_FLAG_SHRINKABLE;
i915_gem_object_set_volatile(obj);
--
2.26.3
More information about the Intel-gfx-trybot
mailing list