Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5181479imm; Tue, 12 Jun 2018 04:02:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKghvgkL7CtOVypHk0RpgoPTGv5lGhqhkp9z+fiI7vIuovGvxNUCMycsev0GPEd4IUEZXJn X-Received: by 2002:a65:6491:: with SMTP id e17-v6mr2841150pgv.44.1528801365507; Tue, 12 Jun 2018 04:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528801365; cv=none; d=google.com; s=arc-20160816; b=gAkH5FpzOxWEiS7himY4dmoqzSJMAe+EO8BqpWi4UVrpvuisSsxfN+qmshxmcMHuvz Zroe9fbpvQwhKeRCdk9fEh6St5zwiW6UIiwjgfIaiYPgHzHC68iwWaHHYczUMZ7c8kvA Jg99Frk1ghnzBev3bSgGbvGRsLSPN6Wp9IlfeiBFSCkn0vhD5bv5XUTqmWvIZKCuza97 4tXL3Y5B2YAUA7bkb4rlAhTov4Hje/hn+Y6dAodCwN76hRePqKF7Wd0byqT5ScMEvboA fWnVBkxajOFdaxr/goVLHDS+sTanF4HhboR9zis1YeUzdLpwsXL/PiWVAcz/vves1kJX wOYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=qEg6McSGkFXpYhGLf5BYCnKukPo2F+S8hE+ufLjFetA=; b=drfXq+t7PzIh9Vj/01AMf6IMsTwlVwDnwKrpYow9Q6Dp6gLfI10p3TIOVSnRyO9T6y 0BRnMDDRHIeMGX7UnkDB9H9EhsAD1+UPqem8to0mfnV2PzvIgIDL/DQbrMtke2JGU5YF aFalpXKmqy2oYcjCuM0mcaXToxQdTnBC8Nm0CNMegEJj4bRplmSg8RTOX4YCYZpj5fbE NjaGJh8a3FEnzEDszJYBQ3r2Ur8WdxVwygBCa7DvFGBURrZ1jziQWkIQw8r9+Ja3iO9i 6xLzquRGt+iLoquErGakyphFGAhClknCZz71kkArF+KksjvR/K/nSQ5r6GqxnOT2wGjB 8rhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z14-v6si555346pgr.62.2018.06.12.04.02.31; Tue, 12 Jun 2018 04:02:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932627AbeFLLBY (ORCPT + 99 others); Tue, 12 Jun 2018 07:01:24 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:56247 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932286AbeFLLBX (ORCPT ); Tue, 12 Jun 2018 07:01:23 -0400 Received: from 79.184.255.56.ipv4.supernova.orange.pl (79.184.255.56) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83) id 57f6f2dc109e2e6c; Tue, 12 Jun 2018 13:01:21 +0200 From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Greg Kroah-Hartman , Ulf Hansson , Lukas Wunner , Marek Szyprowski , Bartlomiej Zolnierkiewicz , Jon Hunter Subject: [PATCH] PM / core: Fix supplier device runtime PM usage counter imbalance Date: Tue, 12 Jun 2018 13:00:20 +0200 Message-ID: <10125310.W3e2TP0641@aspire.rjw.lan> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki If a device link is added via device_link_add() by the driver of the link's consumer device, the supplier's runtime PM usage counter is going to be dropped by the pm_runtime_put_suppliers() call in driver_probe_device(). However, in that case it is not incremented unless the supplier driver is already present and the link is not stateless. That leads to a runtime PM usage counter imbalance for the supplier device in a few cases. To prevent that from happening, bump up the supplier runtime PM usage counter in device_link_add() for all links with the DL_FLAG_PM_RUNTIME flag set that are added at the consumer probe time. Use pm_runtime_get_noresume() for that as the callers of device_link_add() who want the supplier to be resumed by it should pass DL_FLAG_RPM_ACTIVE in flags to it anyway. Fixes: 21d5c57b3726 (PM / runtime: Use device links) Reported-by: Ulf Hansson Signed-off-by: Rafael J. Wysocki --- This is a replacement for commit 1e8378619841 (PM / runtime: Fixup reference counting of device link suppliers at probe) that is going to be reverted. --- drivers/base/core.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) Index: linux-pm/drivers/base/core.c =================================================================== --- linux-pm.orig/drivers/base/core.c +++ linux-pm/drivers/base/core.c @@ -216,6 +216,13 @@ struct device_link *device_link_add(stru link->rpm_active = true; } pm_runtime_new_link(consumer); + /* + * If the link is being added by the consumer driver at probe + * time, balance the decrementation of the supplier's runtime PM + * usage counter after consumer probe in driver_probe_device(). + */ + if (consumer->links.status == DL_DEV_PROBING) + pm_runtime_get_noresume(supplier); } get_device(supplier); link->supplier = supplier; @@ -234,14 +241,6 @@ struct device_link *device_link_add(stru case DL_DEV_DRIVER_BOUND: switch (consumer->links.status) { case DL_DEV_PROBING: - /* - * Balance the decrementation of the supplier's - * runtime PM usage counter after consumer probe - * in driver_probe_device(). - */ - if (flags & DL_FLAG_PM_RUNTIME) - pm_runtime_get_sync(supplier); - link->status = DL_STATE_CONSUMER_PROBE; break; case DL_DEV_DRIVER_BOUND: