lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
 <GV1PR08MB105212F94288290E4DD6602DFFB682@GV1PR08MB10521.eurprd08.prod.outlook.com>
Date: Tue, 24 Sep 2024 07:13:31 +0000
From: Yeo Reum Yun <YeoReum.Yun@....com>
To: "rostedt@...dmis.org" <rostedt@...dmis.org>, "mhiramat@...nel.org"
	<mhiramat@...nel.org>, "mathieu.desnoyers@...icios.com"
	<mathieu.desnoyers@...icios.com>, "a.p.zijlstra@...llo.nl"
	<a.p.zijlstra@...llo.nl>, "mingo@...e.hu" <mingo@...e.hu>, Mark Rutland
	<Mark.Rutland@....com>, "james.clark@...aro.org" <james.clark@...aro.org>
CC: nd <nd@....com>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, "linux-trace-kernel@...r.kernel.org"
	<linux-trace-kernel@...r.kernel.org>
Subject: Re: [PATCH v2] trace/trace_event_perf: remove duplicate samples on
 the first tracepoint event

Gentle ping

________________________________________
From: Levi Yun <yeoreum.yun@....com>
Sent: 13 September 2024 03:13
To: rostedt@...dmis.org; mhiramat@...nel.org; mathieu.desnoyers@...icios.com; a.p.zijlstra@...llo.nl; mingo@...e.hu; Mark Rutland; james.clark@...aro.org
Cc: nd; linux-kernel@...r.kernel.org; linux-trace-kernel@...r.kernel.org; Yeo Reum Yun
Subject: [PATCH v2] trace/trace_event_perf: remove duplicate samples on the first tracepoint event

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

Fixes: bd2b5b12849a ("perf_counter: More aggressive frequency adjustment")
Signed-off-by: Levi Yun <yeoreum.yun@....com>
---
Changes in v2:
  - Fix build error.
---
 kernel/trace/trace_event_perf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 05e791241812..3ff9caa4a71b 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -352,10 +352,16 @@ void perf_uprobe_destroy(struct perf_event *p_event)
 int perf_trace_add(struct perf_event *p_event, int flags)
 {
        struct trace_event_call *tp_event = p_event->tp_event;
+       struct hw_perf_event *hwc = &p_event->hw;

        if (!(flags & PERF_EF_START))
                p_event->hw.state = PERF_HES_STOPPED;

+       if (is_sampling_event(p_event)) {
+               hwc->last_period = hwc->sample_period;
+               perf_swevent_set_period(p_event);
+       }
+
        /*
         * If TRACE_REG_PERF_ADD returns false; no custom action was performed
         * and we need to take the default action of enqueueing our event on
--
LEVI:{C3F47F37-75D8-414A-A8BA-3980EC8A46D7}


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