]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
samples/bpf, xdpsock: Fix race when running for fix duration of time
authorNiklas Söderlund <niklas.soderlund@corigine.com>
Tue, 15 Mar 2022 10:29:48 +0000 (11:29 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 27 Apr 2022 09:57:56 +0000 (11:57 +0200)
commit10e664451ce840f6ac7e32fb7638cbb8e92b2920
tree8a797b0a841409bd32daed05506605368c095dee
parent3c5ce86a4606e13aac35769fb47e3081f82d7d46
samples/bpf, xdpsock: Fix race when running for fix duration of time

BugLink: https://bugs.launchpad.net/bugs/1969110
[ 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: d3f11b018f6c ("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>
(cherry picked from commit bc2c4dc5b566662193fe3f76b941bb3b1257c44f)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
samples/bpf/xdpsock_user.c