Skip to contentSkip to conversation

PCI: hv: Fix a crash in hv_pci_restore_msi_msg() during hibernation

PATCH Applied Dexuan Cui 5 participants 8 messages Aug 16, 2023 – Aug 22, 2023

Subsystems (4)
lore
Share & tools
lore

Dexuan Cui

author maintainer
#0 lore raw

PATCH v2 1/1 PCI: hv: Fix a crash in hv_pci_restore_msi_msg() during hibernation

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

    Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
      Thanks Michael!
    Updated the changelog accordingly.
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -0
index 2d93d0c4f10d..bed3cefdaf19 100644
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg)
 	struct msi_desc *entry;
 	int ret = 0;
 
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;
+
 	msi_lock_descs(&pdev->dev);
 	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
 		irq_data = irq_get_irq_data(entry->irq);
Signature · 1 line
2.25.1
author maintainer
#1 lore raw
Quoted 9 lines

From: Dexuan Cui <[email protected]>
Sent: Wednesday, August 16, 2023 11:00 AM
[...]
When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Quoted 4 lines

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

Sorry, I forgot to add
Cc: [email protected]

#2 lore raw
In reply to Dexuan Cui
Quoted 26 lines · Dexuan Cui

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

     Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
       Thanks Michael!
     Updated the changelog accordingly.
  drivers/pci/controller/pci-hyperv.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +0 -0
index 2d93d0c4f10d..bed3cefdaf19 100644

drivers/pci/controller/pci-hyperv.c static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg) · line 3987

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +2 -0
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg)
  	struct msi_desc *entry;
  	int ret = 0;
 
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;

Isn't this is a error condition? Don't you want to return error here?

Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +1 -0
+
  	msi_lock_descs(&pdev->dev);
  	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
  		irq_data = irq_get_irq_data(entry->irq);
author maintainer
#3 lore raw
Quoted 33 lines

From: Kuppuswamy Sathyanarayanan
<[email protected]>
Sent: Wednesday, August 16, 2023 11:12 AM
[...]

drivers/pci/controller/pci-

Quoted 22 lines · Dexuan Cui

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

     Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
       Thanks Michael!
     Updated the changelog accordingly.
  drivers/pci/controller/pci-hyperv.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/pci/controller/pci- renamed from drivers/pci/controller/pci-hyperv.c +0 -0

hyperv.c

drivers/pci/controller/pci-hyperv.c static int hv_pci_restore_msi_msg(struct pci_dev

Quoted 4 lines

index 2d93d0c4f10d..bed3cefdaf19 100644

drivers/pci/controller/pci-hyperv.c +0 -0
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev

*pdev, void *arg)

Quoted 6 lines

drivers/pci/controller/pci-hyperv.c static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg) · line 3987

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +2 -0
  	struct msi_desc *entry;
  	int ret = 0;
 
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;

Isn't this is a error condition? Don't you want to return error here?

This is not an error. If a PCI device driver is not loaded or not installed, MSI-X/MSI is not enabled on the device, so pdev->msi_enabled is 0 and pdev->msix_enabled is 0. In this case, it's still legit for a user to request the system (i.e. here it's a Linux VM running on Hyper-V) to hibernate -- in this case, we should not try to save/restore the MSI/MSI-X state, and we should not let the hibernation fail; here we should just ignore the device by returning a success ("return 0;").

Quoted 4 lines
Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +1 -0
+
  	msi_lock_descs(&pdev->dev);
  	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
  		irq_data = irq_get_irq_data(entry->irq);
#4 lore raw
Quoted 39 lines · Dexuan Cui
Quoted 33 lines

From: Kuppuswamy Sathyanarayanan
<[email protected]>
Sent: Wednesday, August 16, 2023 11:12 AM
[...]

drivers/pci/controller/pci-

Quoted 22 lines · Dexuan Cui

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

      Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
        Thanks Michael!
      Updated the changelog accordingly.
   drivers/pci/controller/pci-hyperv.c | 3 +++
   1 file changed, 3 insertions(+)
drivers/pci/controller/pci- renamed from drivers/pci/controller/pci-hyperv.c +0 -0

hyperv.c

drivers/pci/controller/pci-hyperv.c static int hv_pci_restore_msi_msg(struct pci_dev

Quoted 4 lines

index 2d93d0c4f10d..bed3cefdaf19 100644

drivers/pci/controller/pci-hyperv.c +0 -0
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev

*pdev, void *arg)

Quoted 6 lines

drivers/pci/controller/pci-hyperv.c static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg) · line 3987

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +2 -0
   	struct msi_desc *entry;
   	int ret = 0;
 
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;

Isn't this is a error condition? Don't you want to return error here?

Quoted 7 lines

This is not an error. If a PCI device driver is not loaded or not installed, MSI-X/MSI is not enabled on the device, so pdev->msi_enabled is 0 and pdev->msix_enabled is 0. In this case, it's still legit for a user to request the system (i.e. here it's a Linux VM running on Hyper-V) to hibernate -- in this case, we should not try to save/restore the MSI/MSI-X state, and we should not let the hibernation fail; here we should just ignore the device by returning a success ("return 0;").

Got it. Looks good to me.

Reviewed-by [email protected]
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +1 -0
+
   	msi_lock_descs(&pdev->dev);
   	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
   		irq_data = irq_get_irq_data(entry->irq);
Reviewed-by on v2 1/1
#5 lore raw
In reply to Dexuan Cui

From: Dexuan Cui <[email protected]> Sent: Wednesday, August 16, 2023 11:00 AM

Quoted 37 lines

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

    Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
      Thanks Michael!
    Updated the changelog accordingly.
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -1
index 2d93d0c4f10d..bed3cefdaf19 100644
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg)
 	struct msi_desc *entry;
 	int ret = 0;
 
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;
+
 	msi_lock_descs(&pdev->dev);
 	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
 		irq_data = irq_get_irq_data(entry->irq);
--
Quoted 1 line

2.25.1

maintainer
#6 lore raw
Quoted 31 lines · Michael Kelley (LINUX)

From: Dexuan Cui <[email protected]> Sent: Wednesday, August 16, 2023 11:00 AM

Quoted 30 lines

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

Fixes dc2b453290c4 ("PCI: hv: Rework MSI handling")

---

Changes in v2:

    Replaced the test "if (!pdev->dev.msi.data)" with
		      "if (!pdev->msi_enabled && !pdev->msix_enabled)".
      Thanks Michael!
    Updated the changelog accordingly.
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +0 -0
index 2d93d0c4f10d..bed3cefdaf19 100644
@@ -3983,6 +3983,9 @@ static int hv_pci_restore_msi_msg(struct pci_dev *pdev, void *arg)
 	struct msi_desc *entry;
 	int ret = 0;
 
Quoted 12 lines
Quoted 8 lines
drivers/pci/controller/pci-hyperv.c +3 -1
+	if (!pdev->msi_enabled && !pdev->msix_enabled)
+		return 0;
+
 	msi_lock_descs(&pdev->dev);
 	msi_for_each_desc(entry, &pdev->dev, MSI_DESC_ASSOCIATED) {
 		irq_data = irq_get_irq_data(entry->irq);
--

2.25.1

I expect this to go through the PCI tree. Just let me know if I should pick this up.

Thanks,
Wei.

maintainer Applied
#7 lore raw
In reply to Dexuan Cui
Quoted 9 lines · Dexuan Cui

When a Linux VM with an assigned PCI device runs on Hyper-V, if the PCI device driver is not loaded yet (i.e. MSI-X/MSI is not enabled on the device yet), doing a VM hibernation triggers a panic in hv_pci_restore_msi_msg() -> msi_lock_descs(&pdev->dev), because pdev->dev.msi.data is still NULL.

Avoid the panic by checking if MSI-X/MSI is enabled.

[...]

Applied to controller/hv, thanks!

[1/1] PCI: hv: Fix a crash in hv_pci_restore_msi_msg() during hibernation

      https://git.kernel.org/pci/pci/c/04bbe863241a

Thanks,
Lorenzo