Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2718031pxj; Mon, 10 May 2021 09:11:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdXpcUIL3C8v56CCHeo3qem008qKzlb5wmsjiFoRgK7tQoWcqO4tPTD8EOOl4P5mbvhFvm X-Received: by 2002:a92:3307:: with SMTP id a7mr22181172ilf.113.1620663076203; Mon, 10 May 2021 09:11:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620663076; cv=none; d=google.com; s=arc-20160816; b=kVABGtnMBwzE6llJr1pNwrDvOQZ5PoMqLL12X+FcDL2voWxNdhbtGj4m6zPZyl2t1j 9PIcGhP8pYNGGrFwjCexB7Poy6ofeFsg4IH6CmwNlsjPbWfsZQjQV8IeyTNMHCnpa4/I mYlqWsYhAE7Vg+sRX0B9l01VAir4TX9od9r3vv3Xl2Bcz0qrDjPeDKIsI1SC8w4XnUWe b4qE3nP7EIa9+PD6LfuZAVvRuZcIbCPRJYq39+OmUYZQyo0g9O1iAfDQ8K+xRwKSOjXC PJT5fakDxbaRSMGlEiW4Wjr2n9TjySYcWya2q660XSyBXK+vo+/0HyQM9gHMADwew84F 6/ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=6eqFtigL6XPzGHvJOyisC/fKX/gihfHqH7WepbpRLGM=; b=Szjjtslz0xaV/VA9BpKxZyag/QUAPNls1gd7OvlYLnIgW7MBXfo4NGK/4ndB+qJcgQ 8rs8QebNrgtxurlI2kQ43zsEqMdNBoi/fE70yaxjQKp+pVgTm8uG64X10OU7Jn8/oyo3 lwX9luTk/b0QtbmFyyysvPiEln2PxVpy4kw36r27gC7Ny0qR6YmFmkI/Hs8w1JsvUqgB AI9RHQ4HFxHRYVFhKh8x7vp8jgsCzqCU07e85qv6t8KZtMh6s0cy4hvvg01pRwIwfl74 SfvvowArhjJdnTxJXl+bIpfKv7ZhCjxl4jmQmNoqEdKXDSZUFjFgj3scV9n431p7zUHI LRSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=F3TEsHWz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si16522202ilq.155.2021.05.10.09.11.01; Mon, 10 May 2021 09:11:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=F3TEsHWz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231311AbhEJQGh (ORCPT + 99 others); Mon, 10 May 2021 12:06:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230444AbhEJQGb (ORCPT ); Mon, 10 May 2021 12:06:31 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50DC9C061574 for ; Mon, 10 May 2021 09:05:25 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id x5so17177255wrv.13 for ; Mon, 10 May 2021 09:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=6eqFtigL6XPzGHvJOyisC/fKX/gihfHqH7WepbpRLGM=; b=F3TEsHWzvJZFJyaQrrPbpZEVzsQhRp1y6QD4jZXdGpbaDNU5E0thA+IcC5hThHgB5H mRIU7AqDRXc1ic3jAMSuLp+Icr+Z6lC82kVLx7g3bkvOuR3FWTicBn8hdUrtgCwI0dSA Ing8bBWnxGumxPoJBAowFRgULclwwqwt2M9B8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=6eqFtigL6XPzGHvJOyisC/fKX/gihfHqH7WepbpRLGM=; b=bVBzHCTKQAzxpuMrEuGBk4jt8Oode1rKoOM7DMfg3PCmUlmmHRHKn8vZJ1RMutI+Go /khEa8HTiTaV4k31qCKfkXIqtrmdGZmLZldI7xhXKUKmkLWfB9prpGyvjz54QCvCipny TqDrwmlp9c3NCcxblcbHAk6eKg43L1K6kSq0yjX+t5C/qeJhTQPfCpP9sT9NxBRYk0fv cTVfMf1M0VN6yXFsApz3bA+uU3bjjxagCh7A6elrYPgMM2TdI4cpQFR66eBYBDTuo+b2 PJ8aA5W7nkMbVvTVZCEzBq+IJb7I8RPavWKF4FEshecN8qXoolVQo0e+c5KQXqUS+2ht 28xg== X-Gm-Message-State: AOAM533mEi/bYpHNzTEtotVVA/alwIWHn/4oBsMkFZY6r5UCAtYIyuk3 YtRe55SZH26aNy9o8ph2DeEK+g== X-Received: by 2002:adf:df04:: with SMTP id y4mr31401027wrl.358.1620662724075; Mon, 10 May 2021 09:05:24 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id p10sm3981987wmq.14.2021.05.10.09.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 May 2021 09:05:23 -0700 (PDT) Date: Mon, 10 May 2021 18:05:21 +0200 From: Daniel Vetter To: Stephen Boyd Cc: Greg Kroah-Hartman , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Daniel Vetter , Russell King , Rob Clark , dri-devel@lists.freedesktop.org Subject: Re: [PATCH] component: Move host device to end of device lists on binding Message-ID: Mail-Followup-To: Stephen Boyd , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Russell King , Rob Clark , dri-devel@lists.freedesktop.org References: <20210508074118.1621729-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210508074118.1621729-1-swboyd@chromium.org> X-Operating-System: Linux phenom 5.10.32scarlett+ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 08, 2021 at 12:41:18AM -0700, Stephen Boyd wrote: > The device lists are poorly ordered when the component device code is > used. This is because component_master_add_with_match() returns 0 > regardless of component devices calling component_add() first. It can > really only fail if an allocation fails, in which case everything is > going bad and we're out of memory. The host device (called master_dev in > the code), can succeed at probe and be put on the device lists before > any of the component devices are probed and put on the lists. > > Within the component device framework this usually isn't that bad > because the real driver work is done at bind time via > component{,master}_ops::bind(). It becomes a problem when the driver > core, or host driver, wants to operate on the component device outside > of the bind/unbind functions, e.g. via 'remove' or 'shutdown'. The > driver core doesn't understand the relationship between the host device > and the component devices and could possibly try to operate on component > devices when they're already removed from the system or shut down. > > Normally, device links or probe defer would reorder the lists and put > devices that depend on other devices in the lists at the correct > location, but with component devices this doesn't happen because this > information isn't expressed anywhere. Drivers simply succeed at > registering their component or host with the component framework and > wait for their bind() callback to be called once the other components > are ready. We could make various device links between 'master_dev' and > 'component->dev' but it's not necessary. Let's simply move the hosting > device to the end of the device lists when the component device fully > binds. This way we know that all components are present and have probed > properly and now the host device has really probed so it's safe to > assume the host driver ops can operate on any component device. > > This fixes the msm display driver shutdown path when the DSI controller > is connected to a DSI bridge that is controlled via i2c. In this case, > the msm display driver wants to tear down the display pipeline on > shutdown at msm_pdev_shutdown() by calling drm_atomic_helper_shutdown(), > and it can't do that unless the whole display chain is still probed and > active in the system. When a display bridge is on i2c, the i2c device > for the bridge will be created whenever the i2c controller probes, which > could be before or after the msm display driver probes. If the i2c > controller probes after the display driver, then the i2c controller will > be shutdown before the display controller during system wide shutdown > and thus i2c transactions will stop working before the display pipeline > is shut down. This means we'll have the display bridge trying to access > an i2c bus that's shut down because drm_atomic_helper_shutdown() is > trying to disable the bridge after the bridge is off. > > Moving the host device to the end of the lists at bind time moves the > drm_atomic_helper_shutdown() call before the i2c bus is shutdown. > This fixes the immediate problem, but we could improve it a bit by > modeling device links from the component devices to the host device > indicating that they supply something, although it is slightly different > because the consumer doesn't need the suppliers to probe to succeed. > > Cc: "Rafael J. Wysocki" > Cc: Daniel Vetter > Cc: Russell King > Cc: Rob Clark > Cc: > Signed-off-by: Stephen Boyd Entirely aside, but an s/master/aggregate/ or similar over the entire component.c codebase would help a pile in making it easier to understand which part does what. Or at least I'm always terribly confused about which bind binds what and all that, so maybe an additional review whether we have a clear split into aggregate and individual components after that initial fix is needed. On the actual topic: I agree there's a problem here, but I'm honestly not sure how it should be fixed. That's way over my understanding of all the device probe and pm interactions. Of which there are plenty. One question I have: Why is the bridge component driver not correctly ordered wrt the i2c driver it needs? The idea is that the aggregate driver doesn't access any hw itself, but entirely relies on all its components. So as long as all the component drivers are sorted correctly in the device list, things /should/ work. And as soon as we drop out a single component, the aggregate gets unbound (and then does all the drm_atomic_helper_shutdown and all the other drm teardown). So is the bug perhaps that msm does the drm teardown in the wrong callback? -Daniel > --- > drivers/base/component.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/base/component.c b/drivers/base/component.c > index dcfbe7251dc4..de645420bae2 100644 > --- a/drivers/base/component.c > +++ b/drivers/base/component.c > @@ -15,6 +15,8 @@ > #include > #include > > +#include "base.h" > + > /** > * DOC: overview > * > @@ -657,6 +659,14 @@ int component_bind_all(struct device *master_dev, void *data) > c = master->match->compare[i - 1].component; > component_unbind(c, master, data); > } > + } else { > + /* > + * Move to the tail of the list so that master_dev driver ops > + * like 'shutdown' or 'remove' are called before any of the > + * dependencies that the components have are shutdown or > + * removed. > + */ > + device_pm_move_to_tail(master_dev); > } > > return ret; > > base-commit: 9f4ad9e425a1d3b6a34617b8ea226d56a119a717 > -- > https://chromeos.dev > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch