Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4479692ivc; Tue, 3 Nov 2020 13:07:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCFaEuDJjdS6XZ2xnESkvJN/tqBUY54rwWZgGwkuKfii+0f6Q4tPtz/r+FWuHdvNDjbfRh X-Received: by 2002:a17:906:31cb:: with SMTP id f11mr21665018ejf.142.1604437635666; Tue, 03 Nov 2020 13:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437635; cv=none; d=google.com; s=arc-20160816; b=osmzMJeaCbnCTluvvi7quS1bAwhD1vuKY81GTGr3QwFBaL7rTQ/UKaAnXHeON5vkBT 2tvOPV2jlVs6jiQsAZ94rZy+CLWBOOqtioyqsCF51ZqV7RrSxFAfBZw8kaJfFTP2plyy 0KNL9OM7qJO+LS0jxFL9ljglqorUNR2rtY2p/6ibgI+G+OiByWySPCcqKIdVOGVl/SaR TNuFGfleueaWxbnfTmrlzq1W2d2Fg5S2c1eKYeN59oCzZ2gP9uQVja+51ghJw5AKQ8io h+zBPNFnNv3bJV92X5opHF1dxGmqEc/K9+OhF2PagPI+q370AMdPFEro26TkDdc9s81a h88Q== 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=9qsenJvu9f9eHJisx8dBud/6zYuNoaGHTODf3/xe8ZI=; b=KG433SV2vSGx7lbABi8jx6+m0j8D5qwcI+/WpHegK9aIcRQUro2qS1cSmHVuHg0FlV SvUL5XohTGVs6dhhzP5ekuJHThbEhqTzugxQBYAjMhE5F41feMiuzny1Zzoee/xGfY6u Q6MGIqhJXBWdN6N+k/qw0hzoCXE8Her9fOcka0jydbJ8xPe6QMpFiSm6ggjKuBGiuKBs AHTkeXLQ7fU4pwvWEnVJST88do8R2cusJEart/iEdrbSXY92RQxKv/jA1VZG5cT7/HZT qs4xMSFNwthUgrPFq+YRzqaGo8vWuZEimQctaoLRhvjCD4bR90I7XdBtrK7fz+Bum6kK ZyHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JoKUof71; 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 g18si6156872edh.40.2020.11.03.13.06.51; Tue, 03 Nov 2020 13:07:15 -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=JoKUof71; 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 S2387451AbgKCVFe (ORCPT + 99 others); Tue, 3 Nov 2020 16:05:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:43946 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387735AbgKCVF0 (ORCPT ); Tue, 3 Nov 2020 16:05:26 -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 BA87F205ED; Tue, 3 Nov 2020 21:05:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437526; bh=5E6Ms5SfmAhlWvxTxvU+REQ6RjzNmk5P07PNfAQXR/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JoKUof71QkzIhQn5K/Qe/2VnRCrJ1yGaYLYKEWLWZeaWc+kQlOODM56PJG7V2F2yn e31c4jXUuqyKHXS1kujDbXlqSikBPxYxeQ3y6cxsfCn4oW/1sMoAinYaA9bKseF4t2 8dpEuZ0OQUabZ6x7Nag7WsZLDKvJMCm4OKOaLdns= 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.19 114/191] perf/x86/amd/ibs: Dont include randomized bits in get_ibs_op_count() Date: Tue, 3 Nov 2020 21:36:46 +0100 Message-Id: <20201103203244.086262036@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 @@ -347,11 +347,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; }