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: 896988 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=apm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=apm.com header.i=@apm.com header.b="SQbtaPrF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40LPH93qLCz9s1p for ; Wed, 11 Apr 2018 09:57:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752091AbeDJX5X (ORCPT ); Tue, 10 Apr 2018 19:57:23 -0400 Received: from mail-qt0-f172.google.com ([209.85.216.172]:40323 "EHLO mail-qt0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751888AbeDJX5W (ORCPT ); Tue, 10 Apr 2018 19:57:22 -0400 Received: by mail-qt0-f172.google.com with SMTP id g5so39588qth.7 for ; Tue, 10 Apr 2018 16:57:21 -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=nOv2CgKAoM6Fz/Qgu6SPxP8iG/C9M2rijm93MOh3b7dFqdG88Yfx33froYxYSHzHSr 8xGlB2WPy0JNFkNBKUD9l/loxTKC0qVfu+EkMtFDYCVGN2zP50nzpPxJOCfb0VytN7QR QQRnUrT5mvluOOwNee4es4u+htGgwRiHslAjyhUfJLZCwybRWLuQBXBQGL2lbjtqeep+ ZL9i0jp8yJiXgDbt21hkmwxkxEnllsPSxiS8GGr9wBQXRP9C9VsfCa6I6s9fNTugIFWY 8QiXgPj5aFX+R3+UPqCHbA3xMakkmXqfOqu0RtQ10usVl+e3y8Zb9FtZ6/77upKAvQPI IOzw== X-Gm-Message-State: ALQs6tAAO4zS+HEPKhLoc2h3sfqtKwsGsXVMCrr2z9yCeE4FX9TaZAIV 6Y6cu6vjk5gq2gKaw/KM2pjjZA== 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 Cc: Feng Kan , Toan Le 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 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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)