Skip to content

Commit 2c9df1e

Browse files
committed
drm/vmwgfx: Port the framebuffer code to drm fb helpers
jira VULN-8161 cve CVE-2023-5633 commit-author Zack Rusin <zackr@vmware.com> commit df42523 Instead of using vmwgfx specific framebuffer implementation use the drm fb helpers. There's no change in functionality, the only difference is a reduction in the amount of code inside the vmwgfx module. drm fb helpers do not deal correctly with changes in crtc preferred mode at runtime, but the old fb code wasn't dealing with it either. Same situation applies to high-res fb consoles - the old code was limited to 1176x885 because it was checking for legacy/deprecated memory limites, the drm fb helpers are limited to the initial resolution set on fb due to first problem (drm fb helpers being unable to handle hotplug crtc preferred mode changes). This also removes the kernel config for disabling fb support which hasn't been used or supported in a very long time. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com> Reviewed-by: Martin Krastev <krastevm@vmware.com> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://patchwork.freedesktop.org/patch/msgid/20221022040236.616490-14-zack@kde.org (cherry picked from commit df42523) Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent b9aaad2 commit 2c9df1e

File tree

7 files changed

+28
-991
lines changed

7 files changed

+28
-991
lines changed

drivers/gpu/drm/vmwgfx/Kconfig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ config DRM_VMWGFX
1616
virtual hardware.
1717
The compiled module will be called "vmwgfx.ko".
1818

19-
config DRM_VMWGFX_FBCON
20-
depends on DRM_VMWGFX && DRM_FBDEV_EMULATION
21-
bool "Enable framebuffer console under vmwgfx by default"
22-
help
23-
Choose this option if you are shipping a new vmwgfx
24-
userspace driver that supports using the kernel driver.
25-
2619
config DRM_VMWGFX_MKSSTATS
2720
bool "Enable mksGuestStats instrumentation of vmwgfx by default"
2821
depends on DRM_VMWGFX

drivers/gpu/drm/vmwgfx/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \
1212
vmwgfx_devcaps.o ttm_object.o vmwgfx_system_manager.o \
1313
vmwgfx_gem.o
1414

15-
vmwgfx-$(CONFIG_DRM_FBDEV_EMULATION) += vmwgfx_fb.o
16-
1715
obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
#include <drm/drm_aperture.h>
3737
#include <drm/drm_drv.h>
38+
#include <drm/drm_fb_helper.h>
3839
#include <drm/drm_gem_ttm_helper.h>
3940
#include <drm/drm_ioctl.h>
4041
#include <drm/drm_module.h>
@@ -52,9 +53,6 @@
5253

5354
#define VMWGFX_DRIVER_DESC "Linux drm driver for VMware graphics devices"
5455

55-
#define VMW_MIN_INITIAL_WIDTH 800
56-
#define VMW_MIN_INITIAL_HEIGHT 600
57-
5856
/*
5957
* Fully encoded drm commands. Might move to vmw_drm.h
6058
*/
@@ -265,7 +263,6 @@ static const struct pci_device_id vmw_pci_id_list[] = {
265263
};
266264
MODULE_DEVICE_TABLE(pci, vmw_pci_id_list);
267265

268-
static int enable_fbdev = IS_ENABLED(CONFIG_DRM_VMWGFX_FBCON);
269266
static int vmw_restrict_iommu;
270267
static int vmw_force_coherent;
271268
static int vmw_restrict_dma_mask;
@@ -275,8 +272,6 @@ static int vmw_probe(struct pci_dev *, const struct pci_device_id *);
275272
static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
276273
void *ptr);
277274

278-
MODULE_PARM_DESC(enable_fbdev, "Enable vmwgfx fbdev");
279-
module_param_named(enable_fbdev, enable_fbdev, int, 0600);
280275
MODULE_PARM_DESC(restrict_iommu, "Try to limit IOMMU usage for TTM pages");
281276
module_param_named(restrict_iommu, vmw_restrict_iommu, int, 0600);
282277
MODULE_PARM_DESC(force_coherent, "Force coherent TTM pages");
@@ -626,8 +621,8 @@ static void vmw_get_initial_size(struct vmw_private *dev_priv)
626621
width = vmw_read(dev_priv, SVGA_REG_WIDTH);
627622
height = vmw_read(dev_priv, SVGA_REG_HEIGHT);
628623

