Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10470356rwr; Fri, 12 May 2023 08:32:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66GznmNfF8kgwE4GfRtRJujMYN8o/wmThwCLQ3vrYs05F2rf9othzIwDJ14WNWC8wi/Lhd X-Received: by 2002:a05:6a20:160e:b0:101:1008:6b84 with SMTP id l14-20020a056a20160e00b0010110086b84mr21007899pzj.8.1683905520582; Fri, 12 May 2023 08:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683905520; cv=none; d=google.com; s=arc-20160816; b=dbRX9Grx7DgqfA2xBrFnjDsDfN/N0ErgICGE6oV1m0M/Y8wZQXPYFoXj3KvkcKYstN M8Cc8AOL2zgGzfvTCwmK/bNhB7jYebEFapLdcKaeGRVCBLYJ40403QPMTGuRKhCvLK21 BELcZMFn074ZCWuaU/FQn6tlniI/fpZQebfXnJ5Rf7bEx5DVJTdumWnVYiIddO23I1q3 8KFY1J/r4LLySrVaDCG0UkTlw9J3lzAcLXq4bjxMx53sOgybIz+2v5faQKrVFt46PZ0x P1B/c8tOHFiNDI2ZT+4RuEmanaSkhUWD1NLBKmV2j7BWqwEgdo852FZWuGfg6tlAcIDL q9HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=viAE7TNLiBHVosAHhGllIGS/aC3ChNaF5V7ywPA9HKU=; b=rhq2M6dzH7z+5coygE2CoiFC2bqgmRdW7RNeue6OgEL1Z7cQ/HELUtYtKJ5elH2sy4 5yZ2P3/obomGrh2JUY748d8BnCnsMGa70IawcLgBD3jkk6R8ivsyZyMiQBdMWMnzeaEE lsA4O86U3n1PNbeC6fZcFf7emwrez3y3/+m2LBNiJ4SEIjVoz3shwDXJA7MzgbV30tS/ u5NnY0yOnmld33KrpIaQ2WeMWkN71qB9cFR3bYFp1dCTjw5a6egLncB+MEGiPj/7y7hW iaIXyIivsBed1xfiin//SZVW9ztEHMP2bx0/2TgljXt9IxGihPwLYhOpzrrzSffoJZi6 CUeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCEGMZ05; 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 d12-20020a63734c000000b00502fdce9dcasi9489522pgn.114.2023.05.12.08.31.48; Fri, 12 May 2023 08:32:00 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OCEGMZ05; 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 S241358AbjELPAz (ORCPT + 99 others); Fri, 12 May 2023 11:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241581AbjELPAy (ORCPT ); Fri, 12 May 2023 11:00:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EC15106D8 for ; Fri, 12 May 2023 08:00:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 07CE765765 for ; Fri, 12 May 2023 15:00:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 578F4C433EF; Fri, 12 May 2023 15:00:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683903623; bh=UoKuHtR2zuyhdc4m74j2RrwL7ta0qNtOKzLYO/kUwlo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OCEGMZ05vb1KpdVRCHMpOMNXSep+RzW+Q7i8zUFMR9rcazp7j66lUf0LAOltb1MDf Bj21vSQpWgcdJXuHO/phJ0hT0/pnCXzI/g7pCYX2qCttAxAIDwdz5fNdpgrGqwVzLc zd9++AXd22tuB74rm07eVmM4WMl7GWMmXEgu8qhoqO36sO7Z54fW0mkxn5+P8jDHJc p/ZXqq+weemUImmxD1G1PzPGm27E1TOa0Ko1DpL0IijvzjPls4TTheBKUvtknHRmVJ yvTRlWtA2IkA/N5tNSaGdLfbv8rqwkY7s6TsQCHkGpDGjL+EyZxdONrPjFkDyefmeF xGgKnyidUAdwg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pxUGK-0001Tb-18; Fri, 12 May 2023 17:00:52 +0200 Date: Fri, 12 May 2023 17:00:52 +0200 From: Johan Hovold To: "Rafael J. Wysocki" Cc: Uwe =?utf-8?Q?Kleine-K=C3=B6nig?= , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: Re: [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove() Message-ID: References: <20230511073428.10264-1-u.kleine-koenig@pengutronix.de> <20230511103923.hvibdyo5ges4bab2@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Fri, May 12, 2023 at 04:04:59PM +0200, Rafael J. Wysocki wrote: > On Fri, May 12, 2023 at 9:39 AM Johan Hovold wrote: > > > > On Thu, May 11, 2023 at 04:44:25PM +0200, Rafael J. Wysocki wrote: > > > On Thu, May 11, 2023 at 1:48 PM Johan Hovold wrote: > > > > > > No, this seems like very bad idea and even violates the documentation > > > > which clearly states that the usage counter is balanced before calling > > > > remove() so that drivers can use pm_runtime_suspend() to put devices > > > > into suspended state. > > > > > > I missed that, sorry. > > > > > > > There's is really no good reason to even try to change as this is in no > > > > way a fast path. > > > > > > Still, I think that while the "put" part needs to be done before > > > device_remove(), the actual state change can be carried out later. > > > > > > So something like > > > > > > pm_runtime_put_noidle(dev); > > > > > > device_remove(dev); > > > > > > pm_runtime_suspend(dev); > > > > > > would generally work, wouldn't it? > > > > No, as drivers typically disable runtime pm in their remove callbacks, > > What exactly do you mean by "typically"? None of the PCI drivers > should do that, for instance. I had platform drivers in mind, but so do i2c drivers for example. > > that pm_runtime_suspend() would amount to a no-op (and calling the > > driver pm ops post unbind and the driver having freed its data would > > not work either). > > Well, not really. > > There are drivers and there are bus types/PM domains. Drivers need > not disable PM-runtime in their "remove" callbacks if they know that > the bus type/PM domain will take care of handling PM-runtime properly > after the driver's remove callback has run and the bus type/PM domain > may very well want its PM-runtime suspend callback to run then (for > example, to remove power from the unused device). Arguably it can > invoke runtime_suspend() from its "remove" callback, so it's not like > this is a big deal, but IMO it helps if the most general case is > considered. My point was that hundreds of drivers do and for these this call becomes a no-op. Same for buses that disable runtime pm at remove. > Anyway, the question here really is: Does it make sense to carry out a > runtime suspend immediately before device_remove()? Honestly, I'm not > sure about that. I'd say it doesn't really matter as driver unbind is not a common operation and drivers using autosuspend would generally not be affected either. You can try to rework this, but clearly it needs more thought than simply moving the put sync and some drivers may also be relying on the current behaviour. A quick grep reveals a few which would be left active if you change pm_runtime_put_sync() to pm_runtime_put_noidle(), even if that could be fixed driver by driver of course. Johan