Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10443518rwr; Fri, 12 May 2023 08:13:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zSOwqvxqbR6k40nRWD2R48l1I+NsTweN6l2d8tpOk3JfYGJIbOcgJysjmIBdLQT5wU0R5 X-Received: by 2002:a17:90a:d498:b0:24e:10b3:c9cc with SMTP id s24-20020a17090ad49800b0024e10b3c9ccmr23961907pju.14.1683904381565; Fri, 12 May 2023 08:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683904381; cv=none; d=google.com; s=arc-20160816; b=kVDtIn6UNqDAFgkII3TtnId02p1EZMEcqF9TfAUnn0vlCSGk2k9Ge2oqCL0qtru5Ve LFMu9AIqMFGv2Xm54oS0UHwY+Lz5Ua6vwDzL8oqMMUjFevDLIiN0a0Cva06Zpj5yzuXk 7CuAHKyjfA7e1584WwCuf1wWiGHVlv0XwuhMD3VX83EUenasx2pYvlBWp2jjb8Q2MGwj TKE8p5KYxLy585BshwQqHkaKnWILxMCW8MWMwkhYPZN+fbeMhIj03Q6zqb43wx5R8BY3 y+5fHklhiHHu7WkSFJRfvAqbDr7Ae4jvDduAzpf8PrLIH/E0uwDGU6f7vKS7Tke1tjvh jLTQ== 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=W6m5KSOp88goUmNDQtMvZ9D7nOhsG+OW7C7DkzgeHl8=; b=F0oeE8x9egJeIUIjaoQO81U8PBnl0q/2ECl9+pX/21vcVLqMUFowbtZb58nnA9kDE6 Gldbr1nZo637qR+KExjfAvFEPvWdy5uT9vZvoKs+IMmsD+OUtJmTKMq2aS0ceE8sOH41 oDPva4TdM14yFXImhqiFBrSEhzuv0jJRaNOcyCEp5F4WXXUQ19kgphzs2SNEKdsjn5Qm ZqlyJxqaMmXyQusb/NjMryV/oX0YXocF1saDGV1Tpt8aBHSYxdMONLIQ/hVg6TAEBxVT Ygwu/NCspS+K7TbqupYOTaT8sQifp+x/v8+JIcVr12X7q7ui8N3R9/ffXhrk5OFoiBmd po7w== 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 mq18-20020a17090b381200b0024e1c1b3004si29971631pjb.78.2023.05.12.08.12.49; Fri, 12 May 2023 08:13:01 -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 S241689AbjELPEX convert rfc822-to-8bit (ORCPT + 99 others); Fri, 12 May 2023 11:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241670AbjELPEV (ORCPT ); Fri, 12 May 2023 11:04:21 -0400 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2BB22D60 for ; Fri, 12 May 2023 08:04:20 -0700 (PDT) Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-50d8d4efd13so1794312a12.0 for ; Fri, 12 May 2023 08:04:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683903859; x=1686495859; 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=/8r8EIzdiXeXG/Z0ECjEsALK1soC+rf/Zy6+YvirHCY=; b=gkIGnebHLXVYcubZfxuDYjPZsQ3QSgd9q+VoAc9Sqi+gxO3vwcCKqFQ74lVLsYDn0u rJ265Yf4CajzLJaMgIKlLqmWz4lwj7mJ3dcxRPUbiqbbTUZlDGwSNhFm7pYiVbcnKv8D CAiwp+sIimLNw+O2K3ILzbcCYhfGX7X0PyOf10U/TSfe8jFVh3qE8X+/ot3Uh8HjQuRx vBCScFVhOfC0TDXFI+SnXLXm25o1nbrEkXBLkqX3MhDEU5HQplin26EadLPksFF2OKdQ gXGxL9ZcbYUdG6E6JxyIFkg1uXHtKPm6QG+BdRnxhWAV4aq/2ZznYHssVlUjmHVurcWI 7CHg== X-Gm-Message-State: AC+VfDxbN1I8vJuyuwXy+qiddyA/ls/2hz7zOgaVUguKrQDyOIqTESxZ NL23m6HiviHrJk0iUp1T+tidxYfcMR0nj/O1ieMDbpuu X-Received: by 2002:a17:906:2252:b0:965:bc62:fe38 with SMTP id 18-20020a170906225200b00965bc62fe38mr21176956ejr.7.1683903858828; Fri, 12 May 2023 08:04:18 -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 17:04:07 +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 5:00 PM Johan Hovold wrote: > > 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. OK, fair enough.