629-
width = max_t(uint32_t, width, VMW_MIN_INITIAL_WIDTH);
630-
height = max_t(uint32_t, height, VMW_MIN_INITIAL_HEIGHT);
624+
width = max_t(uint32_t, width, VMWGFX_MIN_INITIAL_WIDTH);
625+
height = max_t(uint32_t, height, VMWGFX_MIN_INITIAL_HEIGHT);
631626

632627
if (width > dev_priv->fb_max_width ||
633628
height > dev_priv->fb_max_height) {
@@ -636,8 +631,8 @@ static void vmw_get_initial_size(struct vmw_private *dev_priv)
636631
* This is a host error and shouldn't occur.
637632
*/
638633

639-
width = VMW_MIN_INITIAL_WIDTH;
640-
height = VMW_MIN_INITIAL_HEIGHT;
634+
width = VMWGFX_MIN_INITIAL_WIDTH;
635+
height = VMWGFX_MIN_INITIAL_HEIGHT;
641636
}
642637

643638
dev_priv->initial_width = width;
@@ -886,9 +881,6 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
886881

887882
dev_priv->assume_16bpp = !!vmw_assume_16bpp;
888883

889-
dev_priv->enable_fb = enable_fbdev;
890-
891-
892884
dev_priv->capabilities = vmw_read(dev_priv, SVGA_REG_CAPABILITIES);
893885
vmw_print_bitmap(&dev_priv->drm, "Capabilities",
894886
dev_priv->capabilities,
@@ -1135,12 +1127,6 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id)
11351127
VMWGFX_DRIVER_PATCHLEVEL, UTS_RELEASE);
11361128
vmw_write_driver_id(dev_priv);
11371129

1138-
if (dev_priv->enable_fb) {
1139-
vmw_fifo_resource_inc(dev_priv);
1140-
vmw_svga_enable(dev_priv);
1141-
vmw_fb_init(dev_priv);
1142-
}
1143-
11441130
dev_priv->pm_nb.notifier_call = vmwgfx_pm_notifier;
11451131
register_pm_notifier(&dev_priv->pm_nb);
11461132

@@ -1187,12 +1173,9 @@ static void vmw_driver_unload(struct drm_device *dev)
11871173
unregister_pm_notifier(&dev_priv->pm_nb);
11881174

11891175
vmw_sw_context_fini(dev_priv);
1190-
if (dev_priv->enable_fb) {
1191-
vmw_fb_off(dev_priv);
1192-
vmw_fb_close(dev_priv);
1193-
vmw_fifo_resource_dec(dev_priv);
1194-
vmw_svga_disable(dev_priv);
1195-
}
1176+
vmw_fifo_resource_dec(dev_priv);
1177+
1178+
vmw_svga_disable(dev_priv);
11961179

11971180
vmw_kms_close(dev_priv);
11981181
vmw_overlay_close(dev_priv);
@@ -1330,8 +1313,6 @@ static void vmw_master_drop(struct drm_device *dev,
13301313
struct vmw_private *dev_priv = vmw_priv(dev);
13311314

13321315
vmw_kms_legacy_hotspot_clear(dev_priv);
1333-
if (!dev_priv->enable_fb)
1334-
vmw_svga_disable(dev_priv);
13351316
}
13361317

