Skip to contentSkip to conversation

pci: apply workaround for Intel errata HSE43 and BDF2

PATCH Superseded Roger Pau Monne 2 participants 5 messages Nov 29, 2018 – Dec 4, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: apply workaround for Intel errata HSE43 and BDF2

This errata affect the values read from the BAR registers, and could render vPCI (and by extension PVH Dom0 unusable).

HSE43 is a Haswell erratum where a non-BAR register is implemented at the position where the first BAR of the device should be found in the Power Control Unit device. Note that there are no BARs on this device, apart from the bogus CSR register positioned on top of the first BAR.

BDF2 is a Broadwell erratum where BARs in the Home Agent device will return bogus non-zero values.

In both cases the solution is to treat such devices as having no BARs in the vPCI code.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
---
Some testing would be nice has I don't seem to have any box ATM that contains this errata.

---
 xen/drivers/passthrough/pci.c | 30 ++++++++++++++++++++++++++++++
 xen/drivers/vpci/header.c     |  3 +++
 xen/include/xen/pci.h         |  3 +++
 3 files changed, 36 insertions(+)
xen/drivers/passthrough/pci.c +30 -0
index 7584ce2fbb..d27046c9ea 100644
@@ -17,6 +17,7 @@
 #include <xen/sched.h>
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
+#include <xen/pci_ids.h>
 #include <xen/list.h>
 #include <xen/prefetch.h>
 #include <xen/iommu.h>
@@ -298,6 +299,34 @@ static void check_pdev(const struct pci_dev *pdev)
 #undef PCI_STATUS_CHECK
 }
 
+static void apply_quirks(struct pci_dev *pdev)
+{
+    uint16_t vendor = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_VENDOR_ID);
+    uint16_t device = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_DEVICE_ID);
+
+    if ( vendor == PCI_VENDOR_ID_INTEL && (device == 0x2fc0 ||
+         device == 0x6f60 || device == 0x6fa0 || device == 0x6fc0) )
+        /*
+         * Device [8086:2fc0]
+         * Erratum HSE43
+         * CONFIG_TDP_NOMINAL CSR Implemented at Incorrect Offset
+         * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v3-spec-update.html
+         *
+         * Devices [8086:6f60,6fa0,6fc0]
+         * Erratum BDF2
+         * PCI BARs in the Home Agent Will Return Non-Zero Values During Enumeration
+         * http://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v4-spec-update.html
+         *
+         * For both erratas force ignoring the BARs, this prevents vPCI from
+         * trying to size the BARs or add handlers to trap accesses.
+         */
+        pdev->ignore_bars = true;
+}
+
 static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
 {
     struct pci_dev *pdev;
@@ -397,6 +426,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
     }
 
     check_pdev(pdev);
+    apply_quirks(pdev);
 
     return pdev;
 }
xen/drivers/vpci/header.c +3 -0
index 43cac3f7d3..71d316112e 100644
@@ -480,6 +480,9 @@ static int init_bars(struct pci_dev *pdev)
         return -EOPNOTSUPP;
     }
 
+    if ( pdev->ignore_bars )
+        num_bars = 0;
+
     /* Setup a handler for the command register. */
     rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, PCI_COMMAND,
                            2, header);
xen/include/xen/pci.h +3 -0
index 3c361cf0c0..5be9de2df8 100644
@@ -115,6 +115,9 @@ struct pci_dev {
 
     /* Data for vPCI. */
     struct vpci *vpci;
+
+    /* Device with errata, ignore the BARs. */
+    bool ignore_bars;
 };
 
 #define for_each_pdev(domain, pdev) \
Signature · 7 lines
2.19.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.11.18 at 18:11, <[email protected]> wrote:

This errata affect the values read from the BAR registers, and could render vPCI (and by extension PVH Dom0 unusable).

HSE43 is a Haswell erratum where a non-BAR register is implemented at the position where the first BAR of the device should be found in the

s/in the/in a/ or something like this, because out of the several Power Control Unit devices only one kind is really affected.

Quoted 5 lines

Power Control Unit device. Note that there are no BARs on this device, apart from the bogus CSR register positioned on top of the first BAR.

BDF2 is a Broadwell erratum where BARs in the Home Agent device will return bogus non-zero values.

I'm afraid there's quite a bit of confusion in Intel's docs here: The vol 2 datasheet link for this CPU from
https://www.intel.com/content/www/us/en/processors/xeon/xeon-technical-resources.html
looks to be dead, and the local copy I have of this lists PCI IDs identical to E5v3. The E7v4 link still works, and vol 2 has the same issue. (I really just wanted to cross check that we fully cover the issue with the three PCI IDs used.)

