Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9473451rwp; Thu, 20 Jul 2023 05:37:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlFyr+o2OcW5tRbqUWKLND02G8zSCuxLCeGRj1fkxqFyBTyD3SfvwNDG4aXGS1WY50MgVNfH X-Received: by 2002:a17:906:40cc:b0:98d:f953:f473 with SMTP id a12-20020a17090640cc00b0098df953f473mr4676152ejk.50.1689856662024; Thu, 20 Jul 2023 05:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689856662; cv=none; d=google.com; s=arc-20160816; b=U8Bw9wI+hlv4zKrsOT6Q8p90DH4Ebr3VZv+QO1bJoDHFWlDq/tTqkQpiHBmOoflOQa CgvParRn8vM0E2Ga2NXkw72MZSV18uzHYXuUZFzBpynP/HMZjPBsTRbGI7gg24JuRGvl NTILqn5HcIhBFDWWqq2ZbKU1hx9uvU9gHEMO/N6lzAy/CNDXASfKfTQO/i8fNbOv+TjW JlpLB/zE/wvDtBvhL3ILesULP9HZCtCFd/ZngAmKJ02yz6SWUCDd8wcRn7UcIsuZnX71 saiZrSpluKSACHL5HzQUZJmPoJOqXZ0a1X5kF4nb4RE23Y+nwhxux0TFSepMMd8aTpM4 kc3A== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a1709061d1100b00987606c11a2si539661ejh.349.2023.07.20.05.37.16; Thu, 20 Jul 2023 05:37:42 -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 S229776AbjGTM1E (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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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; } } -- 2.30.0