drm/i915: Store owning file on the i915_address_space
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 4 Aug 2016 06:52:25 +0000 (07:52 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 4 Aug 2016 07:09:17 +0000 (08:09 +0100)
For the global GTT (and aliasing GTT), the address space is owned by the
device (it is a global resource) and so the per-file owner field is
NULL. For per-process GTT (where we create an address space per
context), each is owned by the opening file. We can use this ownership
information to both distinguish GGTT and ppGTT address spaces, as well
as occasionally inspect the owner.

v2: Whitespace, tells us who owns i915_address_space

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1470293567-10811-6-git-send-email-chris@chris-wilson.co.uk
drivers/gpu/drm/i915/i915_debugfs.c
drivers/gpu/drm/i915/i915_drv.h
drivers/gpu/drm/i915/i915_gem_context.c
drivers/gpu/drm/i915/i915_gem_gtt.c
drivers/gpu/drm/i915/i915_gem_gtt.h

index e7724be9f4db96ac606e9aea09bcd04fb6ffb989..9bd5eb3af277d8fc3404bd1aa3bb5af9da6b8c7c 100644 (file)
@@ -354,7 +354,7 @@ static int per_file_stats(int id, void *ptr, void *data)
                } else {
                        struct i915_hw_ppgtt *ppgtt = i915_vm_to_ppgtt(vma->vm);
 
-                       if (ppgtt->file_priv != stats->file_priv)
+                       if (ppgtt->base.file != stats->file_priv)
                                continue;
                }
 
index 9b18b9c875ec7219e9655885c7359b36249e0915..7452a401595669049a78e9a758ab07f66476db21 100644 (file)
@@ -3300,7 +3300,6 @@ i915_vm_to_ppgtt(struct i915_address_space *vm)
        return container_of(vm, struct i915_hw_ppgtt, base);
 }
 
