Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit bb9bb45

Browse files
KAGA-KOKOPeter Zijlstra
authored andcommitted
perf/x86: Serialize set_attr_rdpmc()
Yue and Xingwei reported a jump label failure. It's caused by the lack of serialization in set_attr_rdpmc(): CPU0 CPU1 Assume: x86_pmu.attr_rdpmc == 0 if (val != x86_pmu.attr_rdpmc) { if (val == 0) ... else if (x86_pmu.attr_rdpmc == 0) static_branch_dec(&rdpmc_never_available_key); if (val != x86_pmu.attr_rdpmc) { if (val == 0) ... else if (x86_pmu.attr_rdpmc == 0) FAIL, due to imbalance ---> static_branch_dec(&rdpmc_never_available_key); The reported BUG() is a consequence of the above and of another bug in the jump label core code. The core code needs a separate fix, but that cannot prevent the imbalance problem caused by set_attr_rdpmc(). Prevent this by serializing set_attr_rdpmc() locally. Fixes: a667342 ("perf/x86: Add /sys/devices/cpu/rdpmc=2 to allow rdpmc for all tasks") Closes: https://lore.kernel.org/r/CAEkJfYNzfW1vG=ZTMdz_Weoo=RXY1NDunbxnDaLyj8R4kEoE_w@mail.gmail.com Reported-by: Yue Sun <samsun1006219@gmail.com> Reported-by: Xingwei Lee <xrivendell7@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20240610124406.359476013@linutronix.de
1 parent c80c449 commit bb9bb45

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

arch/x86/events/core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,7 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
25472547
struct device_attribute *attr,
25482548
const char *buf, size_t count)
25492549
{
2550+
static DEFINE_MUTEX(rdpmc_mutex);
25502551
unsigned long val;
25512552
ssize_t ret;
25522553

@@ -2560,6 +2561,8 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
25602561
if (x86_pmu.attr_rdpmc_broken)
25612562
return -ENOTSUPP;
25622563

2564+
guard(mutex)(&rdpmc_mutex);
2565+
25632566
if (val != x86_pmu.attr_rdpmc) {
25642567
/*
25652568
* Changing into or out of never available or always available,

0 commit comments

Comments
 (0)