stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Douglas Anderson <dianders@chromium.org>,
	Kuogee Hsieh <quic_khsieh@quicinc.com>,
	Abhinav Kumar <quic_abhinavk@quicinc.com>,
	Rob Clark <robdclark@chromium.org>,
	Sasha Levin <sashal@kernel.org>,
	robdclark@gmail.com, sean@poorly.run, airlied@linux.ie,
	daniel@ffwll.ch, khsieh@codeaurora.org, swboyd@chromium.org,
	linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	freedreno@lists.freedesktop.org
Subject: [PATCH AUTOSEL 5.15 04/24] drm/msm/dp: Avoid unpowered AUX xfers that caused crashes
Date: Mon,  6 Dec 2021 16:12:09 -0500	[thread overview]
Message-ID: <20211206211230.1660072-4-sashal@kernel.org> (raw)
In-Reply-To: <20211206211230.1660072-1-sashal@kernel.org>

From: Douglas Anderson <dianders@chromium.org>

[ Upstream commit d03fcc1de0863b1188ceb867cfa84a578fdc96bc ]

If you happened to try to access `/dev/drm_dp_aux` devices provided by
the MSM DP AUX driver too early at bootup you could go boom. Let's
avoid that by only allowing AUX transfers when the controller is
powered up.

Specifically the crash that was seen (on Chrome OS 5.4 tree with
relevant backports):
  Kernel panic - not syncing: Asynchronous SError Interrupt
  CPU: 0 PID: 3131 Comm: fwupd Not tainted 5.4.144-16620-g28af11b73efb #1
  Hardware name: Google Lazor (rev3+) with KB Backlight (DT)
  Call trace:
   dump_backtrace+0x0/0x14c
   show_stack+0x20/0x2c
   dump_stack+0xac/0x124
   panic+0x150/0x390
   nmi_panic+0x80/0x94
   arm64_serror_panic+0x78/0x84
   do_serror+0x0/0x118
   do_serror+0xa4/0x118
   el1_error+0xbc/0x160
   dp_catalog_aux_write_data+0x1c/0x3c
   dp_aux_cmd_fifo_tx+0xf0/0x1b0
   dp_aux_transfer+0x1b0/0x2bc
   drm_dp_dpcd_access+0x8c/0x11c
   drm_dp_dpcd_read+0x64/0x10c
   auxdev_read_iter+0xd4/0x1c4

I did a little bit of tracing and found that:
* We register the AUX device very early at bootup.
* Power isn't actually turned on for my system until
  hpd_event_thread() -> dp_display_host_init() -> dp_power_init()
* You can see that dp_power_init() calls dp_aux_init() which is where
  we start allowing AUX channel requests to go through.

In general this patch is a bit of a bandaid but at least it gets us
out of the current state where userspace acting at the wrong time can
fully crash the system.
* I think the more proper fix (which requires quite a bit more
  changes) is to power stuff on while an AUX transfer is
  happening. This is like the solution we did for ti-sn65dsi86. This
  might be required for us to move to populating the panel via the
  DP-AUX bus.
* Another fix considered was to dynamically register / unregister. I
  tried that at <https://crrev.com/c/3169431/3> but it got
  ugly. Currently there's a bug where the pm_runtime() state isn't
  tracked properly and that causes us to just keep registering more
  and more.

