Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2834691rwb; Sun, 15 Jan 2023 23:28:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3mw84Q7dwCkq1q97gF+rz54Dz4AVyGkLlSslRqRjjG9bYmiGfez9a5fUCVFNbeSIyZYWZ X-Received: by 2002:a05:6402:b9d:b0:49b:58ca:ebb9 with SMTP id cf29-20020a0564020b9d00b0049b58caebb9mr12677647edb.34.1673854120675; Sun, 15 Jan 2023 23:28:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673854120; cv=none; d=google.com; s=arc-20160816; b=rLzzB9IZpOrJ4gnaYYZcZ7tkx9q5Q3S6BEfYzln6Ma0oT82fTriJNT+GIjnLsmaSIX 86ox5S+UxREGkR0d4pZ7waMn6QQtN6APet24G+qSxBb7U+2ndNHHVNURzvDPq8YR5l1q GJpQjeDmN1dQw4lAJRZC5qDXwsMQ7Ych9N9CM7p6luNgxlSCWEiUOkdiGu/AMl7r0JOG kwi6K1PYaMEw3lXCZ6NTZXHefWpW/FZIWaVS6G6SHNiMwBrwGvLtp4wP6jbkAm2KipXG BIzZ9CuQNmJ5QB1Iz81kFGhJNANZ3IEqrsfLhjB2tiY4FWs7XgTXwTu/F1K9iSgA5UOM +RHw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=tZlwyHU0q6JC27YvA9BdhJPum2JD/n8URNFA6KT24h8=; b=YvRXd8Itc8YxKgHMuA0JLTWC0mQxyFm9k4V0Pps28KRz8vV/HcLF6eXDorVdOpG1nS 6GdvpuvGTgan0DUZYpUKVSxmCpOKwSMnUR/JWhF6QTPyY+vYdk6V97p5XEQqPvIbz3qc AU55VyuwMCPbKikR9yAfqJH3kEcmUdV4H/Kz+SP7VQdqHA7uUdQODuCHb1K+Wjg2BzTL GTfsr4GaLdfNtQzCA6EBzbWuIT3+RFyzJfjRQ0rwasyVNZXjZlOs9SUlGSZhkheZbQl2 MSKTXwie1+bVIyCaMbcSrqntgfOpKAhICOXdGam7SNx1CCfTSobcuXX6wLQ92kkkeER/ a88g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kMmQfKb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b19-20020aa7cd13000000b0049bb59bd0c3si9740477edw.51.2023.01.15.23.28.27; Sun, 15 Jan 2023 23:28:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kMmQfKb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231972AbjAPHWz (ORCPT + 53 others); Mon, 16 Jan 2023 02:22:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231897AbjAPHWm (ORCPT ); Mon, 16 Jan 2023 02:22:42 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B096ACDCA for ; Sun, 15 Jan 2023 23:22:40 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id v23so28238381pju.3 for ; Sun, 15 Jan 2023 23:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tZlwyHU0q6JC27YvA9BdhJPum2JD/n8URNFA6KT24h8=; b=kMmQfKb+r0zYkzjchG3CDWSWiBDiHYXVp0qckSFSQ3tkW1Zdr/t0ip0Ka1dbJpkV86 uOsS29nMm4DhliSASwTKPhH6Yi1alB2pWZpgKE041O4xGqgN6r9EVElvOFjvAWCrEp1n OYc7pkUNobj334k8wQCWQVbXkzt4e+6zP05dw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tZlwyHU0q6JC27YvA9BdhJPum2JD/n8URNFA6KT24h8=; b=3wc9mM25arWCXWJ0zc+hueaGkphPeZy6OSb+KmdchQmR93RetmTmzGTP4VQu+mHYyB BR7TMPQlcsmJZsi+OcETU5hcEdT/qJi2mc2BZCYBPFiJX6IJjLBf/xEmPsS7vkUwfkDF PPp9dwLlY76j3rVmoh89bqIZd9IK2EYcgCWQCH5uGmzMiGpivfcK63yTKQgvny4yZ8t/ syZ3d5jZVT2WPgXkc4DmayS/u+7svS5yOdE+2GY38KmCMU/3clULPEu7tMOrvhyK4ST7 0E+8Cer2pMZU2au7Clfe6CNTe8jiwLHXTvQAdL2jDJyv3jMQfQRx1vwivw+rYQxm1Yn6 5Gnw== X-Gm-Message-State: AFqh2kqmLds1EaJf24o/CZWgtgzrp1O77/kctjCLxHtAbzmdzx1of1w6 3JmvFRCci9Jbg/2vxA3pGaVmOw== X-Received: by 2002:a17:902:834c:b0:194:4ad0:88d6 with SMTP id z12-20020a170902834c00b001944ad088d6mr19415846pln.29.1673853760054; Sun, 15 Jan 2023 23:22:40 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:1d4f:b969:9e53:5eb0]) by smtp.gmail.com with ESMTPSA id i12-20020a1709026acc00b00189d4c666c8sm3328206plt.153.2023.01.15.23.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Jan 2023 23:22:39 -0800 (PST) From: Chen-Yu Tsai To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Cc: Chen-Yu Tsai , Xin Ji , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/bridge: anx7625: Drop device lock before drm_helper_hpd_irq_event() Date: Mon, 16 Jan 2023 15:22:34 +0800 Message-Id: <20230116072234.3970768-1-wenst@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The device lock is used to serialize the low level power sequencing operations. Since drm_helper_hpd_irq_event() could end up calling .atomic_enable, which also calls power sequencing functions through runtime PM, this results in a real deadlock. This was observed on an MT8192-based Chromebook's external display (with appropriate patches [1] and DT changes applied). Move the drm_helper_hpd_irq_event() call outside of the lock range. The lock only needs to be held so that the device status can be read back. This is the bare minimum change to avoid the deadlock. The lock could be dropped completely and have pm_runtime_get_if_in_use() increase the reference count, but this is not the same as pm_runtime_suspended(). This also causes the internal display of the same device to not function correctly. Both the internal and external display of said device each use one anx7625 bridge. [1] https://lore.kernel.org/dri-devel/20230112042104.4107253-1-treapking@chromium.org/ Fixes: 60487584a79a ("drm/bridge: anx7625: refactor power control to use runtime PM framework") Signed-off-by: Chen-Yu Tsai --- FWIW I'm aware that this driver could be refactored a lot better. The work function might be simplified and merged into the threaded interrupt handler. The .detect op should be reading the HPD state from the hardware, not some cached state. drivers/gpu/drm/bridge/analogix/anx7625.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 7e1fb93a6ce4..bf1770b79bba 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -1597,18 +1597,17 @@ static void anx7625_work_func(struct work_struct *work) mutex_lock(&ctx->lock); - if (pm_runtime_suspended(&ctx->client->dev)) - goto unlock; + if (pm_runtime_suspended(&ctx->client->dev)) { + mutex_unlock(&ctx->lock); + return; + } event = anx7625_hpd_change_detect(ctx); - if (event < 0) - goto unlock; + + mutex_unlock(&ctx->lock); if (ctx->bridge_attached) drm_helper_hpd_irq_event(ctx->bridge.dev); - -unlock: - mutex_unlock(&ctx->lock); } static irqreturn_t anx7625_intr_hpd_isr(int irq, void *data) -- 2.39.0.314.g84b9a713c41-goog