In any event in the code I'd like to see BDX2 mentioned as well (the same erratum on E7v4). However, given the situation with the datasheets I can't see a way to associate the device IDs used with the individual errata (I would generally suspect there being a 3rd erratum for the 3rd device ID). Several years ago spec updates also used to have PCI device ID tables, but this doesn't appear to be the case anymore.

Quoted 5 lines
xen/drivers/passthrough/pci.c +1 -0
@@ -298,6 +299,34 @@ static void check_pdev(const struct pci_dev *pdev)
 #undef PCI_STATUS_CHECK
 }
 
+static void apply_quirks(struct pci_dev *pdev)

xen/drivers/passthrough/pci.c static void check_pdev(const struct pci_dev *pdev) · line 312

Quoted 10 lines
xen/drivers/passthrough/pci.c +10 -0
+{
+    uint16_t vendor = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_VENDOR_ID);
+    uint16_t device = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_DEVICE_ID);
+
+    if ( vendor == PCI_VENDOR_ID_INTEL && (device == 0x2fc0 ||
+         device == 0x6f60 || device == 0x6fa0 || device == 0x6fc0) )

Instead of such an ever growing if(), could we make this table based?

xen/drivers/passthrough/pci.c static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) · line 429

Quoted 5 lines
xen/drivers/passthrough/pci.c +1 -0
@@ -397,6 +426,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
     }
 
     check_pdev(pdev);
+    apply_quirks(pdev);

At which point putting the small loop into check_pdev() might be as good as adding a new function.

xen/drivers/vpci/header.c static int init_bars(struct pci_dev *pdev) · line 484

Quoted 8 lines
xen/drivers/vpci/header.c +2 -0
@@ -480,6 +480,9 @@ static int init_bars(struct pci_dev *pdev)
         return -EOPNOTSUPP;
     }
 
+    if ( pdev->ignore_bars )
+        num_bars = 0;

While benign for the errata currently dealt with I wonder whether the ROM BAR wouldn't better be left alone as well with this flag set. Since additionally enabling memory decoding on a device without BARs is a questionable operation I wonder whether you couldn't better move this a few lines down immediately ahead of the loop over the BARs, and make it return instead of zeroing num_bars.

xen/include/xen/pci.h struct pci_dev { · line 120

Quoted 9 lines
xen/include/xen/pci.h +3 -0
@@ -115,6 +115,9 @@ struct pci_dev {
 
     /* Data for vPCI. */
     struct vpci *vpci;
+
+    /* Device with errata, ignore the BARs. */
+    bool ignore_bars;

Please can you put this into (one of?) the existing hole(s), instead of at the end?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 24 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.11.18 at 18:11, <[email protected]> wrote:

This errata affect the values read from the BAR registers, and could render vPCI (and by extension PVH Dom0 unusable).

HSE43 is a Haswell erratum where a non-BAR register is implemented at the position where the first BAR of the device should be found in the

s/in the/in a/ or something like this, because out of the several Power Control Unit devices only one kind is really affected.

Quoted 5 lines

Power Control Unit device. Note that there are no BARs on this device, apart from the bogus CSR register positioned on top of the first BAR.

BDF2 is a Broadwell erratum where BARs in the Home Agent device will return bogus non-zero values.

I'm afraid there's quite a bit of confusion in Intel's docs here: The vol 2 datasheet link for this CPU from
https://www.intel.com/content/www/us/en/processors/xeon/xeon-technical-resources.html
looks to be dead, and the local copy I have of this lists PCI IDs identical to E5v3. The E7v4 link still works, and vol 2 has the same issue. (I really just wanted to cross check that we fully cover the issue with the three PCI IDs used.)

Quoted 7 lines

In any event in the code I'd like to see BDX2 mentioned as well (the same erratum on E7v4). However, given the situation with the datasheets I can't see a way to associate the device IDs used with the individual errata (I would generally suspect there being a 3rd erratum for the 3rd device ID). Several years ago spec updates also used to have PCI device ID tables, but this doesn't appear to be the case anymore.

I guess I can add BDX2, I've mainly used the information from the Linux changeset that you pointed me to (6af7e4f77259ee946103387372cb159f2e99a6d4), but it doesn't mention BDX2 at all.

Quoted 4 lines
Quoted 4 lines
xen/drivers/passthrough/pci.c +0 -0
@@ -298,6 +299,34 @@ static void check_pdev(const struct pci_dev *pdev)
 #undef PCI_STATUS_CHECK
 }
 
Quoted 13 lines

xen/drivers/passthrough/pci.c static void check_pdev(const struct pci_dev *pdev) · line 312

Quoted 11 lines
xen/drivers/passthrough/pci.c +11 -0
+static void apply_quirks(struct pci_dev *pdev)
+{
+    uint16_t vendor = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_VENDOR_ID);
+    uint16_t device = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_DEVICE_ID);
+
+    if ( vendor == PCI_VENDOR_ID_INTEL && (device == 0x2fc0 ||
+         device == 0x6f60 || device == 0x6fa0 || device == 0x6fc0) )

