Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2487961pxj; Mon, 10 May 2021 04:18:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgVDAoMBfJonRz0pgUBwHK6Rjyf8V3CooLGoRzxtobUxXqkTtHPIWLILTxPTzPe+p36Rf0 X-Received: by 2002:a05:6402:b2c:: with SMTP id bo12mr28968906edb.196.1620645495446; Mon, 10 May 2021 04:18:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645495; cv=none; d=google.com; s=arc-20160816; b=CVCXA1PamiREKyFnezbAdKRZtRUtRWaItswbM7Qnq13qKuvfLiPqmldW7pdQkhnvUi SUFS1uKr1bUHA0TrlcEY5gmljaK6SsjYyjUxmjD7efxqqTbhN8oRetILWNCOU9wSya0u 2sZGkPhsKjtegtnPBuvnYS0PfEPOrkKu1YBbyDNDTPcT8HZ3STTCgttr2QRM/ncE+fte EIg7XtPDtO2Ka1aeeKjWXXQnLJu2R+7O9lUeafSlmlwuOg+vo6SwsmkpNzXwh2Z9zGNq zWYbTvBt3G3VaJjG3CIWg5Z0g3c5qJ/j1V7kGs2mu4mIspobuxsRGHkIwzkZlYzGU4Om w9pg== 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=1I3F2mrnf2R+7BfHLDIogwuu4ExmbUpOZCMAG9x3rjpH6LY/cuuzIeHQy0dMsaPXSP 8FF4PQTlYBTmxpAFOnjyg783sb3h2PuvvtPNNJWG0scTvnvwZFwKRNBVlVYmnsmTA8+T HhEVyjzooKpAOt7eqEr2f75TMMMRRVHG3QgyZtRn5DoyRLOrzUFB4IXEQ3TBhhd8G0OY Ax1qIlSEdzCEdqfAjCeQl7sKk3NvFqE6/Dvdr2Shz//K0lpXBji2wcVB4dQXFffmPqju 7OXLeaBXeBCl2iH5r/M1A/rESaPJI/NXGjyqUTjocY8IuEC1ZP1dvw/HLNzcMj/9XyCV EwEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0GCazAY9; 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 jl17si13654342ejc.327.2021.05.10.04.17.50; Mon, 10 May 2021 04:18:15 -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=0GCazAY9; 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 S234618AbhEJLNB (ORCPT + 99 others); Mon, 10 May 2021 07:13:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:33618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233523AbhEJKuL (ORCPT ); Mon, 10 May 2021 06:50:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F592619E6; Mon, 10 May 2021 10:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643151; bh=iHP5PI9dFvN+iJnh0PXIZUJf03sir2CeqLFELWPo6tY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0GCazAY9pfKHc0EoCAwl3N4DTXm6+AcdHmhLAsaZyfFcELsuMmr2xyS7C2dFneEs+ BdjRdGmdZ2TVU7S2DR0w9puuxiQ3dmFVILzZaR/0z0iklsTVi7gNUxpok/3SoknZgw 1HNGXdgx3Jc2rz5ThJFKjBhP+S3e/rTKummAFl0g= 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.10 163/299] selftests/resctrl: Fix incorrect parsing of iMC counters Date: Mon, 10 May 2021 12:19:20 +0200 Message-Id: <20210510102010.340979798@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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