Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp522909ima; Wed, 6 Feb 2019 04:12:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IbXYlgOn0NvOaUXzwpAXlvTnQBSAZdgIkXgFnvJ8Lbj1iFNW8IdwsKAmfqTkU38CyzVDMuz X-Received: by 2002:a17:902:7882:: with SMTP id q2mr10618036pll.305.1549455141949; Wed, 06 Feb 2019 04:12:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549455141; cv=none; d=google.com; s=arc-20160816; b=auIirJcXuDMpfM3yxjQHhGC1wUg4hBrooBPeVUxxiMRsTHEER6FOXVV1bemYRRrd1b HSMqca0RxK2axMdB3dvoF2pINkJUEtEyQqqnx9WIoODML28rCLZ+FVdKPYk5g8wY5BMT FC8Uej0dvbr7u4FeHMKqndPz4i2zCeb3495Xq5/aRJYpcN9fBDusrVbPifGoVlRwP1RJ xBmzAEz/8xj8plEf+6qqgsSyhGdHZSTCoYzesfc8QdXuSvq2kFfYx5/Gtrdz4MZvS5y2 5/M37UJNwNSRlac5UqeL0OdoJsgv2vSeIAAg8RVwxKQ2a8ndIeYL6dkB2D/rR/kRRiPh FueQ== 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=iU9FZ7LsLqk37gyhfU2Cej00CA9dwq7wg+MRo8yI1FU=; b=XSWz0vFkT6LMVOmeqigcHbmnlntGgpr9KHnMcZK3O3oceDOvBk8Jcy5N8C/J1l/ae9 vgMaCuzJ5wuT/qM1oO3GPCJh1WGAQVoW+2sjCKxhojjYRaFWZBNL0akRIea1T6gDKCqK nWafMyQqzx+BTXSgERfu+LcdvVka75YueOIjgPg2u1UrYrkr+rtyxpbqb7HVXRCkbqh1 T94lM3WLPgWHrKgPimMAbJLbjOjqixv5k8rqMrcMQWRhU4dcFhLwfGaSeyr4QTCIaaqZ /uWQXb1NOCPh10FQvRxalp2scJtG8biU7G4KeXkzGBnLPj+YGULJan3URPl1NwRUGSzY /zoA== 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 u25si1428819pgm.532.2019.02.06.04.12.06; Wed, 06 Feb 2019 04:12:21 -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 S1730353AbfBFMKt (ORCPT + 99 others); Wed, 6 Feb 2019 07:10:49 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:43985 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbfBFMKt (ORCPT ); Wed, 6 Feb 2019 07:10:49 -0500 Received: by mail-ot1-f68.google.com with SMTP id a11so11376159otr.10; Wed, 06 Feb 2019 04:10:48 -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=iU9FZ7LsLqk37gyhfU2Cej00CA9dwq7wg+MRo8yI1FU=; b=AxmtxzdTNwwUYp6Faf7vbmiI8N980z8sGz7lU6o5dxkKxoq6AmysENWxcKupXgKhMi p0UYxKLxktS40UEKuP2NDUduLFUL/sG0Mpr5iiipjQqYJ8E/O5Y0Wo5VQXtpcYcRxq7+ hE3WmdSlDffMsrJuYNS39whA8lUrouZSj3ROySibrwc2TfroV5G0YrJtvdWrS8Vc5YBa /DFy/Zp1+JQ849yx3MPmveV7ihWMjWU2NVTRGhYyuA8UOSyiMTm4S7VHF0IUogHZt1wS Aq4VRwTTaM5tbMcEG6kCbohX9xymMdhVTzwBTGjTcyXCDCRQ0IUZNVfQQXOJ+Yfdsch7 EzUQ== X-Gm-Message-State: AHQUAuab/Al5TnyRCkdGOl9Otk8O5cP8Xjqc7MFXcG7/OkFZhN7G/yBJ b/CZH4KtkXqd/krtj+FiXfjxzOvnNujxINHg1J0= X-Received: by 2002:a9d:5f06:: with SMTP id f6mr5656765oti.258.1549455047618; Wed, 06 Feb 2019 04:10:47 -0800 (PST) MIME-Version: 1.0 References: <1952449.TVsm6CJCTy@aspire.rjw.lan> <24600564.pMaimVIQbW@aspire.rjw.lan> In-Reply-To: From: "Rafael J. Wysocki" Date: Wed, 6 Feb 2019 13:10:35 +0100 Message-ID: Subject: Re: [PATCH v2 0/9] driver core: Fix some device links issues and add "consumer autoprobe" flag To: Ulf Hansson Cc: "Rafael J. Wysocki" , "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, 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. > 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? > 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. :-)