From patchwork Wed Feb 28 18:45:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Kan X-Patchwork-Id: 10249339 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 8511760384 for ; Wed, 28 Feb 2018 18:46:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7669728E52 for ; Wed, 28 Feb 2018 18:46:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A94128E5A; Wed, 28 Feb 2018 18:46:33 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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 E201A28E52 for ; Wed, 28 Feb 2018 18:46:32 +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=KIO2mjdRxVLII+JFmE6mV+SJoqPn0fCVKwhBG1tfRhI=; b=c3S oxYxmVPRYXr6uvdrP/B+U5xx4MCVgjWRN51XE639H116jb+E9eKR5Qa4OPCJG2LMN6aNzdyxr3olo QIJYmeCLZzPUtDpEcASAsk7iyfpyQXV0ijfsc3MF5QNXDgAKo5E7U7bc7rbJ7kn+oajDyRmqpzO12 WnEo2z6HFBR12Xnk3vQFzIM2L/q0wwrgAeDz1993tZo/Bj2Ss/MC964xl19zWDOVUfWb9AbjIbJuP jM255md2b16l0hZu5gncdvg0JG/fBETOsjUQOibbeJ0RJptzFQUpEgxrPzSLOv6KzCCgkc3GrLtD4 2uVDEfeMG/jWiMByT1LdtEU7jZ2W02Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1er6kF-0006jL-Gn; Wed, 28 Feb 2018 18:46:27 +0000 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1er6kB-0006eH-TI for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2018 18:46:25 +0000 Received: by mail-pl0-x243.google.com with SMTP id ay8-v6so2044181plb.4 for ; Wed, 28 Feb 2018 10:46:12 -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=KJ1PLUv7XKSZTn423lWgv7nwMV3GYF0QgL+EOVznF5s=; b=nEY7X/LbYFwWvJipWUaLg1dlyYWWiVQgdENii4M+bdTUf50hB0ojNXJD/W49EK6W7q FFAULcVrDE2LlwtjAW7/3B6lcaIDl4de8ofAwqJcFU9+/o0IRfZPWAbFuV9X83Gyk/2s Xg8kjPXUfP29hwdXlrKQ/cy2v68HvqHH7VPIs= 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=KJ1PLUv7XKSZTn423lWgv7nwMV3GYF0QgL+EOVznF5s=; b=SclZHj6QLtleP4VZY5WKPnqXPtmb8izj8JLchqeNfnILJAcAXaTHZNrhFvvU+dPSaW iBo0jttetEJZdKm3yfnKBGROMvDpfL1uTeX1+s4KPh5nQ+dV7cvCOE6BRA3ty8CePjt6 Ql9adIRMF9wYEUXDQ+5CYWClB1f0jmqz9qVpr7kaY2MRAINC+aOzyiw4kcDusUS8jbXr 1uFbaQMbj/B5Gj3QlXq1Ij33EsCSubiac33C+C2byxzNHYnxhzF7qQ3NZqAq63UhY0NZ QMzGkUHUGsfZ88T9mMODuw8GcMo2vCSJtTjnRQC2QKRO5cI1Ydzf/94ryG+LeN0fOKYG 0FOg== X-Gm-Message-State: APf1xPCiTk5w979q81761xbmq3Dj2xHtsonWXjXk8ryLw9PLb2CowEOw PYcmrmi1vNhGYwqbEWoMOe7CRDUU X-Google-Smtp-Source: AG47ELvIJlN1A+iUF5QPZ8CwS3Bu6kftGZ9NMGJR3+kSyRSo/5VNSOvlmLADfp4iWwsAsW7gLCFang== X-Received: by 2002:a17:902:2cc1:: with SMTP id n59-v6mr6185346plb.215.1519843572074; Wed, 28 Feb 2018 10:46:12 -0800 (PST) Received: from goldengate.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id 14sm5491096pfi.132.2018.02.28.10.46.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 28 Feb 2018 10:46:10 -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 Subject: [PATCH] PM / core: move device and its children to end of dpm list Date: Wed, 28 Feb 2018 10:45:55 -0800 Message-Id: <1519843555-982-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-20180228_104624_023888_CD81E761 X-CRM114-Status: GOOD ( 16.99 ) 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 enumated 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 re-position the bridge and its children so the order for suspend and resume is not altered. Signed-off-by: Feng Kan Signed-off-by: Toan Le --- drivers/base/core.c | 20 ++++++++++++++++++++ drivers/base/dd.c | 8 ++++---- include/linux/device.h | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 110230d..0b4ad99 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_reorder - reorder device and its children to end of dpm list + * @dev: current device pointer + * + * This is a lock held version of reordering the device to dpm list tail. + * This will move the device to the end of the dpm list if it not registered. + * Afterward, it will iterate through its children and do the same for them. + */ +void device_pm_reorder(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); +} +EXPORT_SYMBOL_GPL(device_pm_reorder); + +/** * 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..3223a30 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. Also move any children + * belong to the device to the end of the list as well. + * This way the suspend resume order won't be corrupted. */ - device_pm_lock(); - device_pm_move_last(dev); - device_pm_unlock(); + device_pm_reorder(dev); dev_dbg(dev, "Retrying from deferred list\n"); if (initcall_debug && !initcalls_done) diff --git a/include/linux/device.h b/include/linux/device.h index 9d32000..1ec12d5 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -1272,6 +1272,9 @@ extern void devm_device_remove_group(struct device *dev, /* debugging and troubleshooting/diagnostic helpers. */ extern const char *dev_driver_string(const struct device *dev); +/* reorder device and its children to end of dpm list */ +void device_pm_reorder(struct device *dev); + /* Device links interface. */ struct device_link *device_link_add(struct device *consumer, struct device *supplier, u32 flags);