drm/hyperv: wait for flip_done instead of vblanks in commit tail
Subsystems (6)
PATCH 1/1 drm/hyperv: wait for flip_done instead of vblanks in commit tail
Since commit 52e6b1988334 ("drm/hypervdrm: Use vblank timer"), the driver's vblanks are generated by an hrtimer, and the default commit tail waits in drm_atomic_helper_wait_for_vblanks() for that timer to fire. In a VM, a timer can fire arbitrarily late, for instance when the host does not run the vCPU that the timer is queued on while the committing task keeps running on another vCPU. If the delay exceeds the helper's timeout, it warns, even though the display works fine:
[CRTC:35:crtc-0] vblank wait timed out
WARNING: drivers/gpu/drm/drm_atomic_helper.c:1921 at drm_atomic_helper_wait_for_vblanks.part.0+0x212/0x230, CPU#30: setfont/559 Call Trace: drm_atomic_helper_commit_tail commit_tail drm_atomic_helper_commit drm_atomic_commit drm_client_modeset_commit_atomic drm_client_modeset_commit_locked drm_fb_helper_pan_display fb_pan_display bit_update_start fbcon_switch redraw_screen fbcon_do_set_font fbcon_set_font con_font_op vt_ioctl
This was seen intermittently on Azure VMs during boot, when setfont redraws the console right after hyperv_drm has taken it over.
---
This is inspired by VKMS (which also uses DRM's vblank timer), wait for the commit's flip_done instead. It completes once the vblank event that drm_crtc_vblank_atomic_flush() armed has been sent on the next timer tick.
--- drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +24 -0
@@ -504,6 +504,29 @@ static const struct drm_mode_config_funcs hv_drm_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +/* +* Like drm_atomic_helper_commit_tail(), but wait for the commit's vblank +* events rather than for the vblank counter to advance. The host can delay +* the vblank timer for longer than drm_atomic_helper_wait_for_vblanks() +* waits before warning. +*/ +static void hv_drm_atomic_commit_tail (struct drm_atomic_commit *state) +{ +struct drm_device *dev = state->dev; + +drm_atomic_helper_commit_modeset_disables (dev, state); +drm_atomic_helper_commit_planes (dev, state,0 ); +drm_atomic_helper_commit_modeset_enables (dev, state); +drm_atomic_helper_fake_vblank (state); +drm_atomic_helper_commit_hw_done (state); +drm_atomic_helper_wait_for_flip_done (dev, state); +drm_atomic_helper_cleanup_planes (dev, state); +} + +static const struct drm_mode_config_helper_funcs hv_drm_mode_config_helper_funcs = { + .atomic_commit_tail = hv_drm_atomic_commit_tail, +}; +int hv_drm_mode_config_init (struct hv_drm_device *hv) {struct drm_device *dev = &hv->dev;
@@ -526,6 +549,7 @@ int hv_drm_mode_config_init(struct hv_drm_device *hv) dev->mode_config.prefer_shadow =0 ; dev->mode_config.funcs = &hv_drm_mode_config_funcs; + dev->mode_config.helper_private = &hv_drm_mode_config_helper_funcs; ret =hv_drm_pipe_init (hv);if (ret) {
Signature · 1 line
2.56.0
Saurabh Singh Sengar
maintainerQuoted 56 lines · Hamza Mahfooz
Since commit
52e6b1988334("drm/hypervdrm: Use vblank timer"), the driver's vblanks are generated by an hrtimer, and the default commit tail waits indrm_atomic_helper_wait_for_vblanks()for that timer to fire. In a VM, a timer can fire arbitrarily late, for instance when the host does not run the vCPU that the timer is queued on while the committing task keeps running on another vCPU. If the delay exceeds the helper's timeout, it warns, even though the display works fine:[CRTC:35:crtc-0] vblank wait timed out
WARNING: drivers/gpu/drm/drm_atomic_helper.c:1921 at drm_atomic_helper_wait_for_vblanks.part.0+0x212/0x230, CPU#30: setfont/559 Call Trace: drm_atomic_helper_commit_tail commit_tail drm_atomic_helper_commit drm_atomic_commit drm_client_modeset_commit_atomic drm_client_modeset_commit_locked drm_fb_helper_pan_display fb_pan_display bit_update_start fbcon_switch redraw_screen fbcon_do_set_font fbcon_set_font con_font_op vt_ioctlThis was seen intermittently on Azure VMs during boot, when setfont redraws the console right after
hyperv_drmhas taken it over.Fixes 52e6b1988334 ("drm/hypervdrm: Use vblank timer")Signed-off-by Hamza Mahfooz <[email protected]>---
This is inspired by VKMS (which also uses DRM's vblank timer), wait for the commit'sflip_doneinstead. It completes once the vblank event thatdrm_crtc_vblank_atomic_flush()armed has been sent on the next timer tick.--- drivers/gpu/drm/hyperv/hyperv_drm_modeset.c | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+)drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +6
-0@@ -504,6 +504,29 @@ static const struct drm_mode_config_funcs hv_drm_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +/* +* Like drm_atomic_helper_commit_tail(), but wait for the commit's vblank +* events rather than for the vblank counter to advance. The host can delay +* the vblank timer for longer than drm_atomic_helper_wait_for_vblanks() +* waits before warning. +*/
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c static const struct drm_mode_config_funcs hv_drm_mode_config_funcs = { · line 522
Quoted 10 lines
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c +10
-0+static void hv_drm_atomic_commit_tail (struct drm_atomic_commit *state) +{ +struct drm_device *dev = state->dev; + +drm_atomic_helper_commit_modeset_disables (dev, state); +drm_atomic_helper_commit_planes (dev, state,0 ); +drm_atomic_helper_commit_modeset_enables (dev, state); +drm_atomic_helper_fake_vblank (state); +drm_atomic_helper_commit_hw_done (state); +drm_atomic_helper_wait_for_flip_done (dev, state);
Thanks for the patch. Below are my thoughts:
Since flip_done is normally signalled through the same vblank timer, this change does not remove the dependency on that timer. However, drm_atomic_helper_wait_for_vblanks() has a 1-second timeout, whereas drm_atomic_helper_wait_for_flip_done() waits up to 10 seconds. Could you clarify whether the change resolves the reported case because of the longer timeout, or because it avoids waiting for another vblank after the commit's event has already completed ?
This seems relevant to other timer-backed virtual DRM drivers as well. The older wait_for_vblanks helper also predates flip_done tracking and has previously been described as an interim solution [1].
We already have a vblank timeout increase [2], and Thomas's timer reliability series [3] also discusses delayed vblank handling triggering DRM checks, although it is not clear whether those changes address this particular case.
Using flip_done is consistent with VKMS and seems reasonable. However, rather than duplicating the default commit tail in each affected driver, could we consider a common DRM solution for all ?
It would help to identify the precise condition causing the hyperv_drm warning and explain why the existing generic timeout increase is insufficient. If this is needed as a targeted stable fix, please document this in the commit message and as a comment in code.
[1] https://patchwork.freedesktop.org/patch/318967/
[2] https://git.kernel.org/linus/79ae8510b5b81b9500370f89c619b50ca9c0990f
[3] https://lore.kernel.org/dri-devel/[email protected]/
- Saurabh
Quoted 10 lines · Saurabh Singh Sengar
Thanks for the patch. Below are my thoughts:
Since
flip_doneis normally signalled through the same vblank timer, this change does not remove the dependency on that timer. However,drm_atomic_helper_wait_for_vblanks()has a 1-second timeout, whereasdrm_atomic_helper_wait_for_flip_done()waits up to 10 seconds. Could you clarify whether the change resolves the reported case because of the longer timeout, or because it avoids waiting for another vblank after the commit's event has already completed ?
It does come down to the longer timeout, I've done some stress testing and the timeout doesn't seem to exceed 2-3 seconds (on Azure and even on the lowest end SKUs).
Quoted 9 lines
This seems relevant to other timer-backed virtual DRM drivers as well. The older
wait_for_vblankshelper also predatesflip_donetracking and has previously been described as an interim solution [1].We already have a vblank timeout increase [2], and Thomas's timer reliability series [3] also discusses delayed vblank handling triggering DRM checks, although it is not clear whether those changes address this particular case.
From my testing they don't address the issue.
Quoted 4 lines
Using
flip_doneis consistent with VKMS and seems reasonable. However, rather than duplicating the default commit tail in each affected driver, could we consider a common DRM solution for all ?
Most drivers implicitally rely on drm_atomic_helper_wait_for_vblanks() through drm_atomic_helper_commit_tail(), so I don't think we should touch that unless we can prove it doesn't regress anyone. Though it is worth nothing that fbdev has a similiar timeout that is fixed by [1].
Quoted 5 lines
It would help to identify the precise condition causing the
hyperv_drmwarning and explain why the existing generic timeout increase is insufficient. If this is needed as a targeted stable fix, please document this in the commit message and as a comment in code.
The vblank timer is an hrtimer, so it can't fire while its vCPU isn't running, whereas the committing task can keep running on another vCPU and time out. On Azure, a 10 ms timer sampling the vCPU run time that Hyper-V reports caught the host not running a vCPU for up to 128 ms, mostly inside storvsc's vmbus_set_event() hypercall. As the warnings coincide with boot-time disk I/O, the host appears to hold a vCPU like that for seconds at times. Also, it doesn't really need to go into stable if we don't enable panic_on_warn() (and assuming no one is complaining about the timeout in stable releases).
[1] https://lore.kernel.org/dri-devel/[email protected]/
Hamza