Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3991934pxb; Mon, 4 Oct 2021 14:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz33tQ2ALwX40Rwn1jQmqLWGBuKeEuUnmOetPTiQJj+a2xL1kUAeHJAtPdvLHrATp8H2lOq X-Received: by 2002:a17:902:bf07:b0:138:e32d:9f2e with SMTP id bi7-20020a170902bf0700b00138e32d9f2emr1716887plb.59.1633383537862; Mon, 04 Oct 2021 14:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633383537; cv=none; d=google.com; s=arc-20160816; b=qkr5wcxxZCMqkwkhL7996EEDGYN5OHSHbYKayKk6VAYgvQk+oYE5+OV3HLo6GkWsgh x2ASZFiC85kWsoDm7RVSxhQbg9+rrHFTKxFvUjetMWhdSGpvu66g91X1jFJamZ84A4Rc vnaHd8xZ0YUfziPs5WvwfRX72wt1EXQVtlStOgYznuI8lGiKfsI6N5yZA4jUgsi5a7DT D6r5qDg/LUgKM3qSD7/0QZst670upsY/y0gJ1zBdL/r+OFFQtbATdTv14hoFoDwMmt0s Vnsdvz3Xz3aUKyxLHKglsByGN2x9kKC7rtGBB5ThBUXoVG7WZNkPsRtecp6m/QBuDgpW UDOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k3VIJPdlWzCgjv52/QXh4wW/sFZHEqafqblHyRHdQeI=; b=NVBfUioQab8aBgVL/6VVOurUGmxnUbemX/Lcw7Z9Y3F8P5HhBijoFMPXlXEzsFtKME Bdw+0ojwxBOxGibXuv42nuVh0VoRXYWPY3pA00rMu08AgZcZqu34hcuUWrJZTmiJ4Ypi d/Qn7nCS2eL56AAgbxm2Xxff5qzr0jRP/nnr6GZJHZDINaHIU5HGmqtFHmqrQCK5BTmg DpjJQz7F4iVYuBH1FZ3kq/dG8Pa9v4QBdCsrYIbs6TZO0dufg3X8sNzszlcNThtJif01 36hXuC9pxGYiLeRGxZUZ9qOABq3hKsNIaepfWJaclr0mPjSvgwVucRFJ//d8XGU53liz AxEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=njNWONOl; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si5868967pjd.41.2021.10.04.14.38.44; Mon, 04 Oct 2021 14:38:57 -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=@linuxfoundation.org header.s=korg header.b=njNWONOl; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238660AbhJDNlB (ORCPT + 99 others); Mon, 4 Oct 2021 09:41:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:53180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238617AbhJDNiu (ORCPT ); Mon, 4 Oct 2021 09:38:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35B356324B; Mon, 4 Oct 2021 13:18:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353481; bh=1MLeZklQqxtUfQ7JboQfwHPWxFjt2Oe4JLxtf++UOGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njNWONOlmSCVg+LKKRF3cVFFDNZBxyda04Xm2zny2ekPp9YVRtPF694lrV+i++o15 aIRF6/C9PBK+paJxi/T3dZOGOvZ5+ZAcdAOm33ew4YCt3HFawDA0cv8ZW9mPudvTq4 NIggtNF5L1kipb5/XdznZECtcnVu3TcBVC72Vfqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , Saravana Kannan Subject: [PATCH 5.14 146/172] driver core: fw_devlink: Improve handling of cyclic dependencies Date: Mon, 4 Oct 2021 14:53:16 +0200 Message-Id: <20211004125049.685211278@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Saravana Kannan commit 2de9d8e0d2fe3a1eb632def2245529067cb35db5 upstream. 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") Cc: stable Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski Signed-off-by: Saravana Kannan Link: https://lore.kernel.org/r/20210915170940.617415-2-saravanak@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/base/core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1790,14 +1790,21 @@ static int fw_devlink_create_devlink(str * 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 { /*