Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1518487pxm; Thu, 24 Feb 2022 04:56:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCT2g7UDeUPwUcLYVzIbCJIBphnw1+MJDYRq6+JGstmrpRRszwHUUFf93/hMhDUXEbYMnB X-Received: by 2002:a17:902:9683:b0:14f:b8f1:9b63 with SMTP id n3-20020a170902968300b0014fb8f19b63mr2415567plp.11.1645707369076; Thu, 24 Feb 2022 04:56:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645707369; cv=none; d=google.com; s=arc-20160816; b=zuJpZBfN0VeGBER2dW6l24+5xT5pY+U89+/Ifg7H5qisu/OMFrwNpn9DpC5HHCrlL8 AeJ7AOmhDppfIT3j/3xGWNFVtPUtk9nDqd/BXteHBqKXCkGVhzei52a/hfa1LuRaVmtT 4uPA3jybH7YMgMyiCt6sYNo068csG+h461L+1Xc39SoDQmk6MJPQeMym5c8owEA8UFpF S3N0WsbhMADueC1owN+D2NVDOwcuOS3gGuezRLzPb8N8AD+t+Wlu06F9N2bQJc9p9lQ+ B6WnqvwL880GMcX+VOjeAMPwuZSqVerqLe8NMKsJH/yrvvUGghxKkAQEtwT2SQJfeHd4 dscQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=81r9gBlL6CltEHa9imGKhxVLgl48ZYJlw+00fkpxIQo=; b=rgMkX5q6RktnzdNKuzN7S0Bi7lXgv6gUke0u1Cn42ooNuWaZ6Ca4aNzHLx3RMVAR7x 60H/oGziBU6drELb7xM8X2Ie3BLeobx+gtMF4wcvFxvCQzB0FwWDBzvjK3HasMC/VLTd enwneoXWf8YU+lCe3lO0tt/NM8Ix9OR4D4I/lOOYAowXuTYK/IZKordIjf43IcKZ6pjH L4Ux9zuSHP5dAACAFiVJjK+Y9mVhymfs+BXwIVbnFliJTsHzxX8/id2FcptZoiQYwzaA dtWl94uNdnfA5Q2qv6xCkfivgCmAHyAHE+IEWpfsFTnJzdVs9lNBxQhrkmajn5ZDGav4 lnyQ== 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 s23si2147151pji.127.2022.02.24.04.55.51; Thu, 24 Feb 2022 04:56:09 -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; 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 S234194AbiBXL5o (ORCPT + 99 others); Thu, 24 Feb 2022 06:57:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234150AbiBXL5j (ORCPT ); Thu, 24 Feb 2022 06:57:39 -0500 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 167D249932; Thu, 24 Feb 2022 03:57:10 -0800 (PST) Received: from fraeml711-chm.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4K4B8y22VHz687sK; Thu, 24 Feb 2022 19:52:18 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml711-chm.china.huawei.com (10.206.15.60) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 24 Feb 2022 12:57:08 +0100 Received: from localhost.localdomain (10.69.192.58) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 24 Feb 2022 11:57:05 +0000 From: John Garry To: , CC: , , , Qi Liu , John Garry Subject: [PATCH 3/6] scsi: hisi_sas: Free irq vectors in order for v3 HW Date: Thu, 24 Feb 2022 19:51:26 +0800 Message-ID: <1645703489-87194-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1645703489-87194-1-git-send-email-john.garry@huawei.com> References: <1645703489-87194-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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: Qi Liu If the driver probe fails to request the channel IRQ or fatal IRQ, the driver will free the IRQ vectors before freeing the IRQs in free_irq(), and this will cause a kernel BUG like this: ------------[ cut here ]------------ kernel BUG at drivers/pci/msi.c:369! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Call trace: free_msi_irqs+0x118/0x13c pci_disable_msi+0xfc/0x120 pci_free_irq_vectors+0x24/0x3c hisi_sas_v3_probe+0x360/0x9d0 [hisi_sas_v3_hw] local_pci_probe+0x44/0xb0 work_for_cpu_fn+0x20/0x34 process_one_work+0x1d0/0x340 worker_thread+0x2e0/0x460 kthread+0x180/0x190 ret_from_fork+0x10/0x20 ---[ end trace b88990335b610c11 ]--- So we use devm_add_action() to control the order in which we free the vectors. Signed-off-by: Qi Liu Signed-off-by: John Garry --- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c index 29a566a19219..5b5557cab7ed 100644 --- a/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +++ b/drivers/scsi/hisi_sas/hisi_sas_v3_hw.c @@ -2397,17 +2397,25 @@ static irqreturn_t cq_interrupt_v3_hw(int irq_no, void *p) return IRQ_WAKE_THREAD; } +static void hisi_sas_v3_free_vectors(void *data) +{ + struct pci_dev *pdev = data; + + pci_free_irq_vectors(pdev); +} + static int interrupt_preinit_v3_hw(struct hisi_hba *hisi_hba) { int vectors; int max_msi = HISI_SAS_MSI_COUNT_V3_HW, min_msi; struct Scsi_Host *shost = hisi_hba->shost; + struct pci_dev *pdev = hisi_hba->pci_dev; struct irq_affinity desc = { .pre_vectors = BASE_VECTORS_V3_HW, }; min_msi = MIN_AFFINE_VECTORS_V3_HW; - vectors = pci_alloc_irq_vectors_affinity(hisi_hba->pci_dev, + vectors = pci_alloc_irq_vectors_affinity(pdev, min_msi, max_msi, PCI_IRQ_MSI | PCI_IRQ_AFFINITY, @@ -2419,6 +2427,7 @@ static int interrupt_preinit_v3_hw(struct hisi_hba *hisi_hba) hisi_hba->cq_nvecs = vectors - BASE_VECTORS_V3_HW; shost->nr_hw_queues = hisi_hba->cq_nvecs; + devm_add_action(&pdev->dev, hisi_sas_v3_free_vectors, pdev); return 0; } @@ -4768,7 +4777,7 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id) rc = scsi_add_host(shost, dev); if (rc) - goto err_out_free_irq_vectors; + goto err_out_debugfs; rc = sas_register_ha(sha); if (rc) @@ -4799,8 +4808,6 @@ hisi_sas_v3_probe(struct pci_dev *pdev, const struct pci_device_id *id) sas_unregister_ha(sha); err_out_register_ha: scsi_remove_host(shost); -err_out_free_irq_vectors: - pci_free_irq_vectors(pdev); err_out_debugfs: debugfs_exit_v3_hw(hisi_hba); err_out_ha: @@ -4824,7 +4831,6 @@ hisi_sas_v3_destroy_irqs(struct pci_dev *pdev, struct hisi_hba *hisi_hba) devm_free_irq(&pdev->dev, pci_irq_vector(pdev, nr), cq); } - pci_free_irq_vectors(pdev); } static void hisi_sas_v3_remove(struct pci_dev *pdev) -- 2.26.2