From patchwork Tue Apr 10 23:57:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Kan X-Patchwork-Id: 10334663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A041A601A0 for ; Tue, 10 Apr 2018 23:57:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 825671FE8B for ; Tue, 10 Apr 2018 23:57:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7538320453; Tue, 10 Apr 2018 23:57:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7A431FE8B for ; Tue, 10 Apr 2018 23:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=cNTMf71vIwtdq2ULRKRZGFZt87V79BqYI3HXC6Pi9RA=; b=ZEx ROknJiTAgK9ZrTrNZ1vj3rUj4GvMke1meJr1KctTAqidWHQzYnAeT2dQvJG9LMOHmbJchThE9ES0j O+wBfidIgLtDMEQOyaJMTTXKWHmt/ly5iaCptZKnx88+Mxv00gScWdpgp3RzADPnCYXgo/LDDFS4o +dChteBUhp5vZlAki3i6i6CpWD3NdFfSN805Av+YlSOBVzP2iU9LyUlIHE8FT4Vmg2N85/6427gze 9gIxBYN+USB7rrYk01MxKy/PAK86dXRDZQ/ApCm1g9RXDfZraSJ8OredjH2Qluo4BWRC2OLnnGAv8 1UBZZjlYsHIVDUuZpL2Xx27ZrMLh2Yg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f638p-0006TV-Gx; Tue, 10 Apr 2018 23:57:35 +0000 Received: from mail-qt0-x231.google.com ([2607:f8b0:400d:c0d::231]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f638n-0006Ro-0J for linux-arm-kernel@lists.infradead.org; Tue, 10 Apr 2018 23:57:34 +0000 Received: by mail-qt0-x231.google.com with SMTP id j3so37045qtn.9 for ; Tue, 10 Apr 2018 16:57:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=5dWlf2EtYoe0gri7cW1DwUUiVodAVWCNu2bnQYpvg4g=; b=SQbtaPrFXZ8srEtCMq+6uAWL/RM4phDT2oloTqm/m86qq5E2jlI4QG/4/eELjA4M3Y 9/SlzMdfvGdXIdQOywNFfhzhQr1Z/r2+a4YEMiksIUmsJqWW/riLcvyxUa00RAZEWALx PfrWAPGFkqG1d7Q4DdKWtLjr3gzyWL4ZRV13U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=5dWlf2EtYoe0gri7cW1DwUUiVodAVWCNu2bnQYpvg4g=; b=s0Ru1Q2xnqxsv0J9XyxpblZaybNNIFXxIosk+7LR07kg51q9V+uu+wR+E+nSsIklhV gK3YtAh+PS8mJLCDuFsJWqqEXUBFhBn3S4PO1wUBkYdgUVJ8266yHNg4nRoO/EMlJSm8 Ik6t7vrtv3IcFi0p+MWLNfPKFJ3XkJ250xFmc6f2S7GnfA/iF8xbl+SbtGX6Sd7/HGgF ML+e+6EU3zmd0BnFDHFOm3wG1wlvn4s//CbFNMllZOsthMg5Hj/8ehjr6xWdgaTJyaZ9 OCaWz3k8xOykESBBd60BwEgYYVhkdsH9h/MA/8RB3Q9mq57ZuxBZZTpCrZ3QBzKDQtIV i5RA== X-Gm-Message-State: ALQs6tBHiytIGlnZKXwKDowcEcDyEByRIGSj1TsKr3IJTw5TwjbEvdQP 5siW7mOIrJ7jQrF/9PgfT8Papg== X-Google-Smtp-Source: AIpwx4/C4oEhOl19kXfHVbnaXceOstBP40hPzhEzOTgHVWvGeO5w5LfVUrSYl3PJQYi8YjvnvUZs5g== X-Received: by 10.200.82.87 with SMTP id y23mr4101697qtn.89.1523404641319; Tue, 10 Apr 2018 16:57:21 -0700 (PDT) Received: from goldengate.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id d1sm12865qkc.4.2018.04.10.16.57.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Apr 2018 16:57:20 -0700 (PDT) From: Feng Kan To: rjw@rjwysocki.net, linux-pm@vger.kernel.org, lorenzo.pieralisi@arm.com, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, bhelgaas@google.com, gregkh@linuxfoundation.org Subject: [PATCH V4] PM / core: fix deferred probe breaking suspend resume order Date: Tue, 10 Apr 2018 16:57:06 -0700 Message-Id: <1523404626-1466-1-git-send-email-fkan@apm.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_165733_050393_7C5932B0 X-CRM114-Status: GOOD ( 16.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Feng Kan , Toan Le MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When bridge and its endpoint is enumerated the devices are added to the dpm list. Afterward, the bridge defers probe when IOMMU is not ready. This causes the bridge to be moved to the end of the dpm list when deferred probe kicks in. The order of the dpm list for bridge and endpoint is reversed. Add reordering code to move the bridge and its children and consumers to the end of the pm list so the order for suspend and resume is not altered. The code also move device and its children and consumers to the tail of device_kset list if it is registered. Signed-off-by: Feng Kan Signed-off-by: Toan Le --- V4: 1. additional comment change from Rafael V3: 1. additional code comment changes V2: 1. change patch title from "move device and its children..." 2. move define based on Bjorn's comment 3. rename function name and comment content drivers/base/base.h | 3 +++ drivers/base/core.c | 20 ++++++++++++++++++++ drivers/base/dd.c | 4 +--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index d800de6..a75c302 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -161,3 +161,6 @@ static inline void module_remove_driver(struct device_driver *drv) { } extern void device_links_no_driver(struct device *dev); extern bool device_links_busy(struct device *dev); extern void device_links_unbind_consumers(struct device *dev); + +/* device pm support */ +void device_pm_move_to_tail(struct device *dev); diff --git a/drivers/base/core.c b/drivers/base/core.c index 110230d..eaa5d9f 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -148,6 +148,26 @@ static int device_reorder_to_tail(struct device *dev, void *not_used) } /** + * device_pm_move_to_tail - Move set of devices to the end of device lists + * @dev: Device to move + * + * This is a device_reorder_to_tail() wrapper taking the requisite locks. + * + * It moves the @dev along with all of its children and all of its consumers + * to the ends of the device_kset and dpm_list, recursively. + */ +void device_pm_move_to_tail(struct device *dev) +{ + int idx; + + idx = device_links_read_lock(); + device_pm_lock(); + device_reorder_to_tail(dev, NULL); + device_pm_unlock(); + device_links_read_unlock(idx); +} + +/** * device_link_add - Create a link between two devices. * @consumer: Consumer end of the link. * @supplier: Supplier end of the link. diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 2c964f5..96fab29 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -123,9 +123,7 @@ static void deferred_probe_work_func(struct work_struct *work) * the list is a good order for suspend but deferred * probe makes that very unsafe. */ - device_pm_lock(); - device_pm_move_last(dev); - device_pm_unlock(); + device_pm_move_to_tail(dev); dev_dbg(dev, "Retrying from deferred list\n"); if (initcall_debug && !initcalls_done)