From patchwork Thu Jul 20 12:24:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Zhan X-Patchwork-Id: 123238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3085670vqt; Thu, 20 Jul 2023 05:36:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlEApnMdSqa++1wYZQrYGpFESbDceq/LrNcYL+8tzk9/hOOLNQNKHPR+qdxgUV3p+jKVtOfw X-Received: by 2002:a17:907:7d8a:b0:98d:5ae2:f1c with SMTP id oz10-20020a1709077d8a00b0098d5ae20f1cmr5542809ejc.34.1689856598202; Thu, 20 Jul 2023 05:36:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689856598; cv=none; d=google.com; s=arc-20160816; b=ZL1/m20w0+H54/v73bK5h2Kk4c9RvT9S4x+afaVldlkxTh0HlYUJCHygGmJAJuRTvx HtIXcYzGpj/npqnZucObl6nlV0JaFS0cpeyyLKvyT65vYRdH6tUQfUdmO2NMYhrsQQsT Bh5YViKNKvtY77krsTYPPM+zGTvFAnLE7dPMA0wTBkQjiQg49yBi9zYzx2rqkyZ+JJu7 CmNGRVMAV+MctWV41t05RHnh/4BXlnvS5knoD37RjYSKzT/EzrWxFs4KOdEjRHmrc9q/ qZe2zCHQXJvzQVGMeqYHWAF3dxW7EBKLpjwDhWAUT+7DNHlxsfdxJhTeECA8rxLx1H/z SHkQ== 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 :message-id:date:subject:cc:to:from; bh=488Jxbwl7uQO/Mr6KSQ3dpzo6BXedlGk2e7/xu/056M=; fh=ZwfzKS7z+kEBzHxI/ir9TNOa3NSbqm2znrACmSJSOX0=; b=ruBm6dW5YcVrfJAIylmkfdW1OzyDNL3XJV9inaC3wVmIgf7TPcbW2GBiKTOmUnuEiO QPyS9GQ+DzgIPf/qHcB5tH/rxseelN694uitbVu0+rt53EG91+zqxerfITJceUtggVU9 rU0DVitmiTZacuRY9OjxvAw8g6WRBo4nYaoPT/1/LeyfxrX33SbQNqb1cF5aQA8SAw7V YZE6FPJRt0yCuOIOig3ER4Kv1xaarB9Og7vzG2riEbXrq8XNojGeQVDkx6dVgx9FipqD uoqc9lYtu+lxoPXZDM9vpoYVSmpTYxNvdOyJB7EChoKUjW9JdxR4eK9+CgI8sRx3zANd F3rA== 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=hisilicon.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qc6-20020a170906d8a600b0099332d4ed30si625329ejb.677.2023.07.20.05.36.13; Thu, 20 Jul 2023 05:36:38 -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=hisilicon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229848AbjGTM1E (ORCPT + 99 others); Thu, 20 Jul 2023 08:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjGTM1D (ORCPT ); Thu, 20 Jul 2023 08:27:03 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 968D8A2 for ; Thu, 20 Jul 2023 05:27:02 -0700 (PDT) Received: from dggpeml500019.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R6BgJ17GYzNmQV; Thu, 20 Jul 2023 20:23:40 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by dggpeml500019.china.huawei.com (7.185.36.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 20 Jul 2023 20:27:00 +0800 From: Jie Zhan To: , CC: , , , , , , , Subject: [PATCH] irqdomain: Fix driver re-inserting failures when IRQs not being freed completely Date: Thu, 20 Jul 2023 20:24:29 +0800 Message-ID: <20230720122429.4123447-1-zhanjie9@hisilicon.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500019.china.huawei.com (7.185.36.137) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771943072626084236 X-GMAIL-MSGID: 1771943072626084236 Since commit 4615fbc3788d ("genirq/irqdomain: Don't try to free an interrupt that has no mapping"), we have found failures when re-inserting some specific drivers: [root@localhost ~]# rmmod hisi_sas_v3_hw [root@localhost ~]# modprobe hisi_sas_v3_hw [ 1295.622525] hisi_sas_v3_hw: probe of 0000:30:04.0 failed with error -2 This comes from the case where some IRQs allocated from a low-level domain, e.g. GIC ITS, are not freed completely, leaving some leaked. Thus, the next driver insertion fails to get the same number of IRQs because some IRQs are still occupied. Free a contiguous group of IRQs in one go to fix this issue. A previous discussion can be found at: https://lore.kernel.org/lkml/3d3d0155e66429968cb4f6b4feeae4b3@kernel.org/ This solution was originally written by Marc Zyngier in the discussion, but no code ends up upstreamed in that thread. Hopefully, this patch could get some notice back. Fixes: 4615fbc3788d ("genirq/irqdomain: Don't try to free an interrupt that has no mapping") Signed-off-by: Jie Zhan Reviewed-by: Liao Chang Signed-off-by: Zheng Zengkai --- kernel/irq/irqdomain.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index f34760a1e222..f059e00dc827 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -1445,13 +1445,24 @@ static void irq_domain_free_irqs_hierarchy(struct irq_domain *domain, unsigned int nr_irqs) { unsigned int i; + int n; if (!domain->ops->free) return; for (i = 0; i < nr_irqs; i++) { - if (irq_domain_get_irq_data(domain, irq_base + i)) - domain->ops->free(domain, irq_base + i, 1); + /* Find the largest possible span of IRQs to free in one go */ + for (n = 0; + ((i + n) < nr_irqs) && + (irq_domain_get_irq_data(domain, irq_base + i + n)); + n++) + ; + + if (!n) + continue; + + domain->ops->free(domain, irq_base + i, n); + i += n; } }