Received: by 2002:ab2:7988:0:b0:1f4:b336:87c4 with SMTP id g8csp101991lqj; Thu, 11 Apr 2024 11:00:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVRFq/PnY/MAMSKKxTvwkanFuACLYpEbrON7KDw3SeF52Q8v1bQaTLzgG6AGoPopKRXFIqK4w5UmNGcWMh8MxMF63oJblz4BXSQd1eF3Q== X-Google-Smtp-Source: AGHT+IHs10w7bdxS3QbKL17T++je3Ka27Addobit7cd3agB3aCQIjdii+4iw28J3hut0dbHe8ufW X-Received: by 2002:a05:620a:1720:b0:78d:70d8:5e2f with SMTP id az32-20020a05620a172000b0078d70d85e2fmr537160qkb.7.1712858446329; Thu, 11 Apr 2024 11:00:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712858446; cv=pass; d=google.com; s=arc-20160816; b=W2bbp27SEvHEDDrFhPdH8EIlfUaT9Mcx/JYR/AM8rRD43a9niOUfhIdWNYa60ZzvO7 kBzA63jgVEcIArA57OYoTnI2cmPJtMogvHrGIgBpqM+Xs7GcaTRviqGI2E3svHMJPC+x YPvXnWvyKS8oTq+MnX0uXmo6rBSavB681Z+nmNp0MnNx95jVjL+kb97NX3Qjn81sOYtk YDdhdE0pCYlf53SSJWHPx5Ywrk3s/IRNg0Fy5jVSHRZbBVvs3zZDomHyigNvwCdQTPxw L0ZyS2F2R1+X95YSJosxK7Gi+4U+bcSp008Lbx7tRgIQTGY9/caXUmf0c37+UXH/C/kE /FEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=KGS9UFJvB6INMsQL2N/uv5nxLkUjHaniFpZl0Oeq4Eg=; fh=KLPt0mIFgjtq69d/twJqF45A0tm9w0s9qEjGyRz6ZBo=; b=ddVmYX6SwrahSlsV/dQdLoYJRJWz6KZFyM9whTIu5dSSb2rU6cOw170Tyhf/Owmt4E 7xsZDa8vhTWTtfINfyu7snFINS4PG8ey09XYLPxTuJJMWFNJlaNRlfjtYduQuZDMkk4B 6YBMOEC1G6p9BW8ezZmitRhvfv6Hb3/uBfSCaxorzxl3tIW1wUsM00owQe3KDc2OR1Ia j6JVinHJo/ehuJWEmdrnUsniKiCk3IhKGVubxe86RilxeoeenM/BlAfNbRJ+RroBKjZU LJ4RNwYfKSuLti65tTiDdavIzXlhQaPR7JXvyuDjCuGSTERjm6UO0hspaqsaN6+dcLb2 wlCw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=grh4jBWY; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-141348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 10-20020a05620a040a00b0078d6b285d16si1960793qkp.170.2024.04.11.11.00.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 11:00:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=grh4jBWY; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-141348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 12AE21C23C00 for ; Thu, 11 Apr 2024 18:00:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B94F47A55; Thu, 11 Apr 2024 16:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="grh4jBWY" Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68F721755A; Thu, 11 Apr 2024 16:45:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712853959; cv=none; b=oQCcx/T7kRR0SaQ/j8bv22No8IHhqI+Vk1wa2eWCi7xnCl+fL5IS/+Kjn5pUSIq8VuffUqi52EezJm1994GeUcqKLvj1r3w0Z8vC++KErflAxfCLSUPNFWyzjEi0kbmO7w+WusIOlFCNnWcXS7EjtGq2IkEl+kiAcGwd277pBMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712853959; c=relaxed/simple; bh=kiPDqDvi+Ykrw3Tnxv4YKrQ7z/MDfq4V9qYasuo2lg8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bIYudv6QbE4z4UJkE54Yp7HK3iOYG2Br6MzSNiT5rK7lr/75m4rOCI7/yQVxUA/bdb1aSk9QNpDuOHyYg1H+pRwLQtp4Be2Slwnq6QFSVOtH7e4xl+c26v2NpIFShPulfNIhV07nXw468Iw5Cfa3feSiKmQezV/8GzIBbRn1HHU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=grh4jBWY; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 4D162E0002; Thu, 11 Apr 2024 16:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1712853955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KGS9UFJvB6INMsQL2N/uv5nxLkUjHaniFpZl0Oeq4Eg=; b=grh4jBWYb7zuVyICONUx6Ou1qN3vXf1keaNOV+2neFaVc/J4oL0qXYTTMCHzAiNIQH6rDK 2iRPdGZz7JPUS0LpVUL/5b6oX+CMxhGTUXY6OWvMJDAfjD9GgDa1gtR6S6CHNaaCvRPo9C KIa0hwHlA61Pz/U59Uf8e/qwUN0R/tDTLA3qohCtmV4BfY9a5OCtRYylsCzUF9o5GhWE6t qoNuY8wbX8IL4Ca+8o329xSzpzfDGGZ8jQCr3tH5FduUOX8LJqUO/vMlPUqZUcgKD6ZzBZ eyvayM21UlOTjwoI0uU1iWfsPvQRBXr8dtuTT61BOV9HY39X8elMPLFBRIK1/g== Date: Thu, 11 Apr 2024 18:45:51 +0200 From: Luca Ceresoli To: Maxime Ripard Cc: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Maarten Lankhorst , Thomas Zimmermann , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Paul Kocialkowski , =?UTF-8?Q?He?= =?UTF-8?Q?rv=C3=A9?= Codina , Thomas Petazzoni , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Kocialkowski Subject: Re: [PATCH 4/4] drm/bridge: hotplug-bridge: add driver to support hot-pluggable DSI bridges Message-ID: <20240411184551.317184ba@booty> In-Reply-To: <20240327170849.0c14728d@booty> References: <20240326-hotplug-drm-bridge-v1-0-4b51b5eb75d5@bootlin.com> <20240326-hotplug-drm-bridge-v1-4-4b51b5eb75d5@bootlin.com> <20240327-radiant-cherry-myna-25afc4@houat> <20240327170849.0c14728d@booty> Organization: Bootlin X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-GND-Sasl: luca.ceresoli@bootlin.com Hi Maxime, On Wed, 27 Mar 2024 17:08:49 +0100 Luca Ceresoli wrote: [...] > > There's several additional hurdles there: > > > > - You mentioned the connector in your ideal scenario. But as soon as > > you remove the last bridge, the connector will probably go away too. > > There's two scenarii here then: > > > > - The driver is ok, and it will stay there until the last user its to > > the main DRM device. Which means that if you create a new one, > > you'll have the old one and the new one together, but you can't > > tell which one you're supposed to use. > > > > - If the driver isn't ok, the connector will be freed immediately. > > There's plenty of lingering pointers in the framework, and > > especially the states though, leading to use-after-free errors. > > > > - So far, we told everyone that the graphics pipeline wasn't going to > > change. How do you expect applications to deal with a connector going > > away without any regression? I guess the natural thing here would be > > to emit a uevent just like we do when the connection status change, > > but the thing is: we're doing that for the connector, and the > > connector is gone. > > Thanks for your feedback. I probably should have discussed this aspect > in my cover letter, sorry about that, let me amend now. > > I think there are two possible approaches. > > The first approach is based on removing the drm_connector. My laptop > uses the i915 driver, and I have observed that attaching/removing a > USB-C dock with an HDMI connector connected to a monitor, a new > drm_connector appears/disappears for the card. User space gets notified > and the external monitor is enabled/disabled, just the way a desktop > user would expect, so this is possible. I had a look at the driver but > how this magic happens was not clear to me honestly. > > The second approach is simpler and based on keeping the drm_connector > always instantiated, and it is what this driver does. The drm_connector > is added by the hotplug-bridge driver in the drm_bridge_funcs.attach op, > which happens initially, and only removed by drm_bridge_funcs.detach, > so it is never removed when detaching the _following_ part of the > pipeline (which the card is unaware of). So the encoder always has a > drm_connector. > > Note when attaching to the downstream bridge we pass the > DRM_BRIDGE_ATTACH_NO_CONNECTOR flag, which _should_ prevent creation of a > second connector. I'd expect some drivers to not honour that flag, but > they can be fixed if needed. > > When the tail of the pipeline is connected/removed, the > hpb->next_bridge pointer becomes valid/NULL. And > hotplug_bridge_detect() looks at exactly that pointer to return a > connected or disconnected status. > > The result is that when the add-on is connected, 'modetest -c' shows: > > Connectors: > id encoder status name size (mm) modes encoders > 37 0 connected DSI-1 293x165 1 36 > modes: > index name refresh (Hz) hdisp hss hse htot vdisp vss vse vtot > #0 1920x1080 60.00 1920 1978 2020 2108 1080 1088 1102 1116 141140 flags: ; type: preferred, driver > props: > ... > > and when it is disconnected, it shows: > > Connectors: > id encoder status name size (mm) modes encoders > 37 0 disconnected DSI-1 0x0 0 36 > props: > ... > > weston detects the HPD events from the connector and starts/stops using > the removable display correctly. > > Does this clarify the approach? > > I could be missing some aspects of course, especially in case of more > complex hardware setups than the one I have. However the code in this > series has been tested for a long time and no memory-safety issue has > appeared. > > > Between the userspace expectations and the memory-safety issue plaguing > > way too many drivers, I'm not sure this approach can work. > > > > I guess one way to somewhat achieve what you're trying to do would be to > > introduce the connection status at the bridge level, reflect the > > aggregate connection status of all bridges on the connector, and make > > each bridge driver probe its device in the connect hook through DCS or > > I2C. > > I think you mean: keeping all the bridge drivers instantiated, even > when the physical chip is removed. > > This is of course another possible approach. However it would be more > invasive, forcing bridge drivers to change their current behaviour. And > it would violate the design that a driver is probed when a device is > there, and removed when the hardware goes away. > > The approach I took firstly allows to have zero modifications to > existing bridge drivers -- not necessarily the right thing to do, but I > didn't find any good reason to require that. > > Additionally, it is designed to allow removing an add-on having bridge > XYZ and then plugging in another add-on with bridge ABC, having a > different driver. Keeping alive the XYZ driver on unplug would not make > sense in such a case. This is not a tested scenario as I have no > hardware allowing that, but it is part of the design goals and I see no > obvious reason it wouldn't work with this patch as is, since the > downstream bridge driver is removed on disconnect and probed on connect > for whatever bridge will be connected. Did you have a chance to think about this? I was wondering whether my comments addresses some of your concerns, and whether these additional clarifications make my approach look reasonable to you. Best regards, Luca -- Luca Ceresoli, Bootlin Embedded Linux and Kernel engineering https://bootlin.com