Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp264489pxb; Wed, 15 Sep 2021 01:14:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYo9/mGxrn9JGpuQDPoTn+tnzCF+krO6Oy3yvDKzE38TGusZSNTGMvEuJ8eWo7nAVmE+ym X-Received: by 2002:a05:6512:468:: with SMTP id x8mr16846035lfd.369.1631693651528; Wed, 15 Sep 2021 01:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631693651; cv=none; d=google.com; s=arc-20160816; b=gQNVxqeKEW7fDPu+yB6AToZiP1S3yGGtPNrj5iTWNZDbcEYzJTH5xF7TjqeDiCnWi6 mUz5GNWaXCJnI3kkwqzMweuyloQ8YS32W91efkxjoVkTHGYpgMkEl9n/Ero6+MHz8kQk NnrFSz++VmFiv3ctGXw+JoTm2KxNNO3QvbNMf/9K8TWonFarjb+k9CR0o5c/0LW79YD6 EIkEmdAE3yOqaMEUPpGsu5zZ1WNRTZyt8aCG0P6WybXdDwRziz9a+xeVqN+1kr4Stmgw E71lxJDzDDIW9msH381gL+CsG+SmbJoS+1WkgHh9ka8QzNrCXMEEzfal4lq69wY2/RgH 2QNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=WuAb6MBtSzivvvxQ/9C3pYrE2NS/OY1FoVAPECcMVH8=; b=wNvC0qXgAa121yavSPlBZ0BPTPQOs3ta0L0xBQOuo0/4m2z0Kqckvi+gNuCNYTECv9 tErEoHW8/DOze3fQd7304hnHi9BVq5OuUoGlP/5u/QLW7WiztUQ3pEwgJg0vuvi2iY3Q WLMYHOokt0qsTig9d3HMPqldr2U6nGzwBJ0f0yzFw/oBEax3FzEqbBMmPkr42OyDliit SqeVTurgWwOYAN+1twyuskgoSi6oy6N9kURdb2R8RwcyD6VNdMKRE80wZKvP8W7v7eI7 oXr26LDHu+pBzQDLfaGvh/hPFrYSRGxqeg/eoDQ68cDuoCdkvkzC+wTsWQlwel6a7UZl u2Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=K9Yt53VW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a17si15999370ljd.348.2021.09.15.01.13.44; Wed, 15 Sep 2021 01:14:11 -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=@google.com header.s=20210112 header.b=K9Yt53VW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236986AbhIOINZ (ORCPT + 99 others); Wed, 15 Sep 2021 04:13:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236882AbhIOINM (ORCPT ); Wed, 15 Sep 2021 04:13:12 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D42C0613EE for ; Wed, 15 Sep 2021 01:11:46 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 83-20020a251956000000b0059948f541cbso2628343ybz.7 for ; Wed, 15 Sep 2021 01:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WuAb6MBtSzivvvxQ/9C3pYrE2NS/OY1FoVAPECcMVH8=; b=K9Yt53VW22oqgQL+/rMGeYCH6nAlDx+0sOi3uZ6egzz66Ue1dohvyJJVcpfqKb9MYT juYS7Kyo38+lI7/M1iZ0Z4LP1zO/geJkWdmbjD+VW46+r72EWzdWXBBjv6lwUPpwVOLJ RKWsGAW/YqC9HI2ozQ1evL2equN9q9opQg87fjJ1w12AJHd3SeeNoSWY3xTcAF3iCPc3 7dMTUMxxWAs0XGTMOqf7mzVoy4VO8rAgkUmbhH7W4fbEoBAz+uanJZUcidlE8FgcVkQh F1Ce0/hd6ycGUBSU+woVOxO9EyU6qcaYuMYcMbN0CeJ4TKjsBOuHQ6WAbs15fhFdbdLx phAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WuAb6MBtSzivvvxQ/9C3pYrE2NS/OY1FoVAPECcMVH8=; b=VpH1sfrSC7vYxdfjfWglZnS66AkD0ziHt2H7M7lzQ025JT8oBDmt5btDEFpAj4xvXC SI2fjLDvg9QlUL5y2xBOyjH2wLFHbEYuTB+hjmk2uD1C9yA96iuaDbdN2ENONTvhQaN9 X+bvcbAk52Rwy4apFoU5XAU2dhiJSn9XLuDNqBqlxtTQBRYTVn9MQiJavrav2UfVAr5s WRc2rBs5zPRh7hDovGTK9lmOeOdqQl4YS3Ce6imJFY+VyfvOYJrchbMXpKyj/KgBkt5m kPkm7niGaeVncR3aTtNUrCezRRfl6u6GccP1AtX3w88uO1CMwr/5pNdtsZFoqyaHFpsE 1eBg== X-Gm-Message-State: AOAM531qm0qVZD8maulWPz4WUK0YxlUCT/GYuXvlxzzsmHBXaYtfPsQh drb4o+1E60om9G5nQpQxo2AOdQiCWuvYMcw= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:16d1:ab0e:fc4a:b9b1]) (user=saravanak job=sendgmr) by 2002:a25:1b89:: with SMTP id b131mr4526177ybb.40.1631693506005; Wed, 15 Sep 2021 01:11:46 -0700 (PDT) Date: Wed, 15 Sep 2021 01:11:33 -0700 In-Reply-To: <20210915081139.480263-1-saravanak@google.com> Message-Id: <20210915081139.480263-2-saravanak@google.com> Mime-Version: 1.0 References: <20210915081139.480263-1-saravanak@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v2 1/6] driver core: fw_devlink: Improve handling of cyclic dependencies From: Saravana Kannan To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Jakub Kicinski , Len Brown , Saravana Kannan Cc: John Stultz , Marek Szyprowski , Rob Herring , Geert Uytterhoeven , Vladimir Oltean , kernel-team@android.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we have a dependency of the form: Device-A -> Device-C Device-B Device-C -> Device-B Where, * Indentation denotes "child of" parent in previous line. * X -> Y denotes X is consumer of Y based on firmware (Eg: DT). We have cyclic dependency: device-A -> device-C -> device-B -> device-A fw_devlink current treats device-C -> device-B dependency as an invalid dependency and doesn't enforce it but leaves the rest of the dependencies as is. While the current behavior is necessary, it is not sufficient if the false dependency in this example is actually device-A -> device-C. When this is the case, device-C will correctly probe defer waiting for device-B to be added, but device-A will be incorrectly probe deferred by fw_devlink waiting on device-C to probe successfully. Due to this, none of the devices in the cycle will end up probing. To fix this, we need to go relax all the dependencies in the cycle like we already do in the other instances where fw_devlink detects cycles. A real world example of this was reported[1] and analyzed[2]. [1] - https://lore.kernel.org/lkml/0a2c4106-7f48-2bb5-048e-8c001a7c3fda@samsung.com/ [2] - https://lore.kernel.org/lkml/CAGETcx8peaew90SWiux=TyvuGgvTQOmO4BFALz7aj0Za5QdNFQ@mail.gmail.com/ Fixes: f9aa460672c9 ("driver core: Refactor fw_devlink feature") Reported-by: Marek Szyprowski Signed-off-by: Saravana Kannan --- drivers/base/core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index e65dd803a453..316df6027093 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1772,14 +1772,21 @@ static int fw_devlink_create_devlink(struct device *con, * be broken by applying logic. Check for these types of cycles and * break them so that devices in the cycle probe properly. * - * If the supplier's parent is dependent on the consumer, then - * the consumer-supplier dependency is a false dependency. So, - * treat it as an invalid link. + * If the supplier's parent is dependent on the consumer, then the + * consumer and supplier have a cyclic dependency. Since fw_devlink + * can't tell which of the inferred dependencies are incorrect, don't + * enforce probe ordering between any of the devices in this cyclic + * dependency. Do this by relaxing all the fw_devlink device links in + * this cycle and by treating the fwnode link between the consumer and + * the supplier as an invalid dependency. */ sup_dev = fwnode_get_next_parent_dev(sup_handle); if (sup_dev && device_is_dependent(con, sup_dev)) { - dev_dbg(con, "Not linking to %pfwP - False link\n", - sup_handle); + dev_info(con, "Fixing up cyclic dependency with %pfwP (%s)\n", + sup_handle, dev_name(sup_dev)); + device_links_write_lock(); + fw_devlink_relax_cycle(con, sup_dev); + device_links_write_unlock(); ret = -EINVAL; } else { /* -- 2.33.0.309.g3052b89438-goog