Received: by 10.213.65.68 with SMTP id h4csp2866904imn; Mon, 2 Apr 2018 15:52:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx49AGjOh/yvTn7Lus2KpqNCNBRF/LLu5GNwhfxXLeKV0TKb9rhGUEHfwYiWe90myhaz3MNPl X-Received: by 10.99.164.18 with SMTP id c18mr7410327pgf.85.1522709551116; Mon, 02 Apr 2018 15:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522709551; cv=none; d=google.com; s=arc-20160816; b=sWSoBaHyItI+tYnA1eAUjPAhCVv7sOdFh3S8xsWpFO6SVsj7yky+FBC7t96R696t/j 9SODX/39oq3GboicwRL+9grsYZG+GCtYdPDtWB2AHo3lIAonNFtA1QzVLXr0zPi9JicE r6c72RLw5PpT/NiWkOHJw06Tsk8XcRRlCoaOE3Fmn4cS5U6gLUYExuQXcIEme0kkvHIv Ylc/TruwQ37gBX1DhKXOTxj1tPhnHuRBXvoLtZE2hHULwqWmyGOUPj6uDPPO+hwWP/YA KE0SmZdGB2+LPNVJ1ooxbcNGwGT0p1YpfZOsnJVfCqKn9PwgV+wuTv6mDP3UuWmQAwYV oo7w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=enGMeAnz+jqK2GW5TM/iV4m/t5xohKX7KbACeuhbmAo=; b=m5gsrABT8tWHjST/RODtUYlIHFbI+LHdFy57utV5AsRaCBM5xgSz7nUqeZzOeX7B2O vaJY5ktI8IKst7SoIc/S0ZZAYqAsJCwcpTHGVbJI/DiNGvM113mKBkjcJO7ZIBPw6Ujx PEUBx3yl3CfhaBiUS+5DSSOYs7u0DeOsIxliff/DyA+PjfCi3QycbY88h+YVFS1yq9cl VFdjoLZGR5GhDPiuSnjXfLyEg45Lc0L66+4WbkU34UJWBVY9kr2JoMjv24yu6+0pKqeG bXEdsiVi4md3OqEq5dE2J1tKjDBW6jfg4rGpIVUNoWNUX5QshKr592p/El+6DysiNi9S 32iQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z127si959196pfb.397.2018.04.02.15.52.16; Mon, 02 Apr 2018 15:52:31 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754775AbeDBWtd (ORCPT + 99 others); Mon, 2 Apr 2018 18:49:33 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754702AbeDBWsc (ORCPT ); Mon, 2 Apr 2018 18:48:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3AD54057291; Mon, 2 Apr 2018 22:48:31 +0000 (UTC) Received: from malachite.bss.redhat.com (dhcp-10-20-1-55.bss.redhat.com [10.20.1.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24D96111DCE8; Mon, 2 Apr 2018 22:48:29 +0000 (UTC) From: Lyude Paul To: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Manasi Navare , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , linux-kernel@vger.kernel.org Subject: [PATCH v5 08/10] drm/i915: Make intel_dp_mst_atomic_check() idempotent Date: Mon, 2 Apr 2018 18:47:44 -0400 Message-Id: <20180402224800.16080-9-lyude@redhat.com> In-Reply-To: <20180402224800.16080-1-lyude@redhat.com> References: <20180402224800.16080-1-lyude@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Apr 2018 22:48:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 02 Apr 2018 22:48:31 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lyude@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current way of handling changing VCPI allocations doesn't make a whole ton of sense. Since drm_atomic_helper_check_modeset() can be called multiple times which means that intel_dp_mst_atomic_check() can also be called multiple times. However, since we make the silly mistake of trying to free VCPI slots based off the /new/ atomic state instead of the old atomic state, we'll end up potentially double freeing the vcpi slots for the ports. This also has another unintended consequence that came back up while implementing MST fallback retraining: if a modeset is forced on a connector that's already part of the state, but it's atomic_check() has already been run once and doesn't get run again, we'll end up not freeing the VCPI allocations on the connector at all. The easiest way to solve this is to be clever and, with the exception of connectors that are being disabled and thus will never have compute_config() ran on them, move vcpi freeing out of the atomic check and into compute_config(). Cc: Manasi Navare Cc: Ville Syrjälä Signed-off-by: Lyude Paul --- drivers/gpu/drm/i915/intel_dp_mst.c | 78 +++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_dp_mst.c b/drivers/gpu/drm/i915/intel_dp_mst.c index d3040dd06859..7e97b4ee534e 100644 --- a/drivers/gpu/drm/i915/intel_dp_mst.c +++ b/drivers/gpu/drm/i915/intel_dp_mst.c @@ -30,6 +30,38 @@ #include #include +static int +intel_dp_mst_atomic_release_vcpi_slots(struct drm_atomic_state *state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct drm_crtc_state *new_crtc_state; + struct intel_crtc_state *intel_crtc_state = + to_intel_crtc_state(crtc_state); + struct drm_encoder *encoder; + struct drm_dp_mst_topology_mgr *mgr; + int slots, ret; + + slots = intel_crtc_state->dp_m_n.tu; + if (slots <= 0) + return 0; + + encoder = conn_state->best_encoder; + mgr = &enc_to_mst(encoder)->primary->dp.mst_mgr; + + ret = drm_dp_atomic_release_vcpi_slots(state, mgr, slots); + if (ret) { + DRM_DEBUG_KMS("failed releasing %d vcpi slots:%d\n", + slots, ret); + } else { + new_crtc_state = drm_atomic_get_crtc_state(state, + crtc_state->crtc); + to_intel_crtc_state(new_crtc_state)->dp_m_n.tu = 0; + } + + return ret; +} + static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, struct intel_crtc_state *pipe_config, struct drm_connector_state *conn_state) @@ -41,11 +73,15 @@ static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, struct intel_connector *connector = to_intel_connector(conn_state->connector); struct drm_atomic_state *state = pipe_config->base.state; + struct drm_connector_state *old_conn_state = + drm_atomic_get_old_connector_state(state, &connector->base); + struct drm_crtc *old_crtc; struct intel_dp_mst_topology_state *mst_state; int bpp; int slots; const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; int mst_pbn; + int ret; bool reduce_m_n = drm_dp_has_quirk(&intel_dp->desc, DP_DPCD_QUIRK_LIMITED_M_N); @@ -78,6 +114,17 @@ static bool intel_dp_mst_compute_config(struct intel_encoder *encoder, mst_pbn = drm_dp_calc_pbn_mode(adjusted_mode->crtc_clock, bpp); pipe_config->pbn = mst_pbn; + /* Free any VCPI allocations on this connector from the previous + * state */ + old_crtc = old_conn_state->crtc; + if (old_crtc) { + ret = intel_dp_mst_atomic_release_vcpi_slots( + state, drm_atomic_get_old_crtc_state(state, old_crtc), + old_conn_state); + if (ret) + return ret; + } + slots = drm_dp_atomic_find_vcpi_slots(state, &intel_dp->mst_mgr, connector->port, mst_pbn); if (slots < 0) { @@ -107,31 +154,20 @@ static int intel_dp_mst_atomic_check(struct drm_connector *connector, { struct drm_atomic_state *state = new_conn_state->state; struct drm_connector_state *old_conn_state; - struct drm_crtc *old_crtc; - struct drm_crtc_state *crtc_state; - int slots, ret = 0; + int ret = 0; old_conn_state = drm_atomic_get_old_connector_state(state, connector); - old_crtc = old_conn_state->crtc; - if (!old_crtc) - return ret; - crtc_state = drm_atomic_get_new_crtc_state(state, old_crtc); - slots = to_intel_crtc_state(crtc_state)->dp_m_n.tu; - if (drm_atomic_crtc_needs_modeset(crtc_state) && slots > 0) { - struct drm_dp_mst_topology_mgr *mgr; - struct drm_encoder *old_encoder; - - old_encoder = old_conn_state->best_encoder; - mgr = &enc_to_mst(old_encoder)->primary->dp.mst_mgr; + /* Only free VCPI here if we're not going to be detaching the + * connector's current CRTC, since no config will be computed + */ + if (new_conn_state->crtc || !old_conn_state->crtc) + return ret; - ret = drm_dp_atomic_release_vcpi_slots(state, mgr, slots); - if (ret) - DRM_DEBUG_KMS("failed releasing %d vcpi slots:%d\n", slots, ret); - else - to_intel_crtc_state(crtc_state)->dp_m_n.tu = 0; - } - return ret; + return intel_dp_mst_atomic_release_vcpi_slots( + state, + drm_atomic_get_new_crtc_state(state, old_conn_state->crtc), + old_conn_state); } static void intel_mst_disable_dp(struct intel_encoder *encoder, -- 2.14.3