Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2518681iof; Wed, 8 Jun 2022 06:41:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhhkBrc3OTvPIKimRra1HeSayZcTGYyTZOdgRqWnt+RSQgcrf0gBNVzgtLlsFUXeJYLdgF X-Received: by 2002:a17:90b:1b08:b0:1e7:71de:7714 with SMTP id nu8-20020a17090b1b0800b001e771de7714mr32021180pjb.214.1654695718220; Wed, 08 Jun 2022 06:41:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654695718; cv=none; d=google.com; s=arc-20160816; b=VtfKSiwE10TMNsle0Ti8vvgdG+P/vEJ+BDDgoeaTWwIXVKLG0rPInT3TkiUzx8USwE 7Dz32+KmjxIn7F/l0i1mqtOwqDLTJDIws/LWGinP7bZ0LrPxKfP7T+NyVKJg/D0gWnrN bUnE9itA1qNNhFoAhybJj4RcrSUK3NNWRQStsH9PDD+JzYPQbx5kzgxOMq9NfftszJlJ HRjgkECqSFCgXCpicRf2sCMZLtHI3aJX4RIVSslTyj4zOUErgx/3Ku/BMUZsZzCzkEtO xfZP1udQxKfipNtC/e3/OMOITf+WDxwrcWGZGXvZ1vnufOYfQam8Rohbol3BsuL81iam 2ezg== 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:dkim-signature; bh=qbE4NOSoSmz8Bk9zM8BJuuluMSrujcIpd2/DIXfe5UE=; b=SWOmM4zE30gXmTZ5rISloQ/FVaGCu065gct1gpYl/fdmzoTv9QlhrFDr/zXxQ+ZSQu egf+edpqyjD9GzFSORmNxiB5lY5eXYh48S1icETM9yEMLzuqDIoxWrxM4DmV0GChvZUP /4Bg881KMZWS9FqQ1ofL8Y16eMhdH/9t2uue6BO3pNhH923IUSDi2DsK4ckPcIb0l+Ca M9BJKq2Q1gJ2T011L2B4NK/624+WE8/3DK0NGh60stUVKRf9DAl0RWD7wiT3Y5oHixob +pBEs6k9AP+r209cglo7h6c3O3K+cxp9sPE94aRB4/artixVrcJTW6R1AJl2muRTLSQk GGXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WKyiXeJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id lr1-20020a17090b4b8100b001e896f91ba0si10894868pjb.64.2022.06.08.06.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 06:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WKyiXeJL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6B98CF5AD; Wed, 8 Jun 2022 06:16:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240020AbiFHNQf (ORCPT + 99 others); Wed, 8 Jun 2022 09:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239852AbiFHNQd (ORCPT ); Wed, 8 Jun 2022 09:16:33 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60A3A3BA55; Wed, 8 Jun 2022 06:16:32 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id s13so22695464ljd.4; Wed, 08 Jun 2022 06:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qbE4NOSoSmz8Bk9zM8BJuuluMSrujcIpd2/DIXfe5UE=; b=WKyiXeJLu4/8Chr1j17Br1vQyABHDAuyeJzKGzY39Jw+8OqPJ3qhT2ubPdKMKGfXwj gUSHE9G1kZASr+rGuEtD9WoBScdzsuW3/Gr50xRGhS+6KCLo6RqDroN4lZIiAC+iSp47 lBZkd2lQFUs7rPyKCvVYxxOBfIZlKlfyXrLszhmYt+JFoc0PDQwb4gsAqHRX6nbV88ld Tw6UIm+iNPu670/IccroXCI6vIL0jCQO2IyDKsveZfbKR7vQYsdS3FU2RlI9GhSeUstA m+ehWbazzMRUaINfzdc+1uzlmVr6L9tPKa//kHBr4H9Mvlw8y2kTwNAka2ysUPkYjMTX JYww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qbE4NOSoSmz8Bk9zM8BJuuluMSrujcIpd2/DIXfe5UE=; b=tI84d8nLSI1VLxfjvPlcK9nbV7NgXb/D+NxmrY8gkQHJRHU9jDSZJ5TUBJzqM16LlF DOcm6rh6FgpLlsuUOrv4EBqVOlXx0SZisPf7n9uuq/E1TYBeaPewV2HDs93X6Auy4bSb 789xVPNEjst8DLDS85xgXc2Fe6mdfxcjdLGQNMS2v0/ZrCdEPAwGgk6i+k9QZ5JJWto+ KfOsZHsiTtKAlcI9xMhWEnyesScya6eyTE8/v5nFNJmIMUNl2r9aIquLJmQAg3h3Kcir kyvY0KqTa3mY5P5TP3aLFNqKjzDW/i2KP5EOHj3FM1vFYI8Bb0b1uIyD9+21TP7duCxg obnw== X-Gm-Message-State: AOAM533t5Q/MWfAxsHmKkmzDvexbhYMj65MeugIWiV1xwFmyr2Of4csT SpZsU5diZcDZn6aJvjzz505hTjDha/P3TCr/wME6MSitcr0= X-Received: by 2002:a2e:b0c4:0:b0:255:6c75:36b3 with SMTP id g4-20020a2eb0c4000000b002556c7536b3mr19893592ljl.212.1654694190646; Wed, 08 Jun 2022 06:16:30 -0700 (PDT) MIME-Version: 1.0 References: <20220523171517.32407-1-windy.bi.enflame@gmail.com> In-Reply-To: <20220523171517.32407-1-windy.bi.enflame@gmail.com> From: Sheng Bi Date: Wed, 8 Jun 2022 21:16:23 +0800 Message-ID: Subject: Re: [PATCH v3] PCI: Fix no-op wait after secondary bus reset To: Bjorn Helgaas , Bjorn Helgaas , Alex Williamson , Lukas Wunner Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bjorn, Alex, Lukas, Is this acceptable or anything needs to be improved? Thanks windy On Tue, May 24, 2022 at 1:15 AM Sheng Bi wrote: > > pci_bridge_secondary_bus_reset() triggers SBR followed by 1 second sleep, > and then uses pci_dev_wait() for waiting device ready. The dev parameter > passes to the wait function is currently the bridge itself, but not the > device been reset. > > If we call pci_bridge_secondary_bus_reset() to trigger SBR to a device, > there is 1 second sleep but not waiting device ready, since the bridge > is always ready while resetting downstream devices. pci_dev_wait() here > is a no-op actually. This would be risky in the case which the device > becomes ready after more than 1 second, especially while hotplug enabled. > The late coming hotplug event after 1 second will trigger hotplug module > to remove/re-insert the device. > > Instead of waiting ready of bridge itself, changing to wait all the > downstream devices become ready with timeout PCIE_RESET_READY_POLL_MS > after SBR, considering all downstream devices are affected during SBR. > Once one of the devices doesn't reappear within the timeout, return > -ENOTTY to indicate SBR doesn't complete successfully. > > Fixes: 6b2f1351af56 ("PCI: Wait for device to become ready after secondary bus reset") > Signed-off-by: Sheng Bi > --- > drivers/pci/pci.c | 30 +++++++++++++++++++++++++++++- > 1 file changed, 29 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index eb7c0a08ff57..4653a9ae6e5b 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5049,6 +5049,34 @@ void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev) > } > } > > +static int pci_bridge_secondary_bus_wait(struct pci_dev *bridge, int timeout) > +{ > + struct pci_dev *dev; > + unsigned long start_jiffies; > + > + down_read(&pci_bus_sem); > + > + if (!bridge->subordinate || list_empty(&bridge->subordinate->devices)) { > + up_read(&pci_bus_sem); > + return 0; > + } > + > + list_for_each_entry(dev, &bridge->subordinate->devices, bus_list) { > + start_jiffies = jiffies; > + > + if (timeout < 0 || pci_dev_wait(dev, "bus reset", timeout)) { > + up_read(&pci_bus_sem); > + return -ENOTTY; > + } > + > + timeout -= jiffies_to_msecs(jiffies - start_jiffies); > + } > + > + up_read(&pci_bus_sem); > + > + return 0; > +} > + > void pci_reset_secondary_bus(struct pci_dev *dev) > { > u16 ctrl; > @@ -5092,7 +5120,7 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) > { > pcibios_reset_secondary_bus(dev); > > - return pci_dev_wait(dev, "bus reset", PCIE_RESET_READY_POLL_MS); > + return pci_bridge_secondary_bus_wait(dev, PCIE_RESET_READY_POLL_MS); > } > EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); > > > base-commit: 617c8a1e527fadaaec3ba5bafceae7a922ebef7e > -- > 2.36.1 >