Instead of such an ever growing if(), could we make this table based?

Sure, I guess using something similar to Linux's would be fine, so a table with the vendor ID, device ID and a pointer to a function to be called in case of match?

Quoted 15 lines

xen/drivers/passthrough/pci.c static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) · line 429

Quoted 5 lines
xen/drivers/passthrough/pci.c +1 -0
@@ -397,6 +426,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
     }
 
     check_pdev(pdev);
+    apply_quirks(pdev);

At which point putting the small loop into check_pdev() might be as good as adding a new function.

Quoted 6 lines
xen/drivers/vpci/header.c +0 -0
@@ -480,6 +480,9 @@ static int init_bars(struct pci_dev *pdev)
         return -EOPNOTSUPP;
     }
 
Quoted 9 lines

xen/drivers/vpci/header.c static int init_bars(struct pci_dev *pdev) · line 484

Quoted 2 lines
xen/drivers/vpci/header.c +2 -0
+    if ( pdev->ignore_bars )
+        num_bars = 0;

While benign for the errata currently dealt with I wonder whether the ROM BAR wouldn't better be left alone as well with this flag set. Since additionally enabling memory decoding on a device without BARs is a questionable operation I wonder whether you couldn't better move this a few lines down immediately ahead of the loop over the BARs, and make it return instead of zeroing num_bars.

On a device without BARs I expect the memory decoding will already be disabled, but I can certainly return early instead ahead of the loop and also skip the ROM probing.

Quoted 4 lines
Quoted 4 lines
xen/include/xen/pci.h +0 -0
@@ -115,6 +115,9 @@ struct pci_dev {
 
Quoted 8 lines

xen/include/xen/pci.h struct pci_dev { · line 120

Quoted 5 lines
xen/include/xen/pci.h +3 -0
     /* Data for vPCI. */
     struct vpci *vpci;
+
+    /* Device with errata, ignore the BARs. */
+    bool ignore_bars;

Please can you put this into (one of?) the existing hole(s), instead of at the end?

I will place it after nodeid_t.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 03.12.18 at 18:36, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 29.11.18 at 18:11, <[email protected]> wrote:
xen/drivers/passthrough/pci.c +0 -0
@@ -298,6 +299,34 @@ static void check_pdev(const struct pci_dev *pdev)
 #undef PCI_STATUS_CHECK
 }
 
Quoted 13 lines

xen/drivers/passthrough/pci.c static void check_pdev(const struct pci_dev *pdev) · line 312

Quoted 11 lines
xen/drivers/passthrough/pci.c +11 -0
+static void apply_quirks(struct pci_dev *pdev)
+{
+    uint16_t vendor = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_VENDOR_ID);
+    uint16_t device = pci_conf_read16(pdev->seg, pdev->bus,
+                                      PCI_SLOT(pdev->devfn),
+                                      PCI_FUNC(pdev->devfn), PCI_DEVICE_ID);
+
+    if ( vendor == PCI_VENDOR_ID_INTEL && (device == 0x2fc0 ||
+         device == 0x6f60 || device == 0x6fa0 || device == 0x6fc0) )

Instead of such an ever growing if(), could we make this table based?

Quoted 3 lines

Sure, I guess using something similar to Linux's would be fine, so a table with the vendor ID, device ID and a pointer to a function to be called in case of match?

You could go this far, but I wouldn't: For now a table of (vendor,device) tuples would suffice. Once we need to deal with further quirks, we could then decide whether we want something callback-based.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
In reply to Jan Beulich
Quoted 9 lines · Jan Beulich

xen/drivers/passthrough/pci.c static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) · line 429

Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 29.11.18 at 18:11, <[email protected]> wrote:
xen/drivers/passthrough/pci.c +1 -0
@@ -397,6 +426,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn)
     }
 
     check_pdev(pdev);
+    apply_quirks(pdev);

At which point putting the small loop into check_pdev() might be as good as adding a new function.

I will add a new function, check_pdev takes a const pci_dev, and I don't want to deconst it in order to set the quirk.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel