Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp78518ybt; Thu, 18 Jun 2020 18:49:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgM+Lh2vetn6DZbdcELUSLGkGl+1NQgqgyJ6n0n1wHQj+2XuZ+6joS0BaGi8ZsSZbTjLL1 X-Received: by 2002:a50:e387:: with SMTP id b7mr986244edm.190.1592531387691; Thu, 18 Jun 2020 18:49:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592531387; cv=none; d=google.com; s=arc-20160816; b=wjB5pSqM5jMM0OfWiXoTMSZcukzj/MGG9b6xNcXFIfyFDIOasHGwVxhCwC5Kxbm2le fIiH9771SsTX5h57IegGWxVLE2RW5mReLoMHx3nkREYP3/NslTTU/lCh/zfYhycuYqNG yaAuWQv5ANfmltSA359Hlw/ZwdBG+fU4sekHuRQaqLILu/asa1JFlm5CJUvOYMjNM0x/ jZeZU6J0FemC0D8xb8jYHySD2JvxnuhLkt2CLTH6xF6rsobVMIPNlBra7B2JC5/3xzQx 1vqUQ3K3D9w4p4bbYh/R/y7oByLYZORuYC64ZwSR2B6TjOAl8dk2gHi8c7SBmZ+KbNHc XF9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=yc8mFXvH9+bvXdPbuCrBKeuEjVF5zsJFmzpNjkxHWMo=; b=pFLYsBvVBJrNw+DRXYV0dvH290UZdareB1cPkIEH644qz4k4nGqOW8nyDnBvOlSqYv s89ZhMBX+vVmPUFrL8Uh3lEobEkgARYcz1RKZR9nkRlMjeoGBts8pe2Aw/hpKzkssG8x eRl7hqI10creFfGme71gcmJqmO9oTiGqOfQ3xTNBmimeXL19mYZyjkHMJvyo5nNWIHR3 TrWUnSEDsk81YDdHCtGjRoocaF1gCg21+B73xf5LDbHj8jUT3WS4k7a78FGwW/fkJx8w NRoPTfnsKuRD9At1x24/XcCEB/hAqrqGRMbCfcdLjky6b7ml+4TxLsyn4MAQu0du56fY TGJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F6Qzk43n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz19si2928172edb.40.2020.06.18.18.49.25; Thu, 18 Jun 2020 18:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=F6Qzk43n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1731189AbgFRXBQ (ORCPT + 99 others); Thu, 18 Jun 2020 19:01:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730750AbgFRXBK (ORCPT ); Thu, 18 Jun 2020 19:01:10 -0400 Received: from mail-oo1-xc41.google.com (mail-oo1-xc41.google.com [IPv6:2607:f8b0:4864:20::c41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C7BC0613EE for ; Thu, 18 Jun 2020 16:01:10 -0700 (PDT) Received: by mail-oo1-xc41.google.com with SMTP id i4so1525184ooj.10 for ; Thu, 18 Jun 2020 16:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yc8mFXvH9+bvXdPbuCrBKeuEjVF5zsJFmzpNjkxHWMo=; b=F6Qzk43n9hOMr0F4NODTytpPzKoJejgC53DX0hNIAani5BvakYsEg5BYejBSfJJRFK Xveb1M2471hR5+hXD0nrRKJPWetO+Sm9CXdnLQ/354Jwx2+SAROf9zcH9nOj1f4r2BmG 4OhP4aiWNVP3N1Z3PnwsXKCCcwprjP/r7yknNF074Mqx5ocK34Qoz+i0yhVtZqSNZl8E IbSthlYnPjQ4Ifcop0/QphEEIYcIl9WJqyKdM1ZE+wTYMUHzs/utKyK0LIdSCWoIkVRg TFlIL6ILcD4OJudkIbjNqm5Ppsq4BTPCwfwbR9kT+/5+LeKmP6bHS9Q4Wvj+BLy2p9Uj P1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yc8mFXvH9+bvXdPbuCrBKeuEjVF5zsJFmzpNjkxHWMo=; b=Ad3/op306tosqAUZgXoqlXca9mQhLi8t/8ymE/+DQORe/6B07+OS9Cv+bt5ij+rLzv kWnYJ9NM+BJZE5anGGrZ18TLJ4wMjSLuv+QzuZVpkbaqSTYRwK7P5TYvo/yXyjF+7moS 16k49gaLZVudHJ6PMddQFc+SP1/1ysB4YyrIsZDDtGBHtl/dERWh9wZ/FBJ3YJXfSABb /iv3zip6w7j0hVu44gZE21w7YoEWMpZ9eaiDqNjdhn9Azb3S64jgXZkxn4hix6bNtPVV 8GtWMlQk3PwqgrScdKmOb0Y4CXZ3a4+0WXQ+lQ+5JtGZgLbmMbUDJ6Jp8AR1bYdg2P1i nElg== X-Gm-Message-State: AOAM533uPDRH+Sf1vEOIYwSfqlnRdEqi2cfM0gSvcaA+SEE/6G405rf1 KQc+TNyv+CFyioRMXNQFY9ImJCfxXw3aLDXZomDvNw== X-Received: by 2002:a4a:7ac2:: with SMTP id a185mr1035246ooc.84.1592521269356; Thu, 18 Jun 2020 16:01:09 -0700 (PDT) MIME-Version: 1.0 References: <20200515053500.215929-1-saravanak@google.com> <20200515053500.215929-5-saravanak@google.com> In-Reply-To: From: Saravana Kannan Date: Thu, 18 Jun 2020 16:00:33 -0700 Message-ID: Subject: Re: [PATCH v1 4/4] of: platform: Batch fwnode parsing when adding all top level devices To: Geert Uytterhoeven Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" , Rob Herring , Frank Rowand , Len Brown , Android Kernel Team , Linux Kernel Mailing List , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , ACPI Devel Maling List , Ji Luo , Linux-Renesas , Marek Szyprowski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 18, 2020 at 12:32 AM Geert Uytterhoeven wrote: > > Hi Saravana, > > On Wed, Jun 17, 2020 at 8:36 PM Saravana Kannan wrote: > > On Wed, Jun 17, 2020 at 5:20 AM Geert Uytterhoeven wrote: > > > On Fri, May 15, 2020 at 7:38 AM Saravana Kannan wrote: > > > > The fw_devlink_pause() and fw_devlink_resume() APIs allow batching the > > > > parsing of the device tree nodes when a lot of devices are added. This > > > > will significantly cut down parsing time (as much a 1 second on some > > > > systems). So, use them when adding devices for all the top level device > > > > tree nodes in a system. > > > > > > > > Signed-off-by: Saravana Kannan > > > > > > This is now commit 93d2e4322aa74c1a ("of: platform: Batch fwnode parsing > > > when adding all top level devices") in v5.8-rc1, and I have bisected a > > > regression to it: on r8a7740/armadillo and sh73a0/kzm9g, the system can > > > no longer be woken up from s2ram by a GPIO key. Reverting the commit > > > fixes the issue. > > > > > > On these systems, the GPIO/PFC block has its interrupt lines connected > > > to intermediate interrupt controllers (Renesas INTC), which are in turn > > > connected to the main interrupt controller (ARM GIC). The INTC block is > > > part of a power and clock domain. Hence if a GPIO is enabled as a > > > wake-up source, the INTC is part of the wake-up path, and thus must be > > > kept enabled when entering s2ram. > > > > > > While this commit has no impact on probe order for me (unlike in Marek's > > > case), it does have an impact on suspend order: > > > - Before this commit: > > > 1. The keyboard (gpio-keys) is suspended, and calls > > > enable_irq_wake() to inform the upstream interrupt controller > > > (INTC) that it is part of the wake-up path, > > > 2. INTC is suspended, and calls device_set_wakeup_path() to inform > > > the device core that it must be kept enabled, > > > 3. The system is woken by pressing a wake-up key. > > > > > > - After this commit: > > > 1. INTC is suspended, and is not aware it is part of the wake-up > > > path, so it is disabled by the device core, > > > 2. gpio-keys is suspended, and calls enable_irq_wake() in vain, > > > 3. Pressing a wake-up key has no effect, as INTC is disabled, and > > > the interrupt does not come through. > > > > > > It looks like no device links are involved, as both gpio-keys and INTC have > > > no links. > > > Do you have a clue? > > > > > > Thanks! > > > > That patch of mine defers probe on all devices added by the > > of_platform_default_populate() call, and then once the call returns, > > it immediately triggers a deferred probe. > > > > So all these devices are being probed in parallel in the deferred > > probe workqueue while the main "initcall thread" continues down to > > further initcalls. It looks like some of the drivers in subsequent > > initcalls are assuming that devices in the earlier initcalls always > > probe and can't be deferred? > > > > There are two options. > > 1. Fix these drivers. > > 2. Add a "flush deferred workqueue" in fw_devlink_resume() > > > > I'd rather we fix the drivers so that they handle deferred probes > > correctly. Thoughts? > > While the affected drivers should handle deferred probe fine, none of > the affected drivers is subject to deferred probing: they all probe > successfully on first try (I had added debug prints to > platform_drv_probe() to be sure). > The affected drivers are still probed in the same order (INTC is one of > the earliest drivers probed, gpio-keys is the last). Thanks, this is useful info. Now I know that my patch isn't somehow reordering devices that would have probed as soon as of_platform_default_populate_init() added them. When you say the "The affected drivers are still probed in the same order", are you only referring to the devices that would have probed before of_platform_default_populate_init() returns? Or ALL devices in the system are probing in the same order? I assume gpio-keys gets probed in the "normal init thread" and not by the deferred probe workqueue? I'm guessing this because gpio_keys driver seems to register during late_initcall() whereas of_platform_default_populate_init() runs as an arch_initcall_sync(). > However, during > system suspend, gpio-keys is suspended before INTC, which is wrong, as > gpio-keys uses an interrupt provided by INTC. > > Perhaps the "in parallel" is the real culprit, and there is a race > condition somewhere? I tried digging into the gpio_keys driver code to see how it interacts with INTC and if gpio-keys defers probe if INTC hasn't probed yet. But it seems like a rabbit hole that'd be easier to figure out when you have the device. Can you check if gpio-keys is probing before INTC in the "bad" case? Also, in general, can you see if there's a difference in the probe order between all the devices in the system? Adding a log to really_probe() would be better in case non-platform devices are getting reordered (my change affects all devices that are created from DT, not just platform devices). I want to make sure we understand the real issue before we try to fix it. Thanks, Saravana