Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp900411pxt; Fri, 6 Aug 2021 17:25:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQO4Se3/9CM+txdB3AG8ObCiL9aau7puDrcDNv0TZypng5ufta1K1LIQb5PkiKh43cjeNQ X-Received: by 2002:a92:2911:: with SMTP id l17mr583433ilg.263.1628295926416; Fri, 06 Aug 2021 17:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628295926; cv=none; d=google.com; s=arc-20160816; b=CLTBIzBpBZKLtzrvQK2Fd8VYgwQy57NAz3EZqOgiozn75xWqDDOzwjvxDkKkvY1t4q HBlK+aowVBSG8od1IDgYTnS7xF1jkeRZvdcm6fUWPNpQ6clvN5yvNgDhkyZct9Y4iE0W kyR9pEotorrLXUFk7f3rllnUfhlyDV5jZ/VEwXRtYrZViWN+PxnNt4cUM3MEbjpl+Fc8 56tddwaFE/HZ1RoIEgT8bttAxP3fkBCtXVYCBsCizY91oWRf6owNyQQHxEQ3NSS4OsvB 5/njRfE4yffU2FvqJYPhBUoM/JPwX4SgPCoVQeiy8XqOvFtkp8ZIvlOUo8hPzEcyY4xw ikZA== 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=GqYzADmVgO8eu/I7MSORCLeA3yiZUEks8OI+aWsxxtY=; b=FMDOLNBhSnvP4J3RQs94D3qzVrMS6LExfB90RGSrx2uVSQIMuSMaQxikv+Zp4nGCUJ M3ptQormoVT0DwatOzZ3RMj+SsR1861tD81anxvyx0jmOl0NxF1+oPRPV4nWUyRrfq++ pd/jGVN4K2z4zWAdEz4QRS4NhaczA1B/83mfSTr1NF0Msd2bty/DYUFMYCLZSRSbL/rR GvLOqGAa9aTDywlAkxbwuTcLZZ7W4PzHSbCkuAtKX1jxnf9unj9iWiPzSRKj4wUvJ5Gj nZMEccxNozaBy9IvArXADf8xhhU1UltU/l3WyD1Ypb8oCh9lSuohY2ALH05oYWdGAbFO dnTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FmRQO5jv; 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 g13si12109189ilf.35.2021.08.06.17.25.15; Fri, 06 Aug 2021 17:25:26 -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=FmRQO5jv; 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 S229729AbhHFX4n (ORCPT + 99 others); Fri, 6 Aug 2021 19:56:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229632AbhHFX4m (ORCPT ); Fri, 6 Aug 2021 19:56:42 -0400 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2108EC0613CF for ; Fri, 6 Aug 2021 16:56:25 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id z5so16330978ybj.2 for ; Fri, 06 Aug 2021 16:56:25 -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:content-transfer-encoding; bh=GqYzADmVgO8eu/I7MSORCLeA3yiZUEks8OI+aWsxxtY=; b=FmRQO5jvt5NDkhWtxA1+RCBsrvV/6jAabOMVBUgVL1Kr4vkEI+ttrkR1GFAxSEwPCk /jXZG9P10zlijBANWFhg328mmGyJu8ymGuu3h3NtLkktrn+qHkVv5foJED/B9HGcofjN 7Xfldrdc0SX9Uwc3FQB890l5vXQIvJeALFyUK8Ug0wPVyemf9VBC2VgN+8k9cHOF1CQJ z1dnKv7CPjFypmWXmlobZDB4gokTuiMt/d/d35j3rP68RVtOke4ZAd2IhEB8P5dgapDb WDXZQDXyD+quR+253hfE8iC68d2k9cZvl06Lc+m1+Od1rYvYTpltRIcUYgIuTLRdP5Ck GYxg== 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:content-transfer-encoding; bh=GqYzADmVgO8eu/I7MSORCLeA3yiZUEks8OI+aWsxxtY=; b=HpxTB3rVhepDcPECt6XyFBvEw6IhQStVsomwqgHvDQHELDYQY3z9mcnFyro2aZ/zRn Njk4K8fgxM5mk0Rn1Xx7Y4rlidO1BHMY9FGEM0L7WWKfRgO6APetSoMB2kOEUCNXI41T P0kxoBx1f9xnkW9D/r76zHJok6HKzTgr7yU2uAods4EgM2mm+/A9LfPfe7z1FYB0c6s5 k4OKkOi00Nmfv8v55kbHFtJYESLMBTAfmw0b996YRIXvZkTiMLB9wvfgbxHOxLgj4oaE NAj/qIhKwjhagkFdhb6OWy+3/3Y3lSwqbbJ0/IAt+PeNCGpcjpFOewOQMQ9uwcVm8zv7 lAJA== X-Gm-Message-State: AOAM5330kuPSQLVP7K8mfabppYioRksTZUGyvh++L8DjBAH8xWbHP7yU mHnYXCQLESJCLS02z6bNINO7Vy2zxs7pdoRNGrAkrg== X-Received: by 2002:a25:53c9:: with SMTP id h192mr15299393ybb.310.1628294184035; Fri, 06 Aug 2021 16:56:24 -0700 (PDT) MIME-Version: 1.0 References: <20201020072532.949137-1-narmstrong@baylibre.com> <20201020072532.949137-2-narmstrong@baylibre.com> <7hsga8kb8z.fsf@baylibre.com> <87r1hwwier.wl-maz@kernel.org> <7h7diwgjup.fsf@baylibre.com> <87im0m277h.wl-maz@kernel.org> <87sfzpwq4f.wl-maz@kernel.org> <4e98d876-330f-21a4-846e-94e1f01f0eed@baylibre.com> In-Reply-To: <4e98d876-330f-21a4-846e-94e1f01f0eed@baylibre.com> From: Saravana Kannan Date: Fri, 6 Aug 2021 16:55:48 -0700 Message-ID: Subject: Re: [PATCH 1/2] irqchip: irq-meson-gpio: make it possible to build as a module To: Neil Armstrong Cc: Marc Zyngier , Andrew Lunn , Kevin Hilman , Lee Jones , Jerome Brunet , linux-amlogic@lists.infradead.org, linux-arm-kernel , open list , netdev , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 4, 2021 at 11:31 PM Neil Armstrong wr= ote: > > Hi Saravana, > > On 04/08/2021 23:47, Saravana Kannan wrote: > > On Wed, Aug 4, 2021 at 11:20 AM Saravana Kannan = wrote: > >> > >> On Wed, Aug 4, 2021 at 1:50 AM Marc Zyngier wrote: > >>> > >>> On Wed, 04 Aug 2021 02:36:45 +0100, > >>> Saravana Kannan wrote: > >>> > >>> Hi Saravana, > >>> > >>> Thanks for looking into this. > >> > >> You are welcome. I just don't want people to think fw_devlink is broke= n :) > >> > >>> > >>> [...] > >>> > >>>>> Saravana, could you please have a look from a fw_devlink perspectiv= e? > >>>> > >>>> Sigh... I spent several hours looking at this and wrote up an analys= is > >>>> and then realized I might be looking at the wrong DT files. > >>>> > >>>> Marc, can you point me to the board file in upstream that correspond= s > >>>> to the platform in which you see this issue? I'm not asking for [1], > >>>> but the actual final .dts (not .dtsi) file that corresponds to the > >>>> platform/board/system. > >>> > >>> The platform I can reproduce this on is described in > >>> arch/arm64/boot/dts/amlogic/meson-sm1-khadas-vim3l.dts. It is an > >>> intricate maze of inclusion, node merge and other DT subtleties. I > >>> suggest you look at the decompiled version to get a view of the > >>> result. > >> > >> Thanks. After decompiling it, it looks something like (stripped a > >> bunch of reg and address properties and added the labels back): > >> > >> eth_phy: mdio-multiplexer@4c000 { > >> compatible =3D "amlogic,g12a-mdio-mux"; > >> clocks =3D <0x02 0x13 0x1e 0x02 0xb1>; > >> clock-names =3D "pclk\0clkin0\0clkin1"; > >> mdio-parent-bus =3D <0x22>; > >> > >> ext_mdio: mdio@0 { > >> reg =3D <0x00>; > >> > >> ethernet-phy@0 { > >> max-speed =3D <0x3e8>; > >> interrupt-parent =3D <0x23>; > >> interrupts =3D <0x1a 0x08>; > >> phandle =3D <0x16>; > >> }; > >> }; > >> > >> int_mdio: mdio@1 { > >> ... > >> } > >> } > >> > >> And phandle 0x23 refers to the gpio_intc interrupt controller with the > >> modular driver. > >> > >>>> Based on your error messages, it's failing for mdio@0 which > >>>> corresponds to ext_mdio. But none of the board dts files in upstream > >>>> have a compatible property for "ext_mdio". Which means fw_devlink > >>>> _should_ propagate the gpio_intc IRQ dependency all the way up to > >>>> eth_phy. > >>>> > >>>> Also, in the failing case, can you run: > >>>> ls -ld supplier:* > >>>> > >>>> in the /sys/devices/..../ folder that corresponds to the > >>>> "eth_phy: mdio-multiplexer@4c000" DT node and tell me what it shows? > >>> > >>> Here you go: > >>> > >>> root@tiger-roach:~# find /sys/devices/ -name 'supplier*'|grep -i mdio= | xargs ls -ld > >>> lrwxrwxrwx 1 root root 0 Aug 4 09:47 /sys/devices/platform/soc/ff600= 000.bus/ff64c000.mdio-multiplexer/supplier:platform:ff63c000.system-control= ler:clock-controller -> ../../../../virtual/devlink/platform:ff63c000.syste= m-controller:clock-controller--platform:ff64c000.mdio-multiplexer > >> > >> As we discussed over chat, this was taken after the mdio-multiplexer > >> driver "successfully" probes this device. This will cause > >> SYNC_STATE_ONLY device links created by fw_devlink to be deleted > >> (because they are useless after a device probes). So, this doesn't > >> show the info I was hoping to demonstrate. > >> > >> In any case, one can see that fw_devlink properly created the device > >> link for the clocks dependency. So fw_devlink is parsing this node > >> properly. But it doesn't create a similar probe order enforcing device > >> link between the mdio-multiplexer and the gpio_intc because the > >> dependency is only present in a grand child DT node (ethernet-phy@0 > >> under ext_mdio). So fw_devlink is working as intended. > >> > >> I spent several hours squinting at the code/DT yesterday. Here's what > >> is going on and causing the problem: > >> > >> The failing driver in this case is > >> drivers/net/mdio/mdio-mux-meson-g12a.c. And the only DT node it's > >> handling is what I pasted above in this email. In the failure case, > >> the call flow is something like this: > >> > >> g12a_mdio_mux_probe() > >> -> mdio_mux_init() > >> -> of_mdiobus_register(ext_mdio DT node) > >> -> of_mdiobus_register_phy(ext_mdio DT node) > >> -> several calls deep fwnode_mdiobus_phy_device_register(ethernet_phy = DT node) > >> -> Tried to get the IRQ listed in ethernet_phy and fails with > >> -EPROBE_DEFER because the IRQ driver isn't loaded yet. > >> > >> The error is propagated correctly all the way up to of_mdiobus_registe= r(), but > >> mdio_mux_init() ignores the -EPROBE_DEFER from of_mdiobus_register() a= nd just > >> continues on with the rest of the stuff and returns success as long as > >> one of the child nodes (in this case int_mdio) succeeds. > >> > >> Since the probe returns 0 without really succeeding, networking stuff > >> just fails badly after this. So, IMO, the real problem is with > >> mdio_mux_init() not propagating up the -EPROBE_DEFER. I gave Marc a > >> quick hack (pasted at the end of this email) to test my theory and he > >> confirmed that it fixes the issue (a few deferred probes later, things > >> work properly). > >> > >> Andrew, I don't see any good reason for mdio_mux_init() not > >> propagating the errors up correctly (at least for EPROBE_DEFER). I'll > >> send a patch to fix this. Please let me know if there's a reason it > >> has to stay as-is. > > > > I sent out the proper fix as a series: > > https://lore.kernel.org/lkml/20210804214333.927985-1-saravanak@google.c= om/T/#t > > Thanks a lot for digging here and providing the appropriate fixes ! You are welcome! Btw, 'm too lazy to download the mbox for your original patch (justifiably not cc'ed in it) and reply to it. I made this comment earlier too. Can you please use the IRQCHIP_PLATFORM_DRIVER_BEGIN and IRQCHIP_PLATFORM_DRIVER_END macros? They avoid boilerplate code every irqchip driver has to implement, adds some restrictions to avoid unbinding these drivers/unloading these modules, and also makes it easy to convert from IRQCHIP_DECLARE to a platform driver. It'll also allow you to drop the of_irq_find_parent() call in your probe. Cheers, Saravana > > Neil > > > > > Marc, can you give it a shot please? > > > > -Saravana > > > >> > >> -Saravana > >> > >> index 110e4ee85785..d973a267151f 100644 > >> --- a/drivers/net/mdio/mdio-mux.c > >> +++ b/drivers/net/mdio/mdio-mux.c > >> @@ -170,6 +170,9 @@ int mdio_mux_init(struct device *dev, > >> child_bus_node); > >> mdiobus_free(cb->mii_bus); > >> devm_kfree(dev, cb); > >> + /* Not a final fix. I think it can cause UAF i= ssues. */ > >> + mdio_mux_uninit(pb); > >> + return r; > >> } else { > >> cb->next =3D pb->children; > >> pb->children =3D cb; >