<div dir="ltr"><div dir="ltr">I think there are no direct issues with initialization in the state how it is now. I suspect it's because "drm_kms_helper_poll_enable()" starts the first worker thread with a delay, which gives enough time to initialize required resources. I changed the initialization part to keep it consistent with the finish part, which is the one causing troubles.<div><br></div><div>I am not sure where I could move "drm_kms_helper_poll_enable/disable()", since it is defined in "drm/drm_probe_helper.c", which is only included in "nouveau_display.c" and "nouveau_connector.c". Both creating a new function in "nouveau_display.c", and including "probe_helper.h" and using poll_enable in a different file like "nouveau_fbcon.c" seem like too big changes for such small fix. I don't know.</div><div><br></div><div>Can this new proposed order break something in the finish part as well? Maybe it would be just better to change the order of "nouveau_drm_finish" and keep the current order of "noueau_drm_init"?</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 5, 2022 at 9:57 PM Lyude Paul <<a href="mailto:lyude@redhat.com">lyude@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hmm, I think we might just need to move the drm_kms_helper_poll_enable() call<br>
to the end here instead of all of nouveau_display_init(). I realized this<br>
because in nouveau_display_init() it seems that we actually rely on<br>
nouveau_display_init() to setup hotplug interrupts - which we do actually need<br>
this early on in the driver probe process.<br>
<br>
That being said though, drm_kms_helper_poll_enable() shouldn't be required for<br>
MST short HPD IRQs from working so moving that instead should work.<br>
<br>
On Wed, 2022-05-04 at 19:18 +0200, Mark Menzynski wrote:<br>
> Resources needed for output poll workers are destroyed in<br>
> nouveau_fbcon_fini() before output poll workers are cleared in<br>
> nouveau_display_fini(). This means there is a time between fbcon_fini<br>
> and display_fini, where if output poll happens, it crashes.<br>
> <br>
> BUG: KASAN: use-after-free in<br>
> __drm_fb_helper_initial_config_and_unlock.cold+0x1f3/0x291<br>
> [drm_kms_helper]<br>
> <br>
> Cc: Ben Skeggs <<a href="mailto:bskeggs@redhat.com" target="_blank">bskeggs@redhat.com</a>><br>
> Cc: Karol Herbst <<a href="mailto:kherbst@redhat.com" target="_blank">kherbst@redhat.com</a>><br>
> Cc: Lyude Paul <<a href="mailto:lyude@redhat.com" target="_blank">lyude@redhat.com</a>><br>
> Cc: David Airlie <<a href="mailto:airlied@linux.ie" target="_blank">airlied@linux.ie</a>><br>
> Cc: Daniel Vetter <<a href="mailto:daniel@ffwll.ch" target="_blank">daniel@ffwll.ch</a>><br>
> Cc: Sumit Semwal <<a href="mailto:sumit.semwal@linaro.org" target="_blank">sumit.semwal@linaro.org</a>><br>
> Cc: "Christian König" <<a href="mailto:christian.koenig@amd.com" target="_blank">christian.koenig@amd.com</a>><br>
> Cc: <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
> Cc: <a href="mailto:nouveau@lists.freedesktop.org" target="_blank">nouveau@lists.freedesktop.org</a><br>
> Cc: <a href="mailto:linux-kernel@vger.kernel.org" target="_blank">linux-kernel@vger.kernel.org</a><br>
> Cc: <a href="mailto:linux-media@vger.kernel.org" target="_blank">linux-media@vger.kernel.org</a><br>
> Cc: <a href="mailto:linaro-mm-sig@lists.linaro.org" target="_blank">linaro-mm-sig@lists.linaro.org</a><br>
> Signed-off-by: Mark Menzynski <<a href="mailto:mmenzyns@redhat.com" target="_blank">mmenzyns@redhat.com</a>><br>
> ---<br>
> drivers/gpu/drm/nouveau/nouveau_drm.c | 17 ++++++++---------<br>
> 1 file changed, 8 insertions(+), 9 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c<br>
> b/drivers/gpu/drm/nouveau/nouveau_drm.c<br>
> index 561309d447e0..773efdd20d2f 100644<br>
> --- a/drivers/gpu/drm/nouveau/nouveau_drm.c<br>
> +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c<br>
> @@ -588,12 +588,6 @@ nouveau_drm_device_init(struct drm_device *dev)<br>
> if (ret)<br>
> goto fail_dispctor;<br>
> <br>
> - if (dev->mode_config.num_crtc) {<br>
> - ret = nouveau_display_init(dev, false, false);<br>
> - if (ret)<br>
> - goto fail_dispinit;<br>
> - }<br>
> -<br>
> nouveau_debugfs_init(drm);<br>
> nouveau_hwmon_init(dev);<br>
> nouveau_svm_init(drm);<br>
> @@ -601,6 +595,12 @@ nouveau_drm_device_init(struct drm_device *dev)<br>
> nouveau_fbcon_init(dev);<br>
> nouveau_led_init(dev);<br>
> <br>
> + if (dev->mode_config.num_crtc) {<br>
> + ret = nouveau_display_init(dev, false, false);<br>
> + if (ret)<br>
> + goto fail_dispinit;<br>
> + }<br>
> +<br>
> if (nouveau_pmops_runtime()) {<br>
> pm_runtime_use_autosuspend(dev->dev);<br>
> pm_runtime_set_autosuspend_delay(dev->dev, 5000);<br>
> @@ -641,15 +641,14 @@ nouveau_drm_device_fini(struct drm_device *dev)<br>
> pm_runtime_forbid(dev->dev);<br>
> }<br>
> <br>
> + if (dev->mode_config.num_crtc)<br>
> + nouveau_display_fini(dev, false, false);<br>
> nouveau_led_fini(dev);<br>
> nouveau_fbcon_fini(dev);<br>
> nouveau_dmem_fini(drm);<br>
> nouveau_svm_fini(drm);<br>
> nouveau_hwmon_fini(dev);<br>
> nouveau_debugfs_fini(drm);<br>
> -<br>
> - if (dev->mode_config.num_crtc)<br>
> - nouveau_display_fini(dev, false, false);<br>
> nouveau_display_destroy(dev);<br>
> <br>
> nouveau_accel_fini(drm);<br>
<br>
-- <br>
Cheers,<br>
Lyude Paul (she/her)<br>
Software Engineer at Red Hat<br>
<br>
</blockquote></div>