From patchwork Mon Feb 8 01:13:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 8246131 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D62D5BEEE5 for ; Mon, 8 Feb 2016 01:14:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6E76F201E4 for ; Mon, 8 Feb 2016 01:14:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 78D2C201C8 for ; Mon, 8 Feb 2016 01:14:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B96F96E32C; Sun, 7 Feb 2016 17:14:47 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5AF946E32C for ; Sun, 7 Feb 2016 17:14:46 -0800 (PST) Received: by mail-wm0-f65.google.com with SMTP id g62so13234426wme.2 for ; Sun, 07 Feb 2016 17:14:46 -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=7wgI72yoQVtwn/CUrG7NJlbV3r0mUrm6exY+ErvXYOw=; b=wbKpavJYtsT0mAF78ye8bDbFZvPGkLs2vvd2F8J5VXvVNSl2qvENtjovq/J4TL62za ObeIiWJhh5JkpdURuIl7G8daXKbQOW4KzhORyzcbid0JAspDaORp06F0QUMVhTHtkBTu /EUlxDeUlUIsUN7EPJclAelErPuQxjUFr7ffM0vLM+k/1j4PBXIblnCUbGT0sk2rQ+UN Wj4oy8BwKfPtyv6I8yJh7809GYSjiWXU+U0EfOuV6oigp1U0wQl/heWbsTXhwP6xWwKG HtsJ5aVyEDDWV6ZFj+b3biwtVQK3no2uKFjsap2KIBAUfSGi+pPnRF8TxFQgjTF+ZXh5 u4lA== 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=7wgI72yoQVtwn/CUrG7NJlbV3r0mUrm6exY+ErvXYOw=; b=bLe89I0jpmwMbAITHOyipqqR+9dU7d6XYo8LD6I8d5XeFAJnzDgKXO1G90KCuE5oAk a0QemAz6EF5k4rPpDxWMUxW0de1KQzPtFoe0x5pT1kpakLDBrLR1oMycNjy53R/CLxqo 3KBEKahWerf21z+/PJm/XwMnY+RwnaD7b26sDNn9stdKydo+f0zUyYFuTapilYqxCcQh ReIMKytye/G8WLzbsTOnS3oa2aUMqk/p/SRoiU4sdel5WPCcNkPz+R1PJ90I5UDGAMMr IDwo6Unt+ARtJtLi7P7McNG8XxGUlDyTjFgEWnQYfHGtcEQMdnUwVWfBho/xhl/nFh7X o8HQ== X-Gm-Message-State: AG10YOQf+F48mLKf81KDwdjAa061jIKJj9YOMQZveT6foJqWUVe3XSdF7gHVdJBThSDpVg== X-Received: by 10.28.90.133 with SMTP id o127mr29493726wmb.101.1454894085186; Sun, 07 Feb 2016 17:14:45 -0800 (PST) Received: from twisty.fritz.box (x4d02db5e.dyn.telefonica.de. [77.2.219.94]) by smtp.gmail.com with ESMTPSA id b5sm9486380wmh.15.2016.02.07.17.14.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Feb 2016 17:14:44 -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: Mon, 8 Feb 2016 02:13:26 +0100 Message-Id: <1454894009-15466-4-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1454894009-15466-1-git-send-email-mario.kleiner.de@gmail.com> References: <1454894009-15466-1-git-send-email-mario.kleiner.de@gmail.com> Cc: daniel.vetter@ffwll.ch, michel@daenzer.net, linux@bernd-steinhauser.de, 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.3 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 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 Reviewed-by: Daniel Vetter --- 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 aa2c74b..5c27ad3 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; + } + + /* * Restrict the bump of the software vblank counter to a safe maximum * value of +1 whenever there is the possibility that concurrent readers * of vblank timestamps could be active at the moment, as the current @@ -1573,6 +1588,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)