Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1443362rwr; Wed, 3 May 2023 15:35:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5pvkJ69Xpng2bWYPm6sQlXB6K75aqbRUPXATgz1+8/y8mSeEkaaRHek5JLi23gceAwsU3q X-Received: by 2002:a05:6a21:339f:b0:f2:4f56:be57 with SMTP id yy31-20020a056a21339f00b000f24f56be57mr266701pzb.2.1683153346369; Wed, 03 May 2023 15:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683153346; cv=none; d=google.com; s=arc-20160816; b=eK/5A8Wy6gCys7GW7Lrv8LEhhto/i2gqjZmb+w4Kj9/BOCP+ZTfmA6NMrU95gjku/r MyAqdYmJq0K66THZhYq1gSmH12+u5UhuetVrLpSeLSiiYvkjOM9awdZCfDQZWheBdDct oKEvEmQdAXwo3+NIPMt9Y4451OIllw3T2kod0/OA/EuVFomBBNw3MOXC/N98Fop5Sw6t ITEenNVeSzlUEq6oycptPSfegSqjks2tggQ2O3k61WZ97YMaefj/zXzMMdPoeh57s7Xv D1BphjdBzxnuwolVFFDShTx1wrrkC3Mu0NFYzp607sH8rpSk8GUGtS3VsBWT5qGPT82B GgNg== 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 :dkim-signature; bh=Sw/uh5akf5sYyirenlPiMJ2fqzB54uKSrx04Lkzu3QY=; b=Qk7z5ze+5Tuc4wt5pU2D3U+eKiP44pqV98H33/NmlHxGAaRf0YAAPhWW6ZBZgrakhF qvcLbu7I/K1iTxcMx2UA5mkV8sPuAQGCkSjU915gQtJzmxMBHfIKF/3nJy8ce8g31Fv1 rCIEWfMq7mZXUPRVbjyS96ngmOYGpXw9xKqbEeUH22k1TsWxD0lzrCwExTu9wN9qDkmd 8Czbqow3ZKCHxv+NgTBU+nQ48yY4tdq/mDq3Omfcm7FXa9EpjjH4+nknJ1+wQUcJ0Cx+ uAiWy4GUJG4H03qcV6u/oa1dwwc8KOmUX5QxmkKo3SoFKsbL2ZZc1Mwfp3641EQI33Jn 38Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=BklqgaLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b0051b70782bc7si33921352pgk.234.2023.05.03.15.35.32; Wed, 03 May 2023 15:35:46 -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=@google.com header.s=20221208 header.b=BklqgaLP; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229524AbjECWbk (ORCPT + 99 others); Wed, 3 May 2023 18:31:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbjECWbj (ORCPT ); Wed, 3 May 2023 18:31:39 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E450D7DAC for ; Wed, 3 May 2023 15:31:37 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1aaf702c3ccso302305ad.1 for ; Wed, 03 May 2023 15:31:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683153097; x=1685745097; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Sw/uh5akf5sYyirenlPiMJ2fqzB54uKSrx04Lkzu3QY=; b=BklqgaLPbl6uRq0Dt4LFtNrfjW09mt809Tz5EJ2tmKfX8GCcdB49Whfnf/meC/A8yW dHaI+GCSwoOeb+3AZynNxIu14buIG6A3EIUsJu5AND0ELfYwri4oI5slLKZKMIAqKSiM 4vOvZn0dCjKtEdl56t372JWSmN2ELkvJ/tHfNubv+pzLOBx8vBo/maeQLscRpdy47XTA srAGjyN0aIeUJ6iu8zDKWrWZLo8x1VxYkEt8NetSgurttqJiG88Bhs/5xVEeGZZ89+LI PBxpeu5nFnANsI4GEOO9V3s7YjzW+vAJEb/3VuocP24ZvnAR6XRsW2g8J2VJy8NfEzxf tfhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683153097; x=1685745097; 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=Sw/uh5akf5sYyirenlPiMJ2fqzB54uKSrx04Lkzu3QY=; b=IYVw/S5MJuLGMkkY6O8+yrughp6Qw7RC/mdRHuiBzXzCk3bkpZWG7BUlZDCQRWrAFe ifLqUjV/th1vk6Sy+aystqJm+gKPpnPnVP5i1OaEpWh6I0L0+s2iqN2c2iPZIqDUSK6Z 9TeymW95dmSbfH3kKJcDXCRyEEOq+Gc8SMH3X/tprKT9E6K2TmCSRARKQtjj8oXKaHUd TYo51GRuZnjz1+glMIIyuDqTjk21mlVr1e/XrqNXRb9enCG+WmbnogInfRpELN99eeV9 I0i0rRTJmys/kO0hoHH065GiOHRayWyxDuoJepQsdlhHFUKe3JspNz0EXubRnwK3sirZ wsCw== X-Gm-Message-State: AC+VfDx8mZUknyIOn56x6fpb5Ka3qIezLIm5KRJ7CYSG16aKuGkHm32B J7qF2xUePcLdpAhCzAygQtRLCjz6NV4jhQDbrWF+iQ== X-Received: by 2002:a17:902:d4c4:b0:1a6:42f0:e575 with SMTP id o4-20020a170902d4c400b001a642f0e575mr16024plg.5.1683153097163; Wed, 03 May 2023 15:31:37 -0700 (PDT) MIME-Version: 1.0 References: <20230427221625.116050-1-opendmb@gmail.com> <597ba853-1fe4-9263-c448-422b0c2a91d8@gmail.com> In-Reply-To: <597ba853-1fe4-9263-c448-422b0c2a91d8@gmail.com> From: Saravana Kannan Date: Wed, 3 May 2023 15:31:00 -0700 Message-ID: Subject: Re: [RFC PATCH 0/3] input: gpio-keys - fix pm ordering To: Doug Berger Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Dmitry Torokhov , Lad Prabhakar , Gergo Koteles , Jonathan Cameron , Andy Shevchenko , Dan Williams , Hans de Goede , Thomas Gleixner , Kees Cook , Florian Fainelli , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Android Kernel Team , Linus Walleij Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Wed, May 3, 2023 at 3:21=E2=80=AFPM Doug Berger wrot= e: > > On 5/2/2023 7:18 PM, Saravana Kannan wrote: > > On Mon, May 1, 2023 at 1:40=E2=80=AFPM Saravana Kannan wrote: > >> > >> On Thu, Apr 27, 2023 at 3:18=E2=80=AFPM Doug Berger wrote: > >>> > >>> Commit 52cdbdd49853 ("driver core: correct device's shutdown > >>> order") allowed for proper sequencing of the gpio-keys device > >>> shutdown callbacks by moving the device to the end of the > >>> devices_kset list at probe which was delayed by child > >>> dependencies. > >>> > >>> However, commit 722e5f2b1eec ("driver core: Partially revert > >>> "driver core: correct device's shutdown order"") removed this > >>> portion of that commit causing a reversion in the gpio-keys > >>> behavior which can prevent waking from shutdown. > >>> > >>> This RFC is an attempt to find a better solution for properly > >>> creating gpio-keys device links to ensure its suspend/resume and > >>> shutdown services are invoked before those of its suppliers. > >>> > >>> The first patch here is pretty brute force but simple and has > >>> the advantage that it should be easily backportable to the > >>> versions where the regression first occurred. > >> > >> We really shouldn't be calling device_pm_move_to_tail() in drivers > >> because device link uses device_pm_move_to_tail() for ordering too. > >> And it becomes a "race" between device links and when the driver calls > >> device_pm_move_to_tail() and I'm not sure we'll get the same ordering > >> every time. > >> > >>> > >>> The second patch is perhaps better in spirit though still a bit > >>> inelegant, but it can only be backported to versions of the > >>> kernel that contain the commit in its 'Fixes:' tag. That isn't > >>> really a valid 'Fixes:' tag since that commit did not cause the > >>> regression, but it does represent how far the patch could be > >>> backported. > >>> > >>> Both commits shouldn't really exist in the same kernel so the > >>> third patch reverts the first in an attempt to make that clear > >>> (though it may be a source of confusion for some). > >>> > >>> Hopefully someone with a better understanding of device links > >>> will see a less intrusive way to automatically capture these > >>> dependencies for parent device drivers that implement the > >>> functions of child node devices. > >> > >> Can you give a summary of the issue on a real system? I took a look at > >> the two commits you've referenced above and it's not clear what's > >> still broken in the 6.3+ > >> > >> But I'd think that just teaching fw_devlink about some property should > >> be sufficient. If you are facing a real issue, have you made sure you > >> have fw_devlink=3Don (this is the default unless you turned it off in > >> the commandline when it had issues in the past). > >> > > > > I took a closer look at how gpio-keys work and I can see why > > fw_devlink doesn't pick up the GPIO dependencies. It's because the > > gpio dependencies are listed under child "key-x" device nodes under > > the main "gpio-keys" device tree node. fw_devlink doesn't consider > > dependencies under child nodes as mandatory dependencies of the parent > > node. > > > > The main reason for this was because of how fw_devlink used to work. > > But I might be able to change fw_devlink to pick this up > > automatically. I need to think a bit more about this because in some > > cases, ignoring those dependencies is the right thing to do. Give me a > > few weeks to think through and experiment with this on my end. > Thank you for taking a deeper look at gpio-keys, and for getting through > the gobblety-gook description in my cover-letter ;). > > Yes, the dependencies of children are not automatically inherited by > their parents and it is not clear to me whether or not that should > change, but it definitely creates a problem for the sequencing of > gpio-keys device callbacks. > > I initially prepared the second patch as a way to explicitly create > device links specifically for the gpio-keys device from these child > dependencies as a work around for the fw_devlinks being dropped. I don't > really consider this a viable patch which is why I made it an RFC, but I > hoped it would highlight the issue. Thanks. It definitely made it easier for me to get to the root of the problem/omission. > However, the regression actually occurs in v4.18 and fw_devlink isn't > introduced until v5.7 so it is desirable to think about solutions that > could be backported to older versions. For older versions, if they have device link support, I'd recommend creating device links and letting that take care of it. Also, if you use the right GPIO APIs, at least on newer kernels Linus W was looking into creating device links automatically from the GPIO framework level. So maybe you can backport some variant of that into the older kernels and leave it to fw_devlink on the newer ones. -Saravana > This is why I provided the first > patch for discussion. Again, it is not a desirable solution just an > illustration what could be easily backported to restore the gpio-keys > behavior prior to commit 722e5f2b1eec ("driver core: Partially revert > "driver core: correct device's shutdown order"") without affecting other > devices. > > Thanks again for your willingness to take the time to think this through, > Doug > > > > > -Saravana >