Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2353172pxp; Mon, 7 Mar 2022 13:36:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyu0g3CTqrH3GHoTHzZQh8gaF6IKQDGCA1jOjmlpLegOtTANrUwzce0Q9XGXLNK82M5rKi7 X-Received: by 2002:a05:6402:268c:b0:411:e086:b7d1 with SMTP id w12-20020a056402268c00b00411e086b7d1mr12979785edd.111.1646689012380; Mon, 07 Mar 2022 13:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646689012; cv=none; d=google.com; s=arc-20160816; b=JKHMvxYcn3xE6teuSplK/sq5rJr/q5yn3CtJlBzmqmKicLzOqJxBS3/Q3mBUBH8tG2 IIWA0Vz4gkEzqRgTrgQKbnnKHeDazp7lgOWJFU65XbauFbTs708tWpJMAiTu22JY2q6g 48vTApmtRJj8mkCN5+90xKRnYcSz+OTnkGnY9GDAsKiMemxJAxtYkJlVWGJADHVglyBY kfjDh1i/U2R+LQYZ16nh8JvYjrV/iltMauGSynu6DFTmXYZxfOlJ0gQCm9H/gntYD40s G1e/LNzKR0CCGJch9FdsguinbULmN1upaPrRfpQL1J8jVEpDDUj0NdM07FoIfMKIYGmm zliA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=9CMICOLW0ehmzdvcowkmjY0qR9QjPwXylZuMt39hq2I=; b=uZ82mAvcIL2spZnJpMyd1mvRyKaXV0W12fUk8AtwZjIfFBD1DDD2L56hXmggWjQTZC llF2hpNyuxNX1vKoLeIRsk6Rl8bPG654yORgfm9PKL5z52QLhB6oX4a+QB2Fmm9ZpURj dg5Rvy/lnT9WNOLp1/uZ+GBqjLHU6scm2X+04jnPatJnD7kYW/UQzlZcaGStjf1p5Sey eb2cYvlEEpzayY0/3bxCFzKLTp960QYSnGSq5I0OrtgFFSA8ZlRRv4syFuZnoXzCbjbD QChngy8zneYtQZ6pU7KVs0QQyyFzV8pi4BpoevpCuNijokxiS2YX5Z9Y0wmElCDy+kve fCfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=P84h5fUD; 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 c18-20020a056402143200b00410a0848d92si9428284edx.461.2022.03.07.13.36.30; Mon, 07 Mar 2022 13:36:52 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=P84h5fUD; 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 S235554AbiCGLqn (ORCPT + 99 others); Mon, 7 Mar 2022 06:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbiCGLqm (ORCPT ); Mon, 7 Mar 2022 06:46:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3571865D3D; Mon, 7 Mar 2022 03:45:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A9BBD60C1D; Mon, 7 Mar 2022 11:45:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 044E0C340E9; Mon, 7 Mar 2022 11:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646653547; bh=HuiySr2XK/xcf/nv6byy2sSmP0H0uimJUGFICGPJW+M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=P84h5fUDcTZEXt4/p4iUbrTKpxkZ6eLgBJ0hOY3fIXpHeeXaVpP0wD2Zspi0RCS18 F1OKsCSWrJxFwwIymuTpGR2YtQG8QXTRQX3Jm9hVPU/cFCxgCSCh05doMa7qhrG0R5 /R+zMuHUVbO/qr24jqiztWN5mg0s1gqUkDXqoDj1B6o63HBXMrzSuxGsVCXeCeigTN xKOhXxdvvkEPGeSs6EWqlbVMi2vFC47Io0nr79HDm679hRJaT0Th5iyqOjqty6Q+D4 vwwrRBaaAJq1Cx4O5VOXysb02iFDqSmXEgKIZLqNxHWZ0cGXAIQ/EVMnZvCTYew3wd yC6CiCmcxtXyw== Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nRBo8-00Clmr-N8; Mon, 07 Mar 2022 11:45:44 +0000 Date: Mon, 07 Mar 2022 11:45:44 +0000 Message-ID: <87cziy0yvr.wl-maz@kernel.org> From: Marc Zyngier To: Shawn Guo Cc: Thomas Gleixner , Maulik Shah , Bjorn Andersson , Sudeep Holla , Rob Herring , devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v7 2/2] irqchip: Add Qualcomm MPM controller driver In-Reply-To: <20220306125710.GQ269879@dragon> References: <20220302084028.GL269879@dragon> <877d9c3b2u.wl-maz@kernel.org> <20220302133441.GM269879@dragon> <875yow31a0.wl-maz@kernel.org> <20220303040229.GN269879@dragon> <87fsnytagc.wl-maz@kernel.org> <20220304082342.GO269879@dragon> <87lexp211g.wl-maz@kernel.org> <20220305092420.GP269879@dragon> <87czj0u0bg.wl-maz@kernel.org> <20220306125710.GQ269879@dragon> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: shawn.guo@linaro.org, tglx@linutronix.de, quic_mkshah@quicinc.com, bjorn.andersson@linaro.org, sudeep.holla@arm.com, robh+dt@kernel.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 Sun, 06 Mar 2022 12:57:10 +0000, Shawn Guo wrote: > > On Sat, Mar 05, 2022 at 11:05:07AM +0000, Marc Zyngier wrote: > > On Sat, 05 Mar 2022 09:24:20 +0000, > > Shawn Guo wrote: > > > > > > On Fri, Mar 04, 2022 at 03:24:43PM +0000, Marc Zyngier wrote: > > > > On Fri, 04 Mar 2022 08:23:42 +0000, > > > > Shawn Guo wrote: > > > > > > > > > > On Fri, Mar 04, 2022 at 07:59:15AM +0000, Marc Zyngier wrote: > > > > > > On Thu, 03 Mar 2022 04:02:29 +0000, > > > > > > Shawn Guo wrote: > > > > > > > > > > > > > > On Wed, Mar 02, 2022 at 01:57:27PM +0000, Marc Zyngier wrote: > > > > > > > > This code actually makes me ask more questions. Why is it programming > > > > > > > > 2 'pins' for each IRQ? > > > > > > > > > > > > > > The mapping between MPM pin and GIC IRQ is not strictly 1-1. There are > > > > > > > some rare case that up to 2 MPM pins map to a single GIC IRQ, for > > > > > > > example the last two in QC2290 'qcom,mpm-pin-map' below. > > > > > > > > > > > > > > qcom,mpm-pin-map = <2 275>, /* tsens0_tsens_upper_lower_int */ > > > > > > > <5 296>, /* lpass_irq_out_sdc */ > > > > > > > <12 422>, /* b3_lfps_rxterm_irq */ > > > > > > > <24 79>, /* bi_px_lpi_1_aoss_mx */ > > > > > > > <86 183>, /* mpm_wake,spmi_m */ > > > > > > > <90 260>, /* eud_p0_dpse_int_mx */ > > > > > > > <91 260>; /* eud_p0_dmse_int_mx */ > > > > > > > > > > > > > > > > > > > > > The downstream uses a DT bindings that specifies GIC hwirq number in > > > > > > > client device nodes. In that case, d->hwirq in the driver is GIC IRQ > > > > > > > number, and the driver will need to query mapping table, find out the > > > > > > > possible 2 MPM pins, and set them up. > > > > > > > > > > > > > > The patches I'm posting here use a different bindings that specifies MPM > > > > > > > pin instead in client device nodes. Thus the driver can simply get the > > > > > > > MPM pin from d->hwirq, so that the whole look-up procedure can be saved. > > > > > > > > > > > > It still remains that there is no 1:1 mapping between input and > > > > > > output, which is the rule #1 to be able to use a hierarchical setup. > > > > > > > > > > For direction of MPM pin -> GIC interrupt, it's a 1:1 mapping, i.e. for > > > > > given MPM pin, there is only one GIC interrupt. And that's the > > > > > mapping MPM driver relies on. For GIC interrupt -> MPM pin, it's not > > > > > a strict 1:1 mapping. > > > > > > > > Then this isn't a 1:1 mapping *AT ALL*. The hierarchical setup > > > > mandates that the mapping is a bijective function, and that's exactly > > > > what 1:1 means. There is no such thing a 1:1 in a single > > > > direction. When you take an interrupt, all you see is the GIC > > > > interrupt. How do you know which of the *two* pins interrupted you? Oh > > > > wait, you *can't* know. You end-up never servicing one of the two > > > > interrupts > > > > > > Yes, you are right! But that might be a problem only in theory. I > > > checked all the Qualcomm platforms I know built on MPM, and found that > > > the only 2:1 case is USB DP & DM sensing pins. Since these two pins > > > will be handled by USB driver with a single interrupt handler, it should > > > not cause any problem in practice. That said, the 2:1 mapping is just > > > a special case specific to USB, and MPM driver can be implemented as if > > > it's just a 1:1 mapping. > > > > > > Shawn > > > > > > > (and I suspect this results in memory corruption if you > > > > tear a hierarchy down). > > > > Key point here ^^^^^^^^^^ > > > > You can't have *any* interrupt that fits this 2:1 model if the irqchip > > implements 1:1. Think about the data structures for a second: > > > > Pins x and y and routed to GIC interrupt z. This results in the > > following irq_data structures: > > > > MPM-x ---\ > > GIC-z > > MPM-y ---/ > > > > Now, the driver using these interrupts is being removed, and the > > hierarchies is being freed. Tearing down the interrupt with pin x will > > result in z being also freed. And then you'll process pin y, which > > will just explode. > > I tested with manually unbinding the USB driver and didn't run into any > memory corruption. If I read irq_domain code right, it seems that > irq_domain_alloc_irq_data() will call into irq_domain_insert_irq_data() > to allocate z irq_data in context of virq x and y respectively. So x > and y do not share a single parent (z) irq_data but have their own copy > of z irq_data, no? Which is just another bug you are relying on. Maybe you're OK with that, but I'm not (and I intend to fix this bug). I'm not taking this driver until you either: - prevent a pin sharing a GIC interrupt from triggering an interrupt allocation in the driver - or turn this driver into something that isn't a hierarchical setup M. -- Without deviation from the norm, progress is not possible.