Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1126109imw; Tue, 5 Jul 2022 04:20:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJGGVnyzk5lxBOwnmJ3rcprcRGag+Ow6WJZ7ZS0Mr7SwUgUY8T42K1Myz1p2YqDpIduFjb X-Received: by 2002:a17:902:b215:b0:168:da4b:c925 with SMTP id t21-20020a170902b21500b00168da4bc925mr39435775plr.155.1657020001914; Tue, 05 Jul 2022 04:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657020001; cv=none; d=google.com; s=arc-20160816; b=u1SV3QCvl2HwF0BATKGosnpZBUYkVrHU3JUPh/LOYtPKbg6RIdKM3D9flEvxjwHKZH u68saqr7rEhBx3HEcHwP6fYltE002WimA/yRg3A5RznFCvWzXtjpXQLRTyD9uamKhfHx maJLx4zrgCTVXxU5XFbG8Go/IYPirWuXLRA782E7YBOckD2WdLgz8KPJcXm51TTp28v8 gfAscS1+dGe76arQ+sCf7XV+HwQNVNyzR9kPcdcAOo1/Evrat92RpZNGe0HnjBAcrgmD HQ3s0ETj2oUKrl/DnNw50+eQJMszDO3/nizn8yzyMd7S66INhZjaRSKQe0vvbP0+ouL/ SU0g== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=gJib4yC8ddKU1zGRSABajvBZwLO6na6kBYhX/lvGwUU=; b=1BbHpee6XqOvukNXFksQj/STdEylhg1Da/p5szEPE2f5VPijlAzACxPhVp4SJaHne1 3kg91CNOqR7NkQMmrH6XCzBofDrjqYAyM8rbMkxOqisOM7LLmnmr6TKBITTysUfbYHK0 AcQ6WIkAnG3u5zvBN2F0nYFGgvEuhkVAv9v1Yh3l/z6Nkn/KABJXPXNXb6eQzIasR3LK EsdWHIr3Y2/1Nk3q4lVVLVVEi7jUrYPC5xnY7okP8f2ZwfEkzVS0faanaA+6HXfksMcp yMS5Agox5BD9Dwm4IqktM3UwZHGaa06xU0CTpvDzNOYj7duUVQCM/bqNkisYoJqOH3YU pOfw== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q132-20020a632a8a000000b0040d1569b651si16274335pgq.870.2022.07.05.04.19.50; Tue, 05 Jul 2022 04:20: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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbiGELF3 (ORCPT + 99 others); Tue, 5 Jul 2022 07:05:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbiGELF3 (ORCPT ); Tue, 5 Jul 2022 07:05:29 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AD86113F05 for ; Tue, 5 Jul 2022 04:05:27 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BE3492B; Tue, 5 Jul 2022 04:05:27 -0700 (PDT) Received: from bogus (unknown [10.57.39.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D644C3F792; Tue, 5 Jul 2022 04:05:24 -0700 (PDT) Date: Tue, 5 Jul 2022 12:04:13 +0100 From: Sudeep Holla To: Saravana Kannan Cc: Russell King , Philipp Zabel , Rob Herring , Ulf Hansson , John Stultz , Linus Walleij , Nicolas Saenz Julienne , Geert Uytterhoeven , Marek Szyprowski , Kefeng Wang , kernel-team@android.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4] amba: Remove deferred device addition Message-ID: <20220705110413.vgu6qcpndjpwh5wv@bogus> References: <20220705083934.3974140-1-saravanak@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220705083934.3974140-1-saravanak@google.com> X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,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 Tue, Jul 05, 2022 at 01:39:34AM -0700, Saravana Kannan wrote: > The uevents generated for an amba device need PID and CID information > that's available only when the amba device is powered on, clocked and > out of reset. So, if those resources aren't available, the information > can't be read to generate the uevents. To workaround this requirement, > if the resources weren't available, the device addition was deferred and > retried periodically. > > However, this deferred addition retry isn't based on resources becoming > available. Instead, it's retried every 5 seconds and causes arbitrary > probe delays for amba devices and their consumers. > > Also, maintaining a separate deferred-probe like mechanism is > maintenance headache. > > With this commit, instead of deferring the device addition, we simply > defer the generation of uevents for the device and probing of the device > (because drivers needs PID and CID to match) until the PID and CID > information can be read. This allows us to delete all the amba specific > deferring code and also avoid the arbitrary probing delays. > > Cc: Rob Herring > Cc: Ulf Hansson > Cc: John Stultz > Cc: Saravana Kannan > Cc: Linus Walleij > Cc: Sudeep Holla > Cc: Nicolas Saenz Julienne > Cc: Geert Uytterhoeven > Cc: Marek Szyprowski > Cc: Kefeng Wang > Cc: Russell King > Signed-off-by: Saravana Kannan > --- > > v1 -> v2: > - Dropped RFC tag > - Complete rewrite to not use stub devices. > > v2 -> v3: > - Flipped the if() condition for hard-coded periphids. > - Added a stub driver to handle the case where all amba drivers are > modules loaded by uevents. > - Cc Marek after I realized I forgot to add him. > > v3 -> v4: > - Finally figured out and fixed the issue reported by Kefeng (bus match > can't return an error other than -EPROBE_DEFER). > - I tested the patch on "V2P-CA15" on qemu > - Marek tested v3, but that was so long ago and the rebase wasn't clean, > so I didn't include the tested-by. > > Marek/Kefeng, > > Mind giving a Tested-by? > > -Saravana > > drivers/amba/bus.c | 317 +++++++++++++++++++++------------------------ > 1 file changed, 145 insertions(+), 172 deletions(-) > > diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c > index 0e3ed5eb367b..9590c93b2aea 100644 > --- a/drivers/amba/bus.c > +++ b/drivers/amba/bus.c > @@ -130,11 +130,100 @@ static struct attribute *amba_dev_attrs[] = { > }; > ATTRIBUTE_GROUPS(amba_dev); > > +static int amba_read_periphid(struct amba_device *dev) > +{ > + struct reset_control *rstc; > + u32 size, pid, cid; > + void __iomem *tmp; > + int i, ret; > + > + ret = dev_pm_domain_attach(&dev->dev, true); > + if (ret) { > + dev_dbg(&dev->dev, "can't get PM domain: %d\n", ret); > + goto err_out; > + } > + > + ret = amba_get_enable_pclk(dev); > + if (ret) { > + dev_dbg(&dev->dev, "can't get pclk: %d\n", ret); > + goto err_pm; > + } > + > + /* > + * Find reset control(s) of the amba bus and de-assert them. > + */ > + rstc = of_reset_control_array_get_optional_shared(dev->dev.of_node); > + if (IS_ERR(rstc)) { > + ret = PTR_ERR(rstc); > + if (ret != -EPROBE_DEFER) > + dev_err(&dev->dev, "can't get reset: %d\n", ret); > + goto err_clk; > + } > + reset_control_deassert(rstc); > + reset_control_put(rstc); > + > + size = resource_size(&dev->res); > + tmp = ioremap(dev->res.start, size); > + if (!tmp) { > + ret = -ENOMEM; > + goto err_clk; > + } > + I am seeing constant crash roughly around here. The read below is triggering synchronous external abort. And adding even a single printk above this anywhere seem to be making the issue disappear. While any prints after the below reads just defer the issue and finally hit for some other device while it always hits for the first delayed amba device. > + /* > + * Read pid and cid based on size of resource > + * they are located at end of region > + */ > + for (pid = 0, i = 0; i < 4; i++) > + pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8); > + for (cid = 0, i = 0; i < 4; i++) > + cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8); > + I haven't spent time debugging this any further. -- Regards, Sudeep 1. No logs, always crash Internal error: synchronous external abort: 96000210 [#1] PREEMPT SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.19.0-rc5-next-20220705-00001-g69f8b939ba4c #244 Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform, BIOS EDK II Jun 21 2022 pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : amba_read_periphid+0x128/0x270 lr : amba_read_periphid+0x114/0x270 sp : ffff80000803bc40 x29: ffff80000803bc40 x28: f675a09e14a55da9 x27: ffff800009c56068 x26: 0000000000000007 x25: ffff00080035f500 x24: ffff0008016c6468 x23: ffff80000a5be848 x22: ffff80000a446088 x21: 0000000000000000 x20: ffff0008003e1c00 x19: 0000000000001000 x18: ffffffffffffffff x17: 000000000000001c x16: 000000005885f043 x15: ffff000800032a1c x14: ffffffffffffffff x13: 0000000000000000 x12: 0101010101010101 x11: ffff800008000000 x10: 0000000022010000 x9 : 0140000000000000 x8 : 0040000000000001 x7 : 0000800019e9b000 x6 : 0000000000000000 x5 : ffff800048175000 x4 : 0000000000000000 x3 : ffff800008175fe0 x2 : 0068000000000f13 x1 : 0000000000000000 x0 : ffff800008175000 Call trace: amba_read_periphid+0x128/0x270 amba_match+0x24/0x90 __driver_attach+0x2c/0x1c4 bus_for_each_dev+0x60/0xd0 driver_attach+0x24/0x30 bus_add_driver+0xf4/0x230 driver_register+0xbc/0x110 amba_stub_drv_init+0x6c/0x9c do_one_initcall+0x6c/0x1c0 kernel_init_freeable+0x34c/0x444 kernel_init+0x28/0x13c ret_from_fork+0x10/0x20 Code: d1008263 52800004 8b030003 52800006 (b9400062) ---[ end trace 0000000000000000 ]--- 2. With prints after 2 for loops above amba_read_periphid 20030000.tpiu amba_read_periphid 20040000.funnel amba_read_periphid 20070000.etr amba_read_periphid 20100000.stm amba_read_periphid 20120000.replicator Internal error: synchronous external abort: 96000210 [#1] PREEMPT SMP Modules linked in: CPU: 4 PID: 1 Comm: swapper/0 Not tainted 5.19.0-rc5-next-20220705-00001-g69f8b939ba4c-dirty #243 Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno Development Platform, BIOS EDK II Jun 21 2022 pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : readl+0x4/0x20 lr : amba_read_periphid+0x138/0x250 sp : ffff80000803bc40 x29: ffff80000803bc40 x28: f675a09e14a55da9 x27: ffff800009c56068 x26: 0000000000000007 x25: ffff00080035f500 x24: ffff000800248568 x23: ffff80000a5be848 x22: ffff80000a446088 x21: 0000000000001000 x20: ffff0008003e1c00 x19: 00000000fffffff4 x18: ffffffffffffffff x17: 000000040044ffff x16: 00400032b5503510 x15: 0000000000000000 x14: ffffffffffffffff x13: 0000000000000000 x12: 0101010101010101 x11: ffff800008000000 x10: 0000000022010000 x9 : 0140000000000000 x8 : 0040000000000001 x7 : 0000800019e9b000 x6 : 0000000000000000 x5 : ffff800048175000 x4 : 0000000000000000 x3 : ffff800008175000 x2 : ffff800008175fe0 x1 : 0000000000000000 x0 : ffff800008175fe0 Call trace: readl+0x4/0x20 amba_match+0x24/0x90 __driver_attach+0x2c/0x1c4 bus_for_each_dev+0x60/0xd0 driver_attach+0x24/0x30 bus_add_driver+0xf4/0x230 driver_register+0xbc/0x110 amba_stub_drv_init+0x6c/0x9c do_one_initcall+0x6c/0x1c0 kernel_init_freeable+0x34c/0x444 kernel_init+0x28/0x13c ret_from_fork+0x10/0x20 Code: d50323bf d65f03c0 00000000 d503233f (b9400000) ---[ end trace 0000000000000000 ]---