From patchwork Mon Mar 5 18:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Kan X-Patchwork-Id: 10259471 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 71BCF60365 for ; Mon, 5 Mar 2018 18:29:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 608E328824 for ; Mon, 5 Mar 2018 18:29:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54FAC28BC0; Mon, 5 Mar 2018 18:29:47 +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 D85C528BBF for ; Mon, 5 Mar 2018 18:29:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752519AbeCES3p (ORCPT ); Mon, 5 Mar 2018 13:29:45 -0500 Received: from mail-pl0-f43.google.com ([209.85.160.43]:43548 "EHLO mail-pl0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752508AbeCES3o (ORCPT ); Mon, 5 Mar 2018 13:29:44 -0500 Received: by mail-pl0-f43.google.com with SMTP id f23-v6so10162931plr.10 for ; Mon, 05 Mar 2018 10:29:44 -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=CXsgki8PaEPqhR4yH6FFhzROUlPjXxsfaE+UpZGGGG4=; b=Uky7DwoWOlluARJ0SbHBfL+E4Ytt5qhYvr+bRDLwG0n+zAsZOtc89C9Uwf1luXGNIn hYdQJZE7IgIusm4S2bSFLox06m62wi/8H/Waa7wsSsi+V/mmKMbxn7N97t5z9EcQRDcj 8YyV6T9Y9Mw7VZRrCOjtO/MfCYhPhEw5zoAXw= 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=CXsgki8PaEPqhR4yH6FFhzROUlPjXxsfaE+UpZGGGG4=; b=Zxcp5L8iJjocg5s4KqGK+9cFtEGtinInnSZWmAShUuNJJPE7qQ1dqpLGysAsDUQbQm mHwa2XOswoGK/MDt249dqNy1PB/I4UlKO8xs6egZUjidHpxpDDRgUTzhvA6borNfUHju w3UKeelIGi2zkMLoplEQ8GGAIWCsnCKpT995YMyiuqJq9xvkXn3U8iCZHdfnemv1H1Dx CA6dwg6Y6aJkh85mW92tlaH/D+ghxS8nF4GFQ7gkv51kdTnPJHU1HXOlzBz/PqbVanpO dzM8Tn41UNv/7CPn7wt07iFw1Wep0do5wSityFjBWDeOChFkvkmqc6qGRCiIdnYucZlo /slQ== X-Gm-Message-State: APf1xPB2kS3INBlNvg4Aml+yV6PYTbH/fdlcDuLcaOrjT0M4uh59UrUD WR3EIZGpxMq1qchkytzm2d9xYA== X-Google-Smtp-Source: AG47ELtsZKEU7RD11hMDloYjhcA5BYvzqirmHq67/hWPbyM53hnagbZjpJs3CEdv1HUd9WX6TWVBLw== X-Received: by 2002:a17:902:8501:: with SMTP id bj1-v6mr14313271plb.110.1520274583935; Mon, 05 Mar 2018 10:29:43 -0800 (PST) Received: from goldengate.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id o2sm21856271pgq.54.2018.03.05.10.29.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 10:29:42 -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, gregkh@linuxfoundation.org Cc: Feng Kan , Toan Le Subject: [PATCH V3] PM / core: fix deferred probe breaking suspend resume order Date: Mon, 5 Mar 2018 10:29:39 -0800 Message-Id: <1520274579-30492-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 --- 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..3b37906 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: current device pointer + * + * This is a device_reorder_to_tail() wrapper taking the requisite locks. + * + * It moves the device 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)