linux-stable/samples
Niklas Söderlund 5083178278 samples/bpf, xdpsock: Fix race when running for fix duration of time
[ Upstream commit 8fa42d78f6 ]

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 13:58:18 +02:00
..
acrn
auxdisplay
binderfs
bpf samples/bpf, xdpsock: Fix race when running for fix duration of time 2022-04-08 13:58:18 +02:00
configfs
connector
coresight coresight: syscfg: Example CoreSight configuration loadable module 2021-11-26 11:34:07 -07:00
fanotify Add gitignore file for samples/fanotify/ subdirectory 2021-11-07 11:19:24 -08:00
ftrace - Get rid of all the .fixup sections because this generates 2022-01-12 16:31:19 -08:00
hidraw
hw_breakpoint
kdb
kfifo
kmemleak
kobject
kprobes samples/kretprobes: Fix return value if register_kretprobe() failed 2021-10-26 17:23:46 -04:00
landlock samples/landlock: Fix path_list memory leak 2022-04-08 13:57:25 +02:00
livepatch
mei
nitro_enclaves
pidfd
pktgen
qmi
rpmsg
seccomp samples/seccomp: Adjust sample to also provide kill option 2022-02-10 19:09:12 -08:00
timers
trace_events tracing: Fix mismatched comment in __string_len 2022-01-13 16:23:05 -05:00
trace_printk
uhid
v4l
vfio-mdev Char/Misc driver update for 5.16-rc1 2021-11-04 08:21:47 -07:00
vfs
watch_queue
watchdog
Kconfig Coresight changes for v5.17 2021-12-21 10:07:07 +01:00
Makefile Coresight changes for v5.17 2021-12-21 10:07:07 +01:00