From patchwork Tue Nov 9 13:53:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 12610755 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EF29C433EF for ; Tue, 9 Nov 2021 13:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A706611C5 for ; Tue, 9 Nov 2021 13:54:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235802AbhKIN4p (ORCPT ); Tue, 9 Nov 2021 08:56:45 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:36310 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbhKIN4p (ORCPT ); Tue, 9 Nov 2021 08:56:45 -0500 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1636466038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=sZyll560KLUb+apJiZdozn6h/p8K1VyRcQd9fbMYkV4=; b=jXSyoXrPWQ05v+EcHbQ7JZjBockKD4VEiroRhGrc0CEOj/6umKMjlVhAIK+9UvRlmovoFR C1RdytpWI2aPnqbnNbm1ii17ZopLVQdpNHH7lV1JilPg1ecuDHYoO58gS3lZ7ALXnL7q0P fNIoh2c0+ACQEShg+UH8JPIrJQgTFN9R1IwaF6Jtxxrabvulq1XbKS8Bl2xxw737uCJW2m Jno8CcWCL8Bs9XQ9HDJ0TuysEkTpVazrchSUCLE/H30zBxMt326cUqCjaSejm0BOiKpQEO aisTHwBVdq5+BxoCY0aIqjTw10ud/JPLwlfKJbXCjg5LjsiW+rUMDMZKTWIaxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1636466038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=sZyll560KLUb+apJiZdozn6h/p8K1VyRcQd9fbMYkV4=; b=mClu8lrQG6dpgIyEqMf1tnrd72p22DENy7mQu9j6RsmxmxYhsEfa7eABVBF8nFRv11s00y JP/sVUmPIfhGZ7DA== To: LKML Cc: Greg Kroah Hartmann , Bjorn Helgaas , Marc Zyngier , linux-pci@vger.kernel.org Subject: PCI/MSI: Destroy sysfs before freeing entries Date: Tue, 09 Nov 2021 14:53:57 +0100 Message-ID: <87sfw5305m.ffs@tglx> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org free_msi_irqs() frees the MSI entries before destroying the sysfs entries which are exposing them. Nothing prevents a concurrent free while a sysfs file is read and accesses the possibly freed entry. Move the sysfs release ahead of freeing the entries. Fixes: 1c51b50c2995 ("PCI/MSI: Export MSI mode using attributes, not kobjects") Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Reviewed-by: Greg Kroah-Hartman --- drivers/pci/msi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) --- a/drivers/pci/msi.c +++ b/drivers/pci/msi.c @@ -370,6 +370,11 @@ static void free_msi_irqs(struct pci_dev for (i = 0; i < entry->nvec_used; i++) BUG_ON(irq_has_action(entry->irq + i)); + if (dev->msi_irq_groups) { + msi_destroy_sysfs(&dev->dev, dev->msi_irq_groups); + dev->msi_irq_groups = NULL; + } + pci_msi_teardown_msi_irqs(dev); list_for_each_entry_safe(entry, tmp, msi_list, list) { @@ -381,11 +386,6 @@ static void free_msi_irqs(struct pci_dev list_del(&entry->list); free_msi_entry(entry); } - - if (dev->msi_irq_groups) { - msi_destroy_sysfs(&dev->dev, dev->msi_irq_groups); - dev->msi_irq_groups = NULL; - } } static void pci_intx_for_msi(struct pci_dev *dev, int enable)