lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+KHdyV=0dpJX_v_tcuTQ-_ree-Yb9ch3F_HqfT4YnH8=zyWng@mail.gmail.com>
Date: Wed, 18 Sep 2024 16:40:25 +0200
From: Uladzislau Rezki <urezki@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Vlastimil Babka <vbabka@...e.cz>, David Rientjes <rientjes@...gle.com>, 
	Christoph Lameter <cl@...ux.com>, Andrew Morton <akpm@...ux-foundation.org>, 
	"linux-mm@...ck.org" <linux-mm@...ck.org>, LKML <linux-kernel@...r.kernel.org>, 
	Roman Gushchin <roman.gushchin@...ux.dev>, Hyeonggon Yoo <42.hyeyoo@...il.com>, 
	Christian Brauner <brauner@...nel.org>, RCU <rcu@...r.kernel.org>, 
	Shakeel Butt <shakeel.butt@...ux.dev>
Subject: Re: [GIT PULL] slab updates for 6.11

Hello, Linus!

On Wed, Sep 18, 2024 at 9:06 AM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Mon, 16 Sept 2024 at 11:45, Vlastimil Babka <vbabka@...e.cz> wrote:
> >
> > There's a small conflict with the rcu tree:
> > https://lore.kernel.org/lkml/20240812124748.3725011b@canb.auug.org.au/
>
> Hmm. The conflict resolution is trivial, but the code itself looks buggy.
>
> Look here, commit 2b55d6a42d14 ("rcu/kvfree: Add kvfree_rcu_barrier()
> API") makes kvfree_rcu_queue_batch() do this:
>
>         bool queued = false;
>         ...
>         for (i = 0; i < KFREE_N_BATCHES; i++) {
>                 ...
>                         queued = queue_rcu_work(system_wq, &krwp->rcu_work);
>         ...
>         return queued;
>
> and note how that return value is completely nonsensical. It doesn't
> imply anything got queued. It's returning whether the *last* call to
> queue_rcu_work() resulted in queued work.
>
> There is no way the return value is meaningful that I can see, and
> honestly, that means that the code in kvfree_rcu_barrier() looks
> actively buggy, and at worst might be an endless loop
>
> Now, maybe there's some reason why the code works fine, but it looks
> really really wrong. Please fix.
>
> The fix might be either a big comment about why it's ok, or making the
> "queued" assignment be a '|=' instead, or perhaps breaking out of the
> loop on the first successful queueing, or whatever.
>
> But not this "randomly return _one_ value of many of the queuing success".
>
Thank you for valuable feedback! Indeed it is hard to follow, even
though it works correctly.
I will add the comment and also break the loop on first queuing as you
suggested!

It does not make sense to loop further because following iterations
are never successful
thus never overwrite "queued" variable(it never reaches the
queue_rcu_work() call).

<snip>
         bool queued = false;
         ...
         for (i = 0; i < KFREE_N_BATCHES; i++) {
                if (need_offload_krc(krcp)) {
                         queued = queue_rcu_work(system_wq, &krwp->rcu_work);
         ...
         return queued;
<snip>

if we queued, "if(need_offload_krc())" condition is never true anymore.

Below refactoring makes it clear. I will send the patch to address it.

<snip>
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index a60616e69b66..b1f883fcd918 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -3607,11 +3607,12 @@ kvfree_rcu_queue_batch(struct kfree_rcu_cpu *krcp)
                        }

                        // One work is per one batch, so there are three
-                       // "free channels", the batch can handle. It can
-                       // be that the work is in the pending state when
-                       // channels have been detached following by each
-                       // other.
+                       // "free channels", the batch can handle. Break
+                       // the loop since it is done with this CPU thus
+                       // queuing an RCU work is _always_ success here.
                        queued = queue_rcu_work(system_unbound_wq,
&krwp->rcu_work);
+                       WARN_ON_ONCE(!queued);
+                       break;
                }
        }
<snip>

Thanks!

-- 
Uladzislau Rezki

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