Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1137910pxb; Thu, 15 Apr 2021 15:16:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsDA7HPrJVkz952qDW6qbHOELUYtAnmnxNjnnUgdNGB99ChgN2TWTzSEUT7N9Yka4y5U9v X-Received: by 2002:a63:5857:: with SMTP id i23mr5390534pgm.152.1618525009823; Thu, 15 Apr 2021 15:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618525009; cv=none; d=google.com; s=arc-20160816; b=VzQWGNAWNtDpJ6/HFEnaywk63WDcR5EKbvPsagTeL9v4tvmwAzenSmaWdRHWvly2HB Kz7aCpoK9e+RY//ctlPaTJz4oZ3XKuWU9oLT5upyyxJq968hT595Ava4ExlrtfLGZr/a msEc9RA2PluX/GVKanw3mLrKXRBPEySJI7nElT5ETe0DYg6NP7ebshH0iOeDs7UjVbyc gpru0M8XCg9C63aSA98tYns8nte4+B8HZ3QhiIecEIYRoQqZLIQtk35W3HJ2Ov2+uJ5Q tDlvXU7AR7uoHg0MAQaIQZPDPFi4zwTsVcIrLbX6HRoheoDTR0T6KM0fiNEYL7KuS0Q3 PhWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=A1YbB4nWg8I515DxKyDhPlRW1YT1OlpS6sBH3yDFobQ=; b=Sf1cYttof/eEMdBDzyw4pAQm8hiquOpQg7epaI4ZGo9w3LLDgqcmCuHmhHzSWZxDlJ qmfCF9OcFCcVmmZbwwu5ogfkfC0NIKT0jxr3u0bICuG7uC/GDOrAdGO7iu5ABCT3os8T vRB5LvQxooRWWhobgC51TTZDSCCexN5L6982fEZUg5pjdKRPbg3maFclcHt3xOttjhRl 6bDbSiyR4Pz0RUXZvb5IgTPDj8ca7VaOCEGBsUwwymD5lgN7IfXtM2GQzQc0UTxoXqM6 r709AzN7rBSY/J+DBM8BhRexvWc3l3zhyzpXnyWT7mLz7jjl20PlFKA1j3WicXCS9Qam 8bNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j9si4930649pgq.561.2021.04.15.15.16.37; Thu, 15 Apr 2021 15:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236000AbhDOVak (ORCPT + 99 others); Thu, 15 Apr 2021 17:30:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:8933 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235835AbhDOVaj (ORCPT ); Thu, 15 Apr 2021 17:30:39 -0400 IronPort-SDR: M16VoHaVvbZ4HrTln6WYQAlNpE+sr8X/WBANVhADVQX1OKo+e80cU8db1AvM/2Z+YC0tiAveOt 7r77F2XtkBVg== X-IronPort-AV: E=McAfee;i="6200,9189,9955"; a="195058515" X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="195058515" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2021 14:30:15 -0700 IronPort-SDR: lfTKbKre0OBv6ge5Wa/shNrmskHfegjKmdmgkTJ42VWSuNEm6MRdJMf1DGyVGKmTkDNKAYzlUe CCIa5FkElBLg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="421822574" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga007.jf.intel.com with ESMTP; 15 Apr 2021 14:30:15 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, acme@kernel.org, andreas@oehler-net.de, eranian@google.com, osk@google.com, tglx@linutronix.de, mark@voidzero.net, steve.wahl@hpe.com, Kan Liang Subject: [PATCH] perf/x86/intel/uncore: Remove uncore extra PCI dev HSWEP_PCI_PCU_3 Date: Thu, 15 Apr 2021 14:22:43 -0700 Message-Id: <1618521764-100923-1-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang There may be a kernel panic on the Haswell server and the Broadwell server, if the snbep_pci2phy_map_init() return error. The uncore_extra_pci_dev[HSWEP_PCI_PCU_3] is used in the cpu_init() to detect the existence of the SBOX, which is a MSR type of PMON unit. The uncore_extra_pci_dev is allocated in the uncore_pci_init(). If the snbep_pci2phy_map_init() returns error, perf doesn't initialize the PCI type of the PMON units, so the uncore_extra_pci_dev will not be allocated. But perf may continue initializing the MSR type of PMON units. A null dereference kernel panic will be triggered. The sockets in a Haswell server or a Broadwell server are identical. Only need to detect the existence of the SBOX once. Current perf probes all available PCU devices and stores them into the uncore_extra_pci_dev. It's unnecessary. Use the pci_get_device() to replace the uncore_extra_pci_dev. Only detect the existence of the SBOX on the first available PCU device once. Factor out hswep_has_limit_sbox(), since the Haswell server and the Broadwell server uses the same way to detect the existence of the SBOX. Add some macros to replace the magic number. Fixes: 5306c31c5733 ("perf/x86/uncore/hsw-ep: Handle systems with only two SBOXes") Reported-by: Steve Wahl Signed-off-by: Kan Liang --- arch/x86/events/intel/uncore_snbep.c | 61 +++++++++++++++--------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c index b79951d..9b89376 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1159,7 +1159,6 @@ enum { SNBEP_PCI_QPI_PORT0_FILTER, SNBEP_PCI_QPI_PORT1_FILTER, BDX_PCI_QPI_PORT2_FILTER, - HSWEP_PCI_PCU_3, }; static int snbep_qpi_hw_config(struct intel_uncore_box *box, struct perf_event *event) @@ -2857,22 +2856,33 @@ static struct intel_uncore_type *hswep_msr_uncores[] = { NULL, }; -void hswep_uncore_cpu_init(void) +#define HSWEP_PCU_DID 0x2fc0 +#define HSWEP_PCU_CAPID4_OFFET 0x94 +#define hswep_get_chop(_cap) (((_cap) >> 6) & 0x3) + +static bool hswep_has_limit_sbox(unsigned int device) { - int pkg = boot_cpu_data.logical_proc_id; + struct pci_dev *dev = pci_get_device(PCI_VENDOR_ID_INTEL, device, NULL); + u32 capid4; + + if (!dev) + return false; + + pci_read_config_dword(dev, HSWEP_PCU_CAPID4_OFFET, &capid4); + if (!hswep_get_chop(capid4)) + return true; + return false; +} + +void hswep_uncore_cpu_init(void) +{ if (hswep_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) hswep_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores; /* Detect 6-8 core systems with only two SBOXes */ - if (uncore_extra_pci_dev[pkg].dev[HSWEP_PCI_PCU_3]) { - u32 capid4; - - pci_read_config_dword(uncore_extra_pci_dev[pkg].dev[HSWEP_PCI_PCU_3], - 0x94, &capid4); - if (((capid4 >> 6) & 0x3) == 0) - hswep_uncore_sbox.num_boxes = 2; - } + if (hswep_has_limit_sbox(HSWEP_PCU_DID)) + hswep_uncore_sbox.num_boxes = 2; uncore_msr_uncores = hswep_msr_uncores; } @@ -3135,11 +3145,6 @@ static const struct pci_device_id hswep_uncore_pci_ids[] = { .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV, SNBEP_PCI_QPI_PORT1_FILTER), }, - { /* PCU.3 (for Capability registers) */ - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x2fc0), - .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV, - HSWEP_PCI_PCU_3), - }, { /* end: all zeroes */ } }; @@ -3231,27 +3236,18 @@ static struct event_constraint bdx_uncore_pcu_constraints[] = { EVENT_CONSTRAINT_END }; +#define BDX_PCU_DID 0x6fc0 + void bdx_uncore_cpu_init(void) { - int pkg = topology_phys_to_logical_pkg(boot_cpu_data.phys_proc_id); - if (bdx_uncore_cbox.num_boxes > boot_cpu_data.x86_max_cores) bdx_uncore_cbox.num_boxes = boot_cpu_data.x86_max_cores; uncore_msr_uncores = bdx_msr_uncores; - /* BDX-DE doesn't have SBOX */ - if (boot_cpu_data.x86_model == 86) { - uncore_msr_uncores[BDX_MSR_UNCORE_SBOX] = NULL; /* Detect systems with no SBOXes */ - } else if (uncore_extra_pci_dev[pkg].dev[HSWEP_PCI_PCU_3]) { - struct pci_dev *pdev; - u32 capid4; - - pdev = uncore_extra_pci_dev[pkg].dev[HSWEP_PCI_PCU_3]; - pci_read_config_dword(pdev, 0x94, &capid4); - if (((capid4 >> 6) & 0x3) == 0) - bdx_msr_uncores[BDX_MSR_UNCORE_SBOX] = NULL; - } + if ((boot_cpu_data.x86_model == 86) || hswep_has_limit_sbox(BDX_PCU_DID)) + uncore_msr_uncores[BDX_MSR_UNCORE_SBOX] = NULL; + hswep_uncore_pcu.constraints = bdx_uncore_pcu_constraints; } @@ -3472,11 +3468,6 @@ static const struct pci_device_id bdx_uncore_pci_ids[] = { .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV, BDX_PCI_QPI_PORT2_FILTER), }, - { /* PCU.3 (for Capability registers) */ - PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x6fc0), - .driver_data = UNCORE_PCI_DEV_DATA(UNCORE_EXTRA_PCI_DEV, - HSWEP_PCI_PCU_3), - }, { /* end: all zeroes */ } }; -- 2.7.4