Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3621624pxb; Mon, 21 Feb 2022 02:03:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyo5Jr0SInWOjVsZ3rq4JApa4QY693VU8L1/mai6JgRmpw61vJNaC4UWTtbRrMQGVoBicN5 X-Received: by 2002:a17:903:1c6:b0:14f:45c3:6c29 with SMTP id e6-20020a17090301c600b0014f45c36c29mr17978586plh.77.1645437816996; Mon, 21 Feb 2022 02:03:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645437816; cv=none; d=google.com; s=arc-20160816; b=nICEitTvzAt50wGwrAUZWm79dyGYAD/PZyYi7eoPsQB+ARelTSCZMGKdC5m6qT1wAM OSvdmnjbZmMfz79Xo6eJh0tk9v5RYJqSkanNWitimCgUcXJBe7bsOKxHFhzDZfzz12vn YXy6n7Qc09SAriaE7TmP1QM+d5ChmvNo7RwLtNirMsezB95xzi7raCFJkIxblos5nY/f La9/zbjJ310OXAwdbTyp7obAmO5TkojkikDMCaYxsqHWlOjNWgReNnP4NFsCzl0WTvDW a6GVf/FNjTWEo6eeVINznNWZd1UDmyeABBxWyIBxckJEWd2XqaUEScWTKwmVcUPI+ufP OPKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=VPeVFRqXyH/qkyeIFa43p7nhy+n8Zng6FJUz7oizMQI=; b=EdPXKMWL7MskqTbtVrHYHMwF+d6uY9QprwBz7VnANxqGm9XfXRyoiui4SsS9hUCL+d J3Y9lGkkmCpzBuAhKlBgDea3vmOjPrm1J74PHNgwmA5G/DMnNXBPT6ABS3KjJGQsFikz zSwk4RFkByVZpZd5vk3Rndg9XOemSjScbdCTueZFGEbXIo4bPR0Tda9ghNCJEgtVYMrD OYfwk54D7OhDuZ27vE6EI+EriaW4/BOubgE5TlA+F6AU5PolxIdkO09Ha5kNVpvxnlIu hjExgnwBNZrEe3gaTDt+RuGl6e5R2qDbSIhJqr1NhA8Ut5m6iWPTjFAy8b9V0o3J7Q3p Q5UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="tK4RiO/u"; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b4si9398510pfl.173.2022.02.21.02.03.23; Mon, 21 Feb 2022 02:03:36 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b="tK4RiO/u"; dkim=neutral (no key) header.i=@linutronix.de; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346171AbiBUHbo (ORCPT + 99 others); Mon, 21 Feb 2022 02:31:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbiBUHbn (ORCPT ); Mon, 21 Feb 2022 02:31:43 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A162E7; Sun, 20 Feb 2022 23:31:20 -0800 (PST) Date: Mon, 21 Feb 2022 07:31:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1645428677; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VPeVFRqXyH/qkyeIFa43p7nhy+n8Zng6FJUz7oizMQI=; b=tK4RiO/ufs+nV/sBz4B0MjsW2UxZlm7O8bYpMrA9mczisjRaGkQNbnyyLvq+xzdxkjTklT ipaP9pOiYksBMvXTymfR2m/W0aCA6UbpZIPDVx5Uc96AbOZHeti7MAZ8gRCLlJL15FEeOv ZqnnonXJDH9lnQhGD/vyG6jv4F84MAWe++UhF2xPaaBurP7y0ZgspPTjFG0oikchSBIXmk iSXeab3S6Uk+EAgTZjLawu/ylgwTe/opYHjRlqlj4f8262b9BoXToSC5p+vjbx2HL/nhvD rH/5MdJ7M/8dgcKkkqHY07wHFD/fbqfRX9/UqyrwRzHPvJlFrD/aXTYyxcqRQQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1645428677; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VPeVFRqXyH/qkyeIFa43p7nhy+n8Zng6FJUz7oizMQI=; b=I11DarCzKKF4kFbIfwPnRaNMk42oeJlTjQTniqkBdH01dZVuYbcefrBSeXQj3DHWTLRQyQ uImY5VgPS3eCeOCw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/urgent] PCI: vmd: Prevent recursive locking on interrupt allocation Cc: "Surendrakumar Upadhyay, TejaskumarX" , Thomas Gleixner , linux-pci@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <87a6euub2a.ffs@tglx> References: <87a6euub2a.ffs@tglx> MIME-Version: 1.0 Message-ID: <164542867635.16921.13795049956787158926.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 The following commit has been merged into the irq/urgent branch of tip: Commit-ID: ba1366f3d039e7c3ca1fc29ed00ce3ed2b8fd32f Gitweb: https://git.kernel.org/tip/ba1366f3d039e7c3ca1fc29ed00ce3ed2b8fd32f Author: Thomas Gleixner AuthorDate: Sun, 13 Feb 2022 14:54:05 +01:00 Committer: Thomas Gleixner CommitterDate: Mon, 21 Feb 2022 08:26:53 +01:00 PCI: vmd: Prevent recursive locking on interrupt allocation Tejas reported the following recursive locking issue: swapper/0/1 is trying to acquire lock: ffff8881074fd0a0 (&md->mutex){+.+.}-{3:3}, at: msi_get_virq+0x30/0xc0 but task is already holding lock: ffff8881017cd6a0 (&md->mutex){+.+.}-{3:3}, at: __pci_enable_msi_range+0xf2/0x290 stack backtrace: __mutex_lock+0x9d/0x920 msi_get_virq+0x30/0xc0 pci_irq_vector+0x26/0x30 vmd_msi_init+0xcc/0x210 msi_domain_alloc+0xbf/0x150 msi_domain_alloc_irqs_descs_locked+0x3e/0xb0 __pci_enable_msi_range+0x155/0x290 pci_alloc_irq_vectors_affinity+0xba/0x100 pcie_port_device_register+0x307/0x550 pcie_portdrv_probe+0x3c/0xd0 pci_device_probe+0x95/0x110 This is caused by the VMD MSI code which does a lookup of the Linux interrupt number for an VMD managed MSI[X] vector. The lookup function tries to acquire the already held mutex. Avoid that by caching the Linux interrupt number at initialization time instead of looking it up over and over. Fixes: 82ff8e6b78fc ("PCI/MSI: Use msi_get_virq() in pci_get_vector()") Reported-by: "Surendrakumar Upadhyay, TejaskumarX" Signed-off-by: Thomas Gleixner Tested-by: "Surendrakumar Upadhyay, TejaskumarX" Cc: linux-pci@vger.kernel.org Link: https://lore.kernel.org/r/87a6euub2a.ffs@tglx --- drivers/pci/controller/vmd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index cc166c6..eb05cce 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -99,11 +99,13 @@ struct vmd_irq { * @srcu: SRCU struct for local synchronization. * @count: number of child IRQs assigned to this vector; used to track * sharing. + * @virq: The underlying VMD Linux interrupt number */ struct vmd_irq_list { struct list_head irq_list; struct srcu_struct srcu; unsigned int count; + unsigned int virq; }; struct vmd_dev { @@ -253,7 +255,6 @@ static int vmd_msi_init(struct irq_domain *domain, struct msi_domain_info *info, struct msi_desc *desc = arg->desc; struct vmd_dev *vmd = vmd_from_bus(msi_desc_to_pci_dev(desc)->bus); struct vmd_irq *vmdirq = kzalloc(sizeof(*vmdirq), GFP_KERNEL); - unsigned int index, vector; if (!vmdirq) return -ENOMEM; @@ -261,10 +262,8 @@ static int vmd_msi_init(struct irq_domain *domain, struct msi_domain_info *info, INIT_LIST_HEAD(&vmdirq->node); vmdirq->irq = vmd_next_irq(vmd, desc); vmdirq->virq = virq; - index = index_from_irqs(vmd, vmdirq->irq); - vector = pci_irq_vector(vmd->dev, index); - irq_domain_set_info(domain, virq, vector, info->chip, vmdirq, + irq_domain_set_info(domain, virq, vmdirq->irq->virq, info->chip, vmdirq, handle_untracked_irq, vmd, NULL); return 0; } @@ -685,7 +684,8 @@ static int vmd_alloc_irqs(struct vmd_dev *vmd) return err; INIT_LIST_HEAD(&vmd->irqs[i].irq_list); - err = devm_request_irq(&dev->dev, pci_irq_vector(dev, i), + vmd->irqs[i].virq = pci_irq_vector(dev, i); + err = devm_request_irq(&dev->dev, vmd->irqs[i].virq, vmd_irq, IRQF_NO_THREAD, vmd->name, &vmd->irqs[i]); if (err) @@ -969,7 +969,7 @@ static int vmd_suspend(struct device *dev) int i; for (i = 0; i < vmd->msix_count; i++) - devm_free_irq(dev, pci_irq_vector(pdev, i), &vmd->irqs[i]); + devm_free_irq(dev, vmd->irqs[i].virq, &vmd->irqs[i]); return 0; } @@ -981,7 +981,7 @@ static int vmd_resume(struct device *dev) int err, i; for (i = 0; i < vmd->msix_count; i++) { - err = devm_request_irq(dev, pci_irq_vector(pdev, i), + err = devm_request_irq(dev, vmd->irqs[i].virq, vmd_irq, IRQF_NO_THREAD, vmd->name, &vmd->irqs[i]); if (err)