From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 469AD3B813A; Mon, 5 May 2025 23:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746487304; cv=none; b=epUKtYPDlWRsm+rteDPV2an7EvRFUWWIkI09N/m9pdH+n9DRaCzgbHLH41Td32tCr7X/gDf58Bxue39VTFcZZbNJ/SLQsWjxGMZMcCn04NPLHPi1DemFbgkelk48gN/SdJnbplBZmkbLrOX7493LUvh+YqPasZNIl4L1cDOyjdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746487304; c=relaxed/simple; bh=p0I0U5dP4JlKemWnWbWz6tunlWghl0QXhTgNYnJCC48=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s+3DFKApcgfZAGfRoj6OzH0Na6APU/IHOzICHBa0sSBd8I3OBoeqXzHlcoYuRLjUD0QA35cIf1GLbjDLhfIvc2WLBs4o/IhYqEVOQBgNAilXjEOi7AdzEREUArPNnZV/014jpYnNw4wz0EeJqLDNNiDfUaSMWnW2gx9L88RLrGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rjCpHplA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rjCpHplA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B56A7C4CEE4; Mon, 5 May 2025 23:21:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746487303; bh=p0I0U5dP4JlKemWnWbWz6tunlWghl0QXhTgNYnJCC48=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjCpHplAjSSoOlGVmdwDr9MQubJkJa2rPsN9Hc6I+VUveGTkYoRHQkt4O2fmhtvSh QUjBdmuX68C06bjWnO/kjIlfquBK+RXIQsZ0gcZlN9tuEPXQ1cmumw4DJ+nElE5EZq n9gcUYEOP4kFvV6zqwLvi8Eim6pVkQAKATzZHKa4O6xhjCEN1c4FMvzIGzwGXXhNFM B3jIct6VAPgg2Xu240op5NCYWQWwZKoWFv8GVBIQ4/6ch4NjOJHolQ8RtUHzQSEXfk hEGYFYdJ4QNnpr11YhK/X/qNJrICOgq2F7zQMYblXhlwElECo5ya3/0iUhVsZLMD0l kderuStW6oHog== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ravi Bangoria , Peter Zijlstra , Namhyung Kim , Sasha Levin , mingo@redhat.com, acme@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-perf-users@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 109/114] perf/amd/ibs: Fix perf_ibs_op.cnt_mask for CurCnt Date: Mon, 5 May 2025 19:18:12 -0400 Message-Id: <20250505231817.2697367-109-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250505231817.2697367-1-sashal@kernel.org> References: <20250505231817.2697367-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.237 Content-Transfer-Encoding: 8bit From: Ravi Bangoria [ Upstream commit 46dcf85566170d4528b842bf83ffc350d71771fa ] IBS Op uses two counters: MaxCnt and CurCnt. MaxCnt is programmed with the desired sample period. IBS hw generates sample when CurCnt reaches to MaxCnt. The size of these counter used to be 20 bits but later they were extended to 27 bits. The 7 bit extension is indicated by CPUID Fn8000_001B_EAX[6 / OpCntExt]. perf_ibs->cnt_mask variable contains bit masks for MaxCnt and CurCnt. But IBS driver does not set upper 7 bits of CurCnt in cnt_mask even when OpCntExt CPUID bit is set. Fix this. IBS driver uses cnt_mask[CurCnt] bits only while disabling an event. Fortunately, CurCnt bits are not read from MSR while re-enabling the event, instead MaxCnt is programmed with desired period and CurCnt is set to 0. Hence, we did not see any issues so far. Signed-off-by: Ravi Bangoria Signed-off-by: Peter Zijlstra (Intel) Acked-by: Namhyung Kim Link: https://lkml.kernel.org/r/20250115054438.1021-5-ravi.bangoria@amd.com Signed-off-by: Sasha Levin --- arch/x86/events/amd/ibs.c | 3 ++- arch/x86/include/asm/perf_event.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index 354d52e17ef55..8525b7960787c 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -808,7 +808,8 @@ static __init int perf_event_ibs_init(void) if (ibs_caps & IBS_CAPS_OPCNTEXT) { perf_ibs_op.max_period |= IBS_OP_MAX_CNT_EXT_MASK; perf_ibs_op.config_mask |= IBS_OP_MAX_CNT_EXT_MASK; - perf_ibs_op.cnt_mask |= IBS_OP_MAX_CNT_EXT_MASK; + perf_ibs_op.cnt_mask |= (IBS_OP_MAX_CNT_EXT_MASK | + IBS_OP_CUR_CNT_EXT_MASK); } ret = perf_ibs_pmu_init(&perf_ibs_op, "ibs_op"); diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h index a4e4bbb7795d3..63fc0f50cd38c 100644 --- a/arch/x86/include/asm/perf_event.h +++ b/arch/x86/include/asm/perf_event.h @@ -402,6 +402,7 @@ struct pebs_xmm { */ #define IBS_OP_CUR_CNT (0xFFF80ULL<<32) #define IBS_OP_CUR_CNT_RAND (0x0007FULL<<32) +#define IBS_OP_CUR_CNT_EXT_MASK (0x7FULL<<52) #define IBS_OP_CNT_CTL (1ULL<<19) #define IBS_OP_VAL (1ULL<<18) #define IBS_OP_ENABLE (1ULL<<17) -- 2.39.5