Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp5227452iob; Mon, 9 May 2022 11:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2p+iWklx3llrWqL9lsVJuWJY5FXvgOzQTi+oN7KbpE9hduIoS5xRexUvoOOEAWitIybPe X-Received: by 2002:a05:620a:3190:b0:6a0:31c2:5578 with SMTP id bi16-20020a05620a319000b006a031c25578mr12643623qkb.420.1652120651306; Mon, 09 May 2022 11:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652120651; cv=none; d=google.com; s=arc-20160816; b=Tf7rprsZSc2eb7a5H08oXXLZAF55Wco0OdRG7/vwbm0HjpQ/29a9qSs9Mj/wSB1zUN 544ARkpndBUSpFenLJhqmEEbksOizseibOeO+II1JC32XNpcL4+PzVniqryAOe5FuS0B e2C6AiPF8PYHhRym+AwtNawim5Vl2yVUOZaUaKiYAIVwt8rohOYYiZK0yd5x1ctrc3An UphQbHHaVZUUjAk+KTNMDB2ERwZnDtaVy58ZXPQfg96vCXw8kH/+/GtbQDRBvt4DacIv 0IqTWqaeDPvVvfClbPSIFM1jpHngaIzM5K8m7z5vOjCRYuBVFZfZz0m92o7xoM/zEX8X Ui9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=PDFIEGAmMkYI3lcSgWTP/D9Zx+5IJKr94HLnqcFoXoI=; b=DzpCDbaHIpRNxUDos0W+kyIZS0+MCQg5Wbzhfow8+IloJ1jOP1s8FwCCN9Ip4nYuEu Mnt8xMM2RmUfJnpYSYkia1vd7M5QZHixr8KHhcOjakqKhsH7k7eYMD75qS1smc1fGX/D OLakiarmORwYan20d54vl+T6WURPkmU6mhFpLXTzsbjHE8rhb7zzPgb0n5CYBp/dbQS7 ompdMqD/lpLM/KtdBSgyb7YXyBughy55fSSfcxrB79j+F0n2obplUkRkcoE87W1FA5nF r1DFHrjth1xG6APKHg9YVI58QV60Ybiw2ZorS+G8aTAaqI95rJEwjpuLm5dp8uAV6Sew 2elg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JbkIx0gc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v12-20020a05620a440c00b006a049b24b1asi6541815qkp.329.2022.05.09.11.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 11:24:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JbkIx0gc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 197062D2E14; Mon, 9 May 2022 11:20:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240172AbiEISXm (ORCPT + 99 others); Mon, 9 May 2022 14:23:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240150AbiEISXk (ORCPT ); Mon, 9 May 2022 14:23:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EDA552CE237 for ; Mon, 9 May 2022 11:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652120383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PDFIEGAmMkYI3lcSgWTP/D9Zx+5IJKr94HLnqcFoXoI=; b=JbkIx0gcvx3iZGAwdftphW2Z3cWIeQjcYZBbAdYcn670P275YxucVpr2hCIcRaSWw/UOrS XlYRFKEm5pMx2VL/y7tMCdYfAsTclyjvw8/cm5urj8HOYh9MbjNrSsTR9U3RjKMhZsrdUA 7KuXUbzlVtZ7rjAQ3mTSH3l0m0kIuPY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-627-pqgms_YLNM-tXpkbHb7qnA-1; Mon, 09 May 2022 14:19:42 -0400 X-MC-Unique: pqgms_YLNM-tXpkbHb7qnA-1 Received: by mail-qt1-f197.google.com with SMTP id o16-20020ac87c50000000b002f3b8cd6a7fso12683458qtv.13 for ; Mon, 09 May 2022 11:19:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:user-agent:mime-version :content-transfer-encoding; bh=PDFIEGAmMkYI3lcSgWTP/D9Zx+5IJKr94HLnqcFoXoI=; b=Y5xe6BeMQLCD4CRKzkt0adXSoYooax7lSEfHHJ6ZfSpXY0pIRnklDKa8Euicxdux5a zsgz8zb8Ll0d3rQ/Xv4rMGOXPei/92C/qC3Tad8JyLsYeIjY3yFSwPLTW1rP8gappy+1 6SRowucagFEOCe1VJCJQFv9HGS4fmUFBwDBWoGqhjAzA1vxFniYwq/vi5FXpRFLDOCgt TW986U4HWBgYbCRmFuu9kkN4YAaCM27Edu5F8ws/SSViBwyBHK52RdaG5+ZwXxxqLlT7 JcFCWY5Z6l5V5sF60rz0XAAdwiHObWijvUnfRo9QGqcR0mmsniOTNVgDIuM6JZs8Rioy Kwlw== X-Gm-Message-State: AOAM533clxgpQUiihbdzFuB4etGHcXOGRSqewrC91k13yBdwUqasWBB/ dpBgo4NgWbG7Yg7LIgrNPoPV+aTs0S017EClJpK67w5xpbMJiew4jnvy5O+g/QlfZKeIDLpM08p 8QRSkO5OKS4qapwgHuCnCKOiM X-Received: by 2002:ad4:594b:0:b0:45a:9692:14a3 with SMTP id eo11-20020ad4594b000000b0045a969214a3mr14821467qvb.107.1652120381817; Mon, 09 May 2022 11:19:41 -0700 (PDT) X-Received: by 2002:ad4:594b:0:b0:45a:9692:14a3 with SMTP id eo11-20020ad4594b000000b0045a969214a3mr14821445qvb.107.1652120381597; Mon, 09 May 2022 11:19:41 -0700 (PDT) Received: from [192.168.8.138] (static-71-184-137-158.bstnma.ftas.verizon.net. [71.184.137.158]) by smtp.gmail.com with ESMTPSA id y7-20020ac87c87000000b002f39b99f67csm8127235qtv.22.2022.05.09.11.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 11:19:41 -0700 (PDT) Message-ID: <1deeebc415c188c35f090048f32d7dacd93b14b1.camel@redhat.com> Subject: Re: [PATCH] drm/nouveau: reorder nouveau_drm_device_fini From: Lyude Paul To: Mark Menzynski Cc: linux-kernel@vger.kernel.org, Ben Skeggs , Karol Herbst , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, nouveau Date: Mon, 09 May 2022 14:19:39 -0400 In-Reply-To: <82c9b246bcbe544036d2fc0873f15f8483947a57.camel@redhat.com> References: <20220504171851.17188-1-mmenzyns@redhat.com> <7574d491866ffa7c1a4607885b76140ba4206477.camel@redhat.com> <82c9b246bcbe544036d2fc0873f15f8483947a57.camel@redhat.com> Organization: Red Hat Inc. Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Also JFYI Mark - I just realized that your email client is defaulting to sending HTML mail when you reply to me, that doesn't really make it onto the mailing list at all so you probably want to fix that. Also - I misspoke here again, I think it should actually be a call to drm_kms_helper_poll_fini() instead since that will both cancel the output poll worker and update dev->mode_config.poll_enabled to prevent the output poll worker from starting up again. The documentation doesn't say it's fine to call drm_kms_helper_poll_disable() after that, but it seems to be safe from looking at the code - and I think someone just generally forgot to write docs for drm_kms_helper_poll_fini()… On Mon, 2022-05-09 at 13:59 -0400, Lyude Paul wrote: > On Mon, 2022-05-09 at 15:13 +0200, Mark Menzynski wrote: > > 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. > > I think I may have misspoke on what the issue was here since I was about to > leave work. The MST bit might not actually be an issue, however I think > nouveau_fbcon_init() being called before nouveau_display_init() would be an > issue since nouveau_fbcon_init() can trigger a modeset - and we can't > perform modesets before nouveau_display_init() has set things up. > > Looking at the docs for drm_kms_helper_poll_disable() - I think the actual > fix here (to ensure that we still call drm_kms_helper_poll_disable() at the > right time during suspend) would be to actually add another call to > drm_kms_helper_poll_disable() into nouveau_fbcon_fini() before we call > nouveau_fbcon_accel_fini() and everything after. This should make sure that > we stop the output polling work early on driver unload, and since the docs > mention that it's OK to disable polling more then once with > drm_kms_helper_poll_disable() I don't see any issues with that. > > > > > > 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. > > > > 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"? > > > > On Thu, May 5, 2022 at 9:57 PM Lyude Paul wrote: > > > Hmm, I think we might just need to move the drm_kms_helper_poll_enable() > > > call > > > to the end here instead of all of nouveau_display_init(). I realized > > > this > > > because in nouveau_display_init() it seems that we actually rely on > > > nouveau_display_init() to setup hotplug interrupts - which we do > > > actually need > > > this early on in the driver probe process. > > > > > > That being said though, drm_kms_helper_poll_enable() shouldn't be > > > required for > > > MST short HPD IRQs from working so moving that instead should work. > > > > > > On Wed, 2022-05-04 at 19:18 +0200, Mark Menzynski wrote: > > > > Resources needed for output poll workers are destroyed in > > > > nouveau_fbcon_fini() before output poll workers are cleared in > > > > nouveau_display_fini(). This means there is a time between fbcon_fini > > > > and display_fini, where if output poll happens, it crashes. > > > > > > > > BUG: KASAN: use-after-free in > > > > __drm_fb_helper_initial_config_and_unlock.cold+0x1f3/0x291 > > > > [drm_kms_helper] > > > > > > > > Cc: Ben Skeggs > > > > Cc: Karol Herbst > > > > Cc: Lyude Paul > > > > Cc: David Airlie > > > > Cc: Daniel Vetter > > > > Cc: Sumit Semwal > > > > Cc: "Christian König" > > > > Cc: dri-devel@lists.freedesktop.org > > > > Cc: nouveau@lists.freedesktop.org > > > > Cc: linux-kernel@vger.kernel.org > > > > Cc: linux-media@vger.kernel.org > > > > Cc: linaro-mm-sig@lists.linaro.org > > > > Signed-off-by: Mark Menzynski > > > > --- > > > >  drivers/gpu/drm/nouveau/nouveau_drm.c | 17 ++++++++--------- > > > >  1 file changed, 8 insertions(+), 9 deletions(-) > > > > > > > > diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c > > > > b/drivers/gpu/drm/nouveau/nouveau_drm.c > > > > index 561309d447e0..773efdd20d2f 100644 > > > > --- a/drivers/gpu/drm/nouveau/nouveau_drm.c > > > > +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c > > > > @@ -588,12 +588,6 @@ nouveau_drm_device_init(struct drm_device *dev) > > > >         if (ret) > > > >                 goto fail_dispctor; > > > >   > > > > -       if (dev->mode_config.num_crtc) { > > > > -               ret = nouveau_display_init(dev, false, false); > > > > -               if (ret) > > > > -                       goto fail_dispinit; > > > > -       } > > > > - > > > >         nouveau_debugfs_init(drm); > > > >         nouveau_hwmon_init(dev); > > > >         nouveau_svm_init(drm); > > > > @@ -601,6 +595,12 @@ nouveau_drm_device_init(struct drm_device *dev) > > > >         nouveau_fbcon_init(dev); > > > >         nouveau_led_init(dev); > > > >   > > > > +       if (dev->mode_config.num_crtc) { > > > > +               ret = nouveau_display_init(dev, false, false); > > > > +               if (ret) > > > > +                       goto fail_dispinit; > > > > +       } > > > > + > > > >         if (nouveau_pmops_runtime()) { > > > >                 pm_runtime_use_autosuspend(dev->dev); > > > >                 pm_runtime_set_autosuspend_delay(dev->dev, 5000); > > > > @@ -641,15 +641,14 @@ nouveau_drm_device_fini(struct drm_device *dev) > > > >                 pm_runtime_forbid(dev->dev); > > > >         } > > > >   > > > > +       if (dev->mode_config.num_crtc) > > > > +               nouveau_display_fini(dev, false, false); > > > >         nouveau_led_fini(dev); > > > >         nouveau_fbcon_fini(dev); > > > >         nouveau_dmem_fini(drm); > > > >         nouveau_svm_fini(drm); > > > >         nouveau_hwmon_fini(dev); > > > >         nouveau_debugfs_fini(drm); > > > > - > > > > -       if (dev->mode_config.num_crtc) > > > > -               nouveau_display_fini(dev, false, false); > > > >         nouveau_display_destroy(dev); > > > >   > > > >         nouveau_accel_fini(drm); > > > > -- Cheers, Lyude Paul (she/her) Software Engineer at Red Hat