linux-stable/kernel
Levi Yun 9b6d18b6e8 trace/trace_event_perf: remove duplicate samples on the first tracepoint event
[ Upstream commit afe5960dc2 ]

When a tracepoint event is created with attr.freq = 1,
'hwc->period_left' is not initialized correctly. As a result,
in the perf_swevent_overflow() function, when the first time the event occurs,
it calculates the event overflow and the perf_swevent_set_period() returns 3,
this leads to the event are recorded for three duplicate times.

Step to reproduce:
    1. Enable the tracepoint event & starting tracing
         $ echo 1 > /sys/kernel/tracing/events/module/module_free
         $ echo 1 > /sys/kernel/tracing/tracing_on

    2. Record with perf
         $ perf record -a --strict-freq -F 1 -e "module:module_free"

    3. Trigger module_free event.
         $ modprobe -i sunrpc
         $ modprobe -r sunrpc

Result:
     - Trace pipe result:
         $ cat trace_pipe
         modprobe-174509  [003] .....  6504.868896: module_free: sunrpc

     - perf sample:
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc
         modprobe  174509 [003]  6504.868980: module:module_free: sunrpc

By setting period_left via perf_swevent_set_period() as other sw_event did,
This problem could be solved.

After patch:
     - Trace pipe result:
         $ cat trace_pipe
         modprobe 1153096 [068] 613468.867774: module:module_free: xfs

     - perf sample
         modprobe 1153096 [068] 613468.867794: module:module_free: xfs

