Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1667685pxb; Thu, 16 Sep 2021 12:28:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymkprUEWYD1Urv8BWtuQclh3OSxXVpohQWdon8RrSb7xaKOELDqWDmIcF1j6Dcy20aAg3i X-Received: by 2002:a17:906:50d:: with SMTP id j13mr8217989eja.58.1631820520464; Thu, 16 Sep 2021 12:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631820520; cv=none; d=google.com; s=arc-20160816; b=Sk4Q5RRhCqReDBEbp6gc99He+461iyDL/opWuhjPAn7kMnxNzKhlLckkVrvsDhc9UK /8GVvs0alOp0kg1Kr/RvZHS1i0E9lJgIrN8rFUJxbQeKXF64xvjdKY2J51jogpExGz8k 0+btO/CULh8CUxlqpPGqb/rIgI8nMxK2E54LPHuBRltcWRurxDJzp4kZsN/MLFZC35WD Aep3iEP8FTU6lTRap5zxFqSJue4Z9zt9Fj8G2Vu0y/n/c2KuPjgnYkpZjScaAy7aGejm y0DtC015ad19N8+rHX/66P1CflqUC/vvY7pWx9rturhlY7/WpV06v5PttMu/FbSWFBlq JDhA== 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=woTLdq8l93HW/HjmhSR4+gRXBN3eBIgvca+80DET2IE=; b=gd1YvWT1DkLYDRvCtxfCGnfJT1tAbznQaBJFC58yrK5ZLRxCuWHYxGlUbKO7DY7kPc wgDZjLtmjoF2p5AjttWh6Cm/2KscDIpKXaGB1ACP2iqu9nU3MzqzD3BWaoC1ZMMtFkpw i8KiPcPrn2YQ4wYSjz/4wsgn/W95n8chk2DgKCVDkKF64AdPydhvcg41zE6oMi8/s9aP B6Nk5kf/7G8IqdWNJoXR75mG0nlCvYSY0vItYQrspM+9QtDXjRRaQvikhVFMwtL4KpX7 z1/9T8cUVRLdQEotFJJcd9BPwgro5KVN9asFbqf81IRbnyfOtHWL2CvMNrASBhc7DNjL kGqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bZmqZeau; 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 dn20si4044079edb.294.2021.09.16.12.28.15; Thu, 16 Sep 2021 12:28:40 -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=bZmqZeau; 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 S240521AbhIPQFX (ORCPT + 99 others); Thu, 16 Sep 2021 12:05:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:44394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240518AbhIPQFR (ORCPT ); Thu, 16 Sep 2021 12:05:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 179A060232; Thu, 16 Sep 2021 16:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808236; bh=ObqOYrgdwAJO8POxMzYgQTUoEN6o0v/uM2wFd+WSdug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZmqZeauKUONLcc5o8X8xpj6bLqLJUMYJmA0HhanbFsYYjJMjzRmt1pH2cIjV2VwW xJ6AjwbI4Ug7xg7ukTLDqpLZxegZOGpNBmkAW9/fvPk5dYXX9dd1DrSPmWsX4NI/AJ vWyt/ScC+QEnGPEoYzTRIzge/un3cYIwad4foSm0= 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 5.10 012/306] powerpc/perf/hv-gpci: Fix counter value parsing Date: Thu, 16 Sep 2021 17:55:57 +0200 Message-Id: <20210916155754.337715370@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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 @@ -175,7 +175,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: