From patchwork Tue Oct 24 15:03:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 157546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp2004653vqx; Tue, 24 Oct 2023 08:04:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHCkmzv6QABmydDMvSFjD9MKh0Qmsysnz+opmmsDJ/jcjTcYQHgnzt/McZ9cL5ylz7T+Un X-Received: by 2002:a17:90b:1b49:b0:27d:4513:9c99 with SMTP id nv9-20020a17090b1b4900b0027d45139c99mr10233041pjb.17.1698159846547; Tue, 24 Oct 2023 08:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698159846; cv=none; d=google.com; s=arc-20160816; b=gNntszRykFDpyEiOSB0pYoJHGGAAHetVnK7hI18atgJvx9TCy7c7yLozKOMBmDnDP7 2rNQ2EXR81peSe9Mze5CRLfPugYn67zMmKvnHICou/82Mp8gOXGlmpqckYZE3Bakr+tH Tpv3qP9ia96ZDJqt8ndPDfwhLnEUYPyviu5SUfVkthfPKlJ2wQj8um5X9zv5DGNESlZY J+ylh4ZaRKXp8IN5Sqv+D5CeysYOgUpP0QCPb7aiDxOfmxJoZ5c6s74zalhvz1F8Oode WpuGBzlvZuAr9T1SJjmHzrd3MZ8++HGZy+Ix0bkdnXMv12ItmVkslnFDhvoRWrYjT/Ty 7LCQ== 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:dkim-signature; bh=mnkAD7DkJI94ZoXAZ/b9DAALS/X6VFawfu3j3rG7d3E=; fh=YjkvXkVV97uNDVBXpEc+8v0tfHEQvbOY9RwLVOQCz1s=; b=i6MZza9V9l/0pm/zHN8EIDRze2I9RdP0jucYDNjVmyMe8Y1IbOEvrba6qXNLZyrpzB o+YYdloxKo+34PJUtDMdMM7l8ISwOYf+juqubpnTDLRAw4MZaDT4tcjJCR7Bit5YOHK2 2Z/hS8RmQDza4u3vdaTeg8i68pEYIWCNg1T8gk9FHMhJCPHLyffMA6VgJvQlgSp34VXO fU9ftYYH1CWPhVGUYagfFnhoox0G07ci3lhMPKPfyhYJe1ovvdXmbvPCHlg8Ch6PQ3Yb ph3iqotjIQwD3LGU34UJpo047wMSjsrkjBx65zEyOwDWdCy68YZPAblBsORyQGvF9+3S RFSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HlMf3ubE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id mi18-20020a17090b4b5200b0027cf3fd376bsi11845763pjb.28.2023.10.24.08.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 08:04:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HlMf3ubE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 62A75802DBA4; Tue, 24 Oct 2023 08:04:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbjJXPD5 (ORCPT + 26 others); Tue, 24 Oct 2023 11:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230304AbjJXPDy (ORCPT ); Tue, 24 Oct 2023 11:03:54 -0400 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CE6D7F; Tue, 24 Oct 2023 08:03:51 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPA id 65EA2C0009; Tue, 24 Oct 2023 15:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1698159829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=mnkAD7DkJI94ZoXAZ/b9DAALS/X6VFawfu3j3rG7d3E=; b=HlMf3ubEdI6c9l2+/oyORY3sLlA40G1P7Vm5nLQ/AMYXbOMVRdQG5P5qwh69k59tCRx9Bh o3PrM0DEB6ROXgjOneSl0lxdH31proVxENNo9ml32/qFSvIsctMBfpyL02CL2JaUsl33BL HHOPrZEd1Hg194pBPdLsKSWXCAHVtvMJp7FkjBkh2uwFWu8s50VOSfpNISgDzxLjoPr+fc X5otw/klEF8OZxNx5obWwHbHWyD15ia3v/IEHmwTmt2Mb53Df/mbg8TKxo4CIzrrlLb9xv pf7KcDRbuYItSrmO4AjSuEHeyS2rILXo+vwiH2uVn53HODq35CUSGZ6nC4nHZw== From: Herve Codina To: Thomas Gleixner , Marc Zyngier Cc: linux-kernel@vger.kernel.org, Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Herve Codina , stable@vger.kernel.org Subject: [PATCH 1/1] genirq/generic_chip: Fix irq_remove_generic_chip() when an irq domain is used Date: Tue, 24 Oct 2023 17:03:35 +0200 Message-ID: <20231024150335.322282-1-herve.codina@bootlin.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-GND-Sasl: herve.codina@bootlin.com X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 24 Oct 2023 08:04:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780649659459455015 X-GMAIL-MSGID: 1780649659459455015 irq_remove_generic_chip() can call (depending on the msk parameter value) several operations on irqs based on gc->irq_base such as irq_set_handler(irq, NULL) to remove an handler. When the generic chip is present in an irq domain (created with a call to irq_alloc_domain_generic_chips()), gc->irq_base is the base hardware irq for this chip. It is set to 0 for the first chip in the domain, 0 + n for the next chip (with n the number of hardware irqs per chip) and so on. In that case, the operations done on irqs based on gc->irq_base touch some irqs not related to the chip nor the domain breaking some unrelated components in the system. In order to avoid touching these "outside" irqs, take care of the domain irq mapping and translate the chip hardware irq to an irq number suitable for the several operations done. Fixes: cfefd21e693d ("genirq: Add chip suspend and resume callbacks") Cc: stable@vger.kernel.org Signed-off-by: Herve Codina --- kernel/irq/generic-chip.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c index c653cd31548d..494584e25ef4 100644 --- a/kernel/irq/generic-chip.c +++ b/kernel/irq/generic-chip.c @@ -544,21 +544,28 @@ EXPORT_SYMBOL_GPL(irq_setup_alt_chip); void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk, unsigned int clr, unsigned int set) { - unsigned int i = gc->irq_base; + unsigned int irq; + unsigned int i; raw_spin_lock(&gc_lock); list_del(&gc->list); raw_spin_unlock(&gc_lock); - for (; msk; msk >>= 1, i++) { + for (i = 0; msk; msk >>= 1, i++) { if (!(msk & 0x01)) continue; + irq = gc->domain ? + irq_find_mapping(gc->domain, gc->irq_base + i) : + gc->irq_base + i; + if (!irq) + continue; + /* Remove handler first. That will mask the irq line */ - irq_set_handler(i, NULL); - irq_set_chip(i, &no_irq_chip); - irq_set_chip_data(i, NULL); - irq_modify_status(i, clr, set); + irq_set_handler(irq, NULL); + irq_set_chip(irq, &no_irq_chip); + irq_set_chip_data(irq, NULL); + irq_modify_status(irq, clr, set); } } EXPORT_SYMBOL_GPL(irq_remove_generic_chip);