Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Wang Hai <wanghai38@huawei.com>
To: <bhelgaas@google.com>, <maz@kernel.org>, <tglx@linutronix.de>,
	<song.bao.hua@hisilicon.com>, <gregkh@linuxfoundation.org>
Cc: <linux-pci@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] PCI/MSI: fix page fault when msi_populate_sysfs() failed
Date: Mon, 11 Oct 2021 16:40:49 +0800	[thread overview]
Message-ID: <20211011084049.53643-1-wanghai38@huawei.com> (raw)

I got a page fault report when doing fault injection test:

BUG: unable to handle page fault for address: fffffffffffffff4
...
RIP: 0010:sysfs_remove_groups+0x25/0x60
...
Call Trace:
 msi_destroy_sysfs+0x30/0xa0
 free_msi_irqs+0x11d/0x1b0
 __pci_enable_msix_range+0x67f/0x760
 pci_alloc_irq_vectors_affinity+0xe7/0x170
 vp_find_vqs_msix+0x129/0x560
 vp_find_vqs+0x52/0x230
 vp_modern_find_vqs+0x47/0xb0
 p9_virtio_probe+0xa1/0x460 [9pnet_virtio]
 virtio_dev_probe+0x1ed/0x2e0
 really_probe+0x1c7/0x400
 __driver_probe_device+0xa4/0x120
 driver_probe_device+0x32/0xe0
 __driver_attach+0xbf/0x130
 bus_for_each_dev+0xbb/0x110
 driver_attach+0x27/0x30
 bus_add_driver+0x1d9/0x270
 driver_register+0xa9/0x180
 register_virtio_driver+0x31/0x50
 p9_virtio_init+0x3c/0x1000 [9pnet_virtio]
 do_one_initcall+0x7b/0x380
 do_init_module+0x5f/0x21e
 load_module+0x265c/0x2c60
 __do_sys_finit_module+0xb0/0xf0
 __x64_sys_finit_module+0x1a/0x20
 do_syscall_64+0x34/0xb0
 entry_SYSCALL_64_after_hwframe+0x44/0xae

When populating msi_irqs sysfs failed in msi_capability_init() or
msix_capability_init(), dev->msi_irq_groups will point to ERR_PTR(...).
This will cause a page fault when destroying the wrong
dev->msi_irq_groups in free_msi_irqs().

Fix this by setting dev->msi_irq_groups to NULL when msi_populate_sysfs()
failed.

Fixes: 2f170814bdd2 ("genirq/msi: Move MSI sysfs handling from PCI to MSI core")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 drivers/pci/msi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 0099a00af361..6f75db9f3be7 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -561,6 +561,7 @@ static int msi_capability_init(struct pci_dev *dev, int nvec,
 	dev->msi_irq_groups = msi_populate_sysfs(&dev->dev);
 	if (IS_ERR(dev->msi_irq_groups)) {
 		ret = PTR_ERR(dev->msi_irq_groups);
+		dev->msi_irq_groups = NULL;
 		goto err;
 	}
 
@@ -733,6 +734,7 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
 	dev->msi_irq_groups = msi_populate_sysfs(&dev->dev);
 	if (IS_ERR(dev->msi_irq_groups)) {
 		ret = PTR_ERR(dev->msi_irq_groups);
+		dev->msi_irq_groups = NULL;
 		goto out_free;
 	}
 
-- 
2.17.1


             reply	other threads:[~2021-10-11  8:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11  8:40 Wang Hai [this message]
2021-10-11  8:52 ` [PATCH] PCI/MSI: fix page fault when msi_populate_sysfs() failed Barry Song
2021-10-11  9:15   ` wanghai (M)
2021-10-11 17:11     ` Bjorn Helgaas
2021-10-12  1:59       ` wanghai (M)
2021-10-12  2:09         ` Bjorn Helgaas
2021-10-12  2:25           ` wanghai (M)
2021-10-12  2:39             ` Barry Song
2021-10-12  2:47               ` wanghai (M)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011084049.53643-1-wanghai38@huawei.com \
    --to=wanghai38@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=song.bao.hua@hisilicon.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox