From patchwork Fri Feb 12 19:30:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 8296661 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 24EA69F6E4 for ; Fri, 12 Feb 2016 19:31:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47B0220452 for ; Fri, 12 Feb 2016 19:31:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 36E5F2045A for ; Fri, 12 Feb 2016 19:31:45 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 72A1B6EA55; Fri, 12 Feb 2016 11:31:44 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E9FB6EA55 for ; Fri, 12 Feb 2016 11:31:43 -0800 (PST) Received: by mail-wm0-f66.google.com with SMTP id p63so4400172wmp.1 for ; Fri, 12 Feb 2016 11:31:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gSPZ/5pU0Uxt5+5deH0qpD7LIWjcR6RJjp+uicz8BzM=; b=RaADFe0RuCHhmEzb5VQ7sMWpUUWFsFiLwrvhnwiHCLWqM0kfM1EZGov1Kvxj3A+jhS ej1II/i0ThbARNSw452wDzahpnwdQRebGtEzJyIzjjtEbBr+H7Wdf1FUErHXXZHf/tKB TupOOIAmBVUA70AbZP+GJiFTfJLxd+sA4SAWprUWRIuzcYndfNAUAyo0tw6tBzv93NGV 7mxFRhJhXv6OWdDPMaIA+BBXdZWkCf5umdptg99xPxEDAKEr8e1wFZS3RtspUzvYOYe8 VzQR91b5hgC8tcNHhg9MTMtEM+rT82/pOs3OH32lZ5BtbG/Jp2MYdFozX8sEdLoYgJOt ZcuA== 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=gSPZ/5pU0Uxt5+5deH0qpD7LIWjcR6RJjp+uicz8BzM=; b=Z0zCHMVDBo7iQ36uyDYb3KwR+H/yCbd5+JuN6Tbi2fdSkMS6zsJo6Db69V3qfVnVde g/E9r7Mu1DlKyMd8l1bNYLK93YBga33hPTY0G3KFVrP4M45pdW1URgsZOEvBUBCIYaS0 ZTlrjHqHlCEiyORdQHU5R48J/PAjhzK+UMM9r4mpSCyrlcHbHq0I3LwCu7LqAjecfjjl Y4Pcwhvhfq6flfjEWJ1bvomXMr4qELDjhGiaIw6b9ViP1SbADOBNxen6ijeGeQmqV9Ks uFLStVjZtpoEScsR8floVGDPDQ0QwVvNDDjowtdADHcyU4VWEN/LHlGYw51bhE37dTMT uiDQ== X-Gm-Message-State: AG10YORcZgxiHA8SA3nIekPwswYcEd+CogGHd9Xet+eIGq98l+qq/j+E1FRqNPQLVI0yLg== X-Received: by 10.28.48.137 with SMTP id w131mr4936820wmw.73.1455305456950; Fri, 12 Feb 2016 11:30:56 -0800 (PST) Received: from twisty.cin.medizin.uni-tuebingen.de (cin-11.medizin.uni-tuebingen.de. [134.2.118.242]) by smtp.gmail.com with ESMTPSA id v78sm3637797wmv.23.2016.02.12.11.30.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 11:30:56 -0800 (PST) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/6] drm: Fix drm_vblank_pre/post_modeset regression from Linux 4.4 Date: Fri, 12 Feb 2016 20:30:29 +0100 Message-Id: <1455305432-28770-4-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455305432-28770-1-git-send-email-mario.kleiner.de@gmail.com> References: <1455305432-28770-1-git-send-email-mario.kleiner.de@gmail.com> Cc: daniel.vetter@ffwll.ch, michel@daenzer.net, stable@vger.kernel.org, alexander.deucher@amd.com, christian.koenig@amd.com, vbabka@suse.cz 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, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, 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 Changes to drm_update_vblank_count() in Linux 4.4 broke the behaviour of the pre/post modeset functions as the new update code doesn't deal with hw vblank counter resets inbetween calls to drm_vblank_pre_modeset an drm_vblank_post_modeset, as it should. This causes mistreatment of such hw counter resets as counter wraparound, and thereby large forward jumps of the software vblank counter which in turn cause vblank event dispatching and vblank waits to fail/hang --> userspace clients hang. This symptom was reported on radeon-kms to cause a infinite hang of KDE Plasma 5 shell's login procedure, preventing users from logging in. Fix this by detecting when drm_update_vblank_count() is called inside a pre->post modeset interval. If so, clamp valid vblank increments to the safe values 0 and 1, pretty much restoring the update behavior of the old update code of Linux 4.3 and earlier. Also reset the last recorded hw vblank count at call to drm_vblank_post_modeset() to be safe against hw that after modesetting, dpms on etc. only fires its first vblank irq after drm_vblank_post_modeset() was already called. Reported-by: Vlastimil Babka Signed-off-by: Mario Kleiner Reviewed-by: Daniel Vetter Tested-by: Vlastimil Babka Cc: # 4.4+ Cc: michel@daenzer.net Cc: vbabka@suse.cz Cc: ville.syrjala@linux.intel.com Cc: daniel.vetter@ffwll.ch Cc: dri-devel@lists.freedesktop.org Cc: alexander.deucher@amd.com Cc: christian.koenig@amd.com --- drivers/gpu/drm/drm_irq.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 92ad62f..055b0fa 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -222,6 +222,21 @@ static void drm_update_vblank_count(struct drm_device *dev, unsigned int pipe, } /* + * Within a drm_vblank_pre_modeset - drm_vblank_post_modeset + * interval? If so then vblank irqs keep running and it will likely + * happen that the hardware vblank counter is not trustworthy as it + * might reset at some point in that interval and vblank timestamps + * are not trustworthy either in that interval. Iow. this can result + * in a bogus diff >> 1 which must be avoided as it would cause + * random large forward jumps of the software vblank counter. + */ + if (diff > 1 && (vblank->inmodeset & 0x2)) { + DRM_DEBUG_VBL("clamping vblank bump to 1 on crtc %u: diffr=%u" + " due to pre-modeset.\n", pipe, diff); + diff = 1; + } + + /* * FIMXE: Need to replace this hack with proper seqlocks. * * Restrict the bump of the software vblank counter to a safe maximum @@ -1575,6 +1590,7 @@ void drm_vblank_post_modeset(struct drm_device *dev, unsigned int pipe) if (vblank->inmodeset) { spin_lock_irqsave(&dev->vbl_lock, irqflags); dev->vblank_disable_allowed = true; + drm_reset_vblank_timestamp(dev, pipe); spin_unlock_irqrestore(&dev->vbl_lock, irqflags); if (vblank->inmodeset & 0x2)