Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5859321rwb; Mon, 5 Dec 2022 05:11:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6AHr16sPunCMp+XHPjo/rwKdMc8OgVjDWb/vmX4mZ97KoO1eGdAIBS+iW8miCuuCbuh44s X-Received: by 2002:a63:fa49:0:b0:476:f92f:885b with SMTP id g9-20020a63fa49000000b00476f92f885bmr63182990pgk.31.1670245905804; Mon, 05 Dec 2022 05:11:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670245905; cv=none; d=google.com; s=arc-20160816; b=rsDSE1rex/A6hFTs+pNHs3055S5jB70efjuTeyDm1jwyVDdCthSXxBxj59inqODIx/ g8SHHnqoZkIj/LwHG02UpxKSxrZMZNaFS6ygW04ERPzoYvdcZBCvjNLt+e1f3zH9e/ek ICMqrGXl2dqsxlbFq5RjgD7x1wnmvHItVsY7IdOgGJoOJ0jHA4/2LAh7v8lV4yz3NBAL rVrZ4EJUa8VND/qUWh0s0e0NH5P8Dqp5opo8wEzUPCbGfuau76SzPmi/Fk2INLqDesd8 XFdbqrTLKIbsHna1vd5QYMipyfRsz/P+xXlNuHA63qfhcJkciiyqsoZFTpvkdoQseJL6 IweA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=eHdyoJWg5eG6rs658NAInWWGVgURCxiUmVnybR6Jh4s=; b=VtIeuWesWcfqnBqcEHtzBXF8nQgnOaHrFXZ0vl2ixuPMCIplUdOuIVSafoENLnsydB EZvcfgfTydPA49Jdx+CsFXWYHAB3ntL65bQa0ABOGZ7T88E4ZDS+ne8rWwUeDUuJW9rB 6w08r7sbb6An+LktSV4evK2p7BiaGFpqcx+BL0QkiazeS7yy1QAR/dGELXUZ9Adnw09T 4+tTfAQb6w2d3tolyLbp1AOncqqP596kwfodepRIczLgTVpSWC1Trb/O5v4rVwfTzDqj YY61zDau4+cT9h74zdQc0wPyl5q0Gqm42VegMpg2d6S+b7fs7bSg/u9mjDeUTXJLDawm MOjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a1709029a0100b0016da027a727si13636713plp.116.2022.12.05.05.11.33; Mon, 05 Dec 2022 05:11:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231640AbiLEMNh (ORCPT + 82 others); Mon, 5 Dec 2022 07:13:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbiLEMNg (ORCPT ); Mon, 5 Dec 2022 07:13:36 -0500 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A014EAA; Mon, 5 Dec 2022 04:13:35 -0800 (PST) Received: by mail-qk1-f171.google.com with SMTP id z1so4733849qkl.9; Mon, 05 Dec 2022 04:13:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eHdyoJWg5eG6rs658NAInWWGVgURCxiUmVnybR6Jh4s=; b=DfXGUaSp9nr4uv4pJ5yp+SzA506DocGivsPxiaudL0zaXs6MGBcJEV5gRJ8TNbzfOe ceEkurlxaKil6K4JRZNn6AJSLGM/7AFA745+dnVNv4Kx26IhYZsaDVQiFWpMlPE+YQ8O ncMlB0WGiLTBXvwpRGjqq+WjnLcnqU4cb93eRE7r90iJZvaZKraMl5I+1jj1qyGfQahU HvgXXG6uJ5+Ypgt2k4iopFLLDe0IcCUxDwy8OLHTc0+tyfydyBQ1WRlifH95E2fqnWQD Q5k7LkEPxu6y5RcIlBNx11mLPmq1Wn7giQ8TTsYH4ZUM5eh0bZZsuMTAb/0OiXU1tcdt 5A/w== X-Gm-Message-State: ANoB5plcpxkbbZNTLYZ7cM6sHplKesw9/ymo7eUc7r3epxudIax33lvZ i7HGgRYJeQa6pyCp8LfcY945rA1x9F9586qRlp4= X-Received: by 2002:a05:620a:51ca:b0:6ec:fa04:d97c with SMTP id cx10-20020a05620a51ca00b006ecfa04d97cmr55214682qkb.764.1670242414772; Mon, 05 Dec 2022 04:13:34 -0800 (PST) MIME-Version: 1.0 References: <5627469.DvuYhMxLoT@kreacher> <4789678.31r3eYUQgx@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Mon, 5 Dec 2022 13:13:20 +0100 Message-ID: Subject: Re: [PATCH v1 1/2] PM: runtime: Do not call __rpm_callback() from rpm_idle() To: Ulf Hansson Cc: "Rafael J. Wysocki" , Linux PM , LKML , Tushar Nimkar , Adrian Hunter , "Rafael J. Wysocki" , Nitin Rawat , Peter Wang , Alan Stern Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 5, 2022 at 1:08 PM Ulf Hansson wrote: > > On Fri, 2 Dec 2022 at 15:32, Rafael J. Wysocki wrote: > > > > From: Rafael J. Wysocki > > > > Calling __rpm_callback() from rpm_idle() after adding device links > > support to the former is a clear mistake. > > > > Not only it causes rpm_idle() to carry out unnecessary actions, but it > > is also against the assumption regarding the stability of PM-runtime > > status accross __rpm_callback() invocations, because rpm_suspend() and > > rpm_resume() may run in parallel with __rpm_callback() when it is called > > by rpm_idle() and the device's PM-runtime status can be updated by any > > of them. > > Urgh, that's a nasty bug you are fixing here. Is there perhaps some > links to some error reports that can make sense to include here? There is a bug report, but I have no confirmation that this fix is sufficient to address it (even though I'm quite confident that it will be). > > > > Fixes: 21d5c57b3726 ("PM / runtime: Use device links") > > Signed-off-by: Rafael J. Wysocki > > --- > > drivers/base/power/runtime.c | 12 +++++++++++- > > 1 file changed, 11 insertions(+), 1 deletion(-) > > > > Index: linux-pm/drivers/base/power/runtime.c > > =================================================================== > > --- linux-pm.orig/drivers/base/power/runtime.c > > +++ linux-pm/drivers/base/power/runtime.c > > @@ -484,7 +484,17 @@ static int rpm_idle(struct device *dev, > > > > dev->power.idle_notification = true; > > > > - retval = __rpm_callback(callback, dev); > > Couldn't we just extend __rpm_callback() to take another in-parameter, > rather than open-coding the below? I'd rather not do that. I'd prefer rpm_callback() to be used only in rpm_suspend() and rpm_resume() where all of the assumptions hold and rpm_idle() really is a special case. And there is not much open-coding here, just the locking part. > Note that, __rpm_callback() already uses a "bool use_links" internal > variable, that indicates whether the device links should be used or > not. Yes, it does, but why does that matter? > > + if (dev->power.irq_safe) > > + spin_unlock(&dev->power.lock); > > + else > > + spin_unlock_irq(&dev->power.lock); > > + > > + retval = callback(dev); > > + > > + if (dev->power.irq_safe) > > + spin_lock(&dev->power.lock); > > + else > > + spin_lock_irq(&dev->power.lock); > > > > dev->power.idle_notification = false; > > wake_up_all(&dev->power.wait_queue); > > > > > >