Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2565921lkm; Mon, 20 Sep 2021 18:52:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyuksM8BvmzXqFgkYil4v9me6okdgS7gd0fJ/xvfkemLZXAqz5oNt6+Ub3J+m6ufsKP3L+ X-Received: by 2002:a05:6638:35a9:: with SMTP id v41mr21816166jal.98.1632189025649; Mon, 20 Sep 2021 18:50:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189025; cv=none; d=google.com; s=arc-20160816; b=bDMUllJkzh5Dba7yVJQLJutZRSv6+vQGM5NcNF1358ggxJ9Nn7wG01OtfIi/Sfj3mN yeIYcU1l8tgJlCvCd6nnKs99wYY8hsHv4jEhbfHohY30j7YEGISU+lUl1tfuYq/3nIlA krNtntp7uTXFSP7RQQyk2jVAf7P+X5p027iOdrFEVAK31twiRHlPNcayRkC+NQmGlOCK qUJ4fI5YITfWsSLvDNgoOj4Ct+zAfQZhB5kSBIQdRs6mtww6+11na+XItvHdbebFsHmp 85aeG2YH3okUHLvskk0FFF+dCDWiwdS39dSEWU01UxXbpZJwrR20Rir7uVdm4E0TrFqC omrA== 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=z/ZzggHH9PnbAI2HwIlNtZ45dLvzs/Wmn7KZJXVfEm4=; b=kjF5XMo+JcqJuNYVfmWdxJgLXuY3HbtggpLVz3/Svv/dMMOMAsvo/SXvmvcg6hmiAv ktyvd9nyApc98jms7XfQZ4dO2AWsMIl2i6qpqB7yN00nnZqvXcYpzkZKrjbaBng5uq+2 63o67r3hCn/juBf0fB/aQsmi/SJ9H3ITdKxbbqlcNyyQQpUZDG+2bKmaVuRB6ihC/vGR VCm52bgBH8xp0O04PI2aJ07NmFy38dyZx6hpI3mPIizzhHco4FQk71rxGlt1d8RGb0jG o5y/c/Keop7dPVyxFGhKptWzkSGA2OITXY0TfHIVtUYOv3Els097v3YrgY1dg34+jukb bIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uqKmfb+r; 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 n3si14237065ilj.23.2021.09.20.18.50.14; Mon, 20 Sep 2021 18:50:25 -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=uqKmfb+r; 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 S1358152AbhITSF3 (ORCPT + 99 others); Mon, 20 Sep 2021 14:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:56114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356422AbhITR7y (ORCPT ); Mon, 20 Sep 2021 13:59:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0BC316321C; Mon, 20 Sep 2021 17:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158132; bh=5IvgFW1Cp8AsNIKfVG3uMFoY+f3pzFo6PLa8CtvqLC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uqKmfb+rfoW5JLfqfZ6YcYliw6+1AeoYsOGkgBY2FXg6aqcI83Bm/JzSfq5trKbAV BsZLzjX6/BaUYHEC+ksCShJaoIJEwlN8EEeTKMUK0qkrKPhHUqKivf4wMaMZYqcMgd UQzwTaQhR9gQJY/fvJgkHALi+KLfNxrwjGLv0i+Y= 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.4 007/260] powerpc/perf/hv-gpci: Fix counter value parsing Date: Mon, 20 Sep 2021 18:40:25 +0200 Message-Id: <20210920163931.381780981@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@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 @@ -164,7 +164,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: