From patchwork Tue Jul 12 16:49:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 9226601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EF53660868 for ; Wed, 13 Jul 2016 00:17:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF0A927BFA for ; Wed, 13 Jul 2016 00:17:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2B9C27C39; Wed, 13 Jul 2016 00:17:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6303F27BFA for ; Wed, 13 Jul 2016 00:17:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C25E6E2A8; Wed, 13 Jul 2016 00:17:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.lekensteyn.nl (mail.lekensteyn.nl [IPv6:2a02:2308::360:1:25]) by gabe.freedesktop.org (Postfix) with ESMTPS id A26B16E257; Tue, 12 Jul 2016 16:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2015-q1; h=Message-Id:Date:Subject:Cc:To:From; bh=Vv9Vtd0tt3IpLurKKB7oA8KxFabhaamRK/trdE4ahh0=; b=HX7BxiUlX8sYuZxC+GcWTl98JeW71Ew0+iHIBEwsiUovJ/JWrEhYytIxqGP7CEsK3io07RCtYoDlSIQM0rxAz3wGWQQDGOB1nT/pSX5WGE08NcT7qRV1BxOe8vBqP8bWAKdD2Y+CJZChldyUk5ugmd5Gr/OQy6Gg5M+VyLA1Q3Jtdz+ExXL36dU7QIo/fMD/SPFxpuRzbn3CioEjqxQH4z1ugPP6b0dkcls3dkPYgmoz5P9/uICSbBULwAhgLf01zIgwmoMxV5+dMmfRBQ1p86aGsoZ1ZhxZUmTGiXRHKGEovGFwLHfcfFyzj1AqvzO5UBHBpdCduGsjvz3wrAwdDg==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1bN0sN-0007AP-5Z; Tue, 12 Jul 2016 18:50:00 +0200 From: Peter Wu To: Dave Airlie Subject: [PATCH] drm/nouveau/fbcon: fix deadlock with FBIOPUT_CON2FBMAP Date: Tue, 12 Jul 2016 18:49:34 +0200 Message-Id: <20160712164934.1390-1-peter@lekensteyn.nl> X-Mailer: git-send-email 2.9.0 X-Mailman-Approved-At: Wed, 13 Jul 2016 00:17:01 +0000 Cc: Daniel Vetter , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The FBIOPUT_CON2FBMAP ioctl takes a console_lock(). When this is called while nouveau was runtime suspended, a deadlock would occur due to nouveau_fbcon_set_suspend also trying to obtain console_lock(). Fix this by delaying the drm_fb_helper_set_suspend call. Based on the i915 code (which was done for performance reasons though). Cc: Chris Wilson Cc: Daniel Vetter Signed-off-by: Peter Wu Reviewed-by: Chris Wilson --- Tested on top of v4.7-rc5, the deadlock is gone. --- drivers/gpu/drm/nouveau/nouveau_drm.c | 4 +-- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_fbcon.c | 54 ++++++++++++++++++++++++++++----- drivers/gpu/drm/nouveau/nouveau_fbcon.h | 2 +- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index 11f8dd9..f9a2c10 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -552,7 +552,7 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime) if (dev->mode_config.num_crtc) { NV_INFO(drm, "suspending console...\n"); - nouveau_fbcon_set_suspend(dev, 1); + nouveau_fbcon_set_suspend(dev, FBINFO_STATE_SUSPENDED, true); NV_INFO(drm, "suspending display...\n"); ret = nouveau_display_suspend(dev, runtime); if (ret) @@ -635,7 +635,7 @@ nouveau_do_resume(struct drm_device *dev, bool runtime) NV_INFO(drm, "resuming display...\n"); nouveau_display_resume(dev, runtime); NV_INFO(drm, "resuming console...\n"); - nouveau_fbcon_set_suspend(dev, 0); + nouveau_fbcon_set_suspend(dev, FBINFO_STATE_RUNNING, false); } return 0; diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index 822a021..a743d19 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -147,6 +147,7 @@ struct nouveau_drm { struct nouveau_channel *channel; struct nvkm_gpuobj *notify; struct nouveau_fbdev *fbcon; + struct work_struct fbdev_suspend_work; struct nvif_object nvsw; struct nvif_object ntfy; struct nvif_notify flip; diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c index d1f248f..089156a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c +++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c @@ -492,19 +492,53 @@ static const struct drm_fb_helper_funcs nouveau_fbcon_helper_funcs = { .fb_probe = nouveau_fbcon_create, }; +static void nouveau_fbcon_suspend_worker(struct work_struct *work) +{ + nouveau_fbcon_set_suspend(container_of(work, + struct nouveau_drm, + fbdev_suspend_work)->dev, + FBINFO_STATE_RUNNING, + true); +} + void -nouveau_fbcon_set_suspend(struct drm_device *dev, int state) +nouveau_fbcon_set_suspend(struct drm_device *dev, int state, bool synchronous) { struct nouveau_drm *drm = nouveau_drm(dev); - if (drm->fbcon) { - console_lock(); - if (state == FBINFO_STATE_RUNNING) - nouveau_fbcon_accel_restore(dev); - drm_fb_helper_set_suspend(&drm->fbcon->helper, state); + if (!drm->fbcon) + return; + + if (synchronous) { + /* Flush any pending work to turn the console on, and then + * wait to turn it off. It must be synchronous as we are + * about to suspend or unload the driver. + * + * Note that from within the work-handler, we cannot flush + * ourselves, so only flush outstanding work upon suspend! + */ if (state != FBINFO_STATE_RUNNING) - nouveau_fbcon_accel_save_disable(dev); - console_unlock(); + flush_work(&drm->fbdev_suspend_work); + console_lock(); + } else { + /* + * The console lock can be pretty contented on resume due + * to all the printk activity. Try to keep it out of the hot + * path of resume if possible. This also prevents a deadlock + * with FBIOPUT_CON2FBMAP. + */ + WARN_ON(state != FBINFO_STATE_RUNNING); + if (!console_trylock()) { + schedule_work(&drm->fbdev_suspend_work); + return; + } } + + if (state == FBINFO_STATE_RUNNING) + nouveau_fbcon_accel_restore(dev); + drm_fb_helper_set_suspend(&drm->fbcon->helper, state); + if (state != FBINFO_STATE_RUNNING) + nouveau_fbcon_accel_save_disable(dev); + console_unlock(); } int @@ -526,6 +560,8 @@ nouveau_fbcon_init(struct drm_device *dev) fbcon->dev = dev; drm->fbcon = fbcon; + INIT_WORK(&drm->fbdev_suspend_work, nouveau_fbcon_suspend_worker); + drm_fb_helper_prepare(dev, &fbcon->helper, &nouveau_fbcon_helper_funcs); ret = drm_fb_helper_init(dev, &fbcon->helper, @@ -571,6 +607,8 @@ nouveau_fbcon_fini(struct drm_device *dev) if (!drm->fbcon) return; + flush_work(&drm->fbdev_suspend_work); + nouveau_fbcon_accel_fini(dev); nouveau_fbcon_destroy(dev, drm->fbcon); kfree(drm->fbcon); diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.h b/drivers/gpu/drm/nouveau/nouveau_fbcon.h index ca77ad0..34b2504 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fbcon.h +++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.h @@ -66,7 +66,7 @@ void nouveau_fbcon_gpu_lockup(struct fb_info *info); int nouveau_fbcon_init(struct drm_device *dev); void nouveau_fbcon_fini(struct drm_device *dev); -void nouveau_fbcon_set_suspend(struct drm_device *dev, int state); +void nouveau_fbcon_set_suspend(struct drm_device *dev, int state, bool synchronous); void nouveau_fbcon_accel_save_disable(struct drm_device *dev); void nouveau_fbcon_accel_restore(struct drm_device *dev);