Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp653120pxm; Fri, 25 Feb 2022 16:18:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+B6U+Msh6eQFBCUu7A37LYdxu5AGCte0NnVbCW4PRExA0ym9NEGl2rmBM+1FiEpFK2yaa X-Received: by 2002:a62:1c47:0:b0:4f1:2735:3219 with SMTP id c68-20020a621c47000000b004f127353219mr10192266pfc.70.1645834711199; Fri, 25 Feb 2022 16:18:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645834711; cv=none; d=google.com; s=arc-20160816; b=pNDUE87JuCPSNxsb8pldYAxYKgKUijJY+ZgfjyHS8D2pjEO1dT0yBXzs80kkYKA15r fcm8zh6U6OKDZa4347SuZC2qY8Fn1eB08DI6ESNT6f0DKA5V3GnJMwOTYdsgEL/qvznw eu5NZHA97BJubvHMrCIY/WmfsvNy6EbC1aTK1IP5RnJaBsBsuHRYnXoFyE0flSARH74k 5DaHHtKKGziL8s1JwnFdd43SJoz47fMkJe6l6yIPNLEry2qUhY3wuHqJNQoFKCkPuSyR Tg2+mjVMnFRLAsL7cd/6/y2FW4npc2mJMXHUJzwiu68GxIJ0WhInDslTb5KgLm1iOmgz L+Xw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5kNnVQFzcrT+0wTaxICO6jsXojOxqo+TGa9iDDHFvj8=; b=yk+ASaIQhSKItbCzUkE4FrfjF5ZENjHLmMJcJrM1Yt6egohjYuf962mkOENHTqEKE6 7ii8FTQ9RiF+kgcf+5NZS8uONZuAcKrvj3VLTwBtJAWhhOrhsQkVg+cgTOjjLHUeOjVQ cFCPiiUkY/bcZSefAipOqzCaN3n6H0/SQvgE2FXo75Siu4qzfrqid9oUkBjRpAqLBEs5 /vHtstbpYXdFMbFhU6shpuPEVxDEPqaPw56CgNHMN0UyY6V4x7AGMiLP6CRceMD7p9yQ Hob3Ruzpu7UD7CFhuyJFE2nB738Zgi9hX3DK6qoEHrYLzbAxmy3e+nw5CbjTOxrtNmSJ iH3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="V/oym2rK"; 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=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t137-20020a63788f000000b003743f1b155csi3033747pgc.653.2022.02.25.16.18.16; Fri, 25 Feb 2022 16:18:31 -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=@collabora.com header.s=mail header.b="V/oym2rK"; 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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241632AbiBYNqP (ORCPT + 99 others); Fri, 25 Feb 2022 08:46:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234303AbiBYNqO (ORCPT ); Fri, 25 Feb 2022 08:46:14 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EB18210D74 for ; Fri, 25 Feb 2022 05:45:42 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: rcn) with ESMTPSA id 7A6AF1F45F92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1645796741; bh=PEG3axVN//YyYVluyyyZUdTkTfte6RZExlKRrKGNNGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/oym2rKqKgD8WS1WPUP98b3I3JMruzcQzkNhu3PgRNVN3ZTTJw+3GtVTL7aQoSOC ptLBuP3f9+pjoz9+9FnrgPRUlPo8VUleDaWCGLiwJzBpw/YoZOPgnqe50SuZ7CI3JM cBm7FrVwATP5cHVP41V99XezDyNEe+JLDXvRQJT3FOB6nF4qJGptcikBkNbiOeKqrq cYst4IN9RE4IHAGzU7XZe4bZk0uzpZw6GGOlQiX6xQ8R2LTgwiYm/vHddpjkOwekzs 5rJVyJdqyqIFY/UJ48Ojz3PCzr+Plzv/pWZts6M45eVOhHQ9qPvjsnEhpEV4N01hB+ hqRo5dsRtjmaQ== From: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= To: dri-devel@lists.freedesktop.org Cc: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= , linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, andrzej.hajda@intel.com, narmstrong@baylibre.com, maarten.lankhorst@linux.intel.com, mripard@kernel.org Subject: [PATCH 1/2] drm/bridge: parade-ps8640: avoid race condition on driver unbinding Date: Fri, 25 Feb 2022 14:45:03 +0100 Message-Id: <20220225134504.457245-2-ricardo.canuelo@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220225134504.457245-1-ricardo.canuelo@collabora.com> References: <20220225134504.457245-1-ricardo.canuelo@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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 When unbinding a DRM master driver there's a race condition that sometimes results in an invalid vm access when userspace (gnome-shell) issues a DRM_IOCTL_MODE_GETCONNECTOR ioctl right after a bridge has been removed from an encoder's bridge chain. This means that once a bridge has been disabled and gone through ps8640_post_disable(), if ps8640_bridge_get_edid() runs afterwards as a result of that ioctl call it will call drm_bridge_chain_pre_enable() and drm_bridge_chain_post_disable() again in a bridge that has been already detached. Setting `ps_bridge->pre_enabled = false` at a later stage of the bringdown path and calling drm_bridge_chain_pre_enable() inside ps8640_bridge_get_edid() only if needed avoid this, although a proper subsystem-wide fix would be the proper solution, since the same type of race conditions might happen somewhere else. Tested on an Acer Chromebook R13 (Elm, MT8173) with Debian Sid. Signed-off-by: Ricardo CaƱuelo --- drivers/gpu/drm/bridge/parade-ps8640.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/parade-ps8640.c b/drivers/gpu/drm/bridge/parade-ps8640.c index 3f17337ee389..a927787a89bf 100644 --- a/drivers/gpu/drm/bridge/parade-ps8640.c +++ b/drivers/gpu/drm/bridge/parade-ps8640.c @@ -434,8 +434,6 @@ static void ps8640_post_disable(struct drm_bridge *bridge) { struct ps8640 *ps_bridge = bridge_to_ps8640(bridge); - ps_bridge->pre_enabled = false; - ps8640_bridge_vdo_control(ps_bridge, DISABLE); pm_runtime_put_sync_suspend(&ps_bridge->page[PAGE0_DP_CNTL]->dev); } @@ -487,6 +485,7 @@ static void ps8640_bridge_detach(struct drm_bridge *bridge) drm_dp_aux_unregister(&ps_bridge->aux); if (ps_bridge->link) device_link_del(ps_bridge->link); + ps_bridge->pre_enabled = false; } static struct edid *ps8640_bridge_get_edid(struct drm_bridge *bridge, @@ -508,7 +507,8 @@ static struct edid *ps8640_bridge_get_edid(struct drm_bridge *bridge, * EDID, for this chip, we need to do a full poweron, otherwise it will * fail. */ - drm_bridge_chain_pre_enable(bridge); + if (poweroff) + drm_bridge_chain_pre_enable(bridge); edid = drm_get_edid(connector, ps_bridge->page[PAGE0_DP_CNTL]->adapter); -- 2.25.1