Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp725229rdb; Fri, 2 Feb 2024 01:57:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxAYiLvagAT8pK+SkRkWPB+NLWdRHss6pLMhuxHrxfMTrGpTVuqPbJWYyRo2bJzoJ9yQ1y X-Received: by 2002:a05:6214:1d01:b0:68c:5e0d:6a6e with SMTP id e1-20020a0562141d0100b0068c5e0d6a6emr7084921qvd.47.1706867864037; Fri, 02 Feb 2024 01:57:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706867864; cv=pass; d=google.com; s=arc-20160816; b=fmMJAA/HjOvmPJ6iZ7o21Y8IYvZDdMXcrNR2RD7HD+O1Tuk31jR/KQaJPXawbB1Ewq 9iGKGudApWukMk/tGRQaKH0BHH0PlouKZYgKYwJeFCESvKJapjrvetkrv/RqPic9PNr3 9QtfN/LZl3deFTPUMyVFSkTdUecgQB3tXIpkpTXF/XRZV288L8chY6zgHNDYiVwXKom8 cdXKWLry2tf0s76+w3rEjALOHC1fvBHL4cbzK594wDrouOw/bvJdGd8ra2ll9lQgTP/u Lv+yAu9dOU7ozaelaUMGXT9ig+Uo17ltj4R8jVZuuuHa1r+vxbGHfNDY81ItPb1KN9kf MnXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=r5YNJyMo7T6ZuM5rJpTOCCSH+s00uoF+8fpfMCUPszE=; fh=wyuoJrD296/3TRnyMMO7I8+/Fmp7MwbNhEnDIuzyJ7g=; b=B+fpQ6ea1wfgqYSyWKJIJ48PuhQjRzg62MVRp6ebY14iySPWXk5kCqk86QL2UU9fnw 3We5CoNt3zim2b7uZjfxY1t4o25lREAYSGqg8dQFRZCELxshtToK41puc4WdDNhd23hS utRae7/COQLV4FbqKl55eaHGt8AhZZBv9YxOG0woi0g9uppGt+FaV/RjZlg50jwJzC9E 4QGPoQYxPqRJxgvtCGJjeLpPODf3t8sN3vbpZNhX3/OQ87IM3z8paD4AO0jvifruSnJt Glh+21ApdktBG9OoGI571STvR5oZST06GdpAzBkpFWzWTF9zzpSfN7EepdUTIOR/lpBp KJ9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2ZrE8+qS; arc=pass (i=1 spf=pass spfdomain=flex--saravanak.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49625-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49625-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCWlvKDmcvG3nJG5yXxPjDMcZpjKabe/Gsh4F2fXsApb+jPP0UIaPwyYikW9H+WGKLEqSFi7eHhpY197aeSRtgL17doYAovGkHzFvvpZPw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dk19-20020a056214093300b0068c85b31e39si1370176qvb.597.2024.02.02.01.57.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:57:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49625-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=2ZrE8+qS; arc=pass (i=1 spf=pass spfdomain=flex--saravanak.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-49625-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49625-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B712C1C247FE for ; Fri, 2 Feb 2024 09:57:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10D007CF0A; Fri, 2 Feb 2024 09:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2ZrE8+qS" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88EA87C099 for ; Fri, 2 Feb 2024 09:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706867808; cv=none; b=czV9hA8M5s+WAsA/Vt1afbDMDlWd/9eH9uL7QQH/+CTlGUu4NXku6sfSEIx/L0zip0qJhRToH74Nxd8S4AUObPqcHnII639Fg3gVEt42TYJpKnwX4PaSi+PF4ObWJd+9ktd7IqBVpw3OvDVQQNeHTqYA6OFmPka859R3Z/K6L5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706867808; c=relaxed/simple; bh=dd+eXX+dl1OWEzo7/glw3RkA/h5jaC3FxhfWglqWQKw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=cypZZ3z7odqz2+ExPA2Ne6TbOPNAwGssQq3AW0VZ9WwODd7FnCifHfe7/f7dK7MBDv5jNUlBwGJ/0xfBMEPtQw90gTo3Ea8b8xsXIvHDpzm5HdduslAvV/jmSYRTLAopG27Mqu2ZL391URKo36RMgOzfd+W1x+/tHMbbPkTBhpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--saravanak.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2ZrE8+qS; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--saravanak.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-603cbb4f06dso36340457b3.3 for ; Fri, 02 Feb 2024 01:56:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706867805; x=1707472605; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=r5YNJyMo7T6ZuM5rJpTOCCSH+s00uoF+8fpfMCUPszE=; b=2ZrE8+qSkIyhdbDoG737h+0JS5YkKVsCS5Rhj0dxzoB1Rr3yzonOo1O18/T2jt4ter 1o7z6GfoL85yfkOB7dK3kHDqc2jru1hPger6V2mvFwfxTL6B2Xd5GGwDD+Tvo+4R38hp xYzygVDKrA9BfBApM3z+rd14UWEFfznx0cO1GFTURNS/RjB2/tNo3VXI4MYQk6s98oQH JY+QwmrLVIoKAERWZbsgNKGjHJTIW2JmI1XOIufcbmWqCdJKdb57VzbAnSuqx66xLXz8 o7lo1WrMK4mnelGypTssM6t2JzTljsJbs4RcG6lB/MyeYUUCDf+Np2RB8RZBY2fcceih XZlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706867805; x=1707472605; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r5YNJyMo7T6ZuM5rJpTOCCSH+s00uoF+8fpfMCUPszE=; b=HuYQ+8JIlH9S2bIj/0c/pU9PWhXlFYwCcASPBbDcXCf2/HM31YNpKoDebu2ymoHz1P WgqIOhcbeEJi8AX2NoZ1icNOtU3F5X7JG8irkrETEzWdCEZkW35Chg2U29g9fB9eUcLH FmcfWEEGpHskRmq8kR4TzTBa8mNN36hL3UqX55DyoNYWfamVM9vfRIWzH86znUudB81i hYjFVyIwD+WxHTCmR5pRP/JMxRj+89FBNgsGzQy2+9f6v+HEUG/sDkV6PnQ+HVj6faP9 WHZ+NGmtoRRx2HuS1nQueJSCruDuTS/KTsskwo1P/oGfzYapniOpvm5OcL3gMExKUaFh wepA== X-Gm-Message-State: AOJu0YyBDMvKd0tJHeVlXv36IzqSaOolt215H6RGMlwGdCb25IMfkSch XKbn6n1UyAHX9gekWd+OuPfr0Mc75SiqqPA7luUWd8prxOw2wpbcTprM9eng25HWVohmZBRAbGg fEhr7AO97Tuj5Yg== X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:6f0:da10:9cb3:5b3]) (user=saravanak job=sendgmr) by 2002:a81:7905:0:b0:604:1dc3:122c with SMTP id u5-20020a817905000000b006041dc3122cmr954235ywc.5.1706867805547; Fri, 02 Feb 2024 01:56:45 -0800 (PST) Date: Fri, 2 Feb 2024 01:56:34 -0800 In-Reply-To: <20240202095636.868578-1-saravanak@google.com> Message-Id: <20240202095636.868578-3-saravanak@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202095636.868578-1-saravanak@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v2 2/3] driver core: fw_devlink: Improve detection of overlapping cycles From: Saravana Kannan To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Saravana Kannan Cc: Xu Yang , kernel-team@android.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" fw_devlink can detect most overlapping/intersecting cycles. However it was missing a few corner cases because of an incorrect optimization logic that tries to avoid repeating cycle detection for devices that are already marked as part of a cycle. Here's an example provided by Xu Yang (edited for clarity): usb +-----+ tcpc | | +-----+ | +--| | |----------->|EP| |--+ | | +--| |EP|<-----------| | |--+ | | B | | | +-----+ | A | | +-----+ | ^ +-----+ | | | | | +-----| C |<--+ | | +-----+ usb-phy Node A (tcpc) will be populated as device 1-0050. Node B (usb) will be populated as device 38100000.usb. Node C (usb-phy) will be populated as device 381f0040.usb-phy. The description below uses the notation: consumer --> supplier child ==> parent 1. Node C is populated as device C. No cycles detected because cycle detection is only run when a fwnode link is converted to a device link. 2. Node B is populated as device B. As we convert B --> C into a device link we run cycle detection and find and mark the device link/fwnode link cycle: C--> A --> B.EP ==> B --> C 3. Node A is populated as device A. As we convert C --> A into a device link, we see it's already part of a cycle (from step 2) and don't run cycle detection. Thus we miss detecting the cycle: A --> B.EP ==> B --> A.EP ==> A Looking at it another way, A depends on B in one way: A --> B.EP ==> B But B depends on A in two ways and we only detect the first: B --> C --> A B --> A.EP ==> A To detect both of these, we remove the incorrect optimization attempt in step 3 and run cycle detection even if the fwnode link from which the device link is being created has already been marked as part of a cycle. Reported-by: Xu Yang Closes: https://lore.kernel.org/lkml/DU2PR04MB8822693748725F85DC0CB86C8C792@DU2PR04MB8822.eurprd04.prod.outlook.com/ Fixes: 3fb16866b51d ("driver core: fw_devlink: Make cycle detection more robust") Signed-off-by: Saravana Kannan --- drivers/base/core.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 52215c4c7209..e3d666461835 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -2060,9 +2060,14 @@ static int fw_devlink_create_devlink(struct device *con, /* * SYNC_STATE_ONLY device links don't block probing and supports cycles. - * So cycle detection isn't necessary and shouldn't be done. + * So, one might expect that cycle detection isn't necessary for them. + * However, if the device link was marked as SYNC_STATE_ONLY because + * it's part of a cycle, then we still need to do cycle detection. This + * is because the consumer and supplier might be part of multiple cycles + * and we need to detect all those cycles. */ - if (!(flags & DL_FLAG_SYNC_STATE_ONLY)) { + if (!device_link_flag_is_sync_state_only(flags) || + flags & DL_FLAG_CYCLE) { device_links_write_lock(); if (__fw_devlink_relax_cycles(con, sup_handle)) { __fwnode_link_cycle(link); -- 2.43.0.594.gd9cf4e227d-goog