Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp410801ima; Wed, 6 Feb 2019 02:05:50 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib3H9jdYrvMuUVtv8i25RHgEsc2K0n05xmuEud5UmTFZCABa72dhMSsUSVk3JVk4guXtAT+ X-Received: by 2002:a63:d84e:: with SMTP id k14mr825594pgj.436.1549447550062; Wed, 06 Feb 2019 02:05:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549447550; cv=none; d=google.com; s=arc-20160816; b=K7tGUgSkYWyYpECTTOgM7zAUkn+yDzoUQicez4fH08MnheQO48zdyjE5vt5IFM9ClH XwTqUapW+Ovx32G+Emt5b71En4DrMuvnHYSPJIwrvXxl31AU6q8b575PwEU+HtUmQxmy 0VeG1R8RNDfwz8Pkbb4b+H2wNPOOyJY20R/NXZDYHrofrqbuOX9f+quyWjsr/bCxKInR o1z71rQOrTs221awpDTAFZia0gUiyAjIVw/m0ULd2h1zBYZLztR0WBS2QL9DBBH0Jb8Y QyA7JOb2VQGhj3qatNkN54IFl7JrTD32MOhgZ9FmjrbZC7Upasf6mV6QQ2ib5oi9txbe F3FQ== 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=Eoc/WWCn19tq7HGo1SiAh/m3WRI5CuxD/5M1Hdn2Iho=; b=AmFKXey/5a0brG43I9/cL2FRQ1LkNLJBYUJEhASBPTU7mpiIbRhODx44E+k3LoS/ay 5XI1Ii+nIVY+4zF6pWLnYNObc1OUQUzAncvKVgSu74GF3AYW2OU4Yxvr/Ww6MCJIPPXJ ZLxzn707GXelZpphCl4t9L1LY8cHEfQgsJW8aG37B+rXS3BEInIAaBvDDuf7nJ+Lm14g 28LiYUicvCujJPLihVsgiKoIi+z0EAJxWHo8zTTfMff9pQgz8/YI+mPwGA1tUUNoZlYF FAmgO0QkM931BqDCmCF5XunwhceUHcng6XTYIeQWMWvnAW8cpvNFq8zQVPd4SaaYKFiz Wkzw== 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 g186si5261943pgc.320.2019.02.06.02.05.33; Wed, 06 Feb 2019 02:05:50 -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 S1729098AbfBFJ4Y (ORCPT + 99 others); Wed, 6 Feb 2019 04:56:24 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:45490 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726804AbfBFJ4Y (ORCPT ); Wed, 6 Feb 2019 04:56:24 -0500 Received: by mail-ot1-f65.google.com with SMTP id 32so10800466ota.12; Wed, 06 Feb 2019 01:56:23 -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=Eoc/WWCn19tq7HGo1SiAh/m3WRI5CuxD/5M1Hdn2Iho=; b=eYpRBxig9eZZ8nnCbIyfYmTEnaudz4cI/11EfUWU8npzX5h3jSyOl6SpAQcOENbbpL fmE7auPPiRqN0x5pmKG5dfK+nvzCqFlQBAQvKFupXsf5tyrJRRorzfzjtFTx2Oyw99y9 VS51ag/lKLtdxy57HE6/dwofMATwWHR6EjQ595iFZHIUt4upGA/47HA1t4bbfhM3LT9v ZG9h2sAGOUq6L7KpCMTC8T3kFoO4+5XcC6xS3m0qQn1MbOJM9KdwAbwHu3cu+v/eQxPl 5M2xdtjij3m5LHsNuFooBEFQhWnHIxoK/ovMDIhuqNsN28WFZKxYl/QkjTHXuzgyNZQW vzaQ== X-Gm-Message-State: AHQUAuZ4miSt7XD+LHQg8y7Mw8dEy6dquNNTjun6r0mneAXvSgXP1bG+ htOQMd7wkSpZTR7xjxcr4ZIwK7Ik5VNUwXbp5i0= X-Received: by 2002:a9d:2062:: with SMTP id n89mr4886943ota.244.1549446983432; Wed, 06 Feb 2019 01:56:23 -0800 (PST) MIME-Version: 1.0 References: <1952449.TVsm6CJCTy@aspire.rjw.lan> <24600564.pMaimVIQbW@aspire.rjw.lan> In-Reply-To: <24600564.pMaimVIQbW@aspire.rjw.lan> From: "Rafael J. Wysocki" Date: Wed, 6 Feb 2019 10:56:11 +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: Ulf Hansson , "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 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. 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. Because of the above, I'm just going to post a patch to document the current behavior of the code as a known limitation.