From patchwork Tue Sep 22 00:21:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 7234691 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8F3939F380 for ; Tue, 22 Sep 2015 00:22:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0A5020891 for ; Tue, 22 Sep 2015 00:22:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C016620894 for ; Tue, 22 Sep 2015 00:22:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 72C596EA2D; Mon, 21 Sep 2015 17:22:03 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTP id E566E6EA22; Mon, 21 Sep 2015 17:22:01 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 21 Sep 2015 17:22:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,570,1437462000"; d="scan'208";a="649661723" Received: from mdroper-hswdev.fm.intel.com (HELO mdroper-hswdev) ([10.1.134.215]) by orsmga003.jf.intel.com with ESMTP; 21 Sep 2015 17:22:03 -0700 Received: from mattrope by mdroper-hswdev with local (Exim 4.84) (envelope-from ) id 1ZeBLM-0006Uv-Qd; Mon, 21 Sep 2015 17:22:00 -0700 From: Matt Roper To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/fbdev: Update legacy plane->fb refcounting for atomic restore Date: Mon, 21 Sep 2015 17:21:48 -0700 Message-Id: <1442881308-24940-1-git-send-email-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.1.4 Cc: intel-gfx@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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Starting with commit commit 28cc504e8d52248962f5b485bdc65f539e3fe21d Author: Rob Clark Date: Tue Aug 25 15:36:00 2015 -0400 drm/i915: enable atomic fb-helper I've been seeing some panics on i915 when the DRM master shuts down that appear to be caused by using an already-freed framebuffer (i.e., we're unexpectedly dropping our initial FB's reference count to 0 and freeing it, which causes a crash when we try to restore it later). Digging deeper, the state FB refcounting is working as expected, but we seem to be missing proper refcounting on the legacy plane->fb pointers in the new atomic fbdev code. Tracking plane->old_fb and then doing a ref/unref at the end of the fbdev restore like we do in the legacy ioctl's ensures we don't miscount references on plane->fb and avoids the panics. Cc: Rob Clark Cc: intel-gfx@lists.freedesktop.org Signed-off-by: Matt Roper --- I don't see any existing bugzilla's (or mailing list complaints) for this, which surprises me a bit since it seems to be very easy to reproduce for me on latest drm-intel-nightly running on IVB...boot the system, load X, kill X, panic. drivers/gpu/drm/drm_fb_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 64fc5ca..2149ac7 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -352,6 +352,8 @@ retry: drm_for_each_plane(plane, dev) { struct drm_plane_state *plane_state; + plane->old_fb = plane->fb; + plane_state = drm_atomic_get_plane_state(state, plane); if (IS_ERR(plane_state)) { ret = PTR_ERR(plane_state); @@ -385,6 +387,14 @@ retry: if (ret != 0) goto fail; + drm_for_each_plane(plane, dev) { + if (plane->fb) + drm_framebuffer_reference(plane->fb); + if (plane->old_fb) + drm_framebuffer_unreference(plane->old_fb); + plane->old_fb = NULL; + } + return 0; fail: