drm/vmwgfx: Switch to using DRM_IOCTL_DEF_DRV
Subsystems (3)
PATCH v2 1/4 drm/vmwgfx: Switch to using DRM_IOCTL_DEF_DRV
The macro has been accounting for DRM_COMMAND_BASE for a long time now so there's no reason to still be duplicating it. Plus we were leaving the name undefined which meant that all the DRM ioctl warnings/errors were always listing "null" ioctl at the culprit.
This fixes the undefined ioctl name and removes duplicated code.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 176 +++++++++++++--------------- 1 file changed, 84 insertions(+), 92 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +84 -92
@@ -159,110 +159,102 @@DRM_IOW (DRM_COMMAND_BASE +DRM_VMW_MKSSTAT_REMOVE , \ struct drm_vmw_mksstat_remove_arg) -/* -* The core DRM version of this macro doesn't account for -* DRM_COMMAND_BASE. - */ - -#define VMW_IOCTL_DEF (ioctl, func, flags) \ - [DRM_IOCTL_NR(DRM_IOCTL_##ioctl) - DRM_COMMAND_BASE] = {DRM_IOCTL_##ioctl, flags, func} -/* * Ioctl definitions. */static const struct drm_ioctl_desc vmw_ioctls[] = { -VMW_IOCTL_DEF (VMW_GET_PARAM , vmw_getparam_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_ALLOC_DMABUF , vmw_bo_alloc_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_UNREF_DMABUF , vmw_bo_unref_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_CURSOR_BYPASS , - vmw_kms_cursor_bypass_ioctl, -DRM_MASTER ), - -VMW_IOCTL_DEF (VMW_CONTROL_STREAM , vmw_overlay_ioctl, -DRM_MASTER ), -VMW_IOCTL_DEF (VMW_CLAIM_STREAM , vmw_stream_claim_ioctl, -DRM_MASTER ), -VMW_IOCTL_DEF (VMW_UNREF_STREAM , vmw_stream_unref_ioctl, -DRM_MASTER ), - -VMW_IOCTL_DEF (VMW_CREATE_CONTEXT , vmw_context_define_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_UNREF_CONTEXT , vmw_context_destroy_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_CREATE_SURFACE , vmw_surface_define_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_UNREF_SURFACE , vmw_surface_destroy_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_REF_SURFACE , vmw_surface_reference_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_EXECBUF , vmw_execbuf_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_FENCE_WAIT , vmw_fence_obj_wait_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_FENCE_SIGNALED , - vmw_fence_obj_signaled_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_FENCE_UNREF , vmw_fence_obj_unref_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_FENCE_EVENT , vmw_fence_event_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_GET_3D_CAP , vmw_get_cap_3d_ioctl, -DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GET_PARAM , vmw_getparam_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_ALLOC_DMABUF , vmw_bo_alloc_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_UNREF_DMABUF , vmw_bo_unref_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_CURSOR_BYPASS , + vmw_kms_cursor_bypass_ioctl, +DRM_MASTER ), + +DRM_IOCTL_DEF_DRV (VMW_CONTROL_STREAM , vmw_overlay_ioctl, +DRM_MASTER ), +DRM_IOCTL_DEF_DRV (VMW_CLAIM_STREAM , vmw_stream_claim_ioctl, +DRM_MASTER ), +DRM_IOCTL_DEF_DRV (VMW_UNREF_STREAM , vmw_stream_unref_ioctl, +DRM_MASTER ), + +DRM_IOCTL_DEF_DRV (VMW_CREATE_CONTEXT , vmw_context_define_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_UNREF_CONTEXT , vmw_context_destroy_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_CREATE_SURFACE , vmw_surface_define_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_UNREF_SURFACE , vmw_surface_destroy_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_REF_SURFACE , vmw_surface_reference_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_EXECBUF , vmw_execbuf_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_FENCE_WAIT , vmw_fence_obj_wait_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_FENCE_SIGNALED , + vmw_fence_obj_signaled_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_FENCE_UNREF , vmw_fence_obj_unref_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_FENCE_EVENT , vmw_fence_event_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GET_3D_CAP , vmw_get_cap_3d_ioctl, +DRM_RENDER_ALLOW ),/* these allow direct access to the framebuffers mark as master only */ -VMW_IOCTL_DEF (VMW_PRESENT , vmw_present_ioctl, -DRM_MASTER |DRM_AUTH ), -VMW_IOCTL_DEF (VMW_PRESENT_READBACK , - vmw_present_readback_ioctl, -DRM_MASTER |DRM_AUTH ), +DRM_IOCTL_DEF_DRV (VMW_PRESENT , vmw_present_ioctl, +DRM_MASTER |DRM_AUTH ), +DRM_IOCTL_DEF_DRV (VMW_PRESENT_READBACK , + vmw_present_readback_ioctl, +DRM_MASTER |DRM_AUTH ),/* * The permissions of the below ioctl are overridden in * vmw_generic_ioctl(). We require either * DRM_MASTER or capable(CAP_SYS_ADMIN). */ -VMW_IOCTL_DEF (VMW_UPDATE_LAYOUT , - vmw_kms_update_layout_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_CREATE_SHADER , - vmw_shader_define_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_UNREF_SHADER , - vmw_shader_destroy_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_GB_SURFACE_CREATE , - vmw_gb_surface_define_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_GB_SURFACE_REF , - vmw_gb_surface_reference_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_SYNCCPU , - vmw_user_bo_synccpu_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_CREATE_EXTENDED_CONTEXT , - vmw_extended_context_define_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_GB_SURFACE_CREATE_EXT , - vmw_gb_surface_define_ext_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_GB_SURFACE_REF_EXT , - vmw_gb_surface_reference_ext_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_MSG , - vmw_msg_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_MKSSTAT_RESET , - vmw_mksstat_reset_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_MKSSTAT_ADD , - vmw_mksstat_add_ioctl, -DRM_RENDER_ALLOW ), -VMW_IOCTL_DEF (VMW_MKSSTAT_REMOVE , - vmw_mksstat_remove_ioctl, -DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_UPDATE_LAYOUT , + vmw_kms_update_layout_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_CREATE_SHADER , + vmw_shader_define_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_UNREF_SHADER , + vmw_shader_destroy_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GB_SURFACE_CREATE , + vmw_gb_surface_define_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GB_SURFACE_REF , + vmw_gb_surface_reference_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_SYNCCPU , + vmw_user_bo_synccpu_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_CREATE_EXTENDED_CONTEXT , + vmw_extended_context_define_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GB_SURFACE_CREATE_EXT , + vmw_gb_surface_define_ext_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_GB_SURFACE_REF_EXT , + vmw_gb_surface_reference_ext_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_MSG , + vmw_msg_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_MKSSTAT_RESET , + vmw_mksstat_reset_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_MKSSTAT_ADD , + vmw_mksstat_add_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (VMW_MKSSTAT_REMOVE , + vmw_mksstat_remove_ioctl, +DRM_RENDER_ALLOW ), };static const struct pci_device_id vmw_pci_id_list[] = {
Signature · 1 line
2.30.2
PATCH v2 2/4 drm/vmwgfx: Cleanup logging
The code was using the old DRM logging functions, which made it hard to figure out what was coming from vmwgfx. The newer logging helpers include the driver name in the logs and make it explicit which driver they're coming from. This allows us to standardize our logging a bit and clean it up in the process.
vmwgfx is a little special because technically the hardware it's running on can be anything from the last 12 years or so which is why we need to include capabilities in the logs in the first place or otherwise we'd have no way of knowing what were the capabilities of the platform the guest was running in.
--- drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 224 +++++++++++++++---------- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 10 ++ drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c | 5 +- drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c | 4 - drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c | 5 +- 8 files changed, 151 insertions(+), 106 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +2 -1
@@ -140,7 +140,8 @@ struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv) min =vmw_fifo_mem_read (dev_priv,SVGA_FIFO_MIN ); fifo->capabilities =vmw_fifo_mem_read (dev_priv,SVGA_FIFO_CAPABILITIES ); -DRM_INFO ("Fifo max 0x%08x min 0x%08x cap 0x%08x\n" , +drm_info (&dev_priv->drm, +"Fifo max 0x%08x min 0x%08x cap 0x%08x\n" , (unsigned int ) max, (unsigned int ) min, (unsigned int ) fifo->capabilities);
drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +2 -1
@@ -1272,7 +1272,8 @@ int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size)* submissions to be able to free up space. */ man->default_size =VMW_CMDBUF_INLINE_SIZE ; -DRM_INFO ("Using command buffers with %s pool.\n" , +drm_info (&dev_priv->drm, +"Using command buffers with %s pool.\n" , (man->using_mob) ?"MOB" :"DMA" );return 0 ;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +132 -92
361 lines not on this page · raw message
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +2 -1
@@ -367,7 +367,8 @@ enum vmw_display_unit_type { vmw_du_invalid =0 , vmw_du_legacy, vmw_du_screen_object, - vmw_du_screen_target + vmw_du_screen_target, + vmw_du_max };struct vmw_validation_context ;
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c +10 -0
@@ -1793,6 +1793,13 @@ int vmw_kms_init(struct vmw_private *dev_priv) {struct drm_device *dev = &dev_priv->drm;int ret; +static const char *display_unit_names[] = { +"Invalid" , +"Legacy" , +"Screen Object" , +"Screen Target" , +"Invalid (max)" + };drm_mode_config_init (dev); dev->mode_config.funcs = &vmw_kms_funcs;
@@ -1810,6 +1817,9 @@ int vmw_kms_init(struct vmw_private *dev_priv)if (ret)/* Fallback */ ret =vmw_kms_ldu_init_display (dev_priv); } +BUILD_BUG_ON (ARRAY_SIZE (display_unit_names) != (vmw_du_max +1 )); +drm_info (&dev_priv->drm,"%s display unit initialized\n" , + display_unit_names[dev_priv->active_display_unit]);return ret; }
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c +1 -4
@@ -493,8 +493,7 @@ int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)struct drm_device *dev = &dev_priv->drm;int i, ret; -if (dev_priv->ldu_priv) { -DRM_INFO ("ldu system already on\n" ); +if (unlikely (dev_priv->ldu_priv)) {return -EINVAL ; }
@@ -527,8 +526,6 @@ int vmw_kms_ldu_init_display(struct vmw_private *dev_priv)drm_mode_config_reset (dev); -DRM_INFO ("Legacy Display Unit initialized\n" ); -return 0 ; err_free:
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +0 -4
@@ -954,8 +954,6 @@ int vmw_kms_sou_init_display(struct vmw_private *dev_priv)int i, ret;if (!(dev_priv->capabilities &SVGA_CAP_SCREEN_OBJECT_2 )) { -DRM_INFO ("Not using screen objects," -" missing cap SCREEN_OBJECT_2\n" );return -ENOSYS ; }
@@ -972,8 +970,6 @@ int vmw_kms_sou_init_display(struct vmw_private *dev_priv)drm_mode_config_reset (dev); -DRM_INFO ("Screen Objects Display Unit initialized\n" ); -return 0 ; }
drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c +2 -3
@@ -1889,14 +1889,13 @@ int vmw_kms_stdu_init_display(struct vmw_private *dev_priv) ret =vmw_stdu_init (dev_priv, i);if (unlikely (ret !=0 )) { -DRM_ERROR ("Failed to initialize STDU %d" , i); +drm_err (&dev_priv->drm, +"Failed to initialize STDU %d" , i);return ret; } }drm_mode_config_reset (dev); -DRM_INFO ("Screen Target Display device initialized\n" ); -return 0 ; }
Signature · 1 line
2.30.2
PATCH v2 3/4 drm/vmwgfx: Be a lot more flexible with MOB limits
In reply to Zack RusinThe code was trying to keep a strict limit on the amount of mob memory that was used in the guest by making it match the host settings. There's technically no reason to do that (guests can certainly use more than the host can have resident in renderers at the same time).
In particular this is problematic because our userspace is not great at handling OOM conditions and running out of MOB space results in GL apps crashing, e.g. gnome-shell likes to allocate huge surfaces (~61MB for the desktop on 2560x1600 with two workspaces) and running out of memory there means that the gnome-shell crashes on startup taking us back to the login and resulting in a system where one can not login in graphically anymore.
Instead of letting the userspace crash we can extend available MOB space, we just don't want to use all of the RAM for graphics, so we're going to limit it to half of RAM.
With the addition of some extra logging this should make the "guest has been configured with not enough graphics memory" errors a lot easier to diagnose in cases where the automatic expansion of MOB space fails.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 9 +++++ drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 36 +++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +9 -0
@@ -942,6 +942,15 @@ static int vmw_driver_load(struct vmw_private *dev_priv, u32 pci_id) dev_priv->texture_max_height =8192 ; dev_priv->max_primary_mem = dev_priv->vram_size; } +drm_info (&dev_priv->drm, +"Legacy memory limits: VRAM = %llu kB, FIFO = %llu kB, surface = %u kB\n" , + (u64 )dev_priv->vram_size /1024 , + (u64 )dev_priv->fifo_mem_size /1024 , + dev_priv->memory_size /1024 ); + +drm_info (&dev_priv->drm, +"MOB limits: max mob size = %u kB, max mob pages = %u\n" , + dev_priv->max_mob_size /1024 , dev_priv->max_mob_pages); vmw_print_bitmap(&dev_priv->drm, "Capabilities", dev_priv->capabilities,
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +34 -2
@@ -71,8 +71,40 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,if (gman->max_gmr_pages >0 ) { gman->used_gmr_pages += (*res)->num_pages; -if (unlikely (gman->used_gmr_pages > gman->max_gmr_pages)) - goto nospace; +/* +* Because the graphics memory is a soft limit we can try to +* expand it instead of letting the userspace apps crash. +* We're just going to have a sane limit (half of RAM) +* on the number of MOB's that we create and will try to keep +* the system running until we reach that. +*/ +if (unlikely (gman->used_gmr_pages > gman->max_gmr_pages)) { +const unsigned long max_graphics_pages =totalram_pages () /2 ; +uint32_t new_max_pages =0 ; + +DRM_WARN ("vmwgfx: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n" ); +vmw_host_printf ("vmwgfx, warning: mob memory overflow. Consider increasing guest RAM and graphicsMemory.\n" ); + +if (gman->max_gmr_pages > (max_graphics_pages /2 )) { +DRM_WARN ("vmwgfx: guest requires more than half of RAM for graphics.\n" ); + new_max_pages = max_graphics_pages; + }else + new_max_pages = gman->max_gmr_pages *2 ; +if (new_max_pages > gman->max_gmr_pages && new_max_pages >= gman->used_gmr_pages) { +DRM_WARN ("vmwgfx: increasing guest mob limits to %u kB.\n" , + ((new_max_pages) << (PAGE_SHIFT -10 ))); + + gman->max_gmr_pages = new_max_pages; + }else { +char buf[256 ]; +snprintf (buf,sizeof (buf), +"vmwgfx, error: guest graphics is out of memory (mob limit at: %ukB).\n" , + ((gman->max_gmr_pages) << (PAGE_SHIFT -10 ))); +vmw_host_printf (buf); +DRM_WARN ("%s" , buf); + goto nospace; + } + } } (*res)->start = id;
Signature · 1 line
2.30.2
PATCH v2 4/4 drm/vmwgfx: Use 2.19 version number to recognize mks-stats ioctls
In reply to Zack RusinTo let the userspace recognize that it's running on top of a vmwgfx that supports mks-stat ioctls we need to bump the version number.
--- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +3 -3
@@ -54,10 +54,10 @@#define VMWGFX_DRIVER_NAME "vmwgfx" -#define VMWGFX_DRIVER_DATE "20210218" +#define VMWGFX_DRIVER_DATE "20210722"#define VMWGFX_DRIVER_MAJOR 2 -#define VMWGFX_DRIVER_MINOR 18 -#define VMWGFX_DRIVER_PATCHLEVEL 1 +#define VMWGFX_DRIVER_MINOR 19 +#define VMWGFX_DRIVER_PATCHLEVEL 0#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)#define VMWGFX_MAX_RELOCATIONS 2048#define VMWGFX_MAX_VALIDATIONS 2048
Signature · 1 line
2.30.2