Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2758330pxb; Tue, 19 Jan 2021 05:34:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjx1ciTwqQvw2WYOynKZue7yeA9jCNk//5L5YcfV58zOYS3y3NzWsMXgrnQcpnqgmCYRDd X-Received: by 2002:a17:906:c10e:: with SMTP id do14mr3158084ejc.166.1611063263630; Tue, 19 Jan 2021 05:34:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611063263; cv=none; d=google.com; s=arc-20160816; b=EXw6z2nGoKUKu/RydHu8L7szDFXjzcCLOYDL0SADfQUomxgaOcQdQrBaU9NfX5byiz 2TOBp/0ReI2Xf2q/J+Ik1uLDTPkbiy9CVX4loHs6BbETKpl2zZWWu6N4rfMQZbC5AoJ4 eiNESJmWhwFKtg4o7tWYSmmIHGJddKtYWXH2f8htIAQOCGjFmUOcKNyHUq3qJH4dwAhh z2UMP2qbfnFxbscCuxIoVZCMaIvu+doh3XnrH4Kk1gfI/ZDO5AidBLTCFsmGhbgH63KR NQpDcjrqIApDCbAosP+7wgS2i0oFs+0bXmefDQTYBKWETiwJccIAS2rfRYpvesEMNpwv xZ5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=Idlx9RREqweSUD8lcoD8wW/tGcOzRTqi7qMTCAE3Qko=; b=k4zsLhV7sboo5F7dXtr7BULzm7TUbRHScUb22rCGqFBfPtXu+uQOcSqy6z6mMHus5n i7tyekrDt3uthW8GNjcD2eBFERUhjsUwzxzEBDja5cVfrLPWNGBuHimcC4DChePuMujM ehakGt+wH7+/nwkcpEKf+MyI9EUBrDqgxUpuVvCbsqr4zSXcVDkNShGU1OcCWlrgI392 XvcUngWqQwGyMSO7EeQOQvkPhEDI8Ovy6Re4aveSPwJjO5kcUCd8fcNrigipnikP/MPN zRmO1ImnROytWo9VfTd7VSQYp/FZkPvgsVgj4m4X+vWqkt+wNw5Wm4bVyQzkpclyX6Kv /JkA== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk22si7407062ejb.736.2021.01.19.05.33.57; Tue, 19 Jan 2021 05:34:23 -0800 (PST) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389395AbhASNbV (ORCPT + 99 others); Tue, 19 Jan 2021 08:31:21 -0500 Received: from mail-oi1-f176.google.com ([209.85.167.176]:35991 "EHLO mail-oi1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389267AbhASNZT (ORCPT ); Tue, 19 Jan 2021 08:25:19 -0500 Received: by mail-oi1-f176.google.com with SMTP id 9so21130460oiq.3; Tue, 19 Jan 2021 05:24:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Idlx9RREqweSUD8lcoD8wW/tGcOzRTqi7qMTCAE3Qko=; b=LP0j9td4/h/qiWWMUW/rQuu6r90kvreGW2E4JPLasy23bl2IWJyl8pYtzLBXHgvSKm 7kyuNVSacByAgw4WeoAPGxnW6RVqo5TvF/2RHxaToiXUoNZRZILwNsc8YQjbtgOu7zXb QLVmhAbkq85HFOEDd2Vc9JOPg31tQWGg/XvjyMxA792wG4hxwjekxF7H8/bMzjcu764S oMGhupjSpMFhIQKtnVg4Dlq4s2A/thPNZ0zqUMdRDTc2C3MTCY8WSi1DThZlROIXEP0f jrDKyKPWjlyxhcsBypuealUpDeDRDzdF8fbuCHuiJ3O+9+C9O88Y2T0YKr0ZwTaWewoK ezrw== X-Gm-Message-State: AOAM5312FMEw4TCLhZsTbz32jkv8KrN+zYWlEo4Y7QS9hbVZt6xY5rzy NTnxabb+SlHnMz9xseJOyE6p3TCLhd71CW2EaJ8= X-Received: by 2002:aca:5c05:: with SMTP id q5mr2566295oib.157.1611062636064; Tue, 19 Jan 2021 05:23:56 -0800 (PST) MIME-Version: 1.0 References: <17705994.d592GUb2YH@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 19 Jan 2021 14:23:44 +0100 Message-ID: Subject: Re: [PATCH v2] driver core: Extend device_is_dependent() To: Saravana Kannan Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , LKML , Linux PM , Stephan Gerhold Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 11:03 PM Saravana Kannan wrote: > > On Fri, Jan 15, 2021 at 10:30 AM Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki > > > > If the device passed as the target (second argument) to > > device_is_dependent() is not completely registered (that is, it has > > been initialized, but not added yet), but the parent pointer of it > > is set, it may be missing from the list of the parent's children > > and device_for_each_child() called by device_is_dependent() cannot > > be relied on to catch that dependency. > > > > For this reason, modify device_is_dependent() to check the ancestors > > of the target device by following its parent pointer in addition to > > the device_for_each_child() walk. > > > > Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support") > > Signed-off-by: Rafael J. Wysocki > > Reported-by: Stephan Gerhold > > Tested-by: Stephan Gerhold > > --- > > > > -> v2: > > * Improve the changelog. > > * Add a comment to explain the reason for the extra check. > > * Add tags. > > > > No code changes. > > > > --- > > drivers/base/core.c | 17 ++++++++++++++++- > > 1 file changed, 16 insertions(+), 1 deletion(-) > > > > Index: linux-pm/drivers/base/core.c > > =================================================================== > > --- linux-pm.orig/drivers/base/core.c > > +++ linux-pm/drivers/base/core.c > > @@ -208,6 +208,16 @@ int device_links_read_lock_held(void) > > #endif > > #endif /* !CONFIG_SRCU */ > > > > +static bool device_is_ancestor(struct device *dev, struct device *target) > > +{ > > + while (target->parent) { > > + target = target->parent; > > + if (dev == target) > > + return true; > > + } > > + return false; > > +} > > + > > /** > > * device_is_dependent - Check if one device depends on another one > > * @dev: Device to check dependencies for. > > @@ -221,7 +231,12 @@ int device_is_dependent(struct device *d > > struct device_link *link; > > int ret; > > > > - if (dev == target) > > + /* > > + * The "ancestors" check is needed to catch the case when the target > > + * device has not been completely initialized yet and it is still > > + * missing from the list of children of its parent device. > > + */ > > + if (dev == target || device_is_ancestor(dev, target)) > > return 1; > > > > ret = device_for_each_child(dev, target, device_is_dependent); > > > > Reviewed-by: Saravana Kannan > > fw_devlink_relax_cycle() needs a similar fix. Want me to handle that > as a separate patch to driver-core-next? Or do you want to combine > that in this patch? I would prefer that to be a different patch because of the Fixes: tag. Also fw_devlink_relax_cycle() is in linux-next only for now, so it is better to avoid mixing a mainline fix with updating that one.