Signed-off-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com>
Link: https://lore.kernel.org/r/20211109100403.1.I4e23470d681f7efe37e2e7f1a6466e15e9bb1d72@changeid
Signed-off-by: Rob Clark <robdclark@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/msm/dp/dp_aux.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/msm/dp/dp_aux.c b/drivers/gpu/drm/msm/dp/dp_aux.c
index eb40d8413bca9..6d36f63c33388 100644
--- a/drivers/gpu/drm/msm/dp/dp_aux.c
+++ b/drivers/gpu/drm/msm/dp/dp_aux.c
@@ -33,6 +33,7 @@ struct dp_aux_private {
 	bool read;
 	bool no_send_addr;
 	bool no_send_stop;
+	bool initted;
 	u32 offset;
 	u32 segment;
 
@@ -331,6 +332,10 @@ static ssize_t dp_aux_transfer(struct drm_dp_aux *dp_aux,
 	}
 
 	mutex_lock(&aux->mutex);
+	if (!aux->initted) {
+		ret = -EIO;
+		goto exit;
+	}
 
 	dp_aux_update_offset_and_segment(aux, msg);
 	dp_aux_transfer_helper(aux, msg, true);
@@ -380,6 +385,8 @@ static ssize_t dp_aux_transfer(struct drm_dp_aux *dp_aux,
 	}
 
 	aux->cmd_busy = false;
+
+exit:
 	mutex_unlock(&aux->mutex);
 
 	return ret;
@@ -431,8 +438,13 @@ void dp_aux_init(struct drm_dp_aux *dp_aux)
 
 	aux = container_of(dp_aux, struct dp_aux_private, dp_aux);
 
+	mutex_lock(&aux->mutex);
+
 	dp_catalog_aux_enable(aux->catalog, true);
 	aux->retry_cnt = 0;
+	aux->initted = true;
+
+	mutex_unlock(&aux->mutex);
 }
 
 void dp_aux_deinit(struct drm_dp_aux *dp_aux)
@@ -441,7 +453,12 @@ void dp_aux_deinit(struct drm_dp_aux *dp_aux)
 
 	aux = container_of(dp_aux, struct dp_aux_private, dp_aux);
 
+	mutex_lock(&aux->mutex);
+
+	aux->initted = false;
 	dp_catalog_aux_enable(aux->catalog, false);
+
+	mutex_unlock(&aux->mutex);
 }
 
 int dp_aux_register(struct drm_dp_aux *dp_aux)
-- 
2.33.0


  parent reply	other threads:[~2021-12-06 21:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 21:12 [PATCH AUTOSEL 5.15 01/24] drm/msm: Fix null ptr access msm_ioctl_gem_submit() Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 02/24] drm/msm/a6xx: Fix uinitialized use of gpu_scid Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 03/24] drm/msm/dsi: set default num_data_lanes Sasha Levin
2021-12-06 21:12 ` Sasha Levin [this message]
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 05/24] KVM: arm64: Save PSTATE early on exit Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 06/24] s390/test_unwind: use raw opcode instead of invalid instruction Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 07/24] Revert "tty: serial: fsl_lpuart: drop earlycon entry for i.MX8QXP" Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 08/24] USB: NO_LPM quirk Lenovo Powered USB-C Travel Hub Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 09/24] net/mlx4_en: Update reported link modes for 1/10G Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 10/24] loop: Use pr_warn_once() for loop_control_remove() warning Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 11/24] ALSA: hda: Add Intel DG2 PCI ID and HDMI codec vid Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 12/24] ALSA: hda/hdmi: fix HDA codec entry table order for ADL-P Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 13/24] tools: Fix math.h breakage Sasha Levin
2021-12-06 21:19   ` Matthew Wilcox
2021-12-13 17:10     ` Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 14/24] parisc/agp: Annotate parisc agp init functions with __init Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 15/24] i2c: rk3x: Handle a spurious start completion interrupt flag Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 16/24] net: netlink: af_netlink: Prevent empty skb by adding a check on len Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 17/24] drm/amdgpu: cancel the correct hrtimer on exit Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 18/24] drm/amdgpu: check atomic flag to differeniate with legacy path Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 19/24] drm/amd/display: Fix for the no Audio bug with Tiled Displays Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 20/24] drm/amdkfd: fix double free mem structure Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 21/24] drm/amd/display: add connector type check for CRC source set Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 22/24] drm/amdkfd: process_info lock not needed for svm Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 23/24] tracing: Fix a kmemleak false positive in tracing_map Sasha Levin
2021-12-06 21:12 ` [PATCH AUTOSEL 5.15 24/24] fget: check that the fd still exists after getting a ref to it Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211206211230.1660072-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=khsieh@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_abhinavk@quicinc.com \
    --cc=quic_khsieh@quicinc.com \
    --cc=robdclark@chromium.org \
    --cc=robdclark@gmail.com \
    --cc=sean@poorly.run \
    --cc=stable@vger.kernel.org \
    --cc=swboyd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).