Received: by 10.213.65.68 with SMTP id h4csp846269imn; Tue, 27 Mar 2018 09:52:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+IkltUgdlXn4m2lWDPNURd72LQoqBQUJfJeDbQbNCsHRTdG9j2viDje+Puz8e/o+g2AW5J X-Received: by 10.167.130.22 with SMTP id k22mr71323pfi.73.1522169548977; Tue, 27 Mar 2018 09:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522169548; cv=none; d=google.com; s=arc-20160816; b=s7mRl1WCx6/nT8loHSgKsu220i9dpLTUr/BZxGXf9BQPDoiC7Mp+Gxg7g5ywDWMFzj MvDqEU9zQRR2pROd4ViVMv8bIK1WBT45fbALzw3uccPHBRULqnxXa72tG/eO2svgqLWT EkHX77+qfXooowd9qpP/qNrIDPtaCAvQEOVa8gExo1bnAhESWq8kZdAaRT+zXfDmKaBk sHVd92q90e7Rrs6gH0kkZIJgWot5ZuEEK+xfI8XYN4Nnbrmvag6N3J0IfCK8dPJWErvk 6RlQ9tCWJGh7I1AjLhD15csfqXo3hA7Zx8oMlKDPJzdQudlZh+eTxG2RXaIjviMiyMcV ijtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=OfYpiqvLrindxvZsZP0mtBdbZ6xfO+9GLNk/YRcr4Jg=; b=BBjxITtRw0K3GJGhmRQQYr5KtZ0foFImc4WhiBxXpZyRHNdTipPUk2Pik2FI2pWZYr faOkZZaLh5nvTCZTWWmH9W/4X55XFwhaTk9DREsIukHEe1O569KaUqHVRtnC7T9R6Gv/ M5SJqN08GfNBBdFXYbKZSjfnah6ktAbMK8u1qyWiiHGVcqemJeGxC4Dvgamdl/gUlgY4 lJmyyL5b8YF+rnh8BpWv088CTvHw5ABKsBwYpE1G+8HJXbGx0F6FEv4H4uGkkZsZvvVx snHtzeVnx9rVg63xUE7ynZc977vgaQkGxEJwk7I2iWIwaFDOQID98AeAbjWmRdHE/m3c SCsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j91-v6si1632718pld.14.2018.03.27.09.52.14; Tue, 27 Mar 2018 09:52:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755639AbeC0Qtl (ORCPT + 99 others); Tue, 27 Mar 2018 12:49:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49342 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932846AbeC0Qm5 (ORCPT ); Tue, 27 Mar 2018 12:42:57 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BCC6410D9; Tue, 27 Mar 2018 16:42:55 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Kroening, Gary" , Kan Liang , "Peter Zijlstra (Intel)" , Andy Shevchenko , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , abanman@hpe.com, dimitri.sivanich@hpe.com, hpa@zytor.com, mike.travis@hpe.com, russ.anderson@hpe.com, Ingo Molnar Subject: [PATCH 4.15 098/105] perf/x86/intel/uncore: Fix multi-domain PCI CHA enumeration bug on Skylake servers Date: Tue, 27 Mar 2018 18:28:18 +0200 Message-Id: <20180327162803.996643903@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162757.813009222@linuxfoundation.org> References: <20180327162757.813009222@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kan Liang commit 320b0651f32b830add6497fcdcfdcb6ae8c7b8a0 upstream. The number of CHAs is miscalculated on multi-domain PCI Skylake server systems, resulting in an uncore driver initialization error. Gary Kroening explains: "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()." To fix this bug, query the number of CHAs from the CAPID6 register: it should read bits 27:0 in the CAPID6 register located at Device 30, Function 3, Offset 0x9C. These 28 bits form a bit vector of available LLC slices and the CHAs that manage those slices. Reported-by: Kroening, Gary Tested-by: Kroening, Gary Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andy Shevchenko Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: abanman@hpe.com Cc: dimitri.sivanich@hpe.com Cc: hpa@zytor.com Cc: mike.travis@hpe.com Cc: russ.anderson@hpe.com Fixes: cd34cd97b7b4 ("perf/x86/intel/uncore: Add Skylake server uncore support") Link: http://lkml.kernel.org/r/1520967094-13219-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/uncore_snbep.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -3562,24 +3562,27 @@ static struct intel_uncore_type *skx_msr NULL, }; +/* + * To determine the number of CHAs, it should read bits 27:0 in the CAPID6 + * register which located at Device 30, Function 3, Offset 0x9C. PCI ID 0x2083. + */ +#define SKX_CAPID6 0x9c +#define SKX_CHA_BIT_MASK GENMASK(27, 0) + static int skx_count_chabox(void) { - struct pci_dev *chabox_dev = NULL; - int bus, count = 0; + struct pci_dev *dev = NULL; + u32 val = 0; - while (1) { - chabox_dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x208d, chabox_dev); - if (!chabox_dev) - break; - if (count == 0) - bus = chabox_dev->bus->number; - if (bus != chabox_dev->bus->number) - break; - count++; - } + dev = pci_get_device(PCI_VENDOR_ID_INTEL, 0x2083, dev); + if (!dev) + goto out; - pci_dev_put(chabox_dev); - return count; + pci_read_config_dword(dev, SKX_CAPID6, &val); + val &= SKX_CHA_BIT_MASK; +out: + pci_dev_put(dev); + return hweight32(val); } void skx_uncore_cpu_init(void)