Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10375026rwr; Fri, 12 May 2023 07:23:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OAmAhO/DbtTrEsxHSVwDcCYsOFUEs4RGjNfLXhn8DXroEj42rMIcUCqUcIhAdnbGO1UTB X-Received: by 2002:a05:6a21:78a8:b0:f1:f894:9e6e with SMTP id bf40-20020a056a2178a800b000f1f8949e6emr34233940pzc.5.1683901398094; Fri, 12 May 2023 07:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683901398; cv=none; d=google.com; s=arc-20160816; b=EL74XmHOlxp1BNlsXcanxJqdSaJigkFQJlKwL3hbyJJNav9UclvXadcUdHZavAjErt 1C3EwdOJctiP3kpXSPcoJj6ifyoyVq+jHA7wCWjRHt2chFchVaBdRT1hRaQFnR1H04m0 Vks7rbHv3vVRYtGIO2Q3OOnovdQVb89gKXioWj2/O274L7KSjSAq0J1z1ZXozicdeLEx ztu5JShsrkcf+I2IVzGgsqnkhe5i5pgyClIcTgY6eSu9KgaBWDERpzlBjKloA0P+gYHb 3TQTDZ2pgvYyPYUTn8AxbKJbFPPApdw4/PqvsVrNfTotpl3ThJ/DVpNefexxm0bwkjBF RHBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=YEV3UqFmR6hMEzEfCk8vLzuiaTP2Voj/dr0iZk2eDtg=; b=jYyksQnQ9ri04/oxJlcWf0Qmwj16I3lSfSn5uxj80+/OwuvXr7OdEFt6Nn6qVx26o2 EA3CR39Vkg/ZKvLMMeZ1Au+fzf+Q2cYOb92/kP/Fm5PhI8b4yk5RsXDXyEdsRnpS+QMb lvhKItty3OVeRUmcTv3A8740ofYVHj2xwsASv6VO+KKKlwIRjtfU/YDxFhXWCCof5T+F iiUPZMYDASxTiqKVE125kg+XSlTsh6W8lz0VZAVSyPQostd6BluierTECfeoNl47uySM codGcrjEkrGjptwDaC37PSHemmPJSQ47zt13HFZNQ0etuYUAdawB+/Uka5HMD2JFc5dh Ol8A== 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 d4-20020a17090ab30400b002471f613111si23112505pjr.62.2023.05.12.07.23.02; Fri, 12 May 2023 07:23:18 -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; 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 S241452AbjELOFR convert rfc822-to-8bit (ORCPT + 99 others); Fri, 12 May 2023 10:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241454AbjELOFO (ORCPT ); Fri, 12 May 2023 10:05:14 -0400 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 899303C23 for ; Fri, 12 May 2023 07:05:12 -0700 (PDT) Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-50a20bfe366so2549089a12.0 for ; Fri, 12 May 2023 07:05:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683900311; x=1686492311; h=content-transfer-encoding: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=/hAl6gNGfhK2E+/GN178/0RT+nmB4QgOANVUnLmUqRU=; b=gQFoVt7RhooowNkAp14o/9vrlzVcpBX4aVfouRrNglOQh+q46EwfR/UJF+IUdFvJl3 81HVUxMA93EJQ08Ylk9JFoXOOMswNNvRJJRifahIL7kNVfdBQd2jfHlZuuVwNAyOhaWY Xt7OdymmKZ4coIiMxW2N8Xl+OTfKCVRT3WNTpnY3iGCexQci17lZIE12AQeL3D5UiVyS VQYTQdn5UscPbebV3D7u3AUe2p94MwbicNitGhxgYS5yfisit94mxYgbEOrxBYCSIyUt YZWEG/TF84E1Qh6/xTqogE88wrm4kvvBX3ldy6kAIwxh6EDKIQbZTZd6Wis7s25lFIBk ZuZw== X-Gm-Message-State: AC+VfDwTHikmUdLCs0PQH1CjCXLGOaZMxwXqKTYRhxlgTY5S7TbhmsC1 ct3mwVsCLsjDK5YKA42COcpAEtc5u+N1G7pIGYRQDuhA X-Received: by 2002:a17:906:72cd:b0:965:d4a0:85bc with SMTP id m13-20020a17090672cd00b00965d4a085bcmr18738119ejl.3.1683900310660; Fri, 12 May 2023 07:05:10 -0700 (PDT) MIME-Version: 1.0 References: <20230511073428.10264-1-u.kleine-koenig@pengutronix.de> <20230511103923.hvibdyo5ges4bab2@pengutronix.de> In-Reply-To: From: "Rafael J. Wysocki" Date: Fri, 12 May 2023 16:04:59 +0200 Message-ID: Subject: Re: [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove() To: Johan Hovold Cc: "Rafael J. Wysocki" , =?UTF-8?Q?Uwe_Kleine=2DK=C3=B6nig?= , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, kernel@pengutronix.de Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 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, T_SCC_BODY_TEXT_LINE 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 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. > 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. 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.