Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp478765ima; Wed, 6 Feb 2019 03:24:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IahfS6EKP2+9USeeNqcrqDvnvvURNZmMChf4SYQDchU9sO1I95mX9PVwSNWGvcS+AFNG/Sj X-Received: by 2002:a63:2315:: with SMTP id j21mr9213293pgj.297.1549452268798; Wed, 06 Feb 2019 03:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549452268; cv=none; d=google.com; s=arc-20160816; b=fRhnPXwMU4cMUg99FWveFPCu18hBy9kCQVo6W5wIW+mcYqwvc8uKQbPkJgHWZCmTD9 hIyn6tvGgij/b7iY5hC2dFGAxjfYYoKL7sM7KzrlXuljnWu4whQ+mw7vmaaaZrMiGlpE i2sPUDL+0+FAczqoTXhWUi2tFBWskUf8mAE0y/5I/KB3vK//eSGV4wC9qLEa/QgvMLEK w7FW5wYEcTQhRCRYGsX2byRLnGu2dr9POsRTnHteFG7H1u3GVFv+Eq6ECDkwdffUZzhL bOgs9F68gCjxZTJdy2ZatTaoZGG7/C6tPaeJhuYmIvCVOaaKjyYfYU1PDAXB+jiZtrnh uETg== 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:dkim-signature; bh=wBzByadEqtyMn00ZURP2kVUXxq2O5WTctd4wSpJkOdU=; b=0CEaNgDGlyuG3g6K0LcQF8+Ov0pIRPCmJTUeH1BSzzsWezyQLUUNkc/sCY/5H1L3Li 9OS5BSfY4WOXqP0xpes9yV+zrVhoNPoyYO8fZmBp7o5DW/spqNYOUf+TfVNJxSxsO0qE 020wy0JmdyiQw9+vgUF65BOTUM4bXz0OMetFJ9KHn7lUaml7Gtv6e338wRsbNlOTCtWo MwqRlCWR6ZD0x03dR1RJiks6ueYwcpjKYMfxQDToPzdSy3+s9PLf3IqfBjzovqChklf/ pFr9FlCbGlpfGVohF2s8X4c29c7nVlfrhzdYmtaExJs65T/KuY0y3AIMhiUkCv18Zq4k jorw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eXzgVVbq; 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 f63si6053891pfg.136.2019.02.06.03.24.13; Wed, 06 Feb 2019 03:24:28 -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; dkim=pass header.i=@linaro.org header.s=google header.b=eXzgVVbq; 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 S1729826AbfBFLYF (ORCPT + 99 others); Wed, 6 Feb 2019 06:24:05 -0500 Received: from mail-vs1-f68.google.com ([209.85.217.68]:37866 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728463AbfBFLYE (ORCPT ); Wed, 6 Feb 2019 06:24:04 -0500 Received: by mail-vs1-f68.google.com with SMTP id s16so2092039vsk.4 for ; Wed, 06 Feb 2019 03:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wBzByadEqtyMn00ZURP2kVUXxq2O5WTctd4wSpJkOdU=; b=eXzgVVbqFtp0EhOq+O7UFYWd97qgWwKv5P/m3TqKJdfUpQCEay+24mWymts+6wK7wH inov+kbzxG7Ar15hdVzbViEF9B0d8636C6gvt6Np0zCyUtnLnXW0iDySjNcMsgXpxZdW vxS5dmfN1W9a09ziKnOEpLEAcp7MIvJgKio5z5tVc7wkA/RVulo7ix873d5g6aQNte0Z yeYnCBzUJ9Ypge109F8i305iwkR61w6FIYbZRjkVKDe447nDiLof0KSfgdf75K72idLj irWZCyW+ZTRNpf8F84FaxTCtCsNq8rkxS5L4x6YSHnhXpf/gkiP1JRqefoDf0aJebzrh hhbg== 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=wBzByadEqtyMn00ZURP2kVUXxq2O5WTctd4wSpJkOdU=; b=FD1zdu06manf5K+Zdoyw4kU9znpoMpakOslsGW5MZZ/vF3oGgbTOJ0g77SiUFYqHsU joaZE9Twb22EPl2wHY8OiGVjC53xdZvIqfePM4NP+TN8Ke3XLA9RNvvWzahTN7Ib4AOq o2bXOcbVLdnosd+nIzthPqs2Ds7qLaYFCcT6xzZ8EfORljncKJK11JVEZ1MhMjrs267C 7U5MTijAvHoevRC6yGl++nNifZzuL1DHfHvNjx8qvedotbCrv717aeGt8S1rm9Fd/wr7 /ykNAJkoNHZknvXN2k3QkjhJ0Dm4n3jDzB14UjzRUx7LB5W8Gb5rUe/u/1qnCNzsZsAE BH4Q== X-Gm-Message-State: AHQUAuZY9iPtfvKcfam9eHBQnlN8wog0GBq0A8rzsM/jouHvrFpDtawV GM0F6GrgHnHSrJyDRz4dbB7rmoQswfM4UzstwkIAIA== X-Received: by 2002:a67:7685:: with SMTP id r127mr4076466vsc.35.1549452243118; Wed, 06 Feb 2019 03:24:03 -0800 (PST) MIME-Version: 1.0 References: <1952449.TVsm6CJCTy@aspire.rjw.lan> <24600564.pMaimVIQbW@aspire.rjw.lan> In-Reply-To: From: Ulf Hansson Date: Wed, 6 Feb 2019 12:23:26 +0100 Message-ID: Subject: Re: [PATCH v2 0/9] driver core: Fix some device links issues and add "consumer autoprobe" flag To: "Rafael J. Wysocki" 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 , Joerg Roedel 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 Wed, 6 Feb 2019 at 10:56, Rafael J. Wysocki wrote: > > On Tue, Feb 5, 2019 at 12:27 PM Rafael J. Wysocki wrote: > > > > On Tuesday, February 5, 2019 9:15:49 AM CET Ulf Hansson wrote: > > > On Mon, 4 Feb 2019 at 12:45, Rafael J. Wysocki wrote: > > > > > > > > On Mon, Feb 4, 2019 at 12:40 PM Rafael J. Wysocki wrote: > > > > > > > > > > On Fri, Feb 1, 2019 at 4:18 PM Ulf Hansson wrote: > > [cut] > > > > > > > > > For example, if the consumer device is suspended after the > > > > device_link_add() that incremented the supplier's PM-runtime count and > > > > then resumed again, the rpm_active refcount will be greater than one > > > > because of the last resume and not because of the initial link > > > > creation. In that case, dropping the supplier's PM-runtime count on > > > > link deletion may not work as expected. > > > > > > I see what your are saying and I must admit, by looking at the code, > > > that it has turned into being rather complicated. Assuming of good > > > reasons, of course. > > > > > > Anyway, I will play a little bit more with my tests to see what I can find out. > > > > > > > > > > > > Arguably, device_link_del() could be made automatically drop the > > > > > supplier's PM-runtime count by one if the link's rpm_active refcount > > > > > is not one, but there will be failing scenarios in that case too > > > > > AFAICS. > > > > > > Let's see. > > > > So for the record, below is the (untested) patch I'm thinking about. > > > > Having considered this for some time, I think that it would be better to > > try to drop the supplier's PM-runtime usage counter on link removal even if > > the link doesn't go away then. That would be more consistent at least IMO. > > So I can't convince myself that this is the case. > > Either way, if there are two callers of device_link_add() for one > consumer-supplier pair trying to add a stateless link between them and > one of these callers passes DL_FLAG_RPM_ACTIVE set in the flags to it, > there may be issues regardless of what device_link_del() and > device_link_remove() do. However, if they decrement the link's > rpm_active refcount (and possibly the supplier's PM-runtime usage > counter too), the supplier may be suspended prematurely, whereas in > the other case (no decrementation of rpm_active, which how the code > works after this series) it may just be prevented from suspending. To > me, the former is worse than the latter. Well, I would say it sucks in both cases. :-) > > Moreover, there is a workaround for the latter issue that seems to be > easy enough: it is sufficient to let the consumer runtime suspend > after calling device_link_add() to create the link (with > DL_FLAG_RPM_ACTIVE set) and before trying to remove it. I get your point, but unfortunate I don't think it's that simple. For example, someone (like a child) may prevent runtime suspend for the consumer. Hence, also the supplier is prevented from being runtime suspended. So, if you want to push this responsibility to the driver, then I think we need make __pm_runtime_set_status() to respect device links, similar to how it already deals with child/parents. In that way, the driver could call pm_runtime_set_suspended(), before dropping the device link in ->probe(), which would allow the supplier to also become runtime suspended. I did a quick research of users of device links, unless I am mistaken, this seems like an okay approach. What do you think? > > Because of the above, I'm just going to post a patch to document the > current behavior of the code as a known limitation. Let's not give up, yet, please. I am sure we can figure something out. Kind regards Uffe