[Intel-gfx] [RFC 2/8] drm/i915: Reference count struct drm_i915_file_private
Tvrtko Ursulin
tvrtko.ursulin at linux.intel.com
Thu Dec 19 18:00:13 UTC 2019
From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
In the following patches we will develope a need to peek into the client
owned data from any potential leftover contexts.
To facilitate this add reference counting to file_priv.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
drivers/gpu/drm/i915/i915_drv.c | 4 ----
drivers/gpu/drm/i915/i915_drv.h | 4 +++-
drivers/gpu/drm/i915/i915_gem.c | 14 +++++++++++++-
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index e5a7c6f02a47..b482b2e5f31f 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -853,7 +853,7 @@ int i915_gem_context_open(struct drm_i915_private *i915,
void i915_gem_context_close(struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
- struct drm_i915_private *i915 = file_priv->dev_priv;
+ struct drm_i915_private *i915 = file_priv->i915;
struct i915_gem_context *ctx;
unsigned long idx;
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 8b08cfe30151..0c9c93418068 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1633,13 +1633,9 @@ static void i915_driver_lastclose(struct drm_device *dev)
static void i915_driver_postclose(struct drm_device *dev, struct drm_file *file)
{
- struct drm_i915_file_private *file_priv = file->driver_priv;
-
i915_gem_context_close(file);
i915_gem_release(dev, file);
- kfree_rcu(file_priv, rcu);
-
/* Catch up with all the deferred frees from "this" client */
i915_gem_flush_free_objects(to_i915(dev));
}
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 9226c0515506..6f13f0c619e9 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -190,13 +190,15 @@ struct i915_mm_struct;
struct i915_mmu_object;
struct drm_i915_file_private {
- struct drm_i915_private *dev_priv;
+ struct kref kref;
union {
struct drm_file *file;
struct rcu_head rcu;
};
+ struct drm_i915_private *i915;
+
struct {
spinlock_t lock;
struct list_head request_list;
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index f19c678ebefc..a52fdae95f58 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -1518,6 +1518,14 @@ int i915_gem_freeze_late(struct drm_i915_private *i915)
return 0;
}
+static void gem_release(struct kref *kref)
+{
+ struct drm_i915_file_private *fpriv =
+ container_of(kref, typeof(*fpriv), kref);
+
+ kfree_rcu(fpriv, rcu);
+}
+
void i915_gem_release(struct drm_device *dev, struct drm_file *file)
{
struct drm_i915_file_private *file_priv = file->driver_priv;
@@ -1531,6 +1539,8 @@ void i915_gem_release(struct drm_device *dev, struct drm_file *file)
list_for_each_entry(request, &file_priv->mm.request_list, client_link)
request->file_priv = NULL;
spin_unlock(&file_priv->mm.lock);
+
+ kref_put(&file_priv->kref, gem_release);
}
int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
@@ -1544,8 +1554,10 @@ int i915_gem_open(struct drm_i915_private *i915, struct drm_file *file)
if (!file_priv)
return -ENOMEM;
+ kref_init(&file_priv->kref);
+
file->driver_priv = file_priv;
- file_priv->dev_priv = i915;
+ file_priv->i915 = i915;
file_priv->file = file;
spin_lock_init(&file_priv->mm.lock);
--
2.20.1
More information about the Intel-gfx
mailing list