Skip to content

Commit 703ec3f

Browse files
committed
drm/vmwgfx: Remove the duplicate bo_free function
jira VULN-8161 cve CVE-2023-5633 commit-author Zack Rusin <zackr@vmware.com> commit 6b2e8aa upstream-diff Trivial resolution because our ttm_bo_init_reserved() still has the unused `size` argument. Remove the explicit bo_free parameter which was switching between vmw_bo_bo_free and vmw_gem_destroy which had exactly the same implementation. It makes no sense to keep parameter which is always the same, remove it and all code referencing it. Instead use the vmw_bo_bo_free directly. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Martin Krastev <krastevm@vmware.com> Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com> Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://patchwork.freedesktop.org/patch/msgid/20230131033542.953249-3-zack@kde.org (cherry picked from commit 6b2e8aa) Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent 2d35b65 commit 703ec3f

File tree

8 files changed

+27
-58
lines changed

8 files changed

+27
-58
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
4646
return container_of(bo, struct vmw_buffer_object, base);
4747
}
4848

49+
/**
50+
* vmw_bo_bo_free - vmw buffer object destructor
51+
*
52+
* @bo: Pointer to the embedded struct ttm_buffer_object
53+
*/
54+
static void vmw_bo_bo_free(struct ttm_buffer_object *bo)
55+
{
56+
struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
57+
58+
WARN_ON(vmw_bo->dirty);
59+
WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
60+
vmw_bo_unmap(vmw_bo);
61+
drm_gem_object_release(&bo->base);
62+
kfree(vmw_bo);
63+
}
64+
4965
/**
5066
* bo_is_vmw - check if the buffer object is a &vmw_buffer_object
5167
* @bo: ttm buffer object to be checked
@@ -58,8 +74,7 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
5874
*/
5975
static bool bo_is_vmw(struct ttm_buffer_object *bo)
6076
{
61-
return bo->destroy == &vmw_bo_bo_free ||
62-
bo->destroy == &vmw_gem_destroy;
77+
return bo->destroy == &vmw_bo_bo_free;
6378
}
6479

6580
/**
@@ -376,23 +391,6 @@ void vmw_bo_unmap(struct vmw_buffer_object *vbo)
376391
ttm_bo_kunmap(&vbo->map);
377392
}
378393

379-
380-
/**
381-
* vmw_bo_bo_free - vmw buffer object destructor
382-
*
383-
* @bo: Pointer to the embedded struct ttm_buffer_object
384-
*/
385-
void vmw_bo_bo_free(struct ttm_buffer_object *bo)
386-
{
387-
struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
388-
389-
WARN_ON(vmw_bo->dirty);
390-
WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
391-
vmw_bo_unmap(vmw_bo);
392-
drm_gem_object_release(&bo->base);
393-
kfree(vmw_bo);
394-
}
395-
396394
/* default destructor */
397395
static void vmw_bo_default_destroy(struct ttm_buffer_object *bo)
398396
{
@@ -449,22 +447,18 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
449447
int vmw_bo_create(struct vmw_private *vmw,
450448
size_t size, struct ttm_placement *placement,
451449
bool interruptible, bool pin,
452-
void (*bo_free)(struct ttm_buffer_object *bo),
453450
struct vmw_buffer_object **p_bo)
454451
{
455452
int ret;
456453

457-
BUG_ON(!bo_free);
458-
459454
*p_bo = kmalloc(sizeof(**p_bo), GFP_KERNEL);
460455
if (unlikely(!*p_bo)) {
461456
DRM_ERROR("Failed to allocate a buffer.\n");
462457
return -ENOMEM;
463458
}
464459

465460
ret = vmw_bo_init(vmw, *p_bo, size,
466-
placement, interruptible, pin,
467-
bo_free);
461+
placement, interruptible, pin);
468462
if (unlikely(ret != 0))
469463
goto out_error;
470464

@@ -484,16 +478,14 @@ int vmw_bo_create(struct vmw_private *vmw,
484478
* @placement: Initial placement.
485479
* @interruptible: Whether waits should be performed interruptible.
486480
* @pin: If the BO should be created pinned at a fixed location.
487-
* @bo_free: The buffer object destructor.
488481
* Returns: Zero on success, negative error code on error.
489482
*
490483
* Note that on error, the code will free the buffer object.
491484
*/
492485
int vmw_bo_init(struct vmw_private *dev_priv,
493486
struct vmw_buffer_object *vmw_bo,
494487
size_t size, struct ttm_placement *placement,
495-
bool interruptible, bool pin,
496-
void (*bo_free)(struct ttm_buffer_object *bo))
488+
bool interruptible, bool pin)
497489
{
498490
struct ttm_operation_ctx ctx = {
499491
.interruptible = interruptible,
@@ -503,7 +495,6 @@ int vmw_bo_init(struct vmw_private *dev_priv,
503495
struct drm_device *vdev = &dev_priv->drm;
504496
int ret;
505497

506-
WARN_ON_ONCE(!bo_free);
507498
memset(vmw_bo, 0, sizeof(*vmw_bo));
508499
BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3);
509500
vmw_bo->base.priority = 3;
@@ -515,7 +506,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
515506
ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, size,
516507
ttm_bo_type_device,
517508
placement,
518-
0, &ctx, NULL, NULL, bo_free);
509+
0, &ctx, NULL, NULL, vmw_bo_bo_free);
519510
if (unlikely(ret)) {
520511
return ret;
521512
}

drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
424424
* we can use tryreserve without failure.
425425
*/
426426
ret = vmw_bo_create(dev_priv, new_size, &vmw_mob_placement,
427-
true, true, vmw_bo_bo_free, &buf);
427+
true, true, &buf);
428428
if (ret) {
429429
DRM_ERROR("Failed initializing new cotable MOB.\n");
430430
goto out_done;

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
398398
* user of the bo currently.
399399
*/
400400
ret = vmw_bo_create(dev_priv, PAGE_SIZE,
401-
&vmw_sys_placement, false, true,
402-
&vmw_bo_bo_free, &vbo);
401+
&vmw_sys_placement, false, true, &vbo);
403402
if (unlikely(ret != 0))
404403
return ret;
405404

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -891,21 +891,18 @@ extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
891891
extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
892892
SVGAGuestPtr *ptr);
893893
extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
894-
extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
895894
extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
896895
unsigned long size,
897896
struct ttm_placement *placement,
898897
struct ttm_buffer_object **p_bo);
899898
extern int vmw_bo_create(struct vmw_private *dev_priv,
900899
size_t size, struct ttm_placement *placement,
901900
bool interruptible, bool pin,
902-
void (*bo_free)(struct ttm_buffer_object *bo),
903901
struct vmw_buffer_object **p_bo);
904902
extern int vmw_bo_init(struct vmw_private *dev_priv,
905903
struct vmw_buffer_object *vmw_bo,
906904
size_t size, struct ttm_placement *placement,
907-
bool interruptible, bool pin,
908-
void (*bo_free)(struct ttm_buffer_object *bo));
905+
bool interruptible, bool pin);
909906
extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
910907
struct drm_file *file_priv);
911908
extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
@@ -980,7 +977,6 @@ extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
980977
struct vmw_buffer_object **p_vbo);
981978
extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
982979
struct drm_file *filp);
983-
extern void vmw_gem_destroy(struct ttm_buffer_object *bo);
984980
extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
985981

