Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4353417imj; Tue, 12 Feb 2019 14:29:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IaRT4QaRMv316X6dWyIbDlOEVR5tCWAa/hhjqEYwQXoG80juGCg/788KrYfINOkdeGwKkQV X-Received: by 2002:a62:4851:: with SMTP id v78mr6211091pfa.97.1550010576653; Tue, 12 Feb 2019 14:29:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550010576; cv=none; d=google.com; s=arc-20160816; b=05xCAHcrWSga0aURRDzLWH7gc3oRZjoVEuFVL9XtIBvULi6c+OErDV5oIWNofce2l3 3iDjOW5BLS30SNUq9crGsSaO3YYJDhxl5jW2I4n+UbMiQaayPK0dgSOFrwJucyNWW21a rAAfAdAj+YTIMBxDzvnuWoTboU0VPvqpqpDsh1FfTv8KL61ZZ+p7xRsHI3Q3bluKQn0V ferc0hineEQU8WSIv6MItrgpqyhV9VYciJdvWPMdNBIExYU7AL5NakKjLOdgVe1/KteY SYrBTfDpLGnEMovQp0IthsjvLgCOqbH4hG2Q1gNbXA6GyaHDuB5k8bwn4PHsXM8lK8Ky UCPA== 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 :in-reply-to:references:mime-version; bh=jDaMSUbMNhVugdtyN/BMqr5213ZsUOAvkEukBy+CMpw=; b=NT5NJ4QAzX1RnDinOgN8j7qRixGaCnDQOWpYUC2oBgTUiIWYWoqhWLA3AxCNMRb1U2 zSVPqbn0+h622d6evLX7FX6kG1P5cvAMUIJsmD5tq4gptGds0y3BxjEMonHcKPIVyJ2E GZ2w47iRUMVhvjLOIEip5fnLlrcvNiwGqdT7zui7XZ14fFGqa8ZnaOP54yJc9dpWfoms xjiBBASIEU5we0PeVpGygLNSd+RmBedWkM0wxCNbG89nDo7eSEOq6E+xHfDUq5oYC13g 91pyJ+yLscyaJp9b1vrUqI3/cggDdTpDdWaANVpZWzQpocrqTnjmlllmvy8k4UibLopO Ggew== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q202si8113183pgq.194.2019.02.12.14.29.21; Tue, 12 Feb 2019 14:29:36 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732516AbfBLWJE (ORCPT + 99 others); Tue, 12 Feb 2019 17:09:04 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:33108 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732135AbfBLWJD (ORCPT ); Tue, 12 Feb 2019 17:09:03 -0500 Received: by mail-ot1-f66.google.com with SMTP id i20so564285otl.0; Tue, 12 Feb 2019 14:09:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jDaMSUbMNhVugdtyN/BMqr5213ZsUOAvkEukBy+CMpw=; b=qRfKF2mxXcJF9jvSqIwuSftqA8LSM+kl/c4nf0vodKAO6k5PJgJN9M8mTshHwwp8/h XHTe4jdMnPavkuEpM5/jX6f/WchOZOMeJRxc7Ls6Utesbcad2phFliYYoK/kRVWvKTGA 55YbN4scwghN/CtxJeYZyDZvKh4Oc+YHQKqXtahULoZjzeriCGu3n/jxFafR+jzkufo3 ARiTzN+VlhU12ec/NuPdOFGcN6PGc6HrjkyUOn7FGI4taYlDNo/TMin66Ue+K9T/0G+d 2feJRsRgR5HXfOP8G/dckEOi/7hQDBd7kLngyk6tkaNgo2NnuYwUJj0e3gLyVuWueyIC YpVw== X-Gm-Message-State: AHQUAuZYl9A4AulnX0+p4FOxmk+Da+kYjs6lO96WSjuABHihWdYdxiDD yZrdJa0VJiCb+PbAlalePW8dGMC1/p+U6tcMbz4= X-Received: by 2002:a9d:4c0f:: with SMTP id l15mr6289898otf.139.1550009342512; Tue, 12 Feb 2019 14:09:02 -0800 (PST) MIME-Version: 1.0 References: <5510642.nRbR3bcduN@aspire.rjw.lan> <9351473.C2nPJoyFsE@aspire.rjw.lan> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 12 Feb 2019 23:08:50 +0100 Message-ID: Subject: Re: [PATCH 2/2] driver core: Fix possible supplier PM-usage counter imbalance To: Ulf Hansson Cc: "Rafael J. Wysocki" , Greg Kroah-Hartman , LKML , Linux PM , Daniel Vetter , Lukas Wunner , Andrzej Hajda , Russell King - ARM Linux , Lucas Stach , Linus Walleij , Thierry Reding , Laurent Pinchart , Marek Szyprowski 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 On Tue, Feb 12, 2019 at 10:03 PM Ulf Hansson wrote: > > On Tue, 12 Feb 2019 at 13:10, Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki > > > > If a stateless device link to a certain supplier with > > DL_FLAG_PM_RUNTIME set in the flags is added and then removed by the > > consumer driver's probe callback, the supplier's PM-runtime usage > > counter will be nonzero after that which effectively causes the > > supplier to remain "always on" going forward. > > > > Namely, device_link_add() called to add the link invokes > > device_link_rpm_prepare() which notices that the consumer driver is > > probing, so it increments the supplier's PM-runtime usage counter > > with the assumption that the link will stay around until > > pm_runtime_put_suppliers() is called by driver_probe_device(), > > but if the link goes away before that point, the supplier's > > PM-runtime usage counter will remain nonzero. > > > > To prevent that from happening, first rework pm_runtime_get_suppliers() > > and pm_runtime_put_suppliers() to use the rpm_active refounts of device > > links and make the latter only drop rpm_active and the supplier's > > PM-runtime usage counter for each link by one, unless rpm_active is > > one already for it. Next, modify device_link_add() to bump up the > > new link's rpm_active refcount and the suppliers PM-runtime usage > > counter by two, to prevent pm_runtime_put_suppliers(), if it is > > called subsequently, from suspending the supplier prematurely (in > > case its PM-runtime usage counter goes down to 0 in there). > > > > Due to the way rpm_put_suppliers() works, this change does not > > affect runtime suspend of the consumer ends of new device links (or, > > generally, device links for which DL_FLAG_PM_RUNTIME has just been > > set). > > > > Fixes: e2f3cd831a28 ("driver core: Fix handling of runtime PM flags in device_link_add()") > > Reported-by: Ulf Hansson > > Signed-off-by: Rafael J. Wysocki > > I have tested a several various common probe sequences (including > error paths) by using my RPM test driver, no issues found. Of course > it also fixes the problem that occurred while deleting the device link > during ->probe(). Thanks a lot! > > Reviewed-by: Ulf Hansson > Tested-by: Ulf Hansson Thank you!