Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp575551ima; Wed, 6 Feb 2019 05:06:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IbrvrFcDq+0XVvF3d3vCcade1gpQdijCVdXhCmU9XQgNUSmzbIq4eZUkM9z3kznIcTSRwA/ X-Received: by 2002:a62:35c7:: with SMTP id c190mr10710332pfa.76.1549458382370; Wed, 06 Feb 2019 05:06:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549458382; cv=none; d=google.com; s=arc-20160816; b=lE5zODgX8BzyRg4X64x/Li9qx61pWaunBjBiaZpzQFCKhrap7I5ypX+zZKg7/emgtt 1tdXwJZii2gUNDbDY5Whz24zanNLVKng7S4kj0TOa+mlSws5pNH8I79o0LZw7/SmuMbM 5U6qqI7W8kBvuKohL8Vg3NmGkbDi9br2s0+X2smZEg2AjxvOhc44DghpeFKGwCVgdbJS Th47mhhngfXMqoOWNcSjzBE+HCQzUrzRYUto/TuN2lZGBAuzrU/atztSN981b7kNxCeu oA88yifXSkxd4GVI9MlFecLa1LPn+JNu0xWKC8usj+wv3hNybNpLHAZX47aXDX6z12nO 8Pqw== 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=a6/1hWE3LIM2fJXOQZ2WMd+RZy3RSXMlCl61vcVVSPU=; b=uAKIo0bn9rUEO9xNHzak6kEFf9xl/kFPS+XunfiPdKKONFtf7Vgv5Gi5Kd04gVLNTR i/hYlK2BhpNb2xV+1PpDTTHFpeINc41dCz873hB4YgHYLGaq0wPQgK7VUAWmZQZmnKfQ OuU1T1SP1pKf/FrUmL8pQodNPjmgeNjgxb6cLx+QxFCrOBaOH+OSoMuMTP3mth1MuMDF sAXiz/tghxeLn9ArN+yzozh5EIMOEShoKQ83u4D8as1gUfd0rwAe5uz4bHMnIarDX7DI rLzNJ/0Vaoa2V/HKx1YfJaT9+D7hb6SihhB1z3LD96vaV62jtJGMOGKU+zpMw7R1ozyQ 1ZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="qy/QX56c"; 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 y7si988122pfn.152.2019.02.06.05.06.05; Wed, 06 Feb 2019 05:06:22 -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="qy/QX56c"; 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 S1729691AbfBFNCj (ORCPT + 99 others); Wed, 6 Feb 2019 08:02:39 -0500 Received: from mail-ua1-f65.google.com ([209.85.222.65]:46843 "EHLO mail-ua1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727644AbfBFNCj (ORCPT ); Wed, 6 Feb 2019 08:02:39 -0500 Received: by mail-ua1-f65.google.com with SMTP id v24so2196004uap.13 for ; Wed, 06 Feb 2019 05:02:38 -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=a6/1hWE3LIM2fJXOQZ2WMd+RZy3RSXMlCl61vcVVSPU=; b=qy/QX56cfGFCUD710ej++PJrJY/PpjMCeB8zN43WjiiNoTtWm+uWeH36WoN39x2MN4 xalrgBWnyqPdFYvGxdj7YS64WOaISMRMCNqAcb/n3CdRjmH4SegMzUusBBs5mLcBAV1z ypDyVamjHqFRUwKJWJxnotovtssblR0Wx4hr3gHcKUk/pbvWJiIDXjUnO2C9nJ+ahltA KOqN1jx2cW9X+4rmYk/Trk8UqxgXwuOh9epoq1R3MvHE7qRK4UhqnBjfFeQA1QPv0nW6 nYt+c40l9AqiyDw8Gp3V18R4Er4xQMkzEqVqGKhfYw5/2zmRzxSzyaQkffmbS3R9000+ t8Ag== 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=a6/1hWE3LIM2fJXOQZ2WMd+RZy3RSXMlCl61vcVVSPU=; b=Z6occRcvMT4Xg52D1frXcAbypEMDYEmCGy3koNF9V+7hwaQNumRlspKmIN+H/37YzE 8vtkl9FgFRYeNo9eKUgGzgvs4QBoLVoS3/eLADCsyIe4PXtavqC7AuoZjVcxjaZrNbTu LoOvsZFHL5m+XfrUJCU6lp6m2AzhMoFrPeJxlTpZVTt5dWUUKR2dcjwlnHv3uZOP2w3p 1viNig1GesVo8Nrwswwi2rEFh3/IW/kZhdoiO/2u049dzfCAUG2LE2LbHJVIbImXavI3 Lg7lYtQL+fDaEHtOJKw9LocOUQtFZKkJy9uYiIHI9QcWcb+XjD8UUlXp6KT1mBQLrPrc snHQ== X-Gm-Message-State: AHQUAuacyrSCA6nJuGP/Y+Q2V9eyggnKEKsQQwFwUkqDXnskl7OEneI3 NN2QXE7zKgN110Dap8CFObD3R6RyNKeC7VNJEhAPog== X-Received: by 2002:ab0:b83:: with SMTP id c3mr1983520uak.77.1549458157468; Wed, 06 Feb 2019 05:02:37 -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 14:02:00 +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 13:10, Rafael J. Wysocki wrote: > > On Wed, Feb 6, 2019 at 12:24 PM Ulf Hansson wrote: > > > > 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. > > Well, in that case the supplier should not be suspended until the > consumer can be suspended too. > > IOW, if you call device_link_del() in that case, it would be a bug if > it allowed the supplier suspend. Well, maybe the "child" was a bad example. The point is, the driver doesn't control the RPM child count and nor the RPM usage count for its consumer device - solely by itself. Someone, like the driver/PM core can at some point decide to increase the runtime PM usage count for example for the consumer device. For whatever good reason. > > > 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 guess you mean that runtime PM would be disabled for the consumer at > that point? Yes. Calling pm_runtime_set_suspended() should be a part of the error path in the driver, which includes disabling runtime PM as well (if it enabled it in the first place of course). > > > I did a quick research of users of device links, unless I am mistaken, > > this seems like an okay approach. > > > > What do you think? > > Well, I think I need to know the exact use case you have in mind. :-) The use case is simply a generic driver that fails to probe by returning -EPROBE_DEFER. So it's hypothetical, but I often tests common sequences by using my RPM testdriver, to make sure it all works as expected. The below sequence is common, so then I have added the use of device links, to see how this plays. And it doesn't. ->probe() ... pm_runtime_get_noresume() pm_runtime_set_active() pm_runtime_enable() ... device_link_add(con, supp, DL_FLAG_STATELESS |DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE); we got some errors... goto err: ... err: pm_runtime_put_noidle() pm_runtime_disable() pm_runtime_set_suspended() device_link_remove() return err; Kind regards Uffe