Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2507406pxj; Mon, 10 May 2021 04:48:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSHcc/Or+yklyPWH7fNZi4cIGZ3AiMnB2C96AyRxEjhAHtqg+dlVp1Q6Z2Nx1Czjo0BGyC X-Received: by 2002:a17:906:7c45:: with SMTP id g5mr24720349ejp.368.1620647289094; Mon, 10 May 2021 04:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620647289; cv=none; d=google.com; s=arc-20160816; b=SZJV96BWnF0Lqcq72zkN59iBLeviYwyZjnhvpXVSmORPd04kI7HcuyHPd0EH05KC+R 92HsVP0CcMsyPxAoJp/XsMRIzvwBNxv2LbW4GBODIsHZMwz/6483eF0eJJFV4jC8sOu3 fJvujskvjv1fFS7wpniv2A4zU6IUrXD7ENpuWrPDGt2IRECgRt6dD+Ev3qVIBNB+9BWa kOxivBRF1ZpzrqrkkxcPbysC7zUjBC+ueDJCwDn21AFu6b5G0IaXAxjiw8CuaUtJLT/K ODs3xeSGnb6StqAvs+t5R9246HTerdC6wRAtw4Zb++KqUb17+d5F5mzktacT5a/nkBWz 08Dg== 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=jzdobD8AfxKMiHVDRo3ufUkZT5VsFhXx5E7ysaEj6q3eupCdZvUo9oVzVZGHEB1/eC SKhITw1Js695D0dFRWrJraUMVbJEXZFBkyHq3tNlNu0Vi5pAnY1A+9cfOHmN/wkBtbhZ SuXz/93TzltQ/Eo+yp7DBRI6mxApI1baBM00JdcxAcER0OdaXVZuICZTiaQXrlCO6wVz t+zbmpd281zzkJBwkwls4FUkWcFzGcAg+u1HTOvwLNn0UfAf8bOAJQBXzFIdYFGCCuQq l+CUI6nLDKqOOcIqUr9gIeGlJ216kd0uFOjSU6uARJY3GxYqsZD15Q+Vw1dn1f2Bayqh JWtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0bYOaYzQ; 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 mq29si1293309ejc.517.2021.05.10.04.47.31; Mon, 10 May 2021 04:48:09 -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=0bYOaYzQ; 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 S241975AbhEJLkQ (ORCPT + 99 others); Mon, 10 May 2021 07:40:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:52812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235028AbhEJK5a (ORCPT ); Mon, 10 May 2021 06:57:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A13A0619D4; Mon, 10 May 2021 10:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643863; bh=iHP5PI9dFvN+iJnh0PXIZUJf03sir2CeqLFELWPo6tY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0bYOaYzQKm3uqibpfSDgq7ZGmrzvF1BOqapSnYYhg4R2Joy1qJGms9ILFbKUopxUz n1zKihX3Pxh1bbn/2oTO8OqISFrGMDWMnf/Ax/MdGvZtH7KGQZJssi7DDFKBxiWDH0 y8TwG2rua04d/wOPrWZtH1sYqBwxbrbrXTgNXxKs= 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.11 190/342] selftests/resctrl: Fix incorrect parsing of iMC counters Date: Mon, 10 May 2021 12:19:40 +0200 Message-Id: <20210510102016.370577548@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102010.096403571@linuxfoundation.org> References: <20210510102010.096403571@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