diff options
author | Thomas Zimmermann <tzimmermann@suse.de> | 2019-05-16 19:27:46 +0300 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2019-05-17 14:14:11 +0300 |
commit | 5b24f715042da2a7f3fd059f15cc5a6fbd4f4ec6 (patch) | |
tree | 10786a77f38388273e4a631717232ba30cd3557c /drivers/gpu/drm/drm_gem_vram_helper.c | |
parent | 82ff2fb5d184e95c7877c58359cef4f5d43df9c1 (diff) | |
download | linux-5b24f715042da2a7f3fd059f15cc5a6fbd4f4ec6.tar.xz |
drm: Reserve/unreserve GEM VRAM BOs from within pin/unpin functions
The original bochs and vbox implementations of pin and unpin functions
automatically reserved BOs during validation. This functionality got lost
while converting the code to a generic implementation. This may result
in validating unlocked TTM BOs.
Adding the reserve and unreserve operations to GEM VRAM's pin and unpin
functions fixes the bochs and vbox drivers. Additionally the patch changes
the mgag200, ast and hibmc drivers to not reserve BOs by themselves.
Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reported-by: kernel test robot <lkp@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20190516162746.11636-3-tzimmermann@suse.de
Fixes: a3232987fdbf ("drm/bochs: Convert bochs driver to |struct drm_gem_vram_object|")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/drm_gem_vram_helper.c')
-rw-r--r-- | drivers/gpu/drm/drm_gem_vram_helper.c | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c index a002c03eaf4c..bde8237e8021 100644 --- a/drivers/gpu/drm/drm_gem_vram_helper.c +++ b/drivers/gpu/drm/drm_gem_vram_helper.c @@ -235,10 +235,12 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag) int i, ret; struct ttm_operation_ctx ctx = { false, false }; - if (gbo->pin_count) { - ++gbo->pin_count; - return 0; - } + ret = ttm_bo_reserve(&gbo->bo, true, false, NULL); + if (ret < 0) + return ret; + + if (gbo->pin_count) + goto out; drm_gem_vram_placement(gbo, pl_flag); for (i = 0; i < gbo->placement.num_placement; ++i) @@ -246,11 +248,17 @@ int drm_gem_vram_pin(struct drm_gem_vram_object *gbo, unsigned long pl_flag) ret = ttm_bo_validate(&gbo->bo, &gbo->placement, &ctx); if (ret < 0) - return ret; + goto err_ttm_bo_unreserve; - gbo->pin_count = 1; +out: + ++gbo->pin_count; + ttm_bo_unreserve(&gbo->bo); return 0; + +err_ttm_bo_unreserve: + ttm_bo_unreserve(&gbo->bo); + return ret; } EXPORT_SYMBOL(drm_gem_vram_pin); @@ -308,21 +316,32 @@ int drm_gem_vram_unpin(struct drm_gem_vram_object *gbo) int i, ret; struct ttm_operation_ctx ctx = { false, false }; + ret = ttm_bo_reserve(&gbo->bo, true, false, NULL); + if (ret < 0) + return ret; + if (WARN_ON_ONCE(!gbo->pin_count)) - return 0; + goto out; --gbo->pin_count; if (gbo->pin_count) - return 0; + goto out; for (i = 0; i < gbo->placement.num_placement ; ++i) gbo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT; ret = ttm_bo_validate(&gbo->bo, &gbo->placement, &ctx); if (ret < 0) - return ret; + goto err_ttm_bo_unreserve; + +out: + ttm_bo_unreserve(&gbo->bo); return 0; + +err_ttm_bo_unreserve: + ttm_bo_unreserve(&gbo->bo); + return ret; } EXPORT_SYMBOL(drm_gem_vram_unpin); @@ -377,12 +396,16 @@ int drm_gem_vram_push_to_system(struct drm_gem_vram_object *gbo) int i, ret; struct ttm_operation_ctx ctx = { false, false }; + ret = ttm_bo_reserve(&gbo->bo, true, false, NULL); + if (ret < 0) + return ret; + if (WARN_ON_ONCE(!gbo->pin_count)) - return 0; + goto out; --gbo->pin_count; if (gbo->pin_count) - return 0; + goto out; if (gbo->kmap.virtual) ttm_bo_kunmap(&gbo->kmap); @@ -393,9 +416,16 @@ int drm_gem_vram_push_to_system(struct drm_gem_vram_object *gbo) ret = ttm_bo_validate(&gbo->bo, &gbo->placement, &ctx); if (ret) - return ret; + goto err_ttm_bo_unreserve; + +out: + ttm_bo_unreserve(&gbo->bo); return 0; + +err_ttm_bo_unreserve: + ttm_bo_unreserve(&gbo->bo); + return ret; } EXPORT_SYMBOL(drm_gem_vram_push_to_system); |