Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp135670rwb; Fri, 4 Aug 2023 10:12:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqTfOjyYZQAYTrtYMtb17ntjyrjJWgehVu+kd7u/rNF/zcmL1WuJ4sbA7wqq3GGg72qrMJ X-Received: by 2002:aa7:dc12:0:b0:522:cb97:f198 with SMTP id b18-20020aa7dc12000000b00522cb97f198mr1836238edu.38.1691169150112; Fri, 04 Aug 2023 10:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691169150; cv=none; d=google.com; s=arc-20160816; b=bu6Rk9A9DcN3ztF9J2hiIsqFj8MHaAKutSnngTqs0sGqp61SyZ/SMxzz1elbZxMysJ Ys+109bMY6hiEYsHCBQGZ9NrCI4tzer1Ecjdd7kVpCSNzqau2pOiz4H0JYprq3VXFyWN 4LzWNdP7I8cMBhlf5YM/cOlV5OigpFwvQr6p7NaZ9r/JeROxbXex/yjXzCkwZGbE95ll SYlWwnzOKoOg6QAAgfZFFBsJxUR9yTLZpMiFePCxkR1HOBMeUXaNP0nzt2rx8PR7LFlV JhoaulpGoiaY0PfEmNkgIhUHhRQVkxQlsNqnuk5eMTxpTEnkqnVTGTm5pRBaPLw/6jvE /VlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Fw8XJK2eRpq/MjtADCInfm3bB6bWxPLiBmJyL2/vXAA=; fh=UwM/W5HGM/nEetHB+ilkGPwa1zcrcWVE+39xMMwarLk=; b=kINQHUtfM+Fx0LncJqSkAhCvRuV7f8no7g6+jpLre3XwAYLZk0hN3/ykmRi9PYw8+o uJSc5lbtUXaFAONmXOO3iIP0OuCvAENSkdCkTuee337ozFl5YOm1zOPYU4iaslQ9ooJ/ yXYfc4v1KiqV7m+hZl91LONgHNMbnZYUoRtS5C8AQJcGfYNuVz+/uQ+PHUYbtq9Lzltx ylbc+3rf/Lui32PKnbN30C8j4poTw+pxdD7LQRn+xF0Y7GNYb8vnV42bcBQLezMdEle8 Ma+JrxCmg8g45REWUBV+PWAegjWwCMnK/TrBTqnCNuGqfdte6xBJd5NJLGaSPxA6AIEW lCJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IZ4XbrRb; 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 r14-20020aa7da0e000000b0052227d6e699si1892743eds.686.2023.08.04.10.11.48; Fri, 04 Aug 2023 10:12:30 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IZ4XbrRb; 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 S231439AbjHDQ7w (ORCPT + 99 others); Fri, 4 Aug 2023 12:59:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbjHDQ7u (ORCPT ); Fri, 4 Aug 2023 12:59:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D002D1994 for ; Fri, 4 Aug 2023 09:59:49 -0700 (PDT) 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 6546B620B7 for ; 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-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <458ac4d2-bb8a-0359-f198-dd53f4c84bd3@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 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_get_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 == irq_num && refcount_inc_not_zero(&irq->refcount)) > > > > > + list_for_each_entry(irq, &dmc620_pmu_irqs, irqs_node) { > > > > > + if (irq->irq_num != 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 driver > > > > core handle -EAGAIN coming back from a probe routine? > > > Right, I should add code to handle this error condition. I think it can 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 kernel > 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? __dmc620_pmu_get_irq() and take > dmc620_pmu_irqs_lock only when the linked list is being modified. That will > 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