Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp825993pxb; Tue, 3 Nov 2020 13:38:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxs25B5/5h5xDtp2ZBlHp88ULba2nsnP4+zcTenVFXKGpkVifNIZC0fKLaBqeVzl3QmavIb X-Received: by 2002:a50:bb25:: with SMTP id y34mr23133990ede.249.1604439498453; Tue, 03 Nov 2020 13:38:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439498; cv=none; d=google.com; s=arc-20160816; b=EonH+cZ3qYm4t3RD6/jgIKIdVlSO8uzFGNEEEEfsC13QkGzuRqfIb0+zGUPA0lu4UE mbRbUhUuQsNPVB53QfyPpt+aK/8pe+wbAkYFdRa3iuWocaOtOcXvgk57lInQQB18y7BZ VtwQmk/R+eHQ/l/utMMCsJ24FZ7Ku1P1eaZBWOsFxGz+XFD2/NooxGVD6VxIWA1oIXV/ SrkchULMXor4kYbbrqMRDnFBn2cMXuJfdMq2EqHPwZHQZBuJYsxDldEgFGjAM6sXLqbZ ZFuaWFGOm6d7sWVM5Y1YvQvkeXvVBJzKpUW39TOS0/9BWai+gc3/jtFnWl90FUIoiCBO 8FTg== 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=tTjjzwZiWS2q5tTmt+1LnD0LFHJqLuXhSn9PMteHZoU=; b=Uoh+zySOO+yR0aa4KbcvLNgInhJCHQqlYNE3QD+rfNov8N+0IFc8s0mhGSvXZMzk7F ZLpGUQU0vrI3HZ762pO/3sHvZmsIziuqoGAWbJ8yODDAKP5eKBnDfnu+YJfYeuMEt/j1 O2xKs/FoUHx/pqN/ekJYQGCdTIzS9M2Mj7Fpz8zlEaNM8p2h7IPQrqrFXzuCO91SBFAZ 9nTZUCnfTfDGCcOxi7uJE723yFLJBcFjwaBgW3edVTfh9En1CDcb5ULWelFio9lX3LiY Yxb2gtltg6plOuF1ZIwJcLFOzNfsTBk8ayXcXtAXLVpm0n2LleZ/dlCz+zP6Ig6hyk2U OE6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tWg0sLoD; 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 y98si9711211ede.197.2020.11.03.13.37.55; Tue, 03 Nov 2020 13:38:18 -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=tWg0sLoD; 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 S1733037AbgKCVeR (ORCPT + 99 others); Tue, 3 Nov 2020 16:34:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:58628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732252AbgKCU4k (ORCPT ); Tue, 3 Nov 2020 15:56:40 -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 C4E0820732; Tue, 3 Nov 2020 20:56:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437000; bh=md9wSusj+UYDdkbmuUuq3AZ/paY7fC3MwE3iDZlR9iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tWg0sLoDWfhAL7xDQfo9eD6/5QY5H92dW7qehbraRJDPWP1tW1RNEjXHKJDfeTxKZ DMFq1LG0WRpTi0q1iQ49suN/YcOexndF2KzVimBwGk8GMY+O8//qbI5QXCVfNs5AdC Cw6fBktuV/qSSWNp4n3/RwzFtUYm4MUGEv88s9Po= 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 5.4 102/214] perf/x86/amd/ibs: Dont include randomized bits in get_ibs_op_count() Date: Tue, 3 Nov 2020 21:35:50 +0100 Message-Id: <20201103203300.110510920@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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 @@ -335,11 +335,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; }