Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp793415ybx; Fri, 1 Nov 2019 11:18:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyi2oAZTEfoHyAJRFa9FA6bHkawu5cb3DPfMvhEQm74uy2iXRqkU+KJxDZNqV6p0d7a0BWT X-Received: by 2002:a17:906:73d4:: with SMTP id n20mr11272436ejl.45.1572632333389; Fri, 01 Nov 2019 11:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572632333; cv=none; d=google.com; s=arc-20160816; b=istCeJwLw1sznCMau+Eoll5MAy8XNuW34BL9wqSbFJcGvjmzEqCnvUhTL/vL+IlimV amhFLqOpiEhVlKra549OgboEu5EY8O0RJ3K71Nd5qvy3gtkqt1kdcFS9Vj4lBq60Hycs mpxIM2E0565IjhWYo/yEdde/0c4feGTwkQaM7E0b2yUXpOB4Z0t4o1Duxy0J+Oozlcyz vnEeoEAwv++jUAUqroGVmf/kWgbLgGrAMEIWGSjdpsR11ORE0KTOtUGIXFE4n/JIIwko aiGpFVHhlmGtWuA8QSN2LSiiXJ99vb+Hkal1oSbsw7Dhe3xai0aGSOCY+NgmqdzfTRbh x2mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YeTpB1Wx1lpy3awpQLYzDRRtlZuKfiLn87LhRSvje50=; b=HUb4ZjbZYr/wH4IssWF1y6QNsO0N4YYYER9PNMNoe6s+jy55T+UqCIjDvLsgmKS9qW /bXummHbk2iJV1euXwYEMQztn8epavT2d1pp74vmcdPLkVRgcgSqdqSz1qpKqhqjH4ZV EvlmAf3YxZJ53nZ1X9aOTnw9Cdep2cLDMnip2P4jiMzHzYUFTmz2S5nGwqQ5UcXcfQl8 5egHwIg9Vsfhxo/tfyN3AkL7T8tffHAse4vyzaub0fRfuAkQ8nO3wYf7rX4mYL2o4DRE Q/N2KOZuSGK2zLSZ9U//mPWliwPaXWNkaT/P2kjjF2iXvdHaVlrvTiA7KQP0j5+tA14p mIcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MEejXdvJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a55si983192edc.13.2019.11.01.11.18.28; Fri, 01 Nov 2019 11:18:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MEejXdvJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727254AbfKASJd (ORCPT + 99 others); Fri, 1 Nov 2019 14:09:33 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36684 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727205AbfKASJd (ORCPT ); Fri, 1 Nov 2019 14:09:33 -0400 Received: by mail-pg1-f194.google.com with SMTP id j22so6964180pgh.3 for ; Fri, 01 Nov 2019 11:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YeTpB1Wx1lpy3awpQLYzDRRtlZuKfiLn87LhRSvje50=; b=MEejXdvJ/xWDM7BvqOG6PxfoSYB1nWSgMQfn97OEzsbkg/GVwzIsbSUvmV1wsqV0Qs WIvpo+Z97RKj57DiBqRQ9AjJKfgkiH4umbmx1ElHdLveGg2pwZdKIuDU9PLSdWrvuvw4 uyxc+lD9UbDSxHAjICjQ3u49KgPDQQo91XCvY1kEv0uJ/6EYQKUzPEhiDG3iZ3NFM/e2 RL5Lo8JL0VlxAi+HXAiTTYkQVfY5L4ahPLsGyHsPtgF6UZl26yTQ/9RBeQ0XcCFfnWKc LI+sgSsbOjbhVKVez+ayoElCg9uvUjX2lOj4Cu0gDBVl5HuxyEe9HLh+1iDpOFrfB8Q1 PUsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YeTpB1Wx1lpy3awpQLYzDRRtlZuKfiLn87LhRSvje50=; b=YbD+ovKSPrFNa14uCx8CRotR5EoTL82x/zIcPAvYHjznM/6FV/fzHPZPpik0n4QLbF b6G+ok7Yspb9u1hqLYxCqcrurTyvx/JvsgwceYruFjBYO2FltoovVehYRDCcq0em5aRX O713z95RbWK2Ipx2YaHe0DTmxO/hCsbv7szQxAtWYGtk8xzvHCfLPGHi6fJoLwkW+Igr Rrt9iJUFcCd29ROTRVlD3ToKEVqsKv4fWkX5XktWD/E06l2GFT3vpd29MlaF68eKRBy1 UjhwB5Ikz2cWznPOQlhiZ7CnP/XJ3FN1J2/OXLQ7XDHPK6MeJ0ppWLVPlMvqgdVq/dVV 1xbA== X-Gm-Message-State: APjAAAXu0EI79ajrZViDiv1bOqIrmr7ptEqbEvJ6OGjDinTAPWgroGcD 3tIcWpEmB8MY1hEyWv7hIKI= X-Received: by 2002:a63:f919:: with SMTP id h25mr6789478pgi.85.1572631771170; Fri, 01 Nov 2019 11:09:31 -0700 (PDT) Received: from localhost ([100.118.89.209]) by smtp.gmail.com with ESMTPSA id 16sm9364172pgd.0.2019.11.01.11.09.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2019 11:09:30 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: Sean Paul , Maarten Lankhorst , Rob Clark , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/2] drm/atomic: fix self-refresh helpers crtc state dereference Date: Fri, 1 Nov 2019 11:07:12 -0700 Message-Id: <20191101180713.5470-1-robdclark@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rob Clark drm_self_refresh_helper_update_avg_times() was incorrectly accessing the new incoming state after drm_atomic_helper_commit_hw_done(). But this state might have already been superceeded by an !nonblock atomic update resulting in dereferencing an already free'd crtc_state. Fixes: d4da4e33341c ("drm: Measure Self Refresh Entry/Exit times to avoid thrashing") Cc: Sean Paul Signed-off-by: Rob Clark --- TODO I *think* this will more or less do the right thing.. althought I'm not 100% sure if, for example, we enter psr in a nonblock commit, and then leave psr in a !nonblock commit that overtakes the completion of the nonblock commit. Not sure if this sort of scenario can happen in practice. But not crashing is better than crashing, so I guess we should either take this patch or rever the self-refresh helpers until Sean can figure out a better solution. drivers/gpu/drm/drm_atomic_helper.c | 2 ++ drivers/gpu/drm/drm_self_refresh_helper.c | 11 ++++++----- include/drm/drm_atomic.h | 8 ++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index 3ef2ac52ce94..732bd0ce9241 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2240,6 +2240,8 @@ void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *old_state) int i; for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { + old_state->crtcs[i].new_self_refresh_active = new_crtc_state->self_refresh_active; + commit = new_crtc_state->commit; if (!commit) continue; diff --git a/drivers/gpu/drm/drm_self_refresh_helper.c b/drivers/gpu/drm/drm_self_refresh_helper.c index 68f4765a5896..77b9079fa578 100644 --- a/drivers/gpu/drm/drm_self_refresh_helper.c +++ b/drivers/gpu/drm/drm_self_refresh_helper.c @@ -143,19 +143,20 @@ void drm_self_refresh_helper_update_avg_times(struct drm_atomic_state *state, unsigned int commit_time_ms) { struct drm_crtc *crtc; - struct drm_crtc_state *old_crtc_state, *new_crtc_state; + struct drm_crtc_state *old_crtc_state; int i; - for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, - new_crtc_state, i) { + for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) { + bool new_self_refresh_active = + state->crtcs[i].new_self_refresh_active; struct drm_self_refresh_data *sr_data = crtc->self_refresh_data; struct ewma_psr_time *time; if (old_crtc_state->self_refresh_active == - new_crtc_state->self_refresh_active) + new_self_refresh_active) continue; - if (new_crtc_state->self_refresh_active) + if (new_self_refresh_active) time = &sr_data->entry_avg_ms; else time = &sr_data->exit_avg_ms; diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 927e1205d7aa..86baf2b38bb3 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -155,6 +155,14 @@ struct __drm_crtcs_state { struct drm_crtc *ptr; struct drm_crtc_state *state, *old_state, *new_state; + /** + * @new_self_refresh_active: + * + * drm_atomic_helper_commit_hw_done() stashes new_crtc_state->self_refresh_active + * so that it can be accessed late in drm_self_refresh_helper_update_avg_times(). + */ + bool new_self_refresh_active; + /** * @commit: * -- 2.21.0