mainline inclusion from mainline-v6.11-rc1 commit bb9bb45f746b0f9457de9c3fc4da143a6351bdc9 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IASLM9
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
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: a66734297f78 ("perf/x86: Add /sys/devices/cpu/rdpmc=2 to allow rdpmc for all tasks") Closes: https://lore.kernel.org/r/CAEkJfYNzfW1vG=ZTMdz_Weoo=RXY1NDunbxnDaLyj8R4kEoE_... 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 Conflicts: arch/x86/events/core.c [Using mutex_lock/mutex_unlock instead of guard] Signed-off-by: Luo Gengkun luogengkun2@huawei.com --- arch/x86/events/core.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index a8e97f717669..fec9f1d62c8f 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2235,6 +2235,7 @@ static ssize_t set_attr_rdpmc(struct device *cdev, struct device_attribute *attr, const char *buf, size_t count) { + static DEFINE_MUTEX(rdpmc_mutex); unsigned long val; ssize_t ret;
@@ -2248,6 +2249,8 @@ static ssize_t set_attr_rdpmc(struct device *cdev, if (x86_pmu.attr_rdpmc_broken) return -ENOTSUPP;
+ mutex_lock(&rdpmc_mutex); + if ((val == 2) != (x86_pmu.attr_rdpmc == 2)) { /* * Changing into or out of always available, aka @@ -2263,6 +2266,8 @@ static ssize_t set_attr_rdpmc(struct device *cdev,
x86_pmu.attr_rdpmc = val;
+ mutex_unlock(&rdpmc_mutex); + return count; }
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/11785 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/N...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/11785 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/N...