Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp718445rdb; Fri, 2 Feb 2024 01:36:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgWg8sfT5NHLd0u+KOw+jgMgmEZPq+Sah9SMXSdf8HF0hg8uhSJ7O7p89JN7/RyQFDSErM X-Received: by 2002:a50:9b13:0:b0:55f:fad8:4635 with SMTP id o19-20020a509b13000000b0055ffad84635mr407746edi.27.1706866616226; Fri, 02 Feb 2024 01:36:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706866616; cv=pass; d=google.com; s=arc-20160816; b=IhQC9oyLjVC52qIiPW6nXztKTcGS2J7XUqSAzA3/ZHvtXR1sXxLvjBecwMl7pYr14q tcaaZvxcbr+3fllJdXxKZ3+B5mRW1IlVd4YxMXd4VDG0IzEtM7oirc0yrPXJhz+W9XSJ 242B7L8axrH9PnljghdoFczJS4gBn5WUqmj9Gu3hrKhXtzXTRq9OwpMgI8L0ASqZT5Jj 22afIywc/BvgEZsM94uyxpQwiJAoM7hdAKNwSk1rwXFonILb5lX+RLqVllEWrovi/Nls 7DkleY7BI0AIvEPQcQCkCn6ZZWfbW1SOgkT7PbInD2ewDn9uFiXMjgVkXMqGfvBpd5L3 lXSQ== 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=z56xR9yNZPdN43Rmp9S7qi4yvugz7xxCFU7gWTlvFXQ=; b=YoJpHbiP9dNR1Ysi7HyQtQzKxfAceQVx0+9LClYnYNRWTIAfCHMZuFRpGxQMVTl6uw p1PwGv0/5BGJxLesLZHjzTSlxUweYMY/c8R68UEdNC0CBTXzXMhhiFcZHqRtoBVzjKl7 Ke4b1ofEKKTVnZXuJRV2dQ5+jBKvON/bIwm4LAyQzwn2+DRyuMl58fYyKiUCbjcuITjE hK2n6J5i0RVxErGTDt0aVZbLeJg6w6S6sEI74T8cftZhs+6+YWPypmekgFeDJ/Ct7rfg ik7aq41aeMh2HBMhTXhI9qIZU3xLjJrm06jOf0JXVh8dmNYu3zDsSOGn4ss+c4kpZlIR lliQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QlLhwlnh; 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-49569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49569-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; AJvYcCXOOyaKhine973DcoY6Gb7HQQalyQr6S1Fa7Gwqz6drJjnPP/vXimGXm843AN2FeLrQIndWikBFzDZF624Ky1+siaWek84pBA7IMLvvFA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c17-20020aa7c991000000b0055edfc84a70si648702edt.502.2024.02.02.01.36.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 01:36:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=QlLhwlnh; 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-49569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49569-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5AD211F2D078 for ; Fri, 2 Feb 2024 09:27:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B86979943; Fri, 2 Feb 2024 09:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QlLhwlnh" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 D6A997F46C for ; Fri, 2 Feb 2024 09:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865781; cv=none; b=NA9S4osFlW1l6yHvkKImDdytA3BiSQUXwfG3fZteqrS5q0VPVtPPoRnjzUu5FNEsUXBYVgLwlYz8ULB+1ZK4YsbjmLelR+gAPTEdrGmMm3bCe0y5Lc4e0wbc1l/WR4tncqs2S2jP7rjgTTjwaODEoidu+QvnZ+mj9dezY5rIozY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706865781; 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=DS/h+CtFTSNyLO3a7JGabQnHIITplGg4YlkI7NOb2BKHp2cttJ+OSgmRtTeYZxL8xFVNZZ2MlPD5LE1zMJOQ7RrZ3Lzv8xkkskm6txBVtGVX9ETIkvATjF3QxyKMBhtp5hLbPkjeGLW6AUrtdprI0w7FKsArYMhcY1jYus/GqC8= 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=QlLhwlnh; arc=none smtp.client-ip=209.85.128.201 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-f201.google.com with SMTP id 00721157ae682-6041dbb7a78so27870527b3.0 for ; Fri, 02 Feb 2024 01:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706865779; x=1707470579; 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=QlLhwlnh9hb2TZJz08rXJfQ+XYSL6f+3qqJdy8FSI/ut5npFugRGVm5gEUp9Rf6M/S y90rH5mwq8Ux72JtOT0BuNOkq5hR0DRxP5ZRt2jaDA2dyNjEY+iPc2TzpwdH4w8VAFBX xBZRe7kmNAdZLPpE1j0STlkg9ab1y52uETdgtAn+Nn2gmYM+8zD4xcGPXxyh9S/O42hL wEk3Tt+Di5PnCeoa6bzg8ro4UcDIBTO2e4Dpr5UhIAxnwixmGaNWOCK/v4GlTVDPrHa1 8iT549M9gmmtYXMdBONlRlUBApPafiJBdWp9jpbrnI5EVqt7KQX/6ciYqp1LECqaIIC0 sqbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706865779; x=1707470579; 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=h0BMSJAlYqz9UBX+lFEQfNAPXx2pr5SATwot4EDZD/tyTiSQt9JRU5etx9fQekIxYK iocNRwCgf4j8wAqrlCyvCDFFx9/MxSbbrJPc8Ip7vvUSbNTHH9I+mh6EXbZcu3Q4v3MF V0wGRHqyYxH7fujc5+Lqga4MCHYAIVMASxCUvnfarmOLMFtEDGf6wwewA0gVHl0Tpo2t oGCcjHpKRV1bYvFJa57QSlaWOxapxEv2hSWzISSYArWkUtZ85kBgTFph32RmQeEWCR+K ekR30nn+bM39USYF0Z/XPNwHlBFhENnzAYJ/mG1OEdeScaa2Yxy7tr8JV0VfvV/knYI3 HgCw== X-Gm-Message-State: AOJu0Yz51nGDbN6XUaA9mRc3CZM9mzQGOP0fg3zK1ipqsCT+yPGD/u9r qqcWcU1l57epaPtbM0Owu/NEw0w6OFW/Zkl9Ap+q5wDAaK0vjrRsVwp56RrvooaEi3ZZa1dmXC3 ZekCztxfwg7l6lw== X-Received: from saravanak.san.corp.google.com ([2620:15c:2d:3:6f0:da10:9cb3:5b3]) (user=saravanak job=sendgmr) by 2002:a05:6902:1085:b0:dc6:e5e9:f3af with SMTP id v5-20020a056902108500b00dc6e5e9f3afmr704904ybu.9.1706865778896; Fri, 02 Feb 2024 01:22:58 -0800 (PST) Date: Fri, 2 Feb 2024 01:22:48 -0800 In-Reply-To: <20240202092250.786276-1-saravanak@google.com> Message-Id: <20240202092250.786276-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: <20240202092250.786276-1-saravanak@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v1 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