From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D05BC433FE for ; Wed, 15 Sep 2021 17:09:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4343960E90 for ; Wed, 15 Sep 2021 17:09:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230226AbhIORLL (ORCPT ); Wed, 15 Sep 2021 13:11:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbhIORLI (ORCPT ); Wed, 15 Sep 2021 13:11:08 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C790EC061575 for ; Wed, 15 Sep 2021 10:09:49 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id a15-20020a0ce34f000000b0037a944f655dso6258793qvm.5 for ; Wed, 15 Sep 2021 10:09:49 -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=SK0Awx6gBdtKUkOkh7F3holwbySWbAOSfl3fXGrSMFk=; b=j/6JMqqVwtPJr2PuYNwQ9wHyUtwghqpcHDRgXk+GpqAzIOKLLlEezdzFBuFFcvA3bk lFWUqD4frWgBGCCe5sqKyNW9RTDZkP5GBw+rmHvsu78Kqu3BZ9BFR6OLgKh0+OdBAZ77 LMXJdaaUkF5RaBueu/TL8CHaIDou4p6a4kLpK87FJW3yiy5bAuZylth0AtGOwEDzBt/0 RsnqKLvC7W7ZiPQ+7OPB8fpQxfbzYXS34akl0jznUoy+gFauKX3DjrXQQAYh5A7nD39E 0xtxj7UWDMDfs9lkdv7KBSW1SMh1Uy0qu+e3rf6A6rn9bVwdSYkvFNqs6oFWhtUj27rr KTzw== 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=SK0Awx6gBdtKUkOkh7F3holwbySWbAOSfl3fXGrSMFk=; b=74hzMq8Y8rxtLuQNNEVWx5TV69io36y88cgC2HGqQq77AoaLZjJ4nkIvyqGkCovzYZ EDPIBfRjY7skos8bAkg+SDUWlHs9/Re/T9FAPVNkFuE4DyEZ540Y5W+w9Pqeh3WESLsK PcJU5kd4JzudSM+o5JazhI3AQXQ4H6t3kH8cUIFRAhiJX9eWHrwAyr47yJSE8gty0cGX p261eLRwMy1SERm68SjMTN6MMgXhPRya52GZcnugGzUVovU6U7jI21ik7zfCHXdgutuw dD9ddrw/eMb0Od8ZebUKR+QHxUhqBOlEBud7HirQ4JzSzvwH/QuhjM2WKnY4Imky3AFu s0eg== X-Gm-Message-State: AOAM530yf7AsriIAZs4Up7xkQazU0PDrsHsOr3lgOJ0ObiaXR3PrJXZr lXHLBrz5IyUD1kLB6P33djgz/ElDOTU5Bng= X-Google-Smtp-Source: ABdhPJzpSB08zJBnLwbHl02W9xYuCHlr5gBvgb/tW3BrQDILrEXB073GvlAwzYRJ7nRDUowH61DjK//i7prT180= X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:16d1:ab0e:fc4a:b9b1]) (user=saravanak job=sendgmr) by 2002:a0c:aa01:: with SMTP id d1mr714696qvb.47.1631725789030; Wed, 15 Sep 2021 10:09:49 -0700 (PDT) Date: Wed, 15 Sep 2021 10:09:37 -0700 In-Reply-To: <20210915170940.617415-1-saravanak@google.com> Message-Id: <20210915170940.617415-2-saravanak@google.com> Mime-Version: 1.0 References: <20210915170940.617415-1-saravanak@google.com> X-Mailer: git-send-email 2.33.0.309.g3052b89438-goog Subject: [PATCH v3 1/3] 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: Geert Uytterhoeven , Vladimir Oltean , kernel-team@android.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-acpi@vger.kernel.org, Marek Szyprowski 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 Tested-by: Marek Szyprowski --- 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