Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp744800pxp; Fri, 11 Mar 2022 14:01:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzrWeaIHQd5zV5BMUkYQ/0m3g0fF49lPqh2Opx5CntbwdjzWxVI2trYrGIHtJ2yRCNkk5yD X-Received: by 2002:a17:902:d50f:b0:152:249:ea60 with SMTP id b15-20020a170902d50f00b001520249ea60mr13137382plg.120.1647036086357; Fri, 11 Mar 2022 14:01:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647036086; cv=none; d=google.com; s=arc-20160816; b=h5lbNvevLPG+edSeNiXWRXT98QYdE2e+8vdKaUmxtzRhI0GiJ8dwRHRpsOhidxqJlb CvPsqQSGEbzW/0KslV4zi7qVFFy5nSxbq/PSMd2tJeoSsD27ETe7YGIeaAZvpOysCfyJ qdVG5kq1g0hpXZaYkQducOP2h97uJ0bkofByuIeMijF3PGfGrnLb7ejj4Rijl/9DraWO CLqLrmcFNLQtzlkF0gsK1Q9fPofMeyDJSjbIIFJPgWqsw0Dvp5o/fC+zIPtWeEri7TNl P5markt4k6/qM2f+Jq31pvE8UBc11rO1XtYnfU7Umooh40RPnIBl65m4HcCP6Ds0SLAa RmKQ== 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=x8tiHyMO/AOxppFroDhjRJNf2XKELYwtxrXBurogy9gesfxzanRWDFkgOiuSU/Yxb4 gpNfMh8Va9A5xfqiQtf+EXmdQOwnwwUMGv/JTsryV0XWziW8UOb/rPamymC6KM/A4Bg3 e0u6lD5dFJOocgUa0nQPWqeqt0OIWYPBEa2VSKRhWrlDvsHXZ3q2zqnT66n/5YL1Srii ZoHnl8Mv37eTItoBQmzGvUOoLNVF5OZdfh4gl80Jr5OBMmgQydMXVQwax8kzg14rfNoa ZX4WJYM2A0E4XTKtzdbhl12vb0OGf0e5Cpo/uKTIy3qGNbyIRIpI9cfeODvgH7lvc/jv T2lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IOIevA2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k64-20020a638443000000b003805d702f55si8986439pgd.426.2022.03.11.14.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:01:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=IOIevA2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA9A820A976; Fri, 11 Mar 2022 13:18:36 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347559AbiCKJfl (ORCPT + 99 others); Fri, 11 Mar 2022 04:35:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347546AbiCKJfk (ORCPT ); Fri, 11 Mar 2022 04:35:40 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C521BE0E9 for ; Fri, 11 Mar 2022 01:34:37 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: rcn) with ESMTPSA id 43B4C1F4649B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1646991276; bh=PEG3axVN//YyYVluyyyZUdTkTfte6RZExlKRrKGNNGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOIevA2nantASE3yYn/YUjQS5gP8DD6vEldy8ZnQb7KvSWDexaKr23Q1H3WWldHVX ilMRsF/w8dhmsry9dwQLfOy74iekWPbrKv7KmwjLbbymuI2OupBFSkb0a0Yz6wcVYt eJttIa1fKq1b9rKZnUfRuveC31R3UQ4sqv5aNCGlEiO3fcFGAtfhrZJKiLoQ41KAzc BuGtK0m5eqWa4/7L+i4DCr+9g3CzUy7kEfBv/ebnRbUDdEXply9m6eEh/Yo3PKNic4 9wSSwSlwtBBz6x0ComHm5IrbBXghXwrwqHzMnOBxMa+Ep6dqpMnr7Ey5Lh+ediB8wS fxrSGXNY4OdkQ== From: =?UTF-8?q?Ricardo=20Ca=C3=B1uelo?= To: dri-devel@lists.freedesktop.org Cc: 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 RESEND] drm/bridge: parade-ps8640: avoid race condition on driver unbinding Date: Fri, 11 Mar 2022 10:34:05 +0100 Message-Id: <20220311093406.4068019-2-ricardo.canuelo@collabora.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311093406.4068019-1-ricardo.canuelo@collabora.com> References: <20220311093406.4068019-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.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=no 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