Link: https://lore.kernel.org/20240913021347.595330-1-yeoreum.yun@arm.com
Fixes: bd2b5b1284 ("perf_counter: More aggressive frequency adjustment")
Signed-off-by: Levi Yun <yeoreum.yun@arm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-12-05 10:59:33 +01:00
..
bpf bpf: use kvzmalloc to allocate BPF verifier environment 2024-11-17 14:58:08 +01:00
cgroup cgroup: Fix potential overflow issue when checking max_depth 2024-11-08 16:19:22 +01:00
configs
debug kdb: Use the passed prompt in kdb_position_cursor() 2024-08-19 05:32:06 +02:00
dma dma: fix call order in dmam_free_coherent 2024-08-19 05:32:06 +02:00
events uprobes: fix kernel info leak via "[uprobes]" vma 2024-11-08 16:19:15 +01:00
gcov gcov: add support for GCC 14 2024-07-05 09:00:29 +02:00
irq genirq/cpuhotplug, x86/vector: Prevent vector leak during CPU offline 2024-06-16 13:23:38 +02:00
livepatch livepatch: fix race between fork and KLP transition 2022-10-26 13:19:23 +02:00
locking rtmutex: Drop rt_mutex::wait_lock before scheduling 2024-09-12 11:02:55 +02:00
power PM: suspend: Set mem_sleep_current during kernel command line setup 2024-04-13 12:50:04 +02:00
printk printk: Update @console_may_schedule in console_trylock_spinning() 2024-04-13 12:50:09 +02:00
rcu rcutorture: Fix rcu_torture_one_read() pipe_count overflow comment 2024-07-05 09:00:26 +02:00
sched sched/fair: Allow disabling sched_balance_newidle with sched_relax_domain_level 2024-06-16 13:23:32 +02:00
time time: Fix references to _msecs_to_jiffies() handling of values 2024-12-05 10:59:31 +01:00
trace trace/trace_event_perf: remove duplicate samples on the first tracepoint event 2024-12-05 10:59:33 +01:00
.gitignore
acct.c acct: fix potential integer overflow in encode_comp_t() 2023-01-18 11:30:34 +01:00
async.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
audit_fsnotify.c audit: fix potential double free on error path from fsnotify_add_inode_mark 2022-09-05 10:26:28 +02:00
audit_tree.c audit: Embed key into chunk 2019-12-13 08:51:11 +01:00
audit_watch.c audit: don't WARN_ON_ONCE(!current->mm) in audit_exe_compare() 2023-11-28 16:46:34 +00:00
audit.c audit: Send netlink ACK before setting connection in auditd_set 2024-02-23 08:12:44 +01:00
audit.h audit: fix a net reference leak in audit_list_rules_send() 2020-06-22 09:05:13 +02:00
auditfilter.c audit: fix a net reference leak in audit_list_rules_send() 2020-06-22 09:05:13 +02:00
auditsc.c audit: fix possible soft lockup in __audit_inode_child() 2023-09-23 10:48:04 +02:00
backtracetest.c
bounds.c
capability.c LSM: generalize flag passing to security_capable 2020-01-23 08:21:29 +01:00
compat.c sched_getaffinity: don't assume 'cpumask_size()' is fully initialized 2023-04-05 11:15:39 +02:00
configs.c
context_tracking.c
cpu_pm.c kernel/cpu_pm: Fix uninitted local in cpu_pm 2020-06-22 09:05:28 +02:00
cpu.c hrtimers: Push pending hrtimers away from outgoing CPU earlier 2023-12-13 17:42:15 +01:00
crash_core.c
crash_dump.c
cred.c cred: switch to using atomic_long_t 2023-12-20 15:38:01 +01:00
delayacct.c
dma.c
exec_domain.c
exit.c mm: optimize the redundant loop of mm_update_owner_next() 2024-07-18 11:39:35 +02:00
extable.c kernel/extable.c: use address-of operator on section symbols 2023-06-09 10:24:02 +02:00
fail_function.c fail_function: Remove a redundant mutex unlock 2020-11-24 13:27:23 +01:00
fork.c mm/hugetlb: initialize hugetlb_usage in mm_init 2021-09-22 11:48:09 +02:00
freezer.c
futex.c treewide: Remove uninitialized_var() usage 2023-08-11 11:45:01 +02:00
groups.c
hung_task.c kernel: hung_task.c: disable on suspend 2019-04-20 09:16:02 +02:00
iomem.c
irq_work.c irq_work: Do not raise an IPI when queueing work on the local CPU 2019-05-31 06:46:19 -07:00
jump_label.c locking/static_key: Fix false positive warnings on concurrent dec/inc 2021-03-04 09:39:30 +01:00
kallsyms.c kallsyms: Refactor kallsyms_show_value() to take cred 2020-07-16 08:17:26 +02:00
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
kcov.c kernel/kcov.c: mark write_comp_data() as notrace 2019-02-12 19:47:20 +01:00
kexec_core.c kexec: fix a memory leak in crash_shrink_memory() 2023-08-11 11:45:06 +02:00
kexec_file.c kexec: support purgatories with .text.hot sections 2023-06-21 15:39:57 +02:00
kexec_internal.h
kexec.c
kmod.c kmod: make request_module() return an error when autoloading is disabled 2020-04-17 10:48:52 +02:00
kprobes.c kprobes: Fix possible use-after-free issue on kprobe registration 2024-05-02 16:17:09 +02:00
ksysfs.c
kthread.c kthread: fix task state in kthread worker if being frozen 2024-11-08 16:19:06 +01:00
latencytop.c
Makefile elfcore: fix building with clang 2021-02-10 09:21:06 +01:00
memremap.c mm/memory_hotplug: shrink zones when offlining memory 2020-01-29 16:43:27 +01:00
module_signing.c
module-internal.h
module.c modules: only allow symbol_get of EXPORT_SYMBOL_GPL modules 2023-09-23 10:47:56 +02:00
notifier.c x86/mm: split vmalloc_sync_all() 2020-03-25 08:06:13 +01:00
nsproxy.c
padata.c crypto: pcrypt - Fix hungtask for PADATA_RESET 2023-11-28 16:46:31 +00:00
panic.c exit: Use READ_ONCE() for all oops/warn limit reads 2023-02-06 07:49:46 +01:00
params.c params: lift param_set_uint_minmax to common code 2024-06-16 13:23:35 +02:00
pid_namespace.c memcg: enable accounting for pids in nested pid namespaces 2021-09-22 11:48:09 +02:00
pid.c
profile.c profiling: fix shift too large makes kernel panic 2022-08-25 11:15:20 +02:00
ptrace.c ptrace: Reimplement PTRACE_KILL by always sending SIGKILL 2022-06-14 16:59:14 +02:00
range.c
reboot.c reboot: fix overflow parsing reboot cpu number 2020-11-18 19:18:52 +01:00
relay.c relayfs: fix out-of-bounds access in relay_file_read 2023-05-17 11:13:23 +02:00
resource.c resource: fix locking in find_next_iomem_res() 2019-09-16 08:22:20 +02:00
rseq.c
seccomp.c seccomp: Invalidate seccomp mode to catch death failures 2022-02-16 12:51:47 +01:00
signal.c signal: Replace BUG_ON()s 2024-11-08 16:19:12 +01:00
smp.c smp: Add missing destroy_work_on_stack() call in smp_call_on_cpu() 2024-09-12 11:02:53 +02:00
smpboot.c kthread: Extract KTHREAD_IS_PER_CPU 2021-02-07 14:48:38 +01:00
smpboot.h
softirq.c
stacktrace.c
stop_machine.c
sys_ni.c kernel/sys_ni: add compat entry for fadvise64_64 2022-09-05 10:26:28 +02:00
sys.c Revert "y2038: rusage: use __kernel_old_timeval" 2024-05-02 16:17:14 +02:00
sysctl_binary.c
sysctl.c sched/rt: Disallow writing invalid values to sched_rt_period_us 2024-03-01 13:06:08 +01:00
task_work.c
taskstats.c taskstats: fix data-race 2020-01-09 10:18:59 +01:00
test_kprobes.c
torture.c
tracepoint.c tracepoint: Add tracepoint_probe_register_may_exist() for BPF tracing 2021-07-20 16:15:42 +02:00
tsacct.c taskstats: Cleanup the use of task->exit_code 2022-02-23 11:58:39 +01:00
ucount.c
uid16.c
uid16.h
umh.c usermodehelper: reset umask to default before executing user process 2020-10-14 10:31:21 +02:00
up.c smp: Fix smp_call_function_single_async prototype 2021-05-22 10:59:39 +02:00
user_namespace.c
user-return-notifier.c
user.c
utsname_sysctl.c
utsname.c
watchdog_hld.c watchdog/perf: properly initialize the turbo mode timestamp and rearm counter 2024-08-19 05:32:05 +02:00
watchdog.c watchdog: export lockup_detector_reconfigure 2022-08-25 11:15:46 +02:00
workqueue_internal.h
workqueue.c workqueue: Override implicit ordered attribute in workqueue_apply_unbound_cpumask() 2023-10-25 11:16:26 +02:00