From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, daniel@iogearbox.net, andrii@kernel.org,
alexei.starovoitov@gmail.com, martin.lau@kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH bpf-next v1] selftests/bpf: Fix stdout race condition in traffic monitor
Date: Thu, 13 Feb 2025 17:08:08 -0800 [thread overview]
Message-ID: <e5d5b25f-cee8-436c-ab3a-b92bd417e70e@linux.dev> (raw)
In-Reply-To: <CAMB2axPo5PKKEe3_7opjV4KftCqpDZo9m=iRZZ=g+mUqDeZzqw@mail.gmail.com>
On 2/13/25 4:19 PM, Amery Hung wrote:
> On Thu, Feb 13, 2025 at 3:55 PM Martin KaFai Lau <martin.lau@linux.dev> wrote:
>>
>> On 2/13/25 3:32 PM, Amery Hung wrote:
>>> Fix a race condition between the main test_progs thread and the traffic
>>> monitoring thread. The traffic monitor thread tries to print a line
>>> using multiple printf and use flockfile() to prevent the line from being
>>> torn apart. Meanwhile, the main thread doing io redirection can reassign
>>> or close stdout when going through tests. A deadlock as shown below can
>>> happen.
>>>
>>> main traffic_monitor_thread
>>> ==== ======================
>>> show_transport()
>>> -> flockfile(stdout)
>>>
>>> stdio_hijack_init()
>>> -> stdout = open_memstream(log_buf, log_cnt);
>>> ...
>>> env.subtest_state->stdout_saved = stdout;
>>>
>>> ...
>>> funlockfile(stdout)
>>> stdio_restore_cleanup()
>>> -> fclose(env.subtest_state->stdout_saved);
>>
>> Great debugging.
>>
>> Does it mean that the main thread will start the next test before the
>> traffic_monitor_thread has finished? Meaning the traffic_monitor_stop() does not
>> wait for the traffic_monitor_thread somehow?
>
> That part I think is fine. The race condition here happen between
> subtests within the same "netns_new" scope. For example,
> test_flow_dissector_skb_less_direct_attach.
Got it. Thanks for the fix. Applied.
next prev parent reply other threads:[~2025-02-14 1:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 23:32 [PATCH bpf-next v1] selftests/bpf: Fix stdout race condition in traffic monitor Amery Hung
2025-02-13 23:55 ` Martin KaFai Lau
2025-02-14 0:19 ` Amery Hung
2025-02-14 1:08 ` Martin KaFai Lau [this message]
2025-02-14 1:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e5d5b25f-cee8-436c-ab3a-b92bd417e70e@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.