986982
/**

drivers/gpu/drm/vmwgfx/vmwgfx_gem.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,6 @@ static const struct drm_gem_object_funcs vmw_gem_object_funcs = {
125125
.vm_ops = &vmw_vm_ops,
126126
};
127127

128-
/**
129-
* vmw_gem_destroy - vmw buffer object destructor
130-
*
131-
* @bo: Pointer to the embedded struct ttm_buffer_object
132-
*/
133-
void vmw_gem_destroy(struct ttm_buffer_object *bo)
134-
{
135-
struct vmw_buffer_object *vbo = vmw_buffer_object(bo);
136-
137-
WARN_ON(vbo->dirty);
138-
WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
139-
vmw_bo_unmap(vbo);
140-
drm_gem_object_release(&vbo->base.base);
141-
kfree(vbo);
142-
}
143-
144128
int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
145129
struct drm_file *filp,
146130
uint32_t size,
@@ -153,7 +137,7 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
153137
(dev_priv->has_mob) ?
154138
&vmw_sys_placement :
155139
&vmw_vram_sys_placement,
156-
true, false, &vmw_gem_destroy, p_vbo);
140+
true, false, p_vbo);
157141

158142
(*p_vbo)->base.base.funcs = &vmw_gem_object_funcs;
159143
if (ret != 0)

drivers/gpu/drm/vmwgfx/vmwgfx_resource.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res,
332332

333333
ret = vmw_bo_create(res->dev_priv, res->backup_size,
334334
res->func->backup_placement,
335-
interruptible, false,
336-
&vmw_bo_bo_free, &backup);
335+
interruptible, false, &backup);
337336
if (unlikely(ret != 0))
338337
goto out_no_bo;
339338

drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane,
445445
vmw_overlay_pause_all(dev_priv);
446446
ret = vmw_bo_create(dev_priv, size,
447447
&vmw_vram_placement,
448-
false, true, &vmw_bo_bo_free, &vps->bo);
448+
false, true, &vps->bo);
449449
vmw_overlay_resume_all(dev_priv);
450450
if (ret) {
451451
vps->bo = NULL; /* vmw_bo_init frees on error */

drivers/gpu/drm/vmwgfx/vmwgfx_shader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv,
893893
return -EINVAL;
894894

895895
ret = vmw_bo_create(dev_priv, size, &vmw_sys_placement,
896-
true, true, vmw_bo_bo_free, &buf);
896+
true, true, &buf);
897897
if (unlikely(ret != 0))
898898
goto out;
899899

0 commit comments

Comments
 (0)