-
 static inline bool i915_gem_obj_ggtt_bound(struct drm_i915_gem_object *obj)
 {
        return i915_gem_obj_ggtt_bound_view(obj, &i915_ggtt_view_normal);
index d7a7cc8b6fa4e30d31b8b3421dc261db4373230f..24383f0ea3a486db81ccd5658bff98b8405ff909 100644 (file)
@@ -327,7 +327,8 @@ i915_gem_create_context(struct drm_device *dev,
                return ctx;
 
        if (USES_FULL_PPGTT(dev)) {
-               struct i915_hw_ppgtt *ppgtt = i915_ppgtt_create(dev, file_priv);
+               struct i915_hw_ppgtt *ppgtt =
+                       i915_ppgtt_create(to_i915(dev), file_priv);
 
                if (IS_ERR(ppgtt)) {
                        DRM_DEBUG_DRIVER("PPGTT setup failed (%ld)\n",
index 03801297f85b20d0055720c34e926033ef4b2fb8..ad97892726ce76fc9b02c3c7fe05eaf29a97b50f 100644 (file)
@@ -2104,11 +2104,12 @@ static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt)
        return 0;
 }
 
-static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+static int __hw_ppgtt_init(struct i915_hw_ppgtt *ppgtt,
+                          struct drm_i915_private *dev_priv)
 {
-       ppgtt->base.dev = dev;
+       ppgtt->base.dev = &dev_priv->drm;
 
-       if (INTEL_INFO(dev)->gen < 8)
+       if (INTEL_INFO(dev_priv)->gen < 8)
                return gen6_ppgtt_init(ppgtt);
        else
                return gen8_ppgtt_init(ppgtt);
@@ -2142,15 +2143,17 @@ static void gtt_write_workarounds(struct drm_device *dev)
                I915_WRITE(GEN8_L3_LRA_1_GPGPU, GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT);
 }
 
-static int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt)
+static int i915_ppgtt_init(struct i915_hw_ppgtt *ppgtt,
+                          struct drm_i915_private *dev_priv,
+                          struct drm_i915_file_private *file_priv)
 {
-       struct drm_i915_private *dev_priv = to_i915(dev);
-       int ret = 0;
+       int ret;
 
-       ret = __hw_ppgtt_init(dev, ppgtt);
+       ret = __hw_ppgtt_init(ppgtt, dev_priv);
        if (ret == 0) {
                kref_init(&ppgtt->ref);
                i915_address_space_init(&ppgtt->base, dev_priv);
+               ppgtt->base.file = file_priv;
        }
 
        return ret;
@@ -2182,7 +2185,8 @@ int i915_ppgtt_init_hw(struct drm_device *dev)
 }
 
 struct i915_hw_ppgtt *
-i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv)
+i915_ppgtt_create(struct drm_i915_private *dev_priv,
+                 struct drm_i915_file_private *fpriv)
 {
        struct i915_hw_ppgtt *ppgtt;
        int ret;
@@ -2191,14 +2195,12 @@ i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv)
        if (!ppgtt)
                return ERR_PTR(-ENOMEM);
 
-       ret = i915_ppgtt_init(dev, ppgtt);
+       ret = i915_ppgtt_init(ppgtt, dev_priv, fpriv);
        if (ret) {
                kfree(ppgtt);
                return ERR_PTR(ret);
        }
 
-       ppgtt->file_priv = fpriv;
-
        trace_i915_ppgtt_create(&ppgtt->base);
 
        return ppgtt;
@@ -2784,9 +2786,8 @@ int i915_gem_init_ggtt(struct drm_i915_private *dev_priv)
                if (!ppgtt)
                        return -ENOMEM;
 
-               ret = __hw_ppgtt_init(&dev_priv->drm, ppgtt);
+               ret = __hw_ppgtt_init(ppgtt, dev_priv);
                if (ret) {
-                       ppgtt->base.cleanup(&ppgtt->base);
                        kfree(ppgtt);
                        return ret;
                }
@@ -3179,7 +3180,6 @@ int i915_ggtt_probe_hw(struct drm_i915_private *dev_priv)
        int ret;
 
        ggtt->base.dev = &dev_priv->drm;
-       ggtt->base.is_ggtt = true;
 
        if (INTEL_GEN(dev_priv) <= 5)
                ret = i915_gmch_probe(ggtt);
@@ -3314,7 +3314,7 @@ void i915_gem_restore_gtt_mappings(struct drm_device *dev)
 
                        struct i915_hw_ppgtt *ppgtt;
 
-                       if (vm->is_ggtt)
+                       if (i915_is_ggtt(vm))
                                ppgtt = dev_priv->mm.aliasing_ppgtt;
                        else
                                ppgtt = i915_vm_to_ppgtt(vm);
index 48ce7222cc32b372ffd27288225a543ec04e3029..cf8e3fc0692d030477deeb49dd5f0d586e34ae26 100644 (file)
@@ -272,12 +272,19 @@ struct i915_pml4 {
 struct i915_address_space {
        struct drm_mm mm;
        struct drm_device *dev;
+       /* Every address space belongs to a struct file - except for the global
+        * GTT that is owned by the driver (and so @file is set to NULL). In
+        * principle, no information should leak from one context to another
+        * (or between files/processes etc) unless explicitly shared by the
+        * owner. Tracking the owner is important in order to free up per-file
+        * objects along with the file, to aide resource tracking, and to
+        * assign blame.
+        */
+       struct drm_i915_file_private *file;
        struct list_head global_link;
        u64 start;              /* Start offset always 0 for dri2 */
        u64 total;              /* size addr space maps (ex. 2GB for ggtt) */
 
-       bool is_ggtt;
-
        struct i915_page_scratch *scratch_page;
        struct i915_page_table *scratch_pt;
        struct i915_page_directory *scratch_pd;
@@ -338,7 +345,7 @@ struct i915_address_space {
                        u32 flags);
 };
 
-#define i915_is_ggtt(V) ((V)->is_ggtt)
+#define i915_is_ggtt(V) (!(V)->file)
 
 /* The Graphics Translation Table is the way in which GEN hardware translates a
  * Graphics Virtual Address into a Physical Address. In addition to the normal
@@ -377,8 +384,6 @@ struct i915_hw_ppgtt {
                struct i915_page_directory pd;          /* GEN6-7 */
        };
 
-       struct drm_i915_file_private *file_priv;
-
        gen6_pte_t __iomem *pd_addr;
 
        int (*enable)(struct i915_hw_ppgtt *ppgtt);
@@ -526,7 +531,7 @@ void i915_ggtt_cleanup_hw(struct drm_i915_private *dev_priv);
 
 int i915_ppgtt_init_hw(struct drm_device *dev);
 void i915_ppgtt_release(struct kref *kref);
-struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_device *dev,
+struct i915_hw_ppgtt *i915_ppgtt_create(struct drm_i915_private *dev_priv,
                                        struct drm_i915_file_private *fpriv);
 static inline void i915_ppgtt_get(struct i915_hw_ppgtt *ppgtt)
 {