Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp2769577ybi; Mon, 1 Jul 2019 18:47:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWkKmy4gWlUO62nYppELs+00ogLIHo++KxAnlx0pWd8PcsvdsovZTcsle1vetSwK4gvxPp X-Received: by 2002:a17:902:4aa3:: with SMTP id x32mr30814574pld.119.1562032033319; Mon, 01 Jul 2019 18:47:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562032033; cv=none; d=google.com; s=arc-20160816; b=WhXoWHJG14sZYQu1k1c6dllakVIyAPOdGw1GHjRf1BzD8n/2Xd9PicLIpUPcvfTb9R HRe/WUNHZMEloBO4jej3uzF6/B66zOJKMs253zuKLrsasAKUY0YyGdDUdpypXOSigCEi CIMezgNIhs+TfbmRG++qvi0sTNWoCHQ6Y3g7MNDU+qiObqIZ7UkbrvIL52+1sX0rDiFz jh2S0vBxy5LSma0sB2vvkrkSyDZcN29LDeZ0ziX4eUBHdNTCsAOPtyB2M9VwqCVyeser K1kU8lqhlDS4QPma5ybDK/ZEbJmiRKn0JrS4YM1QtscLrjm0cO1GPv34ODUVCYtEQ5PF zvDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=JtH5mLUOt8QCcq/NYSX4Bp2A2bgHotDB8YcnjA6Zl1Y=; b=rvBd/T270McIybzi3O3e+SlRnrtY6T7a+5AKtFvjobit+bYcy4QiJUWhmZVvyLHO7s y1mBbs8tqVsKC3qJuMoEMZVsGJKpvKZ1izW+cTsABIynSK4kkLY2jCyG6D8Z59KLbAMH IbIW0ICIucEtTm0Phcv02Xt9F34yljV719eRL7gORPK93IgQsKsIMqXVj3N8DHdTanyG wA9XfddTEdTDYE15nNxtqNqQQ0mMyZxtfqqo+lyuZ1+LErv469ec2K08k6pk3h2IoS5p YEuDNLASeTJLf7A/m1agKsI3jgXJF5/M2unTp5I8+37G69SW17zz7RnxQveWhpbn7c1T +ZdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tmlLetHX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si11569311pgg.87.2019.07.01.18.46.57; Mon, 01 Jul 2019 18:47:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tmlLetHX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726993AbfGBBqf (ORCPT + 99 others); Mon, 1 Jul 2019 21:46:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:51708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbfGBBqf (ORCPT ); Mon, 1 Jul 2019 21:46:35 -0400 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2567E216C8; Tue, 2 Jul 2019 01:46:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562031994; bh=W6pjPEN1zb8kE6iBBaNfrMROGIiYPyv9aeswfstgqaE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tmlLetHX7qUM5gy9CoM0JFxzX9V5kbOpnU8ganfCcWXei3UDuyOEMfvo1WXx0HyUO kUl5dT7nfBQ/umRpSPvl21AqOoTpbRjtTuiLtwhA7ABlAowOj8QRfBBER6Rb0LpAOt MM39r1+NnnEYoPwz9tB+KcstSgOGq3MAj13gUN8k= Received: by mail-qk1-f169.google.com with SMTP id a27so12708728qkk.5; Mon, 01 Jul 2019 18:46:34 -0700 (PDT) X-Gm-Message-State: APjAAAV4Q49UPHYuvI1nfJJiqVmsOt7kt0IPsSd+cPl/M7RxICeg4HKZ PvMKAIGZ+dr0ywWGi4WRJM0en7fq0rCZz0V4Nw== X-Received: by 2002:a05:620a:1447:: with SMTP id i7mr23718623qkl.254.1562031993399; Mon, 01 Jul 2019 18:46:33 -0700 (PDT) MIME-Version: 1.0 References: <20190702004811.136450-1-saravanak@google.com> <20190702004811.136450-5-saravanak@google.com> In-Reply-To: <20190702004811.136450-5-saravanak@google.com> From: Rob Herring Date: Mon, 1 Jul 2019 19:46:22 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 4/4] driver core: Add edit_links() callback for drivers To: Saravana Kannan Cc: Mark Rutland , Greg Kroah-Hartman , "Rafael J. Wysocki" , Frank Rowand , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" , David Collins , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 1, 2019 at 6:48 PM Saravana Kannan wrote: > > The driver core/bus adding dependencies by default makes sure that > suppliers don't sync the hardware state with software state before all the > consumers have their drivers loaded (if they are modules) and are probed. > > However, when the bus incorrectly adds dependencies that it shouldn't have > added, the devices might never probe. > > For example, if device-C is a consumer of device-S and they have phandles > to each other in DT, the following could happen: > > 1. Device-S get added first. > 2. The bus add_links() callback will (incorrectly) try to link it as > a consumer of device-C. > 3. Since device-C isn't present, device-S will be put in > "waiting-for-supplier" list. > 4. Device-C gets added next. > 5. All devices in "waiting-for-supplier" list are retried for linking. > 6. Device-S gets linked as consumer to Device-C. > 7. The bus add_links() callback will (correctly) try to link it as > a consumer of device-S. > 8. This isn't allowed because it would create a cyclic device links. > > So neither devices will get probed since the supplier is dependent on a > consumer that'll never probe (because it can't get resources from the > supplier). > > Without this patch, things stay in this broken state. However, with this > patch, the execution will continue like this: > > 9. Device-C's driver is loaded. > 10. Device-C's driver removes Device-S as a consumer of Device-C. > 11. Device-C's driver adds Device-C as a consumer of Device-S. > 12. Device-S probes. > 13. Device-S sync_state() isn't called because Device-C hasn't probed yet. > 14. Device-C probes. > 15. Device-S's sync_state() callback is called. We already have some DT unittests around platform devices. It would be nice to extend them to demonstrate this problem. Could be a follow-up patch though. In the case a driver hasn't been updated, couldn't the driver core just remove all the links of C to S and S to C so that progress can be made and we retain the status quo of what we have today? That would lessen the chances of breaking platforms and reduce the immediate need to fix them. Rob