Skip to content

Commit a2a4f91

Browse files
icklejnikula
authored andcommitted
drm/i915: Allow i915_gem_object_get_page() on userptr as well
commit 033908a Author: Dave Gordon <david.s.gordon@intel.com> Date: Thu Dec 10 18:51:23 2015 +0000 drm/i915: mark GEM object pages dirty when mapped & written by the CPU introduced a check into i915_gem_object_get_dirty_pages() that returned a NULL pointer when called with a bad object, one that was not backed by shmemfs. This WARN was too strict as we can work on all struct page backed objects, and resulted in a WARN + GPF for existing userspace. In order to differentiate the various types of objects, add a new flags field to the i915_gem_object_ops struct to describe their capabilities, with the first flag being whether the object has struct pages. v2: Drop silly const before an integer in the structure declaration. Testcase: igt/gem_userptr_blits/relocations Reported-and-tested-by: Kristian Høgsberg Kristensen <krh@bitplanet.net> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Dave Gordon <david.s.gordon@intel.com> Cc: Kristian Høgsberg Kristensen <krh@bitplanet.net> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Dave Gordon <david.s.gordon@intel.com> Reviewed-by: Kristian Høgsberg Kristensen <krh@bitplanet.net> Tested-by: Michal Winiarski <michal.winiarski@intel.com> Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Fixes: 033908a ("drm/i915: mark GEM object pages dirty when mapped & written by the CPU") Link: http://patchwork.freedesktop.org/patch/msgid/1453487551-16799-1-git-send-email-chris@chris-wilson.co.uk (cherry picked from commit de47266) Signed-off-by: Jani Nikula <jani.nikula@intel.com>
1 parent f2e3051 commit a2a4f91

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,9 @@ enum hdmi_force_audio {
19881988
#define I915_GTT_OFFSET_NONE ((u32)-1)
19891989

19901990
struct drm_i915_gem_object_ops {
1991+
unsigned int flags;
1992+
#define I915_GEM_OBJECT_HAS_STRUCT_PAGE 0x1
1993+
19911994
/* Interface between the GEM object and its backing storage.
19921995
* get_pages() is called once prior to the use of the associated set
19931996
* of pages before to binding them into the GTT, and put_pages() is
@@ -2003,6 +2006,7 @@ struct drm_i915_gem_object_ops {
20032006
*/
20042007
int (*get_pages)(struct drm_i915_gem_object *);
20052008
void (*put_pages)(struct drm_i915_gem_object *);
2009+
20062010
int (*dmabuf_export)(struct drm_i915_gem_object *);
20072011
void (*release)(struct drm_i915_gem_object *);
20082012
};

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4425,6 +4425,7 @@ void i915_gem_object_init(struct drm_i915_gem_object *obj,
44254425
}
44264426

44274427
static const struct drm_i915_gem_object_ops i915_gem_object_ops = {
4428+
.flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE,
44284429
.get_pages = i915_gem_object_get_pages_gtt,
44294430
.put_pages = i915_gem_object_put_pages_gtt,
44304431
};
@@ -5261,7 +5262,7 @@ i915_gem_object_get_dirty_page(struct drm_i915_gem_object *obj, int n)
52615262
struct page *page;
52625263

52635264
/* Only default objects have per-page dirty tracking */
5264-
if (WARN_ON(obj->ops != &i915_gem_object_ops))
5265+
if (WARN_ON((obj->ops->flags & I915_GEM_OBJECT_HAS_STRUCT_PAGE) == 0))
52655266
return NULL;
52665267

52675268
page = i915_gem_object_get_page(obj, n);

drivers/gpu/drm/i915/i915_gem_userptr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,10 @@ i915_gem_userptr_dmabuf_export(struct drm_i915_gem_object *obj)
789789
}
790790

791791
static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
792-
.dmabuf_export = i915_gem_userptr_dmabuf_export,
792+
.flags = I915_GEM_OBJECT_HAS_STRUCT_PAGE,
793793
.get_pages = i915_gem_userptr_get_pages,
794794
.put_pages = i915_gem_userptr_put_pages,
795+
.dmabuf_export = i915_gem_userptr_dmabuf_export,
795796
.release = i915_gem_userptr_release,
796797
};
797798

0 commit comments

Comments
 (0)