]> www.infradead.org Git - nvme.git/commit
jump_label: Fix static_key_slow_dec() yet again
authorPeter Zijlstra <peterz@infradead.org>
Mon, 9 Sep 2024 10:50:09 +0000 (12:50 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 10 Sep 2024 09:57:27 +0000 (11:57 +0200)
commit1d7f856c2ca449f04a22d876e36b464b7a9d28b6
tree36dfab1765b30922b40f7f49ce10fd45fa62e58b
parentfe513c2ef0a172a58f158e2e70465c4317f0a9a2
jump_label: Fix static_key_slow_dec() yet again

While commit 83ab38ef0a0b ("jump_label: Fix concurrency issues in
static_key_slow_dec()") fixed one problem, it created yet another,
notably the following is now possible:

  slow_dec
    if (try_dec) // dec_not_one-ish, false
    // enabled == 1
                                slow_inc
                                  if (inc_not_disabled) // inc_not_zero-ish
                                  // enabled == 2
                                    return

    guard((mutex)(&jump_label_mutex);
    if (atomic_cmpxchg(1,0)==1) // false, we're 2

                                slow_dec
                                  if (try-dec) // dec_not_one, true
                                  // enabled == 1
                                    return
    else
      try_dec() // dec_not_one, false
      WARN

Use dec_and_test instead of cmpxchg(), like it was prior to
83ab38ef0a0b. Add a few WARNs for the paranoid.

Fixes: 83ab38ef0a0b ("jump_label: Fix concurrency issues in static_key_slow_dec()")
Reported-by: "Darrick J. Wong" <djwong@kernel.org>
Tested-by: Klara Modin <klarasmodin@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
kernel/jump_label.c