Skip to content

Commit 4bca7f9

Browse files
committed
drm/vmwgfx: Add a mksstat counter for cotable resizes
jira VULN-8161 cve CVE-2023-5633 commit-author Zack Rusin <zackr@vmware.com> commit 4bb5060 There's been a lot of cotable resizes on startup which we can track by adding a mks stat to measure both the invocation count and time spent doing cotable resizes. This is only used if kernel is configured with CONFIG_DRM_VMWGFX_MKSSTATS The stats are collected on the host size inside the vmware-stats.log file. Signed-off-by: Zack Rusin <zackr@vmware.com> Reviewed-by: Michael Banack <banackm@vmware.com> Reviewed-by: Martin Krastev <krastevm@vmware.com> Reviewed-by: Maaz Mombasawala <mombasawalam@vmware.com> Link: https://patchwork.freedesktop.org/patch/msgid/20221022040236.616490-16-zack@kde.org (cherry picked from commit 4bb5060) Signed-off-by: Sultan Alsawaf <sultan@ciq.com>
1 parent 6d49c27 commit 4bca7f9

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <drm/ttm/ttm_placement.h>
3434

3535
#include "vmwgfx_drv.h"
36+
#include "vmwgfx_mksstat.h"
3637
#include "vmwgfx_resource_priv.h"
3738
#include "vmwgfx_so.h"
3839

@@ -395,9 +396,12 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
395396
int ret;
396397
size_t i;
397398

399+
MKS_STAT_TIME_DECL(MKSSTAT_KERN_COTABLE_RESIZE);
400+
MKS_STAT_TIME_PUSH(MKSSTAT_KERN_COTABLE_RESIZE);
401+
398402
ret = vmw_cotable_readback(res);
399403
if (ret)
400-
return ret;
404+
goto out_done;
401405

402406
cur_size_read_back = vcotbl->size_read_back;
403407
vcotbl->size_read_back = old_size_read_back;
@@ -411,7 +415,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
411415
true, true, vmw_bo_bo_free, &buf);
412416
if (ret) {
413417
DRM_ERROR("Failed initializing new cotable MOB.\n");
414-
return ret;
418+
goto out_done;
415419
}
416420

417421
bo = &buf->base;
@@ -485,6 +489,8 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
485489
/* Release the pin acquired in vmw_bo_init */
486490
ttm_bo_unpin(bo);
487491

492+
MKS_STAT_TIME_POP(MKSSTAT_KERN_COTABLE_RESIZE);
493+
488494
return 0;
489495

490496
out_map_new:
@@ -494,6 +500,9 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
494500
ttm_bo_unreserve(bo);
495501
vmw_bo_unreference(&buf);
496502

503+
out_done:
504+
MKS_STAT_TIME_POP(MKSSTAT_KERN_COTABLE_RESIZE);
505+
497506
return ret;
498507
}
499508

drivers/gpu/drm/vmwgfx/vmwgfx_mksstat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#define _VMWGFX_MKSSTAT_H_
3030

3131
#include <asm/page.h>
32+
#include <linux/kconfig.h>
3233

3334
/* Reservation marker for mksstat pid's */
3435
#define MKSSTAT_PID_RESERVED -1
@@ -41,6 +42,7 @@
4142

4243
typedef enum {
4344
MKSSTAT_KERN_EXECBUF, /* vmw_execbuf_ioctl */
45+
MKSSTAT_KERN_COTABLE_RESIZE,
4446

4547
MKSSTAT_KERN_COUNT /* Reserved entry; always last */
4648
} mksstat_kern_stats_t;

drivers/gpu/drm/vmwgfx/vmwgfx_msg.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ struct rpc_channel {
8585
u32 cookie_low;
8686
};
8787

88-
88+
#if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
89+
/* Kernel mksGuestStats counter names and desciptions; same order as enum mksstat_kern_stats_t */
90+
static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] =
91+
{
92+
{ "vmw_execbuf_ioctl", "vmw_execbuf_ioctl" },
93+
{ "vmw_cotable_resize", "vmw_cotable_resize" },
94+
};
95+
#endif
8996

9097
/**
9198
* vmw_open_channel
@@ -695,12 +702,6 @@ static inline void hypervisor_ppn_remove(PPN64 pfn)
695702
/* Header to the text description of mksGuestStat instance descriptor */
696703
#define MKSSTAT_KERNEL_DESCRIPTION "vmwgfx"
697704

698-
/* Kernel mksGuestStats counter names and desciptions; same order as enum mksstat_kern_stats_t */
699-
static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] =
700-
{
701-
{ "vmw_execbuf_ioctl", "vmw_execbuf_ioctl" },
702-
};
703-
704705
/**
705706
* mksstat_init_record: Initializes an MKSGuestStatCounter-based record
706707
* for the respective mksGuestStat index.
@@ -786,6 +787,7 @@ static int mksstat_init_kern_id(struct page **ppage)
786787
/* Set up all kernel-internal counters and corresponding structures */
787788
pstrs_acc = pstrs;
788789
pstrs_acc = mksstat_init_record_time(MKSSTAT_KERN_EXECBUF, pstat, pinfo, pstrs_acc);
790+
pstrs_acc = mksstat_init_record_time(MKSSTAT_KERN_COTABLE_RESIZE, pstat, pinfo, pstrs_acc);
789791

790792
/* Add new counters above, in their order of appearance in mksstat_kern_stats_t */
791793

0 commit comments

Comments
 (0)