Patch "samples/bpf, xdpsock: Fix race when running for fix duration of time" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    samples/bpf, xdpsock: Fix race when running for fix duration of time

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     samples-bpf-xdpsock-fix-race-when-running-for-fix-du.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 888565d96c07df99fd5eca534e1d2031537ceeb6
Author: Niklas Söderlund <niklas.soderlund@xxxxxxxxxxxx>
Date:   Tue Mar 15 11:29:48 2022 +0100

    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: d3f11b018f6c ("samples/bpf: xdpsock: Add duration option to specify how long to run")
    Signed-off-by: Niklas Söderlund <niklas.soderlund@xxxxxxxxxxxx>
    Signed-off-by: Simon Horman <simon.horman@xxxxxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20220315102948.466436-1-niklas.soderlund@xxxxxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 49d7a6ad7e39..1fb79b3ecdd5 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -1673,14 +1673,15 @@ int main(int argc, char **argv)
 
 	setlocale(LC_ALL, "");
 
+	prev_time = get_nsecs();
+	start_time = prev_time;
+
 	if (!opt_quiet) {
 		ret = pthread_create(&pt, NULL, poller, NULL);
 		if (ret)
 			exit_with_error(ret);
 	}
 
-	prev_time = get_nsecs();
-	start_time = prev_time;
 
 	if (opt_bench == BENCH_RXDROP)
 		rx_drop_all();



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux