Skip to content

Commit c5358f9

Browse files
committed
drm/vmwgfx: Rename vmw_buffer_object to vmw_bo
jira VULN-8161 cve CVE-2023-5633 commit-author Zack Rusin <zackr@vmware.com> commit 09881d2 upstream-diff Trivial resolution because our ttm_bo_init_reserved() still has the unused `size` argument. And then trivial header #include resolution since we have ttm_bo_api.h, not ttm_bo.h. The rest of the drivers which are using ttm have mostly standardized on driver_prefix_bo as the name for subclasses of the TTM buffer object. Make vmwgfx match the rest of the drivers and follow the same naming semantics. This is especially clear given that the name of the file in which the object was defined is vmw_bo.c. 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-4-zack@kde.org (cherry picked from commit 09881d2) Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent 703ec3f commit c5358f9

25 files changed

+419
-385
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0 OR MIT
22
/**************************************************************************
33
*
4-
* Copyright © 2011-2018 VMware, Inc., Palo Alto, CA., USA
4+
* Copyright © 2011-2023 VMware, Inc., Palo Alto, CA., USA
55
* All Rights Reserved.
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -26,55 +26,41 @@
2626
*
2727
**************************************************************************/
2828

29-
#include <drm/ttm/ttm_placement.h>
30-
29+
#include "vmwgfx_bo.h"
3130
#include "vmwgfx_drv.h"
32-
#include "ttm_object.h"
3331

3432

35-
/**
36-
* vmw_buffer_object - Convert a struct ttm_buffer_object to a struct
37-
* vmw_buffer_object.
38-
*
39-
* @bo: Pointer to the TTM buffer object.
40-
* Return: Pointer to the struct vmw_buffer_object embedding the
41-
* TTM buffer object.
42-
*/
43-
static struct vmw_buffer_object *
44-
vmw_buffer_object(struct ttm_buffer_object *bo)
45-
{
46-
return container_of(bo, struct vmw_buffer_object, base);
47-
}
33+
#include <drm/ttm/ttm_placement.h>
4834

4935
/**
50-
* vmw_bo_bo_free - vmw buffer object destructor
36+
* vmw_bo_free - vmw_bo destructor
5137
*
5238
* @bo: Pointer to the embedded struct ttm_buffer_object
5339
*/
54-
static void vmw_bo_bo_free(struct ttm_buffer_object *bo)
40+
static void vmw_bo_free(struct ttm_buffer_object *bo)
5541
{
56-
struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
42+
struct vmw_bo *vbo = to_vmw_bo(&bo->base);
5743

58-
WARN_ON(vmw_bo->dirty);
59-
WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
60-
vmw_bo_unmap(vmw_bo);
44+
WARN_ON(vbo->dirty);
45+
WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
46+
vmw_bo_unmap(vbo);
6147
drm_gem_object_release(&bo->base);
62-
kfree(vmw_bo);
48+
kfree(vbo);
6349
}
6450

6551
/**
66-
* bo_is_vmw - check if the buffer object is a &vmw_buffer_object
52+
* bo_is_vmw - check if the buffer object is a &vmw_bo
6753
* @bo: ttm buffer object to be checked
6854
*
6955
* Uses destroy function associated with the object to determine if this is
70-
* a &vmw_buffer_object.
56+
* a &vmw_bo.
7157
*
7258
* Returns:
73-
* true if the object is of &vmw_buffer_object type, false if not.
59+
* true if the object is of &vmw_bo type, false if not.
7460
*/
7561
static bool bo_is_vmw(struct ttm_buffer_object *bo)
7662
{
77-
return bo->destroy == &vmw_bo_bo_free;
63+
return bo->destroy == &vmw_bo_free;
7864
}
7965

