From patchwork Mon Jul 10 08:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 117734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp4886685vqx; Mon, 10 Jul 2023 02:08:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGsnhdypaISBj+G45zgImHIVEIQriYqdLOClofx97FTmmdBwnORLBu8PxzAUlYK6fvrg67 X-Received: by 2002:a05:6a00:21d6:b0:668:7090:bf18 with SMTP id t22-20020a056a0021d600b006687090bf18mr10777446pfj.34.1688980090080; Mon, 10 Jul 2023 02:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688980090; cv=none; d=google.com; s=arc-20160816; b=rr6kCQElf+siOb78TDmJCOPLmYkZUVBvXvFauYf9R4a3psbwPQQ+pqT5ozG0okk5l0 WgEokTpywxA5akH03YehsNLwbtsKFbT3l0IbYmRf47ss39GSBAMMQKA5BnfYqaUxQz/5 81uEYmMTBLJsTB8QGRd7KP50cDhtERw6j9Ruy7yCAYJnyF2coL7XvPPjbVZYJG6QbCNH MyYYO0Ce5a1YBX7w2j3tq4MjgUFw6xHENU2UedfECyfJY2WQebFiHw4Rkru63jB2I0y4 zOTZSjwaS+locCViofSWlaIdLuS2dIKjCdlMam35siwqDbP6/H/TgwH4VYvPs3ksOxOw 2vWA== 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=2OanSTpq1Hu+eB1tq8Ra7sloAy2DlkjuZwNNKykIg+Y=; fh=ma0Ztk4T/emO10l+VIPTJ1uZ8/RHtRLtL5ErsGq2tbA=; b=K3PZ4FyJELza2RmluZRCKW1VzqJqyIl01dyLKD6D7XY41hozTXG46/CbEuX5koZUne 6AnxIMI4jGXLU6wCRUDTfnmgfgV6O7UBfQJP8+bCcKwy5xC2pzU6aC0q0C1HGhFWDkTn lru/1sAkgjTtpVJ1P+wh6aPG8tv0A7aHDa10tzHyrZj0W9BY0ywM37omxLpVd66GSzkX mjJuc8QJxW+dm6vy275dKW0IRGu+slcvb51OlUU/MXRP9rqUeinuNew8zwTVBS2L2OaW 1DgTvhMmrWm37IlmQD4c5RzlOGMJCLmNsFSf2i49yHQfre0oaU5yIxMBOIAswGfgBXcI KZNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=N80NZ44X; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt8-20020a056a00438800b00665dfbf3b17si8523637pfb.264.2023.07.10.02.07.57; Mon, 10 Jul 2023 02:08:10 -0700 (PDT) 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=N80NZ44X; 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 S232190AbjGJI7e (ORCPT + 99 others); Mon, 10 Jul 2023 04:59:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232140AbjGJI7a (ORCPT ); Mon, 10 Jul 2023 04:59:30 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17F83F9 for ; Mon, 10 Jul 2023 01:59:28 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6687096c6ddso2177549b3a.0 for ; Mon, 10 Jul 2023 01:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688979567; x=1691571567; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2OanSTpq1Hu+eB1tq8Ra7sloAy2DlkjuZwNNKykIg+Y=; b=N80NZ44X0t7thJJ0vLDqvr4zKutEVaCwMMFAPELtgteYsbDVFii3DI0Cx8z9T7Aacg +qdAnK579GkxHladVU00spflDJwR44Mdob9ep2ghfszyHQrUZiZzbDd+9J5A7fvaDZN9 LIoqCRPzLjQw0Avyf6rcTyZs01pPkLs9Os4Jc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688979567; x=1691571567; 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=2OanSTpq1Hu+eB1tq8Ra7sloAy2DlkjuZwNNKykIg+Y=; b=ewKJnoq1vUiZ0lz3oriBEOoWXMLCK916tpk0xdeFWf1zSbLyFWCrlR+tfc+y5IXCaC PqP+zb/TJ14lOGRwTiqp0OttCdG1C0S4ocpnfIv6GrF6mR1P/q2qCRXUqAgqr8ATg1RO GM1KaxzHJDe82cuu5/Wn4AdxFCSslXnWBkg6xN0PN0Fs7Gl089Z7lGf8q5PG/ITL+YMn WvesPhO5ELA162L7toASc0eU55VrxVo8/IdbSDAdZFEbhgZVOe8U+SNXzbqVRlYXe4mI BOHLbF5envVKwPN6L8FlooCfn8zxDSqvTENgk6u0LROOWVynvpbpc1ETcmbiaH3mpmt+ jYjw== X-Gm-Message-State: ABy/qLYly8DcCcNXQMLh3SShwQr/q5Moz0gCSGrcp4VTpFn5xf+X8R+0 Gi9pdXFqaTydO/ZsEsiaEmO1PQ== X-Received: by 2002:a05:6a20:a11f:b0:12c:dac0:a9a4 with SMTP id q31-20020a056a20a11f00b0012cdac0a9a4mr11924214pzk.5.1688979567468; Mon, 10 Jul 2023 01:59:27 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:be97:1d05:f9b6:36a6]) by smtp.gmail.com with ESMTPSA id o7-20020a170902778700b001b8b3108292sm7750701pll.12.2023.07.10.01.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 01:59:27 -0700 (PDT) From: Chen-Yu Tsai To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Xin Ji , =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= , AngeloGioacchino Del Regno Cc: Chen-Yu Tsai , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/bridge: anx7625: Drop device lock before drm_helper_hpd_irq_event() Date: Mon, 10 Jul 2023 16:59:21 +0800 Message-ID: <20230710085922.1871465-1-wenst@chromium.org> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771023987227797513 X-GMAIL-MSGID: 1771023987227797513 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(). Dropping the lock completely also causes the internal display of the same device to not function correctly if the internal bridge's interrupt line is added in the device tree. 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 Reviewed-by: Robert Foss --- Changes since v1: - restore early return if event < 0 drivers/gpu/drm/bridge/analogix/anx7625.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 866d018f4bb1..e93eba89d5ee 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -1593,18 +1593,20 @@ 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); + + mutex_unlock(&ctx->lock); + if (event < 0) - goto unlock; + return; 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)