Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1137908pxb; Thu, 15 Apr 2021 15:16:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyBxOjwiHJ7+P/GABm9iiXYHzYgICaj7IPJ67e1hSgGHXVSSUFw077ST+yD+pPTJB+G20By X-Received: by 2002:a63:5766:: with SMTP id h38mr5292809pgm.250.1618525009745; 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=vQx5NdphqN/wcEXMy+n+B/gqUVuYpMwmoSZlbbHfpK55c3L0ZGHB96qejxrGUfHxOt hG5d5+okc1p67dMCxLSdrxvfqbpNdpGLWxrNuqgPh78xIpv3YbDrhrE5YN8Tyr3CoMu3 dsK1688533tgq9tsT9nq7lvhnLzYME/M+Zh3kEs8IAMndyThV0cX5Zlfh8aCZz914CJP JYbydm5qKQYfoT93n4NtXy6G0Px0/rph84yJWxLVn8+Yd9hfeDfMjJ/EIPq7Ulzc1Uwd zYj27oIHgeU9enW45fkDbEkiky/nAJZr8R2Ig5Q62+4g3eHMF19LcajTy1P4JPw34+T1 Jupw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:to :from:subject:ironport-sdr:ironport-sdr; bh=1lO/RTVIj2NDnvtIaHNviPhg8fYQgi//4FlWl1GXGLw=; b=makk2u9xoriDCoHGu4RwRPa5B6nphnAnMWd9JAG5KFYFNta1BJek24BpHFEBFQXlc6 Sb9sg/J0Hrx9h8YrCg1nGMmU3lKbm2C6tTVwv5G2x0Wga644fxTef8C8ETvBHHY+3DjZ zj3GX+T5phGlNws/0Ho6eMzoOHxmRsGoRgSiCaXuaYbTUVcSV535cWWGB9oQQjE0Efws veBdkqWadSZW/g5sPs9z5PZ6JMVklNs45tk1z54PkNQsWHCtas4wEq8gJLbHxpUdqLCG i9BeSD6+SvZXnj3jtT3p9Di8ZaHJBt5EOZlY9SEXXHrVVashBaTxIt6wHgzlojzMPtsD meyA== 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 g22si4412380pfu.31.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 S235899AbhDOVd6 (ORCPT + 99 others); Thu, 15 Apr 2021 17:33:58 -0400 Received: from mga09.intel.com ([134.134.136.24]:9219 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235046AbhDOVd5 (ORCPT ); Thu, 15 Apr 2021 17:33:57 -0400 IronPort-SDR: CAQmwJ9l9od4j848d73jT8k24CPJ3CQjfLPGGQR+e/fNHz051Id/MYMoZiltsXEsUjqqySA1qG /EUwby9HavVA== X-IronPort-AV: E=McAfee;i="6200,9189,9955"; a="195059079" X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="195059079" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Apr 2021 14:33:25 -0700 IronPort-SDR: vbkqct+ThHQF29cjfBjx+eeaifoIHO1mkrDzJ7PG7h1N4TXKj8NdjOkBcRjx/1MYVYjMsaRUOd 5vdngfQRot/w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,225,1613462400"; d="scan'208";a="425343356" Received: from linux.intel.com ([10.54.29.200]) by orsmga008.jf.intel.com with ESMTP; 15 Apr 2021 14:33:25 -0700 Received: from [10.212.132.71] (kliang2-MOBL.ccr.corp.intel.com [10.212.132.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id 762C058088F; Thu, 15 Apr 2021 14:33:23 -0700 (PDT) Subject: Re: [PATCH] perf/x86/intel/uncore: Avoid null dereferences (uncore_extra_pci_dev) From: "Liang, Kan" To: Steve Wahl , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org References: <20210415203720.334007-1-steve.wahl@hpe.com> Message-ID: Date: Thu, 15 Apr 2021 17:33:22 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/15/2021 5:19 PM, Liang, Kan wrote: > Hi Steve, > > On 4/15/2021 4:37 PM, Steve Wahl wrote: >> If an uncore has no pci_init routine, or that routine fails, >> uncore_pci_init is not called, and memory is not allocated for >> uncore_extra_pci_dev. >> >> So check to make sure uncore_extra_pci_dev is not NULL before use. >> > > I think more after yesterday's discussion. There may be a better > solution than this. > > Actually, we don't have to probe all the PCU devices and stores them > into the uncore_extra_pci_dev for the cpu_init(). > We just need to pick up the first PCU device and check the existence of > the SBOX once. > > I will send out a patch shortly. Here is the patch I mentioned. https://lore.kernel.org/lkml/1618521764-100923-1-git-send-email-kan.liang@linux.intel.com Thanks, Kan > >> And fix the case that led us to discover the null derefs; don't fail >> snbep_pci2phy_map_init if BIOS doesn't supply pcibus_to_node >> information. >> >> Fixes: 9a7832ce3d92 ("perf/x86/intel/uncore: With > 8 nodes, get pci >> bus die id from NUMA info") > > In theory, the pci_read_config_dword() may fails as well. It has > possible that the issue can still be observed before the "> 8 nodes" patch. > > I think the fixes should be 5306c31c5733 ("perf/x86/uncore/hsw-ep: > Handle systems with only two SBOXes") > > Thanks, > Kan > >> Signed-off-by: Steve Wahl >> --- >>   arch/x86/events/intel/uncore_snbep.c | 10 +++++++--- >>   1 file changed, 7 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/events/intel/uncore_snbep.c >> b/arch/x86/events/intel/uncore_snbep.c >> index b79951d0707c..14c24356a2fa 100644 >> --- a/arch/x86/events/intel/uncore_snbep.c >> +++ b/arch/x86/events/intel/uncore_snbep.c >> @@ -1373,11 +1373,11 @@ static int snbep_pci2phy_map_init(int devid, >> int nodeid_loc, int idmap_loc, bool >>           /* >>            * The nodeid and idmap registers only contain enough >>            * information to handle 8 nodes.  On systems with more >> -         * than 8 nodes, we need to rely on NUMA information, >> +         * than 8 nodes, if available we rely on NUMA information, >>            * filled in from BIOS supplied information, to determine >>            * the topology. >>            */ >> -        if (nr_node_ids <= 8) { >> +        if ((nr_node_ids <= 8) || (pcibus_to_node(ubox_dev->bus) == >> -1)) { >>               /* get the Node ID of the local register */ >>               err = pci_read_config_dword(ubox_dev, nodeid_loc, &config); >>               if (err) >> @@ -2865,7 +2865,9 @@ void hswep_uncore_cpu_init(void) >>           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]) { >> +    if (!uncore_extra_pci_dev) >> +        hswep_uncore_sbox.num_boxes = 2; >> +    else 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], >> @@ -3243,6 +3245,8 @@ void bdx_uncore_cpu_init(void) >>       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) { >> +        bdx_msr_uncores[BDX_MSR_UNCORE_SBOX] = NULL; >>       } else if (uncore_extra_pci_dev[pkg].dev[HSWEP_PCI_PCU_3]) { >>           struct pci_dev *pdev; >>           u32 capid4; >>