|
Takashi Iwai |
b63f23 |
From d79cb9f57f5713c100e6ff1b6e94292ebbc41b2d Mon Sep 17 00:00:00 2001
|
|
Takashi Iwai |
b63f23 |
From: Kajol Jain <kjain@linux.ibm.com>
|
|
Takashi Iwai |
b63f23 |
Date: Fri, 13 Aug 2021 13:51:58 +0530
|
|
Takashi Iwai |
b63f23 |
Subject: [PATCH] powerpc/perf/hv-gpci: Fix counter value parsing
|
|
Takashi Iwai |
b63f23 |
Git-commit: f9addd85fbfacf0d155e83dbee8696d6df5ed0c7
|
|
Takashi Iwai |
b63f23 |
Patch-mainline: v5.15-rc1
|
|
Takashi Iwai |
b63f23 |
References: stable-5.14.6
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
commit f9addd85fbfacf0d155e83dbee8696d6df5ed0c7 upstream.
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
H_GetPerformanceCounterInfo (0xF080) hcall returns the counter data in
|
|
Takashi Iwai |
b63f23 |
the result buffer. Result buffer has specific format defined in the PAPR
|
|
Takashi Iwai |
b63f23 |
specification. One of the fields is counter offset and width of the
|
|
Takashi Iwai |
b63f23 |
counter data returned.
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
Counter data are returned in a unsigned char array in big endian byte
|
|
Takashi Iwai |
b63f23 |
order. To get the final counter data, the values must be left shifted
|
|
Takashi Iwai |
b63f23 |
byte at a time. But commit 220a0c609ad17 ("powerpc/perf: Add support for
|
|
Takashi Iwai |
b63f23 |
the hv gpci (get performance counter info) interface") made the shifting
|
|
Takashi Iwai |
b63f23 |
bitwise and also assumed little endian order. Because of that, hcall
|
|
Takashi Iwai |
b63f23 |
counters values are reported incorrectly.
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
In particular this can lead to counters go backwards which messes up the
|
|
Takashi Iwai |
b63f23 |
counter prev vs now calculation and leads to huge counter value
|
|
Takashi Iwai |
b63f23 |
Reporting:
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
#: perf stat -e hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
-C 0 -I 1000
|
|
Takashi Iwai |
b63f23 |
time counts unit events
|
|
Takashi Iwai |
b63f23 |
1.000078854 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
2.000213293 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
3.000320107 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
4.000428392 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
5.000537864 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
6.000649087 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
7.000760312 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
8.000865218 16,448 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
9.000978985 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
10.001088891 16,384 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
11.001201435 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
12.001307937 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
Fix the shifting logic to correct match the format, ie. read bytes in
|
|
Takashi Iwai |
b63f23 |
big endian order.
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
Fixes: e4f226b1580b ("powerpc/perf/hv-gpci: Increase request buffer size")
|
|
Takashi Iwai |
b63f23 |
Cc: stable@vger.kernel.org # v4.6+
|
|
Takashi Iwai |
b63f23 |
Reported-by: Nageswara R Sastry<rnsastry@linux.ibm.com>
|
|
Takashi Iwai |
b63f23 |
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
|
|
Takashi Iwai |
b63f23 |
Tested-by: Nageswara R Sastry<rnsastry@linux.ibm.com>
|
|
Takashi Iwai |
b63f23 |
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
|
|
Takashi Iwai |
b63f23 |
Link: https://lore.kernel.org/r/20210813082158.429023-1-kjain@linux.ibm.com
|
|
Takashi Iwai |
b63f23 |
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
|
|
Takashi Iwai |
b63f23 |
Acked-by: Takashi Iwai <tiwai@suse.de>
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
---
|
|
Takashi Iwai |
b63f23 |
arch/powerpc/perf/hv-gpci.c | 2 +-
|
|
Takashi Iwai |
b63f23 |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
|
|
Takashi Iwai |
b63f23 |
index d48413e28c39..c756228a081f 100644
|
|
Takashi Iwai |
b63f23 |
--- a/arch/powerpc/perf/hv-gpci.c
|
|
Takashi Iwai |
b63f23 |
+++ b/arch/powerpc/perf/hv-gpci.c
|
|
Takashi Iwai |
b63f23 |
@@ -175,7 +175,7 @@ static unsigned long single_gpci_request(u32 req, u32 starting_index,
|
|
Takashi Iwai |
b63f23 |
*/
|
|
Takashi Iwai |
b63f23 |
count = 0;
|
|
Takashi Iwai |
b63f23 |
for (i = offset; i < offset + length; i++)
|
|
Takashi Iwai |
b63f23 |
- count |= arg->bytes[i] << (i - offset);
|
|
Takashi Iwai |
b63f23 |
+ count |= (u64)(arg->bytes[i]) << ((length - 1 - (i - offset)) * 8);
|
|
Takashi Iwai |
b63f23 |
|
|
Takashi Iwai |
b63f23 |
*value = count;
|
|
Takashi Iwai |
b63f23 |
out:
|
|
Takashi Iwai |
b63f23 |
--
|
|
Takashi Iwai |
b63f23 |
2.26.2
|
|
Takashi Iwai |
b63f23 |
|