Skip to content

Commit 1e1e1b5

Browse files
committed
drm/vmwgfx: Simplify fb pinning
jira VULN-8161 cve CVE-2023-5633 commit-author Zack Rusin <zackr@vmware.com> commit 6703e28 Only the legacy display unit requires pinning of the fb memory in vram. Both the screen objects and screen targets can present from any buffer. That makes the pinning abstraction pointless. Simplify all of the code and move it to the legacy display unit, the only place that needs it. 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-5-zack@kde.org (cherry picked from commit 6703e28) Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent c5358f9 commit 1e1e1b5

File tree

5 files changed

+54
-85
lines changed

5 files changed

+54
-85
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_bo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ static bool bo_is_vmw(struct ttm_buffer_object *bo)
7373
* Return: Zero on success, Negative error code on failure. In particular
7474
* -ERESTARTSYS if interrupted by a signal
7575
*/
76-
int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
77-
struct vmw_bo *buf,
78-
struct ttm_placement *placement,
79-
bool interruptible)
76+
static int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
77+
struct vmw_bo *buf,
78+
struct ttm_placement *placement,
79+
bool interruptible)
8080
{
8181
struct ttm_operation_ctx ctx = {interruptible, false };
8282
struct ttm_buffer_object *bo = &buf->base;

drivers/gpu/drm/vmwgfx/vmwgfx_bo.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ int vmw_bo_init(struct vmw_private *dev_priv,
8282
int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
8383
struct drm_file *file_priv);
8484

85-
int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
86-
struct vmw_bo *bo,
87-
struct ttm_placement *placement,
88-
bool interruptible);
8985
int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
9086
struct vmw_bo *buf,
9187
bool interruptible);

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,69 +1487,6 @@ static const struct drm_framebuffer_funcs vmw_framebuffer_bo_funcs = {
14871487
.dirty = vmw_framebuffer_bo_dirty_ext,
14881488
};
14891489

1490-
/*
1491-
* Pin the bofer in a location suitable for access by the
1492-
* display system.
1493-
*/
1494-
static int vmw_framebuffer_pin(struct vmw_framebuffer *vfb)
1495-
{
1496-
struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
1497-
struct vmw_bo *buf;
1498-
struct ttm_placement *placement;
1499-
int ret;
1500-
1501-
buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
1502-
vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
1503-
1504-
if (!buf)
1505-
return 0;
1506-
1507-
switch (dev_priv->active_display_unit) {
1508-
case vmw_du_legacy:
1509-
vmw_overlay_pause_all(dev_priv);
1510-
ret = vmw_bo_pin_in_start_of_vram(dev_priv, buf, false);
1511-
vmw_overlay_resume_all(dev_priv);
1512-
break;
1513-
case vmw_du_screen_object:
1514-
case vmw_du_screen_target:
1515-
if (vfb->bo) {
1516-
if (dev_priv->capabilities & SVGA_CAP_3D) {
1517-
/*
1518-
* Use surface DMA to get content to
1519-
* sreen target surface.
1520-
*/
1521-
placement = &vmw_vram_gmr_placement;
1522-
} else {
1523-
/* Use CPU blit. */
1524-
placement = &vmw_sys_placement;
1525-
}
1526-
} else {
1527-
/* Use surface / image update */
1528-
placement = &vmw_mob_placement;
1529-
}
1530-
1531-
return vmw_bo_pin_in_placement(dev_priv, buf, placement, false);
1532-
default:
1533-
return -EINVAL;
1534-
}
1535-
1536-
return ret;
1537-
}
1538-
1539-
static int vmw_framebuffer_unpin(struct vmw_framebuffer *vfb)
1540-
{
1541-
struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
1542-
struct vmw_bo *buf;
1543-
1544-
buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
1545-
vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
1546-
1547-
if (WARN_ON(!buf))
1548-
return 0;
1549-
1550-
return vmw_bo_unpin(dev_priv, buf, false);
1551-
}
1552-
15531490
/**
15541491
* vmw_create_bo_proxy - create a proxy surface for the buffer object
15551492
*
@@ -1766,9 +1703,6 @@ vmw_kms_new_framebuffer(struct vmw_private *dev_priv,
17661703
if (ret)
17671704
return ERR_PTR(ret);
17681705

1769-
vfb->pin = vmw_framebuffer_pin;
1770-
vfb->unpin = vmw_framebuffer_unpin;
1771-
17721706
return vfb;
17731707
}
17741708

drivers/gpu/drm/vmwgfx/vmwgfx_kms.h

Lines changed: 1 addition & 3 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 2009-2022 VMware, Inc., Palo Alto, CA., USA
4+
* Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a
77
* copy of this software and associated documentation files (the
@@ -217,8 +217,6 @@ struct vmw_kms_dirty {
217217
*/
218218
struct vmw_framebuffer {
219219
struct drm_framebuffer base;
220-
int (*pin)(struct vmw_framebuffer *fb);
221-
int (*unpin)(struct vmw_framebuffer *fb);
222220
bool bo;
223221
uint32_t user_handle;
224222
};

drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c

Lines changed: 49 additions & 8 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 2009-2022 VMware, Inc., Palo Alto, CA., USA
4+
* Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a
77
* copy of this software and associated documentation files (the
@@ -25,11 +25,13 @@
2525
*
2626
**************************************************************************/
2727

28+
#include "vmwgfx_bo.h"
29+
#include "vmwgfx_kms.h"
30+
2831
#include <drm/drm_atomic.h>
2932
#include <drm/drm_atomic_helper.h>
3033
#include <drm/drm_fourcc.h>
3134

32-
#include "vmwgfx_kms.h"
3335

3436
#define vmw_crtc_to_ldu(x) \
3537
container_of(x, struct vmw_legacy_display_unit, base.crtc)
@@ -134,6 +136,47 @@ static int vmw_ldu_commit_list(struct vmw_private *dev_priv)
134136
return 0;
135137
}
136138

139+
/*
140+
* Pin the buffer in a location suitable for access by the
141+
* display system.
142+
*/
143+
static int vmw_ldu_fb_pin(struct vmw_framebuffer *vfb)
144+
{
145+
struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
146+
struct vmw_bo *buf;
147+
int ret;
148+
149+
buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
150+
vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
151+
152+
if (!buf)
153+
return 0;
154+
WARN_ON(dev_priv->active_display_unit != vmw_du_legacy);
155+
156+
if (dev_priv->active_display_unit == vmw_du_legacy) {
157+
vmw_overlay_pause_all(dev_priv);
158+
ret = vmw_bo_pin_in_start_of_vram(dev_priv, buf, false);
159+
vmw_overlay_resume_all(dev_priv);
160+
} else
161+
ret = -EINVAL;
162+
163+
return ret;
164+
}
165+
166+
static int vmw_ldu_fb_unpin(struct vmw_framebuffer *vfb)
167+
{
168+
struct vmw_private *dev_priv = vmw_priv(vfb->base.dev);
169+
struct vmw_bo *buf;
170+
171+
buf = vfb->bo ? vmw_framebuffer_to_vfbd(&vfb->base)->buffer :
172+
vmw_framebuffer_to_vfbs(&vfb->base)->surface->res.backup;
173+
174+
if (WARN_ON(!buf))
175+
return 0;
176+
177+
return vmw_bo_unpin(dev_priv, buf, false);
178+
}
179+
137180
static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
138181
struct vmw_legacy_display_unit *ldu)
139182
{
@@ -145,8 +188,7 @@ static int vmw_ldu_del_active(struct vmw_private *vmw_priv,
145188
list_del_init(&ldu->active);
146189
if (--(ld->num_active) == 0) {
147190
BUG_ON(!ld->fb);
148-
if (ld->fb->unpin)
149-
ld->fb->unpin(ld->fb);
191+
WARN_ON(vmw_ldu_fb_unpin(ld->fb));
150192
ld->fb = NULL;
151193
}
152194

@@ -163,11 +205,10 @@ static int vmw_ldu_add_active(struct vmw_private *vmw_priv,
163205

164206
BUG_ON(!ld->num_active && ld->fb);
165207
if (vfb != ld->fb) {
166-
if (ld->fb && ld->fb->unpin)
167-
ld->fb->unpin(ld->fb);
208+
if (ld->fb)
209+
WARN_ON(vmw_ldu_fb_unpin(ld->fb));
168210
vmw_svga_enable(vmw_priv);
169-
if (vfb->pin)
170-
vfb->pin(vfb);
211+
WARN_ON(vmw_ldu_fb_pin(vfb));
171212
ld->fb = vfb;
172213
}
173214

0 commit comments

Comments
 (0)