From patchwork Thu Mar 1 22:15:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Kan X-Patchwork-Id: 10252685 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 367E36037D for ; Thu, 1 Mar 2018 22:15:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24B0228688 for ; Thu, 1 Mar 2018 22:15:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18AD328695; Thu, 1 Mar 2018 22:15:28 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DFE128685 for ; Thu, 1 Mar 2018 22:15:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162498AbeCAWPZ (ORCPT ); Thu, 1 Mar 2018 17:15:25 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:45106 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162460AbeCAWPY (ORCPT ); Thu, 1 Mar 2018 17:15:24 -0500 Received: by mail-pf0-f174.google.com with SMTP id h19so2199494pfd.12 for ; Thu, 01 Mar 2018 14:15:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=R4KtbEzLfjfOlJDSKEGXOg4uvXqWDrOZ8UuAkSt2tpo=; b=HXh2Uh1IOzfXpoGOc78bs3QK0i9x1+/OMrnexbT3UE/wxDwQtaiX4fjagffBED0rm4 i+16/LkS1KvFgkq52xg5biVe5XOFPLD6eUJFezpfPywwkCZXaP+MYCfc6Fv6EaH2XH2A 3rDYOtMNf/NKZeHhFMSUVXG+vmkz8z8z/VSxk= 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=R4KtbEzLfjfOlJDSKEGXOg4uvXqWDrOZ8UuAkSt2tpo=; b=JqqrJ6QN57qoW9aga6M5Ccj/HsKZ5+QG/FxSVAu6GMSKPaaYa/Tatqo4D4gey1AjgP hIK9bcWQHFnrFS2Ee8NTQh7Rcc9kOm0588OxpMBao+fg/3a+UKcrOW0yrxlMcrdNvlbo LRhNOvkB2zyehpp+cqGDdiMitg+03bMEqwlSH5uAyM2TCTbZEg7+eRDdSYGRiON3BFox ayliovlFBjMjZr40kmw7bskTrULv7CKUFVu7Mw4iVkrkB57p67TtquIiDasORlTXSUQB 2Gl5jwdD8CA2eIEax4PhIMb0br7594IgKp8xOAT3LL4ZYuX2YzuLS1nLxN+Y4Xta1UjL XK0g== X-Gm-Message-State: APf1xPA/PJmebDrHuRr81DTBKhuXsDYG+yDGi15ihripe+BydXhlFEeW UVVxjvHss9gt+kemPezcN4JUAQ== X-Google-Smtp-Source: AG47ELuNugAlyZnra32KhshCaS+mudZlbq1xViG7UBUgqzQ9G/8evV4ijNBPf/CVkhEhlnMcflddXA== X-Received: by 10.101.90.75 with SMTP id z11mr2727915pgs.29.1519942523542; Thu, 01 Mar 2018 14:15:23 -0800 (PST) Received: from goldengate.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id b8sm10189926pff.31.2018.03.01.14.15.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 14:15:22 -0800 (PST) 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 Cc: Feng Kan , Toan Le Subject: [PATCH V2] PM / core: fix deferred probe breaking suspend resume order Date: Thu, 1 Mar 2018 14:15:14 -0800 Message-Id: <1519942514-3350-1-git-send-email-fkan@apm.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.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 --- 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 | 22 ++++++++++++++++++++++ drivers/base/dd.c | 8 ++++---- 3 files changed, 29 insertions(+), 4 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..0a0756b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -148,6 +148,28 @@ static int device_reorder_to_tail(struct device *dev, void *not_used) } /** + * device_pm_move_to_tail - move device and its children and consumers to end of + * pm and device kset list + * @dev: current device pointer + * + * This is a lock held version of the device_reorder_to_tail. Function checks + * if the device is registered and moves it to the end of device_kset list. Also + * if the device is pm initialized, move the device to the end of the pm list. + * Then the function iterate through the children and device link consumers to + * do the same for each found. + */ +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..7e9d1ef 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -121,11 +121,11 @@ static void deferred_probe_work_func(struct work_struct *work) * Force the device to the end of the dpm_list since * the PM code assumes that the order we add things to * the list is a good order for suspend but deferred - * probe makes that very unsafe. + * probe makes that very unsafe. Move any children and + * consumers belong to the device to the end of the list. + * This way the suspend resume order won't be corrupted. */ - 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)