13371318
/**
@@ -1536,25 +1517,19 @@ static int vmw_pm_freeze(struct device *kdev)
15361517
DRM_ERROR("Failed to freeze modesetting.\n");
15371518
return ret;
15381519
}
1539-
if (dev_priv->enable_fb)
1540-
vmw_fb_off(dev_priv);
15411520

15421521
vmw_execbuf_release_pinned_bo(dev_priv);
15431522
vmw_resource_evict_all(dev_priv);
15441523
vmw_release_device_early(dev_priv);
15451524
while (ttm_device_swapout(&dev_priv->bdev, &ctx, GFP_KERNEL) > 0);
1546-
if (dev_priv->enable_fb)
1547-
vmw_fifo_resource_dec(dev_priv);
1525+
vmw_fifo_resource_dec(dev_priv);
15481526
if (atomic_read(&dev_priv->num_fifo_resources) != 0) {
15491527
DRM_ERROR("Can't hibernate while 3D resources are active.\n");
1550-
if (dev_priv->enable_fb)
1551-
vmw_fifo_resource_inc(dev_priv);
1528+
vmw_fifo_resource_inc(dev_priv);
15521529
WARN_ON(vmw_request_device_late(dev_priv));
15531530
dev_priv->suspend_locked = false;
15541531
if (dev_priv->suspend_state)
15551532
vmw_kms_resume(dev);
1556-
if (dev_priv->enable_fb)
1557-
vmw_fb_on(dev_priv);
15581533
return -EBUSY;
15591534
}
15601535

@@ -1574,24 +1549,19 @@ static int vmw_pm_restore(struct device *kdev)
15741549

15751550
vmw_detect_version(dev_priv);
15761551

1577-
if (dev_priv->enable_fb)
1578-
vmw_fifo_resource_inc(dev_priv);
1552+
vmw_fifo_resource_inc(dev_priv);
15791553

15801554
ret = vmw_request_device(dev_priv);
15811555
if (ret)
15821556
return ret;
15831557

1584-
if (dev_priv->enable_fb)
1585-
__vmw_svga_enable(dev_priv);
1558+
__vmw_svga_enable(dev_priv);
15861559

15871560
vmw_fence_fifo_up(dev_priv->fman);
15881561
dev_priv->suspend_locked = false;
15891562
if (dev_priv->suspend_state)
15901563
vmw_kms_resume(&dev_priv->drm);
15911564

1592-
if (dev_priv->enable_fb)
1593-
vmw_fb_on(dev_priv);
1594-
15951565
return 0;
15961566
}
15971567

@@ -1683,6 +1653,10 @@ static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
16831653
if (ret)
16841654
goto out_unload;
16851655

1656+
vmw_fifo_resource_inc(vmw);
1657+
vmw_svga_enable(vmw);
1658+
drm_fbdev_generic_setup(&vmw->drm, 0);
1659+
16861660
vmw_debugfs_gem_init(vmw);
16871661
vmw_debugfs_resource_managers_init(vmw);
16881662

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
#define VMWGFX_MAX_DISPLAYS 16
6363
#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
6464

65+
#define VMWGFX_MIN_INITIAL_WIDTH 1280
66+
#define VMWGFX_MIN_INITIAL_HEIGHT 800
67+
6568
#define VMWGFX_PCI_ID_SVGA2 0x0405
6669
#define VMWGFX_PCI_ID_SVGA3 0x0406
6770

@@ -551,7 +554,6 @@ struct vmw_private {
551554
* Framebuffer info.
552555
*/
553556

554-
void *fb_info;
555557
enum vmw_display_unit_type active_display_unit;
556558
struct vmw_legacy_display *ldu_priv;
557559
struct vmw_overlay *overlay_priv;
@@ -610,8 +612,6 @@ struct vmw_private {
610612
struct mutex cmdbuf_mutex;
611613
struct mutex binding_mutex;
612614

613-
bool enable_fb;
614-
615615
/**
616616
* PM management.
617617
*/
@@ -1189,35 +1189,6 @@ extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
11891189
extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
11901190
u32 flag, int *waiter_count);
11911191

1192-
1193-
/**
1194-
* Kernel framebuffer - vmwgfx_fb.c
1195-
*/
1196-
1197-
#ifdef CONFIG_DRM_FBDEV_EMULATION
1198-
int vmw_fb_init(struct vmw_private *vmw_priv);
1199-
int vmw_fb_close(struct vmw_private *dev_priv);
1200-
int vmw_fb_off(struct vmw_private *vmw_priv);
1201-
int vmw_fb_on(struct vmw_private *vmw_priv);
1202-
#else
1203-
static inline int vmw_fb_init(struct vmw_private *vmw_priv)
1204-
{
1205-
return 0;
1206-
}
1207-
static inline int vmw_fb_close(struct vmw_private *dev_priv)
1208-
{
1209-
return 0;
1210-
}
1211-
static inline int vmw_fb_off(struct vmw_private *vmw_priv)
1212-
{
1213-
return 0;
1214-
}
1215-
static inline int vmw_fb_on(struct vmw_private *vmw_priv)
1216-
{
1217-
return 0;
1218-
}
1219-
#endif
1220-
12211192
/**
12221193
* Kernel modesetting - vmwgfx_kms.c
12231194
*/

0 commit comments

Comments
 (0)