Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3212198pxb; Mon, 9 Nov 2020 05:43:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4nRD5r/LVBcEmkybzYPqgNRvVdBByhNYB0KDs8THPIcRi9ljkNM9PXVjefiFdZhB5hwoR X-Received: by 2002:a17:906:c18c:: with SMTP id g12mr14862173ejz.334.1604929426271; Mon, 09 Nov 2020 05:43:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929426; cv=none; d=google.com; s=arc-20160816; b=pF9xBpN+7agElLkpS6S/MymmQqbVkoMFaSbF+Qh/gNxJvGAOBUpwOD7jBU/TSlJaIc O3ijs/02Ytlu4ksR2qqce3SM7SVmcBy+MGpwpaM9S8qKK91sJdhgaf0kPOA4eBJEeVPM Cfn26a42NRNeZ48R1CbiAM8LePsQ68tK2s/0I68qpCrmaQQL1zH0BQQsb9+rWEbTyIup ghzmxB5y5uFbqFJK/7fb70NqMXFc/TXqlauYlb4BFq9c3ZL36vMPaKxT8CexqoMGsqQd IN7ddwAmtNGeOAcjjDs72P5vs8gLz7cBEoXG/D4df7oDhOGE2hr2SdYCMW8zrWrmaxC4 tlAQ== 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=tztX2UPTA62qO66qlbHw0WK8SXT3H8QNkxx7rCXSw7Q=; b=x/5Vb+aLlERRhUoK0fus05j/mm7cdx2pXzm+3KJHnei6+ctZrUb5EOho4hvFNnTC0G lJyul5Z++AN5qWptMMk426okzgF9eLoXKQ6ATKtLYANZfdiwZt5cWsGZJDIHI5j1pxOi S4AUq185/zu/L04kSQEBhE4yNHI8fgqYpKGiidWAYmwQN63ofcYxoMVUhMSv86x/7QsA 0mB5syOkjpL5SNff7heupZSWc7YmcCfCokFwNwoBpAZVnAsGeaiFwGGQwmermx711I55 3SRCCRk1YlDY8ggZDwUuK6NgjL11rRuZfr0fR+DTOYQ34jw1GgJtfuyPJ5ogRDFuyn4b gMFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ppjwjgzw; 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=fail (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 y1si6702881edp.57.2020.11.09.05.43.23; Mon, 09 Nov 2020 05:43:46 -0800 (PST) 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=@kernel.org header.s=default header.b=Ppjwjgzw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387970AbgKINkI (ORCPT + 99 others); Mon, 9 Nov 2020 08:40:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:56084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730634AbgKINCN (ORCPT ); Mon, 9 Nov 2020 08:02:13 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AED7620684; Mon, 9 Nov 2020 13:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926932; bh=fI+5mHMrsyBSYeS0TcfDWgCZOtJe5ty/pw3ywc610SY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ppjwjgzw2qXwhKMxbbG6krVDfFCCRFZ0/S8lCh+cp1W/w0WN/s0D8h9bFkPVdXSCR C5CyNsxtDbign6CcI18AWjhIi0/L/5agZL+qOl52Khq6EsqDl6ubFm5zIDSu8uyiPY XlxpELXBSZwoYrQMIQdd+S67rIVNRb6Kp7aV0nrw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kim Phillips , "Peter Zijlstra (Intel)" Subject: [PATCH 4.9 046/117] perf/x86/amd/ibs: Dont include randomized bits in get_ibs_op_count() Date: Mon, 9 Nov 2020 13:54:32 +0100 Message-Id: <20201109125027.851885740@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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: Kim Phillips commit 680d69635005ba0e58fe3f4c52fc162b8fc743b0 upstream. get_ibs_op_count() adds hardware's current count (IbsOpCurCnt) bits to its count regardless of hardware's valid status. According to the PPR for AMD Family 17h Model 31h B0 55803 Rev 0.54, if the counter rolls over, valid status is set, and the lower 7 bits of IbsOpCurCnt are randomized by hardware. Don't include those bits in the driver's event count. Fixes: 8b1e13638d46 ("perf/x86-ibs: Fix usage of IBS op current count") Signed-off-by: Kim Phillips Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://bugzilla.kernel.org/show_bug.cgi?id=206537 Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/ibs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -346,11 +346,15 @@ static u64 get_ibs_op_count(u64 config) { u64 count = 0; + /* + * If the internal 27-bit counter rolled over, the count is MaxCnt + * and the lower 7 bits of CurCnt are randomized. + * Otherwise CurCnt has the full 27-bit current counter value. + */ if (config & IBS_OP_VAL) - count += (config & IBS_OP_MAX_CNT) << 4; /* cnt rolled over */ - - if (ibs_caps & IBS_CAPS_RDWROPCNT) - count += (config & IBS_OP_CUR_CNT) >> 32; + count = (config & IBS_OP_MAX_CNT) << 4; + else if (ibs_caps & IBS_CAPS_RDWROPCNT) + count = (config & IBS_OP_CUR_CNT) >> 32; return count; }