Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3288736lfo; Mon, 23 May 2022 00:47:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznEcoYS3YMGmtG7pSeJ8FRks/n9epx1aVzNsMGPKLAKqTc+BHQnARc2EBpC8ftC95lgkvI X-Received: by 2002:aa7:91d8:0:b0:518:4f9f:966a with SMTP id z24-20020aa791d8000000b005184f9f966amr17595114pfa.61.1653292074058; Mon, 23 May 2022 00:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653292074; cv=none; d=google.com; s=arc-20160816; b=bxM64IbcL+QGiYJwK7oIG7WxaVrRjXNoiibZU8c40SO+NYgiIVp3H4p4j/XkCu3cPf /2QkOSRZcWfKC2HmHshYFGbzdsuiaZ0YyqdUdE1oCTuruCnVigRd7EI9jFYTjql8oLlb 6tUZgQgy+v5zpE0f41r9hwWhYxb+19DeHKJSWb8Z+Q50hHiOjR8ZlU81ljUmKeuHQOdB fuSCLxKKftTikJVeph/zi1IK9iOhMlIq2NVCH0cSvXqpXYJoB6UD0WFAAM8sKYBM+v3W +qN3YB4CCJINgXSAci/Wrqs6CriA9QfU6XxQ04rrn/ydhHyvDgMVlQoVsQHMZbUftDpp gHzg== 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=Ei1w+gAULw3a4Sp90/wPAPVRhqkQXbusQfV0z240l4M=; b=hV3wxjTMfBrOvT1XOvJaASmc1unvDkRqB4M5vECFQgJMMdL0Jcf6JrT7ZIqL/jVMVG eNAX+3tSvOAjbETL3W7fP+1UyC1Oz7yahGyxt9f/S2AlHs9Y7/HFDxpgT+JYzY61Hh/e WoUZl0meScCbP7HUtaOauu7eQGI617gcQThyXAxx4gjUksBht0Vr/aWHogqXoJomR2CA ThKrnoug3t/adJljx7ZSKMaTxKAu8sKZwFAm6OkMngTTlZQm5GTroUXROqjCOVwMQFhG JjhKQKTdp9vQLB6tRn2txM37FztlSHw5mBlIlhZR2sgeWc0igyja/RfMm4KvKch2XyI5 0TvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="E+7bjb/Q"; 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 r4-20020a632044000000b003f5d31f8e36si9533261pgm.672.2022.05.23.00.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:47:54 -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="E+7bjb/Q"; 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 126C856FA6; Sun, 22 May 2022 23:52:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241326AbiEUIg1 (ORCPT + 99 others); Sat, 21 May 2022 04:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238936AbiEUIgY (ORCPT ); Sat, 21 May 2022 04:36:24 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 270C536310; Sat, 21 May 2022 01:36:24 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id c2so9111268plh.2; Sat, 21 May 2022 01:36:24 -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=Ei1w+gAULw3a4Sp90/wPAPVRhqkQXbusQfV0z240l4M=; b=E+7bjb/QwmEkUO8deR/PhBs6U3gxuFDSHnbQU7gNn3QKPN5mF5qRPTZ0GWj4l8In3L 4CRgnUMOcbQlDkqioBvhvd1qNGKDjF6Ee1CXwHfqv7aJwjfS8h63grHDSlmaCp4fLwfM kNjWHzEvFnz+pXk+OmQrrDVb6ceE2aYycr6917ddc/9/wh8Z/llY2Ii1XhQkb49vjGTw fqrQC31FXiDfugJcYscTRQU0PLWKXFRBlgNw2hqtSy3QW5V+XU+uwTDZqrZqbo41Ql4C GqgPEr0rJKaEvkSIaCnoD5ZlU8KYD2g6n1Is53prmCWsPY0hgXBLaEnpvUmoc6jueFfR qHaA== 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=Ei1w+gAULw3a4Sp90/wPAPVRhqkQXbusQfV0z240l4M=; b=Uh5B0GjgnhomGRlr3TZq3rjS8zq7c6twpZTKU3bJ5bWA45tmV1lMfXlORsWCBS3/j+ evwg3L4zTVrIERfS/54fYhDw50cyV9xqBargpfLA/107LBC1ffT3Dll4FtsvyQvfOo5L D6F1/QqvNAHOzh45NfTq+gEjbHn+qyTo6Qyv8GQKsvOWp3yyjru+D84Qv9dWTgNfMS7s XwG6fNeziHONVUhdsezcl+o9MkFTWlVgnq7H+zZI+NTvXAWMuLfBrsqY7HfLuVoTqdXt FPeFkspG0AlT0kzCaVYsXrViSx9yWwWzHe3AnIQXhZMJq3UZy1U+QQM+jTZzVxtiEbpx fI2w== X-Gm-Message-State: AOAM533PO+Mmz8CH0e294bLOCI6urANqIIj67QUao7SCtghiDa1DPn9Q kxua4Jx0wNadR+J7zLqBrxptcfoRjBnThIsRm8Q= X-Received: by 2002:a17:903:40cb:b0:162:6ea:a2 with SMTP id t11-20020a17090340cb00b0016206ea00a2mr1789753pld.34.1653122183639; Sat, 21 May 2022 01:36:23 -0700 (PDT) MIME-Version: 1.0 References: <20220516165740.6256af51.alex.williamson@redhat.com> <20220518115432.76183-1-windy.bi.enflame@gmail.com> <20220520064148.GA20418@wunner.de> In-Reply-To: <20220520064148.GA20418@wunner.de> From: Sheng Bi Date: Sat, 21 May 2022 16:36:10 +0800 Message-ID: Subject: Re: [PATCH v2] PCI: Fix no-op wait after secondary bus reset To: Lukas Wunner Cc: Bjorn Helgaas , Alex Williamson , 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 On Fri, May 20, 2022 at 2:41 PM Lukas Wunner wrote: > > On Wed, May 18, 2022 at 07:54:32PM +0800, Sheng Bi wrote: > > +static int pci_bridge_secondary_bus_wait(struct pci_dev *bridge, int timeout) > > +{ > > + struct pci_dev *dev; > > + int delay = 0; > > + > > + if (!bridge->subordinate || list_empty(&bridge->subordinate->devices)) > > + return 0; > > + > > + list_for_each_entry(dev, &bridge->subordinate->devices, bus_list) { > > + while (!pci_device_is_present(dev)) { > > + if (delay > timeout) { > > + pci_warn(dev, "not ready %dms after secondary bus reset; giving up\n", > > + delay); > > + return -ENOTTY; > > + } > > + > > + msleep(20); > > + delay += 20; > > + } > > + > > + if (delay > 1000) > > + pci_info(dev, "ready %dms after secondary bus reset\n", > > + delay); > > + } > > + > > + return 0; > > +} > > An alternative approach you may want to consider is to call > pci_dev_wait() in the list_for_each_entry loop, but instead of > passing it a constant timeout you'd pass the remaining time. > > Get the current time before and after each pci_dev_wait() call > from "jiffies", calculate the difference, convert to msecs with > jiffies_to_msecs() and subtract from the "timeout" parameter > passed in by the caller, then simply pass "timeout" to each > pci_dev_wait() call. Thanks for your proposal, which can avoid doing duplicated things as pci_dev_wait(). If so, I also want to align the polling things mentioned in the question from Alex, since pci_dev_wait() is also used for reset functions other than SBR. To Bjorn, Alex, Lucas, how do you think if we need to change the polling in pci_dev_wait() to 20ms intervals, or keep binary exponential back-off with probable unexpected extra timeout delay. > > As a side note, traversing the bus list normally requires > holding the pci_bus_sem for reading. But it's probably unlikely > that devices are added/removed concurrently to a bus reset > and we're doing it wrong pretty much everywhere in the > PCI reset code, so... Yeah... I think that is why I saw different coding there. I would prefer a separate thread for estimating which ones are real risks. > > (I fixed up one of the reset functions with 10791141a6cf, > but plenty of others remain...) > > Thanks, > > Lukas