Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2567680lkm; Mon, 20 Sep 2021 18:55:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNZtXbnPA6agdQv7lSemBGHX2wligucvOeVtqoUCadkLmzvxeCOkl3Ik+mk7LCONUESkiV X-Received: by 2002:a05:6e02:1a28:: with SMTP id g8mr20789383ile.158.1632188924633; Mon, 20 Sep 2021 18:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188924; cv=none; d=google.com; s=arc-20160816; b=0Tqab4HyzSQ1kv7QNfP4PApt8amgDWXdqhrPTvfvwj+dfaGsjbbhscF1sFP2cy31FH eIiyrPBI1nK4cQZNeB+RWJP6zJU0L+m9QTn0u20Nza/gxAycrMsy0PzL3jGcFGLmJF76 b4hFeJu7Nwlho3muKPyVVTZgLT2QTcHhblKYXsd3uIcEk7RVcTqo3U7MQue9pYN6mka8 /e3qzi2UF0xAs0h4HZi4lymov7TpYQGmOq9Q8nIi4oo6sITeiEXxBG/a7dQMsVgt8ITp 7rvFBrdX4dQ9O9u4pyXu5YT+nFvDHbmX0xolzexh0Da7f/Bl1vmv+v5wtE5gHH24lZ/V kq2g== 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=1EaFVKEWuHDblo05pcq+qMm/CwG270zy4nnp9AjSWsQ=; b=UO8S5kP8Q1Ka0k80XXjGqLRYKaXiovbvm3+ShVGl08dniI3kSA8IUcOHn2dEnf2/kg 6KYzfsjIgo5Y+Kc8LGUJpmggqh69g8oEifV+QU1GKsQV1ZV9hmQpniBtnIz6XcJVOuPx pvnl8JXJHWC/CLcOKL+yt7vdcpMraTn014igpmJXOYf5Bxx3/vEhQQ0FQY3GkBHsorhk uRz/9KIx/FKH/QP17uYUafh0YaE6FMr1/zeUNwDKAiU1vrcAbukrLmktwV9eUe+JrcB5 iFm0D7V56hLfqYLJEARaOCVe0k6O/AZ2BuMM3uKLht1uKl7STVimdXe/ngMJ4pTV5RRS Mygg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SQVJz92s; 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 u5si2182012ilv.63.2021.09.20.18.48.33; Mon, 20 Sep 2021 18:48:44 -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=SQVJz92s; 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 S1353211AbhITRoK (ORCPT + 99 others); Mon, 20 Sep 2021 13:44:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:46840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352592AbhITRmK (ORCPT ); Mon, 20 Sep 2021 13:42:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E4C361B51; Mon, 20 Sep 2021 17:08:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632157726; bh=Ot/FDJFtnw+pBdIG0OnEiwayk1++YKhfnNyyQLhvyLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SQVJz92ssnJ5OZE4ySSALeK8lNmx8AIzcPLF5poXJDAgAzTJX1gOrCJO8JlTVqyCm 51W0XoCXsUi0AZzCdOOl+/ME2uW5MNHAJcN+GOxqA6SLdEWVPxHntZtZNsp0+fwvvK I1AYanCWGG8dqrV7gFmGGOgvP3sRkuPWbnYvwMBY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nageswara R Sastry , Kajol Jain , Michael Ellerman Subject: [PATCH 4.19 123/293] powerpc/perf/hv-gpci: Fix counter value parsing Date: Mon, 20 Sep 2021 18:41:25 +0200 Message-Id: <20210920163937.473366191@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@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: Kajol Jain commit f9addd85fbfacf0d155e83dbee8696d6df5ed0c7 upstream. H_GetPerformanceCounterInfo (0xF080) hcall returns the counter data in the result buffer. Result buffer has specific format defined in the PAPR specification. One of the fields is counter offset and width of the counter data returned. Counter data are returned in a unsigned char array in big endian byte order. To get the final counter data, the values must be left shifted byte at a time. But commit 220a0c609ad17 ("powerpc/perf: Add support for the hv gpci (get performance counter info) interface") made the shifting bitwise and also assumed little endian order. Because of that, hcall counters values are reported incorrectly. In particular this can lead to counters go backwards which messes up the counter prev vs now calculation and leads to huge counter value reporting: #: perf stat -e hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ -C 0 -I 1000 time counts unit events 1.000078854 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 2.000213293 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 3.000320107 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 4.000428392 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 5.000537864 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 6.000649087 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 7.000760312 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 8.000865218 16,448 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 9.000978985 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 10.001088891 16,384 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 11.001201435 0 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ 12.001307937 18,446,744,073,709,535,232 hv_gpci/system_tlbie_count_and_time_tlbie_instructions_issued/ Fix the shifting logic to correct match the format, ie. read bytes in big endian order. Fixes: e4f226b1580b ("powerpc/perf/hv-gpci: Increase request buffer size") Cc: stable@vger.kernel.org # v4.6+ Reported-by: Nageswara R Sastry Signed-off-by: Kajol Jain Tested-by: Nageswara R Sastry Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210813082158.429023-1-kjain@linux.ibm.com Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/perf/hv-gpci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/powerpc/perf/hv-gpci.c +++ b/arch/powerpc/perf/hv-gpci.c @@ -168,7 +168,7 @@ static unsigned long single_gpci_request */ count = 0; for (i = offset; i < offset + length; i++) - count |= arg->bytes[i] << (i - offset); + count |= (u64)(arg->bytes[i]) << ((length - 1 - (i - offset)) * 8); *value = count; out: