kernel_optimize_test/samples
Niklas Söderlund f9a6661009 samples/bpf, xdpsock: Fix race when running for fix duration of time
[ Upstream commit 8fa42d78f6354bb96ad3a079dcbef528ca9fa9e0 ]

When running xdpsock for a fix duration of time before terminating
using --duration=<n>, there is a race condition that may cause xdpsock
to terminate immediately.

When running for a fixed duration of time the check to determine when to
terminate execution is in is_benchmark_done() and is being executed in
the context of the poller thread,

    if (opt_duration > 0) {
            unsigned long dt = (get_nsecs() - start_time);

            if (dt >= opt_duration)
                    benchmark_done = true;
    }

However start_time is only set after the poller thread have been
created. This leaves a small window when the poller thread is starting
and calls is_benchmark_done() for the first time that start_time is not
yet set. In that case start_time have its initial value of 0 and the
duration check fails as it do not correlate correctly for the
applications start time and immediately sets benchmark_done which in
turn terminates the xdpsock application.

Fix this by setting start_time before creating the poller thread.

Fixes: d3f11b018f ("samples/bpf: xdpsock: Add duration option to specify how long to run")
Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220315102948.466436-1-niklas.soderlund@corigine.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-04-08 14:40:21 +02:00
..
auxdisplay
binderfs
bpf samples/bpf, xdpsock: Fix race when running for fix duration of time 2022-04-08 14:40:21 +02:00
configfs samples: configfs: prefer pr_err() over bare printk(KERN_ERR 2020-10-07 15:46:22 +02:00
connector
ftrace ftrace/samples: Add missing prototypes direct functions 2022-01-11 15:25:00 +01:00
hidraw
hw_breakpoint
kdb
kfifo kfifo: fix ternary sign extension bugs 2021-05-14 09:50:45 +02:00
kmemleak mm,kmemleak-test.c: move kmemleak-test.c to samples dir 2020-10-13 18:38:27 -07:00
kobject
kprobes samples/kretprobes: Fix return value if register_kretprobe() failed 2021-11-18 14:04:11 +01:00
livepatch
mei
nitro_enclaves nitro_enclaves: Add sample for ioctl interface usage 2020-09-22 13:58:41 +02:00
pidfd
pktgen samples: pktgen: add missing IPv6 option to pktgen scripts 2021-09-15 09:50:40 +02:00
qmi
rpmsg
seccomp
timers
trace_events
trace_printk
uhid
v4l
vfio-mdev samples: vfio-mdev: fix error handing in mdpy_fb_probe() 2021-06-10 13:39:15 +02:00
vfs
watch_queue watch_queue: Drop references to /dev/watch_queue 2021-03-04 11:37:59 +01:00
watchdog
Kconfig watch_queue: Drop references to /dev/watch_queue 2021-03-04 11:37:59 +01:00
Makefile mm,kmemleak-test.c: move kmemleak-test.c to samples dir 2020-10-13 18:38:27 -07:00