Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9076715rwd; Wed, 21 Jun 2023 02:41:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66GRkXMh68Zq88k9IuyKI1dKSMTloBxiyHeT73BmLQleneCnnpGoYlAIBkYbye5RxeJdqN X-Received: by 2002:a05:6a20:3d0e:b0:123:100e:c8b2 with SMTP id y14-20020a056a203d0e00b00123100ec8b2mr1606111pzi.59.1687340490365; Wed, 21 Jun 2023 02:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687340490; cv=none; d=google.com; s=arc-20160816; b=ITlAGX2ieF13bsplogfJjp0z/f2wYBmV/629W0HNbPKtK1+U9xqFZk93L4KKKW9Nqt g+kMEq8OKHyR5kRRr/KjeKnG1C9ZChZXQP1yCdTmwSe80QJppVnNEvhu4ues+9ZEukD2 LwtQ0AUTELc99sfkAQRX0RS+KtLonRjtZnmoiAOD7Ehw4sFVjI3utPupPSGANpEmD+sG q8urLbRit/q0MUC+rypKrU3vGYliaiZicg15Hv5zrVqsm1/ycfl8K+5X/WKPeLvCkKH7 +K2vwJMk7kvvleZ2wyiwCykt8BLPb0ursER41OalnEPi1b6Nxfv6hFujLJih9Gzm3IPS Lv6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=77JyDNYtTWTC5vBEA5Y4/kTNHlH0NeCR6FArINIQxRU=; b=lZSPXoz58P1+/k85a0cwKfWLXvwSZjm2pqgQqlDXcqYcqwZDYhdn1lFi76EuY0Tla6 lIp03Jb1oCVo2IWaHmD0gD4W5doIvZAts4gH1L4SiLmm1fZzNt7tv4q7WXu7wjP2nGU9 BNci9amom0t6jWW8T14wxS0Cg8JbJkf6FmBk4DTWz6o1BSQ/D0nvfukI7luQUVyNgOj1 U9rGDf15DU+9WqNfD/3gESC99sXMigClcUwvxhTMVeufRmfOyG28lwpktQQqQJb8bg+r 8PGcNocNlxj6NW3Rf6o5jcIULNqE+Kmcf8Qx4UIVZ5L325abIWBMLdQorYVl96I5w7dr p6Zg== 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w186-20020a6382c3000000b0054fa5eb5283si1031688pgd.165.2023.06.21.02.41.15; Wed, 21 Jun 2023 02:41: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; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231655AbjFUJbi (ORCPT + 99 others); Wed, 21 Jun 2023 05:31:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbjFUJap (ORCPT ); Wed, 21 Jun 2023 05:30:45 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8211FE2; Wed, 21 Jun 2023 02:29:45 -0700 (PDT) Received: from canpemm500009.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QmJ9r1TZxzqV3q; Wed, 21 Jun 2023 17:29:36 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by canpemm500009.china.huawei.com (7.192.105.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 21 Jun 2023 17:29:43 +0800 From: Yicong Yang To: , , , , , CC: , , , , , , Subject: [PATCH v6 5/5] hwtracing: hisi_ptt: Fix potential sleep in atomic context Date: Wed, 21 Jun 2023 17:28:04 +0800 Message-ID: <20230621092804.15120-6-yangyicong@huawei.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230621092804.15120-1-yangyicong@huawei.com> References: <20230621092804.15120-1-yangyicong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500009.china.huawei.com (7.192.105.203) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 From: Yicong Yang We're using pci_irq_vector() to obtain the interrupt number and then bind it to the CPU start perf under the protection of spinlock in pmu::start(). pci_irq_vector() might sleep since [1] because it will call msi_domain_get_virq() to get the MSI interrupt number and it needs to acquire dev->msi.data->mutex. Getting a mutex will sleep on contention. So use pci_irq_vector() in an atomic context is problematic. This patch cached the interrupt number in the probe() and uses the cached data instead to avoid potential sleep. [1] commit 82ff8e6b78fc ("PCI/MSI: Use msi_get_virq() in pci_get_vector()") Fixes: ff0de066b463 ("hwtracing: hisi_ptt: Add trace function support for HiSilicon PCIe Tune and Trace device") Reviewed-by: Jonathan Cameron Signed-off-by: Yicong Yang --- drivers/hwtracing/ptt/hisi_ptt.c | 12 +++++------- drivers/hwtracing/ptt/hisi_ptt.h | 2 ++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/hwtracing/ptt/hisi_ptt.c b/drivers/hwtracing/ptt/hisi_ptt.c index 103fb6b9bffb..ba081b6d2435 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.c +++ b/drivers/hwtracing/ptt/hisi_ptt.c @@ -341,13 +341,13 @@ static int hisi_ptt_register_irq(struct hisi_ptt *hisi_ptt) if (ret < 0) return ret; - ret = devm_request_threaded_irq(&pdev->dev, - pci_irq_vector(pdev, HISI_PTT_TRACE_DMA_IRQ), + hisi_ptt->trace_irq = pci_irq_vector(pdev, HISI_PTT_TRACE_DMA_IRQ); + ret = devm_request_threaded_irq(&pdev->dev, hisi_ptt->trace_irq, NULL, hisi_ptt_isr, 0, DRV_NAME, hisi_ptt); if (ret) { pci_err(pdev, "failed to request irq %d, ret = %d\n", - pci_irq_vector(pdev, HISI_PTT_TRACE_DMA_IRQ), ret); + hisi_ptt->trace_irq, ret); return ret; } @@ -1098,8 +1098,7 @@ static void hisi_ptt_pmu_start(struct perf_event *event, int flags) * core in event_function_local(). If CPU passed is offline we'll fail * here, just log it since we can do nothing here. */ - ret = irq_set_affinity(pci_irq_vector(hisi_ptt->pdev, HISI_PTT_TRACE_DMA_IRQ), - cpumask_of(cpu)); + ret = irq_set_affinity(hisi_ptt->trace_irq, cpumask_of(cpu)); if (ret) dev_warn(dev, "failed to set the affinity of trace interrupt\n"); @@ -1394,8 +1393,7 @@ static int hisi_ptt_cpu_teardown(unsigned int cpu, struct hlist_node *node) * Also make sure the interrupt bind to the migrated CPU as well. Warn * the user on failure here. */ - if (irq_set_affinity(pci_irq_vector(hisi_ptt->pdev, HISI_PTT_TRACE_DMA_IRQ), - cpumask_of(target))) + if (irq_set_affinity(hisi_ptt->trace_irq, cpumask_of(target))) dev_warn(dev, "failed to set the affinity of trace interrupt\n"); hisi_ptt->trace_ctrl.on_cpu = target; diff --git a/drivers/hwtracing/ptt/hisi_ptt.h b/drivers/hwtracing/ptt/hisi_ptt.h index 164012dba4ec..e17f045d7e72 100644 --- a/drivers/hwtracing/ptt/hisi_ptt.h +++ b/drivers/hwtracing/ptt/hisi_ptt.h @@ -201,6 +201,7 @@ struct hisi_ptt_pmu_buf { * @pdev: pci_dev of this PTT device * @tune_lock: lock to serialize the tune process * @pmu_lock: lock to serialize the perf process + * @trace_irq: interrupt number used by trace * @upper_bdf: the upper BDF range of the PCI devices managed by this PTT device * @lower_bdf: the lower BDF range of the PCI devices managed by this PTT device * @port_filters: the filter list of root ports @@ -221,6 +222,7 @@ struct hisi_ptt { struct pci_dev *pdev; struct mutex tune_lock; spinlock_t pmu_lock; + int trace_irq; u32 upper_bdf; u32 lower_bdf; -- 2.24.0