Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp365043imm; Wed, 13 Jun 2018 01:29:29 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLpxIc4SojcXpmNOFXcMHsvfzV/HjXjcISFtQm06ad9+BY2/F9BY2oGvZ2QoYuq9IXW0H7R X-Received: by 2002:a65:6504:: with SMTP id x4-v6mr3293534pgv.131.1528878569457; Wed, 13 Jun 2018 01:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528878569; cv=none; d=google.com; s=arc-20160816; b=mPbxlw7OYQr8LlHN+9L6LwKQBn79zXYLofBdT8D7IbJ1h0GRwAfyE03+csqzPGIbbq VaT4SftJAXXCeyvCVaZ3n3SJfe3YezPbccsu+MCaRSic4V6xYvVlwPPDlaX/FXiGrwjO 16X7W9LxW02odOMKHAJKhNIpUw3AePoP+SUgSHjm7jEGcYvQmNJyTyfQQTT27yoCSchk OM62HFg0Lj3daiackdg1HcS7MSMhArRptemOe9EJtbK9aUHOpmFgAiGF79pjgpkMftL7 9zZCUK/krrSWCPRaXW2jPBDECH2Bzt6bGWsDuvEO4Xpxv8MatpevG+pJ2HOmS6mZDTUT kTsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=vc/i/AStmo3DGi6ZL6Ca59tVZ1HFO5WT16lYw7Izu28=; b=xIp5dLtGD9HxIdaV2vtPmQyc2sFbYEz0biQSea9Vu7aeOFKSxuqked7h3X97/gsHuU Dx41mgAdPJ/ficGeExtiSBlu8dhtq06+RK4fVm3RlvwWCSuNRfY+r81S8iDStijlO0gC FMjcTgA6esePbnyPIDm1pS4I5xEeaYSgNuMuJ2QrNJSa9RfM3bQzniWWcU1tOIOqdhUV WbPGq7Gz4FJvVyqpDn7x+3OLlQrM6svYQLneZ8TOWw9WkT2Y1+Yb6GbsALKadaGUkmZo r26ibODFU7hKYP8bzhF/Nu7HCHfqRTXPGJPUuwKJ3ocnf3HBhvwcXcIlT4I8D6sMnAAo bSDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NdDBvB6M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 3-v6si2284173plp.515.2018.06.13.01.29.14; Wed, 13 Jun 2018 01:29:29 -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; dkim=pass header.i=@linaro.org header.s=google header.b=NdDBvB6M; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934925AbeFMI2P (ORCPT + 99 others); Wed, 13 Jun 2018 04:28:15 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:39482 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933912AbeFMI2N (ORCPT ); Wed, 13 Jun 2018 04:28:13 -0400 Received: by mail-io0-f195.google.com with SMTP id f1-v6so2561242ioh.6 for ; Wed, 13 Jun 2018 01:28:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vc/i/AStmo3DGi6ZL6Ca59tVZ1HFO5WT16lYw7Izu28=; b=NdDBvB6MJ0oOGSUFvyMzXp6bVv2AXkd757dC2UTOYqmy+om6YTCGoQUpwRK7NzdVuT 9gUpBUNL7cjLoQW66W/vZZb8iH5NSqe321tLbAwWT4jtZ/vATsoAshv1rLALSSDJSJ2B gDjy0UrXCY4to1QD4PdqQdUAp8wVMWVGzMGnw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vc/i/AStmo3DGi6ZL6Ca59tVZ1HFO5WT16lYw7Izu28=; b=uRde2/Gat1YCZywBvBSXpWKZCyXFV+rRZD8zL9EreYHf521uuNqOvG4xlC2nUyrmpO Tk1LEV0zUlbVzpDTkyPBeMpJMltY6/i5SPPUEKFaPY7UpyaNGwPQT3uYmmB4qByNVlsH g0TN0pLNFUyZNiqcrsudEP1zhN5KIFZiu6mjT9RGnpezQo/3NBsQAww+W39x750VdjcD fFMAIuHEKOwF92e8Hy2rM/gfegc2XVqbcROK7V7Oq4e/+6gJNQRZUqfwEJHr76JrMN0r RT4F4aKWakHAxCK/2XaT35eMYSxTgJu/VVGpSXxxzxLCIe7szEFLkCBBaZrHuKBesvtH tMgQ== X-Gm-Message-State: APt69E20Y3aUw2B18nUUTRc9sxglT8EEbL++y1phoQtf0Anzzp2uJyy3 uk12s2oo76otAwMB1dtp4N0ZyDGYGbkkxS7ikHIq1A== X-Received: by 2002:a6b:c986:: with SMTP id z128-v6mr3897489iof.266.1528878492373; Wed, 13 Jun 2018 01:28:12 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:c054:0:0:0:0:0 with HTTP; Wed, 13 Jun 2018 01:28:11 -0700 (PDT) In-Reply-To: <1692795.7GA92aXxMT@aspire.rjw.lan> References: <10125310.W3e2TP0641@aspire.rjw.lan> <20180612124424eucas1p101e61369a42132234d103ce52918b08e~3akoRUwbQ3138731387eucas1p17@eucas1p1.samsung.com> <1692795.7GA92aXxMT@aspire.rjw.lan> From: Ulf Hansson Date: Wed, 13 Jun 2018 10:28:11 +0200 Message-ID: Subject: Re: [PATCH] PM / core: Fix supplier device runtime PM usage counter imbalance To: "Rafael J. Wysocki" Cc: Marek Szyprowski , Linux PM , LKML , Greg Kroah-Hartman , Lukas Wunner , Bartlomiej Zolnierkiewicz , Jon Hunter Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [...] > --- > From: Rafael J. Wysocki > Subject: [PATCH v2] PM / core: Fix supplier device runtime PM usage counter imbalance > > 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 are > expected to pass DL_FLAG_RPM_ACTIVE in flags to it anyway, but > additionally resume the supplier if the link is added during > consumer driver probe to retain the existing behavior for the > callers depending on it. > > Fixes: 21d5c57b3726 (PM / runtime: Use device links) > Reported-by: Ulf Hansson > Signed-off-by: Rafael J. Wysocki Reviewed-by: Ulf Hansson Kind regards Uffe > --- > drivers/base/core.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 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; > @@ -235,12 +242,12 @@ struct device_link *device_link_add(stru > 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(). > + * Some callers expect the link creation during > + * consumer driver probe to resume the supplier > + * even without DL_FLAG_RPM_ACTIVE. > */ > if (flags & DL_FLAG_PM_RUNTIME) > - pm_runtime_get_sync(supplier); > + pm_runtime_resume(supplier); > > link->status = DL_STATE_CONSUMER_PROBE; > break; >