Skip to contentSkip to conversation

PCI: hv: Hardwire PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN to 0

PATCH In review Hamza Mahfooz 3 participants 4 messages Dec 2

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 PCI: hv: Hardwire PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN to 0

Hyper-V Discrete Device Assignment (DDA) does not support legacy (INTx) interrupts.

The current code recognizes PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN reads and forces a zero value, but only for 8 bit reads. If a 16 or 32 bit read overlaps these fields, they may be returned as a non-zero value. Fix this by recognizing such overlap, and forcing the PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN bytes to zero while retaining the adjacent bytes returned by the host/HW.

Fixes 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs")

---
v2:
- Fix a compilation error
v3:
- Capitalize "Hardwire" in the subject. (Michael)
- Add description/comment clarifications. (Michael)
- Also hardwire PCI_INTERRUPT_LINE to 0 for 16 and 32 bit reads. (Michael)
- Emulate 16 bit reads of PCI_INTERRUPT_LINE/PCI_INTERRUPT_PIN, and clear the low 16 bits of 32 bit reads instead of writing through a char pointer.

---
 drivers/pci/controller/pci-hyperv.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +9 -2
index 824cf27e85e6..05a528df7a51 100644
@@ -1213,8 +1213,7 @@ static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where,
 		   PCI_CAPABILITY_LIST) {
 		/* ROM BARs are unimplemented */
 		*val = 0;
-	} else if ((where >= PCI_INTERRUPT_LINE && where + size <= PCI_INTERRUPT_PIN) ||
-		   (where >= PCI_INTERRUPT_PIN && where + size <= PCI_MIN_GNT)) {
+	} else if (where >= PCI_INTERRUPT_LINE && where + size <= PCI_MIN_GNT) {
 		/*
 		 * Interrupt Line and Interrupt PIN are hard-wired to zero
 		 * because this front-end only supports message-signaled
@@ -1256,6 +1255,14 @@ static void _hv_pcifront_read_config(struct hv_pci_dev *hpdev, int where,
 			mb();
 		}
 		spin_unlock_irqrestore(&hbus->config_lock, flags);
+
+		/*
+		 * Make sure PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN are
+		 * hard-wired to 0, since they may be included in a 32 bit
+		 * read, which is skipped by the above emulation.
+		 */
+		if (where == PCI_INTERRUPT_LINE)
+			*val &= ~0xffff;
 	} else {
 		dev_err(dev, "Attempt to read beyond a function's config space.\n");
 	}
Signature · 1 line
2.56.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

Hyper-V Discrete Device Assignment (DDA) does not support legacy (INTx) interrupts.

The current code recognizes PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN reads and forces a zero value, but only for 8 bit reads. If a 16 or 32 bit read overlaps these fields, they may be returned as a non-zero value. Fix this by recognizing such overlap, and forcing the PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN bytes to zero while retaining the adjacent bytes returned by the host/HW.

Quoted 7 lines
Fixes 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Hamza Mahfooz
Quoted 73 lines · Hamza Mahfooz

Hyper-V Discrete Device Assignment (DDA) does not support legacy (INTx)
interrupts.

The current code recognizes PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN reads and forces a zero value, but only for 8 bit reads. If a 16 or 32
bit read overlaps these fields, they may be returned as a non-zero value. Fix this by recognizing such overlap, and forcing the PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN bytes to zero while retaining
the adjacent bytes returned by the host/HW.

Fixes 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for

Microsoft Hyper-V VMs")

---
v2:
- Fix a compilation error
v3:
- Capitalize "Hardwire" in the subject. (Michael)
- Add description/comment clarifications. (Michael)
- Also hardwire PCI_INTERRUPT_LINE to 0 for 16 and 32 bit reads. (Michael)
- Emulate 16 bit reads of PCI_INTERRUPT_LINE/PCI_INTERRUPT_PIN, and clear
  the low 16 bits of 32 bit reads instead of writing through a char pointer.
---
 drivers/pci/controller/pci-hyperv.c | 11 +++++++++--

 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +0 -1
index 824cf27e85e6..05a528df7a51 100644
@@ -1213,8 +1213,7 @@ static void _hv_pcifront_read_config(struct
 hv_pci_dev *hpdev, int where,
  		   PCI_CAPABILITY_LIST) {
  		/* ROM BARs are unimplemented */
  		*val = 0;
-	} else if ((where >= PCI_INTERRUPT_LINE && where + size <=

PCI_INTERRUPT_PIN) ||

drivers/pci/controller/pci-hyperv.c +0 -1
-		   (where >= PCI_INTERRUPT_PIN && where + size <=

PCI_MIN_GNT)) {

drivers/pci/controller/pci-hyperv.c +1 -0
+	} else if (where >= PCI_INTERRUPT_LINE && where + size <=

PCI_MIN_GNT) {
  /*
  * Interrupt Line and Interrupt PIN are hard-wired to zero
  * because this front-end only supports message- signaled

drivers/pci/controller/pci-hyperv.c +3 -0
@@ -1256,6 +1255,14 @@ static void _hv_pcifront_read_config(struct
 hv_pci_dev *hpdev, int where,
  			mb();
  		}
  		spin_unlock_irqrestore(&hbus->config_lock, flags);
+
+		/*
+		 * Make sure PCI_INTERRUPT_LINE and

PCI_INTERRUPT_PIN are

drivers/pci/controller/pci-hyperv.c +1 -0
+		 * hard-wired to 0, since they may be included in a

32 bit

drivers/pci/controller/pci-hyperv.c +4 -0
+		 * read, which is skipped by the above emulation.
+		 */
+		if (where == PCI_INTERRUPT_LINE)
+			*val &= ~0xffff;
Quoted 4 lines

  } else {
  dev_err(dev, "Attempt to read beyond a function's config space.\n");
  }

Hi Hamza,

No objection to this change.

For the record, it affects qla2xxx under DDA. The driver uses PCI_INTERRUPT_PIN to identify the physical port of a multi-port HBA, which selects that port's NVRAM and WWPN. With the pin reading 0 and every function presented as function 0, all ports get port 0's WWPN. I described this earlier in [1].

Nilesh (Marvell, Cc'd) has a qla2xxx fix that reads the physical port from the ISP control/status register in the HBA's MMIO space instead of from PCI config space, so it is not affected by this patch. I tested it today on an ISP2281 with the DDA conditions simulated (pin and function forced to 0): with the fix each port gets its own WWPN; without it both ports report port 0's WWPN and the second port never comes up on the fabric. Nilesh will post it to linux-scsi.

Since this patch is tagged for stable, the qla2xxx fix should go to stable as well. Otherwise multi-port QLogic HBAs in DDA guests on stable kernels will end up with duplicate WWPNs.

[1] https://lore.kernel.org/linux-hyperv/<your RFC message-id>/

Thanks,
Laurence

#3 lore raw
Quoted 96 lines · Laurence Oberman
Quoted 73 lines · Hamza Mahfooz

Hyper-V Discrete Device Assignment (DDA) does not support legacy (INTx)
interrupts.

The current code recognizes PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN reads and forces a zero value, but only for 8 bit reads. If a 16 or 32
bit read overlaps these fields, they may be returned as a non-zero value. Fix this by recognizing such overlap, and forcing the PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN bytes to zero while retaining
the adjacent bytes returned by the host/HW.

Fixes 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for

Microsoft Hyper-V VMs")

---
v2:
- Fix a compilation error
v3:
- Capitalize "Hardwire" in the subject. (Michael)
- Add description/comment clarifications. (Michael)
- Also hardwire PCI_INTERRUPT_LINE to 0 for 16 and 32 bit reads. (Michael)
- Emulate 16 bit reads of PCI_INTERRUPT_LINE/PCI_INTERRUPT_PIN, and clear
  the low 16 bits of 32 bit reads instead of writing through a char pointer.
---
 drivers/pci/controller/pci-hyperv.c | 11 +++++++++--

 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +0 -1
index 824cf27e85e6..05a528df7a51 100644
@@ -1213,8 +1213,7 @@ static void _hv_pcifront_read_config(struct
 hv_pci_dev *hpdev, int where,
  		   PCI_CAPABILITY_LIST) {
  		/* ROM BARs are unimplemented */
  		*val = 0;
-	} else if ((where >= PCI_INTERRUPT_LINE && where + size <=

PCI_INTERRUPT_PIN) ||

drivers/pci/controller/pci-hyperv.c +0 -1
-		   (where >= PCI_INTERRUPT_PIN && where + size <=

PCI_MIN_GNT)) {

drivers/pci/controller/pci-hyperv.c +1 -0
+	} else if (where >= PCI_INTERRUPT_LINE && where + size <=

PCI_MIN_GNT) {
  /*
  * Interrupt Line and Interrupt PIN are hard-wired to zero
  * because this front-end only supports message- signaled

drivers/pci/controller/pci-hyperv.c +3 -0
@@ -1256,6 +1255,14 @@ static void _hv_pcifront_read_config(struct
 hv_pci_dev *hpdev, int where,
  			mb();
  		}
  		spin_unlock_irqrestore(&hbus->config_lock, flags);
+
+		/*
+		 * Make sure PCI_INTERRUPT_LINE and

PCI_INTERRUPT_PIN are

drivers/pci/controller/pci-hyperv.c +1 -0
+		 * hard-wired to 0, since they may be included in a

32 bit

drivers/pci/controller/pci-hyperv.c +4 -0
+		 * read, which is skipped by the above emulation.
+		 */
+		if (where == PCI_INTERRUPT_LINE)
+			*val &= ~0xffff;
Quoted 4 lines

  } else {
  dev_err(dev, "Attempt to read beyond a function's config space.\n");
  }

Hi Hamza,

No objection to this change.

For the record, it affects qla2xxx under DDA. The driver uses PCI_INTERRUPT_PIN to identify the physical port of a multi-port HBA, which selects that port's NVRAM and WWPN. With the pin reading 0 and every function presented as function 0, all ports get port 0's WWPN. I described this earlier in [1].

Nilesh (Marvell, Cc'd) has a qla2xxx fix that reads the physical port from the ISP control/status register in the HBA's MMIO space instead of from PCI config space, so it is not affected by this patch. I tested it today on an ISP2281 with the DDA conditions simulated (pin and function forced to 0): with the fix each port gets its own WWPN; without it both ports report port 0's WWPN and the second port never comes up on the fabric. Nilesh will post it to linux-scsi.

Quoted 4 lines

Since this patch is tagged for stable, the qla2xxx fix should go to stable as well. Otherwise multi-port QLogic HBAs in DDA guests on stable kernels will end up with duplicate WWPNs.

That sounds reasonable to me, espesically if you have hit the qla2xxx issue on stable kernels.

Hamza

Quoted 4 lines

[1] https://lore.kernel.org/linux-hyperv/<your RFC message-id>/

Thanks,
Laurence