From patchwork Tue May 31 16:49:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cpaul@redhat.com X-Patchwork-Id: 9145851 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 E280860752 for ; Wed, 1 Jun 2016 00:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C898C20072 for ; Wed, 1 Jun 2016 00:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9E6426785; Wed, 1 Jun 2016 00:48:58 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable 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 2530920072 for ; Wed, 1 Jun 2016 00:48:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2AFE86E7A5; Wed, 1 Jun 2016 00:48:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4A0636E6AA; Tue, 31 May 2016 16:50:07 +0000 (UTC) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7E64821C3; Tue, 31 May 2016 16:50:06 +0000 (UTC) Received: from ecstaticemu.bos.redhat.com (dhcp-25-142.bos.redhat.com [10.18.25.142]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4VGo2xB003543; Tue, 31 May 2016 12:50:05 -0400 From: Lyude To: stable@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH 3/4] drm/i915: Discard previous atomic state on resume if connectors change Date: Tue, 31 May 2016 12:49:06 -0400 Message-Id: <1464713347-28982-4-git-send-email-cpaul@redhat.com> In-Reply-To: <1464713347-28982-1-git-send-email-cpaul@redhat.com> References: <1464713347-28982-1-git-send-email-cpaul@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 31 May 2016 16:50:07 +0000 (UTC) X-Mailman-Approved-At: Wed, 01 Jun 2016 00:48:54 +0000 Cc: Daniel Vetter , Lyude , "open list:INTEL DRM DRIVERS excluding Poulsbo, Moorestow..., dri-devel@lists.freedesktop.org open list:INTEL DRM DRIVERS excluding Poulsbo, Moorestow..., linux-kernel@vger.kernel.org open list" 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 If an MST device is disconnected while the machine is suspended, the number of connectors will change as well after we call intel_dp_mst_resume(). This means that any previous atomic state we had before suspending is no longer valid, since it'll still be pointing to missing connectors. We need to check for this before committing the state, otherwise we'll kernel panic on resume whenever if any MST display was disconnected before we started resuming: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 IP: [] drm_atomic_helper_check_modeset+0x29f/0xb40 [drm_kms_helper] Call Trace: [] intel_atomic_check+0x34/0x1180 [i915] [] ? mark_held_locks+0x6f/0xa0 [] ? trace_hardirqs_on_caller+0x129/0x1b0 [] drm_atomic_check_only+0x192/0x620 [drm] [] ? pci_pm_thaw+0x21/0x90 [] drm_atomic_commit+0x17/0x60 [drm] [] intel_display_resume+0xbd/0x160 [i915] [] ? pci_pm_thaw+0x90/0x90 [] i915_drm_resume+0xd8/0x160 [i915] [] i915_pm_resume+0x25/0x30 [i915] [] pci_pm_resume+0x64/0xa0 [] dpm_run_callback+0x90/0x190 [] device_resume+0xd5/0x1f0 [] async_resume+0x1d/0x50 [] async_run_entry_fn+0x48/0x150 [] process_one_work+0x1e9/0x5c0 [] ? process_one_work+0x166/0x5c0 [] worker_thread+0x48/0x4e0 [] ? process_one_work+0x5c0/0x5c0 [] kthread+0xe4/0x100 [] ret_from_fork+0x22/0x50 [] ? kthread_create_on_node+0x200/0x200 Changes since v1: - Move drm_atomic_state_free() call down so we're holding the appropriate locks when destroying the atomic state Changes since v2: - Check that state != NULL before we start accessing it's members This fix is only required for 4.6 and below. David Airlie's patchseries for 4.7 to add connector reference counting provides a more proper fix for this. Upstream fix: 0552f7651bc2 ("drm/i915/mst: use reference counted connectors. (v3)") Reviewed-by: Daniel Vetter Signed-off-by: Lyude --- drivers/gpu/drm/i915/intel_display.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 0104a06..6fdb90e 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -15958,6 +15958,18 @@ void intel_display_resume(struct drm_device *dev) retry: ret = drm_modeset_lock_all_ctx(dev, &ctx); + /* + * With MST, the number of connectors can change between suspend and + * resume, which means that the state we want to restore might now be + * impossible to use since it'll be pointing to non-existant + * connectors. + */ + if (ret == 0 && state && + state->num_connector != dev->mode_config.num_connector) { + drm_atomic_state_free(state); + state = NULL; + } + if (ret == 0 && !setup) { setup = true;