From patchwork Tue Sep 22 10:56:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 7238041 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 7A7979F380 for ; Tue, 22 Sep 2015 10:54:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95F1920781 for ; Tue, 22 Sep 2015 10:54:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9C76A207E8 for ; Tue, 22 Sep 2015 10:53:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F4D16EA69; Tue, 22 Sep 2015 03:53:57 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com [209.85.212.181]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6E5E66EA68 for ; Tue, 22 Sep 2015 03:53:55 -0700 (PDT) Received: by wicfx3 with SMTP id fx3so185789263wic.1 for ; Tue, 22 Sep 2015 03:53:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=05Rt4D5ZYnARPjLV9Kuv6x/ezU4DiFXw4KNt6SKvLAA=; b=QRth8vTvNV3hULav9MaLiuHvWKidFum94CYLae79BP4p43rv4GdOBqZhur1JkWwLQF M8VF+CoQ84afWCTGVcqoIUpAeFi6IsSeZoYUGC0ZsH1ZHY8oJaGvZs+9yR0rBZre6CRK DUwNoLbUef6pZbj06AeU4VJF87hcFLwTPB8z0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=05Rt4D5ZYnARPjLV9Kuv6x/ezU4DiFXw4KNt6SKvLAA=; b=eRrvvjW5Q43p2YAo5FTjrZyLJUX8IYLCPzloQD0G4hRKgzCg7mTSd9jMc5y049MwfW EXeeH9Y70HNmbeXUVZjlpnM7kmGOOB6YoH50gNfIFnVIRjOStAn1J+0sam1ybrXiquCT IpGIqxrL4VPmIYqI0cfKDKLBk6SQB1sh2cyOxFumGXp6/fbL4TzML3ZrERL6KIyGz1Hy fHApw23ZK3TDy1u5NUmyYOXlHnmnAyVrpMUgsorugk1va0LzCdCMIWB8e4/fnFEJP+PB wrg2w+1R2HCiUp/3sYUG3unptE8czq3VexzdVFvqXUYA/9Xl8EmcZG284o0b/5/v/ZrD OtKw== X-Gm-Message-State: ALoCoQk9zIMI+XcwntGj2R92A8nwNoM7/yaNgLDOhmOZWugNYwEXGqz5vimkjpXW+C0g0mcrl0RC X-Received: by 10.180.37.133 with SMTP id y5mr18307180wij.15.1442919233796; Tue, 22 Sep 2015 03:53:53 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id p10sm1247766wjx.7.2015.09.22.03.53.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Sep 2015 03:53:53 -0700 (PDT) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/fbdev: Update legacy plane->fb refcounting for atomic restore Date: Tue, 22 Sep 2015 12:56:42 +0200 Message-Id: <1442919402-4451-1-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1442881308-24940-1-git-send-email-matthew.d.roper@intel.com> References: <1442881308-24940-1-git-send-email-matthew.d.roper@intel.com> Cc: Daniel Vetter , 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 From: Matt Roper 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. v2 from Daniel: Really do what the atomic ioctl does: - Also update plane->fb and plane->crtc. - Clear out plane->old_fb on failures too. v3: git add everything. Oops. Cc: Rob Clark Cc: intel-gfx@lists.freedesktop.org Signed-off-by: Matt Roper (v1) Signed-off-by: Daniel Vetter Reviewed-by: David Herrmann --- drivers/gpu/drm/drm_fb_helper.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 64fc5ca8fda2..8af522afdfc1 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); @@ -382,6 +384,21 @@ retry: } ret = drm_atomic_commit(state); + + drm_for_each_plane(plane, dev) { + if (ret == 0) { + struct drm_framebuffer *new_fb = plane->state->fb; + if (new_fb) + drm_framebuffer_reference(new_fb); + plane->fb = new_fb; + plane->crtc = plane->state->crtc; + + if (plane->old_fb) + drm_framebuffer_unreference(plane->old_fb); + } + plane->old_fb = NULL; + } + if (ret != 0) goto fail;