All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Pravin Pathak <pravinpathakdev@gmail.com>
Cc: dev@dpdk.org, jerinj@marvell.com, tirthendu.sarkar@intel.com,
	bruce.richardson@intel.com, thomas@monjalon.net,
	david.marchand@redhat.com, pravin.pathak.dev@gmail.com
Subject: Re: [PATCH v1] event/dlb2: race condition during dynamic linking
Date: Tue, 27 Oct 2026 14:00:42 -0700	[thread overview]
Message-ID: <20261027140042.2741b628@phoenix.local> (raw)
In-Reply-To: <20261021172041.433881-1-pravin.pathak.dev@gmail.com>

On Wed, 21 Oct 2026 13:20:41 -0400
Pravin Pathak <pravinpathakdev@gmail.com> wrote:

> dlb2 handles dynamic linking and linking asynchronously if queues
> being linked/unlinked have traffic. It starts a thread if not already
> started to handle the process. This change avoids the race condition
> in thread creation where sometimes the thread starts immediately,
> descheduling the calling thread and finishes the job and exits, and then
> caller sets worker launched true when the thread is not running.
> 
> Signed-off-by: Pravin Pathak <pravin.pathak.dev@gmail.com>
> ---

Ran a more detailed AI review on this.

Subject: Re: [PATCH] event/dlb2: fix race condition during dynamic linking

The fix is correct and worth having in stable. Some notes on what it
does and does not cover, since two related problems remain in this
code.

What the patch fixes
--------------------

os_schedule_work() set worker_launched = true after
rte_thread_create_internal_control() returned, but the worker thread
(dlb2_complete_queue_map_unmap()) clears that flag as its last act
before exiting. If the new thread ran to completion before the creator
was scheduled again, the creator stamped true over the worker's false.

The flag is then stuck true for the life of the device:

  - os_worker_active() always reports an active worker
  - all three call sites in dlb2_resource.c (2336, 2370, 6037) are
    guarded by if (!os_worker_active(hw)), so no worker is ever
    launched again
  - deferred map/unmap work is stranded, leaving ports in
    DLB2_QUEUE_MAP_IN_PROG / UNMAP_IN_PROG indefinitely

Setting the flag before thread creation closes that window: creation is
a synchronization point, so the worker is guaranteed to observe true and
its own clear is the last write. Resetting to false on the create-failure
path is right.

Remaining issues
----------------

Both of these predate the patch, so they are follow-up material rather
than objections, but they are in the same few lines and should probably
be cleaned up while the context is fresh.

1. Missed wakeup. resource_mutex is only ever taken inside the worker
loop:

  drivers/event/dlb2/pf/dlb2_main.h:46   rte_spinlock_t resource_mutex
  drivers/event/dlb2/pf/base/dlb2_osdep.h:172,178,190  worker only
  drivers/event/dlb2/pf/dlb2_main.c:34   rte_spinlock_init()

No caller holds it across the check-and-schedule pair, so for one
control thread against the worker:

  - worker's final iteration scans, finds nothing pending
  - control thread marks a new unmap in progress
  - control thread reads worker_launched as true, skips
    os_schedule_work()
  - worker sets worker_launched = false and exits

The work is stranded until the next link/unlink happens to launch a new
worker. This needs no MT-unsafe API use to hit: eventdev link/unlink is
not MT-safe by contract, and a single conforming control thread racing
the worker is enough.

The kernel driver this base code was ported from holds resource_mutex
around the check and the schedule; the DPDK port dropped that. Before
this patch the resulting failure was permanent, now it is transient.

2. worker_launched is a plain bool with mixed access. The worker writes
it under the spinlock, callers read and write it with no
synchronization, which is a C11 data race. The practical impact is
small since the worst case is a duplicate worker and two workers
looping under the same mutex are safe, but it should be
RTE_ATOMIC(bool) with release/acquire.

      parent reply	other threads:[~2026-10-27 21:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 17:20 [PATCH v1] event/dlb2: race condition during dynamic linking Pravin Pathak
2026-10-22 16:46 ` Sarkar, Tirthendu
2026-10-23 12:49   ` Jerin Jacob
2026-10-22 16:51 ` Bruce Richardson
2026-10-27 21:00 ` Stephen Hemminger [this message]

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=20261027140042.2741b628@phoenix.local \
    --to=stephen@networkplumber.org \
    --cc=bruce.richardson@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=jerinj@marvell.com \
    --cc=pravin.pathak.dev@gmail.com \
    --cc=pravinpathakdev@gmail.com \
    --cc=thomas@monjalon.net \
    --cc=tirthendu.sarkar@intel.com \
    /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.