Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2537107pxj; Mon, 10 May 2021 05:26:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx65a91/dZZyE4usWh4m0ujQSjeplghg8iJplhqmSy+2h0OUMfyp5oNNOXPsdVv4yFHx04f X-Received: by 2002:a92:de05:: with SMTP id x5mr21360601ilm.156.1620649590980; Mon, 10 May 2021 05:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620649590; cv=none; d=google.com; s=arc-20160816; b=xsBbFUYnZT5T8yB1XFrlpl6GKRXd489wgLCjVWk/w6AHH4SbIUYpvlRK49LiFASGaX C7TvPlIHm0fbP9YGaFVB7dHJyodO0EBw6pHBYKWWGap+YxfzFan0ZW+kCfe/+j7eX/SD xl5UdGAusn+wx5DHkyDuDoxHHB3Rn56D3m4gC4RuXh6biib2U9BhZq32hpvIy0j5bmsN UY6/4z2PpjZ612NmoMLF4+9UoyuCaaNkPpWgdohLX1+Ieq8EDvB3fZdwqc5Kh5Ex4hxM Un9L5R4CmbEfliuQNHa+OR/wk0dZXatGi9ipr7HKMkKwcQyRiq3w1j+f9o0Prq5oro0g Eb9w== 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=HaNgPNmCRsOU26M5bIqsnB64VwPJ03D3GR4IO6oZmMg=; b=TeLoYjX4KpMmMk5H5ujvVN201W9o9h6Iip/53Ux5DEC55t9HcwLEHJYU5uGfiOQprg XXhMbldgWKb1bohit6LXcRbsans9IFyNTB9lCo5XHDFNFLw7QkAVzsdIgyp985roGeiT Xc0H+kptZ0Qa2a9QYrewz80u2mT19KRV3aJtnd1nXeSfZo9H1pFO9ysv6ppuplrifVpE 63rU7+gRkXQxeSGdq7U3c90LrbDoFqNdSQp6ylQeAateSLc7wmnjgDAlBzEtvLz212V2 RioMnJwYpz0c/djm/ITu4ZEtqaDka9+3eT1/xdYENFxu+riwSyIdOEGaIyKmmp9fYyV/ jI7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="cQh/jEz4"; 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 r14si10100504iod.2.2021.05.10.05.26.18; Mon, 10 May 2021 05:26:30 -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="cQh/jEz4"; 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 S1345236AbhEJMWH (ORCPT + 99 others); Mon, 10 May 2021 08:22:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:46128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236938AbhEJLLA (ORCPT ); Mon, 10 May 2021 07:11:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 386C061432; Mon, 10 May 2021 11:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620644758; bh=iHP5PI9dFvN+iJnh0PXIZUJf03sir2CeqLFELWPo6tY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQh/jEz4yDc4RrKcx4gGo6rBa2wd6D1JE/VYNoUXtxwIb5Mn5th6jNZMm+GtwaeeC HmpkB73lh/Suld9WskS1zE/QkA46j3ZnvoKNrP5LveFqwXMEyzvT+Ioc4D85WIbR7y 5WN6ehulh6cpa3fizE+X/PiTcu/W54UkGHbSt8Lw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Reinette Chatre , Babu Moger , Fenghua Yu , Shuah Khan , Sasha Levin Subject: [PATCH 5.12 212/384] selftests/resctrl: Fix incorrect parsing of iMC counters Date: Mon, 10 May 2021 12:20:01 +0200 Message-Id: <20210510102021.881823874@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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: Fenghua Yu [ Upstream commit d81343b5eedf84be71a4313e8fd073d0c510afcf ] iMC (Integrated Memory Controller) counters are usually at "/sys/bus/event_source/devices/" and are named as "uncore_imc_". num_of_imcs() function tries to count number of such iMC counters so that it could appropriately initialize required number of perf_attr structures that could be used to read these iMC counters. num_of_imcs() function assumes that all the directories under this path that start with "uncore_imc" are iMC counters. But, on some systems there could be directories named as "uncore_imc_free_running" which aren't iMC counters. Trying to read from such directories will result in "not found file" errors and MBM/MBA tests will fail. Hence, fix the logic in num_of_imcs() such that it looks at the first character after "uncore_imc_" to check if it's a numerical digit or not. If it's a digit then the directory represents an iMC counter, else, skip the directory. Reported-by: Reinette Chatre Tested-by: Babu Moger Signed-off-by: Fenghua Yu Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- tools/testing/selftests/resctrl/resctrl_val.c | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c index aed71fd0713b..5478c23c62ba 100644 --- a/tools/testing/selftests/resctrl/resctrl_val.c +++ b/tools/testing/selftests/resctrl/resctrl_val.c @@ -221,8 +221,8 @@ static int read_from_imc_dir(char *imc_dir, int count) */ static int num_of_imcs(void) { + char imc_dir[512], *temp; unsigned int count = 0; - char imc_dir[512]; struct dirent *ep; int ret; DIR *dp; @@ -230,7 +230,25 @@ static int num_of_imcs(void) dp = opendir(DYN_PMU_PATH); if (dp) { while ((ep = readdir(dp))) { - if (strstr(ep->d_name, UNCORE_IMC)) { + temp = strstr(ep->d_name, UNCORE_IMC); + if (!temp) + continue; + + /* + * imc counters are named as "uncore_imc_", hence + * increment the pointer to point to . Note that + * sizeof(UNCORE_IMC) would count for null character as + * well and hence the last underscore character in + * uncore_imc'_' need not be counted. + */ + temp = temp + sizeof(UNCORE_IMC); + + /* + * Some directories under "DYN_PMU_PATH" could have + * names like "uncore_imc_free_running", hence, check if + * first character is a numerical digit or not. + */ + if (temp[0] >= '0' && temp[0] <= '9') { sprintf(imc_dir, "%s/%s/", DYN_PMU_PATH, ep->d_name); ret = read_from_imc_dir(imc_dir, count); -- 2.30.2