8066
/**
@@ -88,7 +74,7 @@ static bool bo_is_vmw(struct ttm_buffer_object *bo)
8874
* -ERESTARTSYS if interrupted by a signal
8975
*/
9076
int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
91-
struct vmw_buffer_object *buf,
77+
struct vmw_bo *buf,
9278
struct ttm_placement *placement,
9379
bool interruptible)
9480
{
@@ -130,7 +116,7 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
130116
* -ERESTARTSYS if interrupted by a signal
131117
*/
132118
int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
133-
struct vmw_buffer_object *buf,
119+
struct vmw_bo *buf,
134120
bool interruptible)
135121
{
136122
struct ttm_operation_ctx ctx = {interruptible, false };
@@ -178,7 +164,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
178164
* -ERESTARTSYS if interrupted by a signal
179165
*/
180166
int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
181-
struct vmw_buffer_object *buf,
167+
struct vmw_bo *buf,
182168
bool interruptible)
183169
{
184170
return vmw_bo_pin_in_placement(dev_priv, buf, &vmw_vram_placement,
@@ -199,7 +185,7 @@ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
199185
* -ERESTARTSYS if interrupted by a signal
200186
*/
201187
int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
202-
struct vmw_buffer_object *buf,
188+
struct vmw_bo *buf,
203189
bool interruptible)
204190
{
205191
struct ttm_operation_ctx ctx = {interruptible, false };
@@ -263,7 +249,7 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
263249
* -ERESTARTSYS if interrupted by a signal
264250
*/
265251
int vmw_bo_unpin(struct vmw_private *dev_priv,
266-
struct vmw_buffer_object *buf,
252+
struct vmw_bo *buf,
267253
bool interruptible)
268254
{
269255
struct ttm_buffer_object *bo = &buf->base;
@@ -308,7 +294,7 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo,
308294
* @pin: Whether to pin or unpin.
309295
*
310296
*/
311-
void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin)
297+
void vmw_bo_pin_reserved(struct vmw_bo *vbo, bool pin)
312298
{
313299
struct ttm_operation_ctx ctx = { false, true };
314300
struct ttm_place pl;
@@ -356,7 +342,7 @@ void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin)
356342
* 3) Buffer object destruction
357343
*
358344
*/
359-
void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo)
345+
void *vmw_bo_map_and_cache(struct vmw_bo *vbo)
360346
{
361347
struct ttm_buffer_object *bo = &vbo->base;
362348
bool not_used;
@@ -381,9 +367,9 @@ void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo)
381367
* @vbo: The buffer object whose map we are tearing down.
382368
*
383369
* This function tears down a cached map set up using
384-
* vmw_buffer_object_map_and_cache().
370+
* vmw_bo_map_and_cache().
385371
*/
386-
void vmw_bo_unmap(struct vmw_buffer_object *vbo)
372+
void vmw_bo_unmap(struct vmw_bo *vbo)
387373
{
388374
if (vbo->map.bo == NULL)
389375
return;
@@ -447,7 +433,7 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
447433
int vmw_bo_create(struct vmw_private *vmw,
448434
size_t size, struct ttm_placement *placement,
449435
bool interruptible, bool pin,
450-
struct vmw_buffer_object **p_bo)
436+
struct vmw_bo **p_bo)
451437
{
452438
int ret;
453439

@@ -473,7 +459,7 @@ int vmw_bo_create(struct vmw_private *vmw,
473459
* vmw_bo_init - Initialize a vmw buffer object
474460
*
475461
* @dev_priv: Pointer to the device private struct
476-
* @vmw_bo: Pointer to the struct vmw_buffer_object to initialize.
462+
* @vmw_bo: Pointer to the struct vmw_bo to initialize.
477463
* @size: Buffer object size in bytes.
478464
* @placement: Initial placement.
479465
* @interruptible: Whether waits should be performed interruptible.
@@ -483,7 +469,7 @@ int vmw_bo_create(struct vmw_private *vmw,
483469
* Note that on error, the code will free the buffer object.
484470
*/
485471
int vmw_bo_init(struct vmw_private *dev_priv,
486-
struct vmw_buffer_object *vmw_bo,
472+
struct vmw_bo *vmw_bo,
487473
size_t size, struct ttm_placement *placement,
488474
bool interruptible, bool pin)
489475
{
@@ -506,7 +492,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
506492
ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, size,
507493
ttm_bo_type_device,
508494
placement,
509-
0, &ctx, NULL, NULL, vmw_bo_bo_free);
495+
0, &ctx, NULL, NULL, vmw_bo_free);
510496
if (unlikely(ret)) {
511497
return ret;
512498
}
@@ -519,7 +505,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
519505
}
520506

521507
/**
522-
* vmw_user_bo_synccpu_grab - Grab a struct vmw_buffer_object for cpu
508+
* vmw_user_bo_synccpu_grab - Grab a struct vmw_bo for cpu
523509
* access, idling previous GPU operations on the buffer and optionally
524510
* blocking it for further command submissions.
525511
*
@@ -532,7 +518,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
532518
*
533519
* A blocking grab will be automatically released when @tfile is closed.
534520
*/
535-
static int vmw_user_bo_synccpu_grab(struct vmw_buffer_object *vmw_bo,
521+
static int vmw_user_bo_synccpu_grab(struct vmw_bo *vmw_bo,
536522
uint32_t flags)
537523
{
538524
bool nonblock = !!(flags & drm_vmw_synccpu_dontblock);
@@ -579,7 +565,7 @@ static int vmw_user_bo_synccpu_release(struct drm_file *filp,
579565
uint32_t handle,
580566
uint32_t flags)
581567
{
582-
struct vmw_buffer_object *vmw_bo;
568+
struct vmw_bo *vmw_bo;
583569
int ret = vmw_user_bo_lookup(filp, handle, &vmw_bo);
584570

585571
if (!ret) {
@@ -610,7 +596,7 @@ int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
610596
{
611597
struct drm_vmw_synccpu_arg *arg =
612598
(struct drm_vmw_synccpu_arg *) data;
613-
struct vmw_buffer_object *vbo;
599+
struct vmw_bo *vbo;
614600
int ret;
615601

616602
if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0
@@ -683,14 +669,14 @@ int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
683669
* @filp: The file the handle is registered with.
684670
* @handle: The user buffer object handle
685671
* @out: Pointer to a where a pointer to the embedded
686-
* struct vmw_buffer_object should be placed.
672+
* struct vmw_bo should be placed.
687673
* Return: Zero on success, Negative error code on error.
688674
*
689675
* The vmw buffer object pointer will be refcounted.
690676
*/
691677
int vmw_user_bo_lookup(struct drm_file *filp,
692678
uint32_t handle,
693-
struct vmw_buffer_object **out)
679+
struct vmw_bo **out)
694680
{
695681
struct drm_gem_object *gobj;
696682

@@ -701,7 +687,7 @@ int vmw_user_bo_lookup(struct drm_file *filp,
701687
return -ESRCH;
702688
}
703689

704-
*out = gem_to_vmw_bo(gobj);
690+
*out = to_vmw_bo(gobj);
705691
ttm_bo_get(&(*out)->base);
706692
drm_gem_object_put(gobj);
707693

@@ -761,7 +747,7 @@ int vmw_dumb_create(struct drm_file *file_priv,
761747
struct drm_mode_create_dumb *args)
762748
{
763749
struct vmw_private *dev_priv = vmw_priv(dev);
764-
struct vmw_buffer_object *vbo;
750+
struct vmw_bo *vbo;
765751
int cpp = DIV_ROUND_UP(args->bpp, 8);
766752
int ret;
767753

@@ -795,12 +781,12 @@ int vmw_dumb_create(struct drm_file *file_priv,
795781
*/
796782
void vmw_bo_swap_notify(struct ttm_buffer_object *bo)
797783
{
798-
/* Is @bo embedded in a struct vmw_buffer_object? */
784+
/* Is @bo embedded in a struct vmw_bo? */
799785
if (!bo_is_vmw(bo))
800786
return;
801787

802788
/* Kill any cached kernel maps before swapout */
803-
vmw_bo_unmap(vmw_buffer_object(bo));
789+
vmw_bo_unmap(to_vmw_bo(&bo->base));
804790
}
805791

806792

@@ -817,13 +803,13 @@ void vmw_bo_swap_notify(struct ttm_buffer_object *bo)
817803
void vmw_bo_move_notify(struct ttm_buffer_object *bo,
818804
struct ttm_resource *mem)
819805
{
820-
struct vmw_buffer_object *vbo;
806+
struct vmw_bo *vbo;
821807

822-
/* Make sure @bo is embedded in a struct vmw_buffer_object? */
808+
/* Make sure @bo is embedded in a struct vmw_bo? */
823809
if (!bo_is_vmw(bo))
824810
return;
825811

826-
vbo = container_of(bo, struct vmw_buffer_object, base);
812+
vbo = container_of(bo, struct vmw_bo, base);
827813

828814
/*
829815
* Kill any cached kernel maps before move to or from VRAM.

0 commit comments

Comments
 (0)