[PATCH 1/1] x86/platform/x86: Fix count of CHas on multi-pci-segment arches

From: Kroening, Gary
Date: Wed Mar 07 2018 - 15:33:27 EST


For systems with a single PCI segment, it is sufficient to look for the
bus number to change in order to determine that all of the CHa's have
been counted for a single socket.

However, for multi PCI segment systems, each socket is given a new
segment and the bus number does NOT change. So looking only for the
bus number to change ends up counting all of the CHa's on all sockets
in the system. This leads to writing CPU MSRs beyond a valid range and
causes an error in ivbep_uncore_msr_init_box().

The fix is to check for either the bus number or segment number to change.

Signed-off-by: Gary Kroening <gary.kroening@xxxxxxx>
Signed-off-by: Mike Travis <mike.travis@xxxxxxx>
Reviewed-by: Dimitri Sivanich <dimitri.sivanich@xxxxxxx>
---
arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

--- linux-4.4.orig/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
+++ linux-4.4/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
@@ -3525,15 +3525,19 @@ static struct intel_uncore_type *skx_msr
static int skx_count_chabox(void)
{
struct pci_dev *chabox_dev = NULL;
- int bus, count = 0;
+ int bus, seg, count = 0;

while (1) {
chabox_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x208d, chabox_dev);
if (!chabox_dev)
break;
- if (count == 0)
+ if (count == 0) {
bus = chabox_dev->bus->number;
- if (bus != chabox_dev->bus->number)
+ seg = pci_domain_nr(chabox_dev->bus);
+ }
+ /* check for change in both bus and domain/segment */
+ if (bus != chabox_dev->bus->number ||
+ seg != pci_domain_nr(chabox_dev->bus))
break;
count++;
}