Received: by 10.213.65.68 with SMTP id h4csp836397imn; Tue, 27 Mar 2018 09:40:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/IPDX+t2XwI3fujzA1wjABwoSKeFPhVSXqBOfzXzdM8SZ0PuIwnacsIAwa8hQgq8gtB/fJ X-Received: by 2002:a17:902:6a17:: with SMTP id m23-v6mr56738plk.342.1522168828014; Tue, 27 Mar 2018 09:40:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522168827; cv=none; d=google.com; s=arc-20160816; b=Ab4E9zbmZeBaOKS2zMVjvBadW3/DJfL6yJ9DaYq8lLyXZvSRD2VbhRiaiwQ3l0nmHk LO1fptbBXHkucJaSzgDJ5iH6jGsTD5ht5xUeo8GjjKIZyrU45SePJW3WAi+5PsUWo0rv AYafQC2+ifUOnOgomkDF3v13j0Ew9kwjeuxDZ3rZTeHPaK5IlaLPcoeKEdxNeHRrAg5O 15r3BD0gnA6x/+ShnxWOjnXdkkBqKr0ZjCHST1JOPasdpgD148mFawVHNjJ2JRYQIjif UDdXFYxmn0vBgYNT1241lmwSIcnLNk3dsgdBbcpwLrIt5u/ZOv3rIG0CHiLQ1SSAGmZh E29w== 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=8jJ+Lp6APAakdDyQ4kvaeHoMlysCz07HN1ZD5tGvh9s=; b=ggT4/OOT+bI/5bdcgeioEusaoOMAd71WCBgE/pzmB2nlUvit7dxcpIWnL5exbxAnoJ s03J854wD16vM9mp/eHQvum58sm5fpNKAjPYaMsqv//NNPjutB/sORKZ8ozjM/Vn8oUn IswiagnbkzIGSMQqJJf/lyhtKYd5CF1bFe4wZUFUfPKBcIBpuSBcgoTbMOq9VMm7ZArB 8rmRhmg5XL2hLfurLNGuNd1TKFJIxCSIc7y65GGmDRQUZuwjr3RZGbSXW3LxuCtBSkUm jVVw5nwGLDk9h8+zgwXMt74lQJVQB7hUyHeqfVBdUrAszazS4nh1MGpIiaiPyEhSyaxV 3IIQ== 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 x9-v6si1711050plo.41.2018.03.27.09.40.12; Tue, 27 Mar 2018 09:40:27 -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 S1755080AbeC0Qh5 (ORCPT + 99 others); Tue, 27 Mar 2018 12:37:57 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46506 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755051AbeC0Qhy (ORCPT ); Tue, 27 Mar 2018 12:37: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 5DEADF92; Tue, 27 Mar 2018 16:37: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.14 091/101] perf/x86/intel/uncore: Fix multi-domain PCI CHA enumeration bug on Skylake servers Date: Tue, 27 Mar 2018 18:28:03 +0200 Message-Id: <20180327162755.615320522@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180327162749.993880276@linuxfoundation.org> References: <20180327162749.993880276@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.14-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 @@ -3554,24 +3554,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)