]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.19-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Mar 2024 13:08:11 +0000 (14:08 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Mar 2024 13:08:11 +0000 (14:08 +0100)
added patches:
perf-core-fix-reentry-problem-in-perf_output_read_group.patch

queue-4.19/perf-core-fix-reentry-problem-in-perf_output_read_group.patch [new file with mode: 0644]
queue-4.19/series

diff --git a/queue-4.19/perf-core-fix-reentry-problem-in-perf_output_read_group.patch b/queue-4.19/perf-core-fix-reentry-problem-in-perf_output_read_group.patch
new file mode 100644 (file)
index 0000000..dc8e492
--- /dev/null
@@ -0,0 +1,80 @@
+From 6b959ba22d34ca793ffdb15b5715457c78e38b1a Mon Sep 17 00:00:00 2001
+From: Yang Jihong <yangjihong1@huawei.com>
+Date: Fri, 2 Sep 2022 16:29:18 +0800
+Subject: perf/core: Fix reentry problem in perf_output_read_group()
+
+From: Yang Jihong <yangjihong1@huawei.com>
+
+commit 6b959ba22d34ca793ffdb15b5715457c78e38b1a upstream.
+
+perf_output_read_group may respond to IPI request of other cores and invoke
+__perf_install_in_context function. As a result, hwc configuration is modified.
+causing inconsistency and unexpected consequences.
+
+Interrupts are not disabled when perf_output_read_group reads PMU counter.
+In this case, IPI request may be received from other cores.
+As a result, PMU configuration is modified and an error occurs when
+reading PMU counter:
+
+                    CPU0                                         CPU1
+                                                     __se_sys_perf_event_open
+                                                       perf_install_in_context
+  perf_output_read_group                                  smp_call_function_single
+    for_each_sibling_event(sub, leader) {                   generic_exec_single
+      if ((sub != event) &&                                   remote_function
+         (sub->state == PERF_EVENT_STATE_ACTIVE))                    |
+  <enter IPI handler: __perf_install_in_context>   <----RAISE IPI-----+
+  __perf_install_in_context
+    ctx_resched
+      event_sched_out
+       armpmu_del
+         ...
+         hwc->idx = -1; // event->hwc.idx is set to -1
+  ...
+  <exit IPI>
+             sub->pmu->read(sub);
+               armpmu_read
+                 armv8pmu_read_counter
+                   armv8pmu_read_hw_counter
+                     int idx = event->hw.idx; // idx = -1
+                     u64 val = armv8pmu_read_evcntr(idx);
+                       u32 counter = ARMV8_IDX_TO_COUNTER(idx); // invalid counter = 30
+                       read_pmevcntrn(counter) // undefined instruction
+
+Signed-off-by: Yang Jihong <yangjihong1@huawei.com>
+Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
+Link: https://lkml.kernel.org/r/20220902082918.179248-1-yangjihong1@huawei.com
+Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/events/core.c |    9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+--- a/kernel/events/core.c
++++ b/kernel/events/core.c
+@@ -6253,9 +6253,16 @@ static void perf_output_read_group(struc
+ {
+       struct perf_event *leader = event->group_leader, *sub;
+       u64 read_format = event->attr.read_format;
++      unsigned long flags;
+       u64 values[6];
+       int n = 0;
++      /*
++       * Disabling interrupts avoids all counter scheduling
++       * (context switches, timer based rotation and IPIs).
++       */
++      local_irq_save(flags);
++
+       values[n++] = 1 + leader->nr_siblings;
+       if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+@@ -6291,6 +6298,8 @@ static void perf_output_read_group(struc
+               __output_copy(handle, values, n * sizeof(u64));
+       }
++
++      local_irq_restore(flags);
+ }
+ #define PERF_FORMAT_TOTAL_TIMES (PERF_FORMAT_TOTAL_TIME_ENABLED|\
index 26fcd12db7b6be367e65562104e138118e13cfcb..001c8f60dc1778987dd13b1cf5ff5ef6ae2a352b 100644 (file)
@@ -85,6 +85,7 @@ loop-remove-sector_t-truncation-checks.patch
 loop-factor-out-setting-loop-device-size.patch
 loop-refactor-loop_set_status-size-calculation.patch
 loop-properly-observe-rotational-flag-of-underlying-device.patch
+perf-core-fix-reentry-problem-in-perf_output_read_group.patch
 loop-factor-out-configuring-loop-from-status.patch
 loop-check-for-overflow-while-configuring-loop.patch
 loop-loop_set_status_from_info-check-before-assignment.patch