Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5903549rwb; Mon, 5 Dec 2022 05:45:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Lah56FP7EI462+/8YGQxGFg4hBXSyDp6VjUzJAnOPQlEqSTKcRi+y7yHLWO+MfqY6MSEz X-Received: by 2002:a05:6402:1156:b0:467:374e:5f9b with SMTP id g22-20020a056402115600b00467374e5f9bmr56653808edw.283.1670247911489; Mon, 05 Dec 2022 05:45:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670247911; cv=none; d=google.com; s=arc-20160816; b=PFl+cb+7dK/SrrSkp2GmcIms/l2xFeL3JfqdJ6eL5Hn5jqvGYRidC+2rwf+k9LAeCf U0LfLSpiV4zKXhNFKYgLxdd2OzKjPBE+8QbJZ/UxdHaKvO3ugB3UjMRmSrpY409ZgIuo baz85nJsooWVS5aTpCuHh3jW6ro/zFbsu0in80IHfKokXn8l6IuqNvBX1sUiKamDEcmD ZToPOmkPwBhzL90TH+gWVIcR74GRzcUf9UOoRapORKnfUVyDrphCtFBZqcCob1+4C4vP DfQtEgbwiuvDmbyfit+ycZpi2ceHSC4X9RzIvGHRLObKcYnBfNcN5kFPSidaQUrKD2lz YvDw== 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=MT4bJVVHqTGTFiANb5Sn2kAnn0LAo6SX5n0rM8AMQ1Q=; b=R1s+mQpoZjSnHaPsyS0REF2T7XozJRQe2+eh6GXqjTYhkUqJWNjgMnO57I8PWHr8HX cQ6sqh68Dy3UTXxdsRTalAjBR7+STae0N2431LK+JG69EQviXPQ9shRiF6bRZVcpmms8 RQHovF7vPLHHb3Dm/cHHPmGYKgxXD9DZ5jnBvcx1oTyaVUkA97PyhlppnOSyeDUllkNV /YXDXx8bWNUnaFHUCqZOI0FL2+7ykNaJhaLUXgzZzQf83lHYnIZVqqdi906xcPxgPfZt /veQvyVsa1tQelt2gXL2NDiOirxDUiqmLp8F/Ir46QfMaNvlSkV05RpwNFSCM2wmbdJq QFxw== 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 ho9-20020a1709070e8900b007b889a69895si42827ejc.589.2022.12.05.05.44.51; Mon, 05 Dec 2022 05:45:11 -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 S231948AbiLEMv7 (ORCPT + 82 others); Mon, 5 Dec 2022 07:51:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiLEMv5 (ORCPT ); Mon, 5 Dec 2022 07:51:57 -0500 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C87481A228; Mon, 5 Dec 2022 04:51:54 -0800 (PST) Received: by mail-qk1-f173.google.com with SMTP id z1so4802251qkl.9; Mon, 05 Dec 2022 04:51:54 -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=MT4bJVVHqTGTFiANb5Sn2kAnn0LAo6SX5n0rM8AMQ1Q=; b=Aq6VQNCzviL9IuOv3UkS920w36CDB9e20ZT4ECIc1GhjtuLCy0vORhbYdHxj9JEM34 rRyoIe2XDnaLHHh6CVEXu5oeqGovJiNcqdcqusLMYrev6/ubJW9Jt5M9psrdHyvrNv6K 6iUQRHugJXimPgmTFK/FQcltt+LyETI0y81yckkwmBoKxouDkEYBH0ii8ZezBJfBc44A sNvjhM3HNbvnCAGGOVLukrWw4OVhnaDOLURYtQisnJNHs8GsnEZ6h5LdMY1ZQfLFY0Tp JqwSLbip/FDSXrSvMVI86YjySOQhUtqS8oyv+Xy9AA7jwDEpMNPXyl7wRzNJSj5pz3Lg zrsA== X-Gm-Message-State: ANoB5pklNn7ZLPwkEzY0fMM8gDt6/aFu3AQnYiUlsje6HWLg+Oys3siC GvYy0rPnGnIdZxmIt7JMVthSngYoqdmpZPRtbks= X-Received: by 2002:a37:b901:0:b0:6ec:2b04:5099 with SMTP id j1-20020a37b901000000b006ec2b045099mr59952260qkf.501.1670244713941; Mon, 05 Dec 2022 04:51:53 -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:51:39 +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" , "Rafael J. Wysocki" , Linux PM , LKML , Tushar Nimkar , Adrian Hunter , 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:47 PM Ulf Hansson wrote: > > On Mon, 5 Dec 2022 at 13:13, Rafael J. Wysocki wrote: > > > > 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. > > That and the actual call to the callback. Not much, but still. Note that it doesn't need to check the callback pointer, though. Moreover, IMO this code is easier to read without having to look at __rpm_callback() and reverse engineer all of the different use cases covered by it. > > > 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? > > It means that __rpm_callback() is already prepared to (almost) cover this case. Well, why does it have to cover all of the cases that are even somewhat related? > > > > > > + 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); > > > > > > > > > > > > > > Note, it's not a big deal to me, if you feel strongly that your > current approach is better, I am fine with that too. OK, thanks!