From patchwork Fri Feb 2 09:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saravana Kannan X-Patchwork-Id: 195763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp318958dyc; Fri, 2 Feb 2024 01:57:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZWylAC4DN7b5F3VRYhbb5zM2lL1G1WpZPzbv8mkxdMzfO9kvH4Ib7OE0VizdBkqmBlD8B X-Received: by 2002:a0c:aa98:0:b0:68c:81d1:cc76 with SMTP id f24-20020a0caa98000000b0068c81d1cc76mr2983966qvb.19.1706867878822; Fri, 02 Feb 2024 01:57:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706867878; cv=pass; d=google.com; s=arc-20160816; b=kRkJqlOpQ9UKj1/MJp5bPAiED5cyaqP3gdBgX0Vct1/upoLzIEKWPEPCCuixoHihOK 8/k0O/O6v3ffwus2aocb1N9f+9qkJwKrbwf4akn8hNwMtXc19WLvTj4bJR9cAx53cxFx RIcAgJUmMgMF+7D4hwyP6RNGguEQBRYoAAeJuk7TTlwEhmcLzU94mAAjEg5R/HAD3SSw ukaH8Wev43AWOkfinnQECexd/mbKEgjI8/9AWL5+GNHVzHF/RbxAuBp+0U06yhpvTpLx jBWN32efCeSAHYuDxLhRA6Tn7jeRIvNPUPVAwGvi7gSL2ZVWlJawjD3mG12BK2WDA5BL Ibww== 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=HNQh2fOKzuAqWNKFcTQYXXg09+N+urRt+kYQhla4m8w=; b=iJTN09ZnVH+d1UMgIBXkfm5ReaOqhjGl/C4ccEdHcishNKrwqemMSHVd7EBGRPZ3Oh eMerquENvMd7USsAzX04a9B0Sb1CTP/5mUdeqrsNmxuIwE3Do/P0KombocOO7wx1WL8U Phu3bm64oPKfVfuRRo0OVhUHSZtPTY9/WNjhFzTDHOKJyfeuy8naF79ZU8l+sOlO7fAs +A4RUa+4ytoeWQ2DG5JTOcaet7GlZ91X3L+gapKVHhTnuDnmOoa3nuXGmeHMHEbcHsnt AkcEbmh6p1Ixr39M5C0602J73dX/G2V+8tuZ2I+bLs8N1RsNviRJaxV/zJmdooAfLvoK ULvA==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49625-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUSe7yuZZ/jEIssIuQTiLH6GogsMtEgPDZMUbvlHNjwKUOePhhtO6N+QzxkhvTuEdOi3CprYCgMus1+rejIij+vgevfsw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c2-20020a0ce7c2000000b0068c3cd4b483si1614521qvo.174.2024.02.02.01.57.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:57:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49625-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49625-ouuuleilei=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 84CC61C24899 for ; Fri, 2 Feb 2024 09:57:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4936D7CF27; Fri, 2 Feb 2024 09:56:51 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789780692855028043 X-GMAIL-MSGID: 1789780692855028043 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);