Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2832879pxb; Mon, 1 Nov 2021 02:47:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwP4oEB8lscKZ+vnvcW8a3RxtEg0WVEHDEf3cUQBubYAwPBECF8z+4s2AY2jiKCRLzuib4o X-Received: by 2002:a05:6e02:1402:: with SMTP id n2mr18727313ilo.160.1635760068433; Mon, 01 Nov 2021 02:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635760068; cv=none; d=google.com; s=arc-20160816; b=T3Om+CEeMQhflPZQ4baOQIsU4MdmayqBFPLybrzRaWBke/ODPT1JiHgR9D8uJfv73w 17steOyEwwO7sZRr0WYA2QIeVQ7Ebg3mCcqh7qxHpCbUbdDzbiBxPh7bA8Ins4cQ+xuj bH+FTdlOAM27DJ6Rp5gEdxY2MiQaH/6IEZ+wxwdI1AZFd9jKZgg3d2zRwQD1bWyvR1w5 A1tdo5CrDmuFPGps+Z0l4fBP5MKa1desxGb1ZsaQrtMOvywMDiRCdKRhZS1WgSZ7Sk28 qzNEQBFE9fE58VdMB0x0FstNXOCfRwNid7IH7RwXGwCfi0SIXNz+ylOBqSDvSw1orHdt lHtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=f/Uf0XoKft+5V9I83Vlsjct1ZFL+Fp9NGN+8qjgDm8Q=; b=rNZTT5+L565I/i2aViVDh6kxzeQgMPIbxKQEqgzHDsblcGCmQ1z/l3+apkdu/dHo5H zDLEnhG2Jh72f18U5ZOfJk1FE+ntUbr9cJNmNt2BclEOu6vG0bsOjea08H9T8CB0Uqtu i1VBpYzvI74++R6JXvOFmLzZIrivVRW0MAmuqZbfLsLVGImOIjpT4+nCYtLHa1OWjkyk Ah6mV0cItoA2LWVb69D6PRLuaCCANR0+SpoGHFVP1OZ91XJTqvUApxaf90NE4zZfHsqy Qe/XKRg5waTWj+k9R1crhidkrUlUvPSUX1F7LWZuvrldXHiJQhXwJUkJT+QdvR7UE7k3 OvAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GQeBW7zc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s15si13461793ild.56.2021.11.01.02.47.37; Mon, 01 Nov 2021 02:47:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GQeBW7zc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234202AbhKAJrp (ORCPT + 99 others); Mon, 1 Nov 2021 05:47:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:47856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233992AbhKAJnp (ORCPT ); Mon, 1 Nov 2021 05:43:45 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BECD4613A3; Mon, 1 Nov 2021 09:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635758938; bh=zDx+N3cq3WeFQo5p1KFkudxQYPfci7eZ44WG7gflmlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GQeBW7zcsrELYPIKrP2IF38lFcDeNMF6+PZEIH7P71KyRuWNRABSl9BATJHMx0/vJ hfeqzjjR8rHWYLXKusTwLVE5pn82BlSuGaK7Vix/Oo2ny+7VLyDgs06yW7Af6OtKNA W4rFsBOIR59Pqq8MWYAF0ck0K32mVD76G9RGJaX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mat Jonczyk , =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= , Jani Nikula , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Imre Deak Subject: [PATCH 5.14 046/125] drm/i915/dp: Skip the HW readout of DPCD on disabled encoders Date: Mon, 1 Nov 2021 10:16:59 +0100 Message-Id: <20211101082541.907535250@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211101082533.618411490@linuxfoundation.org> References: <20211101082533.618411490@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Imre Deak commit 6e6f96630805874fa80b0067e1a57aafc06225f6 upstream. Reading out the DP encoders' DPCD during booting or resume is only required for enabled encoders: such encoders may be modesetted during the initial commit and the link training this involves depends on an initialized DPCD. For DDI encoders reading out the DPCD is skipped, do the same on pre-DDI platforms. Atm, the first DPCD readout without a sink connected - which is a likely scneario if the encoder is disabled - leaves intel_dp->num_common_rates at 0, which resulted in intel_dp_sync_state()->intel_dp_max_common_rate() in a intel_dp->common_rates[-1] access. This by definition results in an undefined behaviour, though to my best knowledge in all HW/compiler configurations it actually results in accessing the array item type value preceding the array. In this case the preceding value happens to be intel_dp->num_common_rates, which is 0, so this issue - by luck - didn't cause a user visible problem. Nevertheless it's still an undefined behaviour and in CONFIG_UBSAN builds leads to a kernel BUG() (which revealed this problem for us), hence CC:stable. A related problem in case the encoder is enabled but the sink is not connected or the DPCD readout fails is fixed by the next patch. v2: Amend the commit message describing the root cause of the CONFIG_UBSAN BUG(). Fixes: a532cde31de3 ("drm/i915/tc: Fix TypeC port init/resume time sanitization") Reported-and-tested-by: Mat Jonczyk Cc: Mat Jonczyk Cc: José Roberto de Souza Cc: Jani Nikula Cc: Ville Syrjälä Cc: Signed-off-by: Imre Deak Reviewed-by: Ville Syrjälä Acked-by: Jani Nikula Link: https://patchwork.freedesktop.org/patch/msgid/20211018094154.1407705-2-imre.deak@intel.com (cherry picked from commit 4ec5ffc341cecbea060739aea1d53398ac2ec3f8) Signed-off-by: Jani Nikula Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/i915/display/intel_dp.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/gpu/drm/i915/display/intel_dp.c +++ b/drivers/gpu/drm/i915/display/intel_dp.c @@ -1924,6 +1924,9 @@ void intel_dp_sync_state(struct intel_en { struct intel_dp *intel_dp = enc_to_intel_dp(encoder); + if (!crtc_state) + return; + /* * Don't clobber DPCD if it's been already read out during output * setup (eDP) or detect.