Received: by 10.213.65.68 with SMTP id h4csp900202imn; Tue, 27 Mar 2018 10:50:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/l/nmC/ypB0PPmkcpN1yiGcw//wZi/5PfHP6RRn7mzWbF0GjbLGEkzabh0jaLD0VB8Iw5g X-Received: by 2002:a17:902:51ce:: with SMTP id y72-v6mr255170plh.157.1522173023146; Tue, 27 Mar 2018 10:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522173023; cv=none; d=google.com; s=arc-20160816; b=pAdz1lM+6EeiwPPL6+ziT2Bk030dFCcNs9hVhyEmG5w9mT0Z4Od9gPCWFYNP+g6eba oE+CWEY3sZZvq2Owf+NbFXisW2l+YhZiXDXpPBJQgXU8LDMkFhZJmuUg/Xp4cr68Kkd0 XV3KnBITP0/32ek6Ef74WUU8qTwV9zLMxt2JMK6a5qgA6EL7is94Qwg79nut9Md9PBxC tQPmiJeFIHTc2Y4JLWtibGXJ5s293Ov2dBHjvE/UwMk54F2cm+5PZAaUgfLipWgGwJm/ a8ElXXqMYhbpKL2TEpO5KKCFEAMSSYR7m6pDCfkzcN4bzxkVzLG4enUov5Fg19cDHEgw mvLg== 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=KnXTzqOOoTaEnb97yVQ/g5bXKM/P5g6QnbnhHQiBU0c=; b=MYIYwF/PrpOoej26QYSrLcDWpruHdKnQhtEh5tdi+cnkTdupDhUkYIKlSfzVj17QKX z5BFbvLihi7cmxCzulqH77CrATff5r9+sIGdr7ppegNtlMgS8OfKx48ypDE5epBTX2bZ TAaATthc7gxn1MsAurU5pIRHF89p/jt1aRN46FIpW8YQozAllf7QFGk2/4VRJdCR6yOE xpt9JHsUG333dQAeDSzeiuNzlfUold5s5l+W2XS6lwSVBZnF3WLpawkFb7ElmSnfr98F bRfYb3VS2lKcpF4ghwFuN02nBxB+0myRN7RxtQvf8pSR94lx+Oa0AkHV1oRmJwFQTDiZ RWMA== 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 f18si1153551pgn.244.2018.03.27.10.50.08; Tue, 27 Mar 2018 10:50:23 -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 S1753921AbeC0RrZ (ORCPT + 99 others); Tue, 27 Mar 2018 13:47:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43614 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753806AbeC0Qcy (ORCPT ); Tue, 27 Mar 2018 12:32:54 -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 428B410CE; Tue, 27 Mar 2018 16:32:53 +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.9 57/67] perf/x86/intel/uncore: Fix multi-domain PCI CHA enumeration bug on Skylake servers Date: Tue, 27 Mar 2018 18:27:49 +0200 Message-Id: <20180327162730.737080200@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162726.702411083@linuxfoundation.org> References: <20180327162726.702411083@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.9-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 @@ -3522,24 +3522,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)