Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3412626pxy; Mon, 26 Apr 2021 00:47:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm54twE11wjneQkLf/UFS8BBluP+/NBtNaQNCtaZrsUiY9Ex6+3sq85YZNwUhs3BxNBEGl X-Received: by 2002:aa7:9806:0:b029:253:e613:4ada with SMTP id e6-20020aa798060000b0290253e6134adamr16378391pfl.65.1619423272965; Mon, 26 Apr 2021 00:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619423272; cv=none; d=google.com; s=arc-20160816; b=k0LON5Wyk7HrYJ16ivJSCfBtY8xjCMIWbTgX69X5uVCEgGP/l2N+q07HPF/fpbdfzu wDLZYQfef+f60ZgGJ+mX589i179eqJAhNuCPZKzCtVpicy4UjZEALMi2d4DCA0DSUkat qtaL9tqENaO3W8c0xPZc/veL/snczn6qGefV6z9w56cvA2Q23BWEy9/6EvmJ5qFqFHib LTSLsDZ4+OyD3g8rpNNHZmonYkfRBvkiDkLIQ8QD5+0Xyz8nXxyPjzyxf9mCiSg+l+cn VxBlaePBR4X+0ZUz7hxRO5D3XZliZ+d10erVHKACS3faXAaCu91KDCNN8EjO4LuSSarZ jLuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1LXXaoEstesbAfZ3iQ7+dL5h0BFMrrZAfDo+rlvKp6U=; b=jnik2xfNT0DgaoTJVBJ7qVUBNSXhT9Na3PtDnyaBaZAQda99imxh8XRjT8TdaC6A9C rAmwTmHTnc7/mR19U6AAizcad++75CWSOgwb5cVFrd7GJwaXfXRRUnrv5KbYDdE/xNfY 242bouUb/QinUMrQ28nW4RqAOZzceXY139eqAAHhJvvQIk5ogwXM7yXxUCkYIcki0c/Z 8HFFcfTsPuMtvvVJWTkxP3yal+V7u99q8ZJSRGoKJxVyO2Bzn8HBKxXaQqbALIcGumYA Dxs0r35jGZyOxq+wJFOOjr/q2jpPDc8y7hSBDikbjaU/7BOxLUg8hwYcwLryjjA0TCGO b+Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jGznGCsK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mn24si1217883pjb.73.2021.04.26.00.47.40; Mon, 26 Apr 2021 00:47:52 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jGznGCsK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233666AbhDZHrw (ORCPT + 99 others); Mon, 26 Apr 2021 03:47:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:56330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233373AbhDZHjX (ORCPT ); Mon, 26 Apr 2021 03:39:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 41597613B1; Mon, 26 Apr 2021 07:37:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1619422638; bh=dyRldP5WwRQox7FWHAv/9vRbVj4P9Q2XOhGBEqwoVFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jGznGCsKzWJYxjQRt8YYEFOSJact1lKEd9wo2lKOOLS4bpuYqd9/lZJt9/JCx145N ntX4egxyarJGsGHN8vP6jqgt5C0vzf6gTAjxUFcsPL5T1/k5B9lpZS0AiU7qbkO7f0 8dzyuAqq7Zl/gMW7Bpoz0h9Rm0mazQMIeTgeuGag= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve Wahl , Kan Liang , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 4.19 46/57] perf/x86/intel/uncore: Remove uncore extra PCI dev HSWEP_PCI_PCU_3 Date: Mon, 26 Apr 2021 09:29:43 +0200 Message-Id: <20210426072822.131385198@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210426072820.568997499@linuxfoundation.org> References: <20210426072820.568997499@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang [ Upstream commit 9d480158ee86ad606d3a8baaf81e6b71acbfd7d5 ] 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 Signed-off-by: Peter Zijlstra (Intel) Tested-by: Steve Wahl Link: https://lkml.kernel.org/r/1618521764-100923-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Sasha Levin --- 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 8e4e8e423839..c06074b847fa 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -1030,7 +1030,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) @@ -2687,22 +2686,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; } @@ -2965,11 +2975,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 */ } }; @@ -3061,27 +3066,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; } @@ -3302,11 +3298,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.30.2