From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D4C4C001DF for ; Fri, 4 Aug 2023 17:00:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r8BdgS9vI0KWDznkhpfHDnoizjddzRdv3O5Qlz2L9xo=; b=LqK0chIO/6AfPQ aGM4PFx22XiBmmpP76kmTUzyhFW1N8iacNdy2468tgqVtYlP6HMQJhm6kdINyCbBg/44Dqg1XU7nX gosAuAQL9O1vJaBsmfUds6a1KymAhUhwqXxtlMimVLjZFztj7Izy9UibAIEnA0tb16zwoXL26dT/0 PbMXk8vujRh0KKs+MIKP45qC0DjIw7ydBUjxGpQzoo8dFPOle+kuP+lqaiGB87Mfap4B9rLoWnWKf KMsRiza0EuCAeC5+2BoMxoStN2m+2urXs7fBrksp+GRCLpbpQazmWZoBY7PCGF6kMZ1H0OTlpnS9R vni6Mqe+3EBWuycxIY5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qRy9Z-00CqYr-1o; Fri, 04 Aug 2023 16:59:53 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qRy9W-00CqYP-0x for linux-arm-kernel@lists.infradead.org; Fri, 04 Aug 2023 16:59:51 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5E380616C4; Fri, 4 Aug 2023 16:59:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A73BDC433C8; Fri, 4 Aug 2023 16:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691168388; bh=PNFOMbmUZdgVT+kh12TTuTIEeamPyZ6PuMBUMdB/kVM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IZ4XbrRbIl86NxQzlvhvul5wzaQkmFJIXJllRkH5or5FFfBnJkDTz/fIOqRE6QPxi TFpzXHGIQAh03K5L270HIMuBDgNnknu7x8+i/vVIBGBo+EqugzvASjKbD3pYH/87Ph DkwPzfsdH/NxYgV4hWSy2eaHYkaAOiP/nVzlTEs8EGonGr4pCypK/tMt/RKXdVQYog wQd2s5zikFfXHdA/OpxGcfnEkCGs4rZAUX56DyFX8W4XSnmqRIPlk/0ZkPPvHSNoon W02BwlixBdOZnWaZmSFWcvMnjVWIUoENpb6L96+9UGiEjKiM9jXQlf/3DeFTigDEgu S536Rb901R5Fw== Date: Fri, 4 Aug 2023 17:59:44 +0100 From: Will Deacon To: Waiman Long Cc: Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Robin Murphy Subject: Re: [PATCH v3] perf/arm-dmc620: Fix dmc620_pmu_irqs_lock/cpu_hotplug_lock circular lock dependency Message-ID: <20230804165943.GG30679@willie-the-truck> References: <20230722031729.3913953-1-longman@redhat.com> <20230728150614.GF21718@willie-the-truck> <62d4b353-0237-9ec6-a63e-8a7a6764aba5@redhat.com> <20230804162812.GC30679@willie-the-truck> <458ac4d2-bb8a-0359-f198-dd53f4c84bd3@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <458ac4d2-bb8a-0359-f198-dd53f4c84bd3@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230804_095950_422826_B6CFC06E X-CRM114-Status: GOOD ( 30.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 04, 2023 at 12:51:47PM -0400, Waiman Long wrote: > On 8/4/23 12:28, Will Deacon wrote: > > > > > struct dmc620_pmu { > > > > > @@ -423,9 +424,14 @@ static struct dmc620_pmu_irq *__dmc620_pmu_g= et_irq(int irq_num) > > > > > struct dmc620_pmu_irq *irq; > > > > > int ret; > > > > > - list_for_each_entry(irq, &dmc620_pmu_irqs, irqs_node) > > > > > - if (irq->irq_num =3D=3D irq_num && refcount_inc_not_zero(&irq-= >refcount)) > > > > > + list_for_each_entry(irq, &dmc620_pmu_irqs, irqs_node) { > > > > > + if (irq->irq_num !=3D irq_num) > > > > > + continue; > > > > > + if (!irq->valid) > > > > > + return ERR_PTR(-EAGAIN); /* Try again later */ > > > > It looks like this can bubble up to the probe() routine. Does the d= river > > > > core handle -EAGAIN coming back from a probe routine? > > > Right, I should add code to handle this error condition. I think it c= an be > > > handled in dmc620_pmu_get_irq(). The important thing is to release the > > > mutex, wait a few ms and try again. What do you think? > > I don't really follow, but waiting a few ms and trying again sounds like > > a really nasty hack for something which doesn't appear to be constrained > > by broken hardware. In other words, we got ourselves into this mess, so > > we should be able to resolve it properly. > = > From my point of view, the proper way to solve the problem is to reverse = the > locking order. Since you don't to add a EXPORT statement to the core kern= el > code, we will have to find a way around it by not holding the > dmc620_pmu_irqs_lock when cpuhp_state_add_instance_nocalls() is called. > Another alternative that I can think of is to add one more mutex that we > will hold just for the entirety of=A0 __dmc620_pmu_get_irq() and take > dmc620_pmu_irqs_lock only when the linked list is being modified. That wi= ll > eliminate the need to introduce arbitrary wait as other caller of > __dmc620_pmu_get_irq() will wait in the new mutex. Will this work for you? Yes. To be honest, I think we've both spent far too much time trying to fix this (and I admire your persistence!), so adding a mutex to make it "obviously" correct sounds like the right thing to me. We can look at optimisations later if anybody cares. Cheers, Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel