Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-10-08 Thread Paul E. McKenney
On Thu, Oct 01, 2020 at 08:07:31PM -0700, Eric Biggers wrote: > On Thu, Sep 24, 2020 at 08:31:02PM -0700, Paul E. McKenney wrote: > > On Thu, Sep 24, 2020 at 07:09:08PM -0700, Eric Biggers wrote: > > > On Thu, Sep 24, 2020 at 05:59:34PM -0700, Paul E. McKenney wrote: > > > > On Tue, Sep 22, 2020 at

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-10-01 Thread Eric Biggers
On Thu, Sep 24, 2020 at 08:31:02PM -0700, Paul E. McKenney wrote: > On Thu, Sep 24, 2020 at 07:09:08PM -0700, Eric Biggers wrote: > > On Thu, Sep 24, 2020 at 05:59:34PM -0700, Paul E. McKenney wrote: > > > On Tue, Sep 22, 2020 at 02:55:58PM -0700, Eric Biggers wrote: > > > > On Tue, Sep 22, 2020 at

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-24 Thread Paul E. McKenney
On Thu, Sep 24, 2020 at 07:09:08PM -0700, Eric Biggers wrote: > On Thu, Sep 24, 2020 at 05:59:34PM -0700, Paul E. McKenney wrote: > > On Tue, Sep 22, 2020 at 02:55:58PM -0700, Eric Biggers wrote: > > > On Tue, Sep 22, 2020 at 01:56:28PM -0700, Paul E. McKenney wrote: > > > > > You're missing the po

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-24 Thread Eric Biggers
On Thu, Sep 24, 2020 at 05:59:34PM -0700, Paul E. McKenney wrote: > On Tue, Sep 22, 2020 at 02:55:58PM -0700, Eric Biggers wrote: > > On Tue, Sep 22, 2020 at 01:56:28PM -0700, Paul E. McKenney wrote: > > > > You're missing the point here. b and c could easily be allocated by a > > > > function >

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-24 Thread Paul E. McKenney
On Tue, Sep 22, 2020 at 02:55:58PM -0700, Eric Biggers wrote: > On Tue, Sep 22, 2020 at 01:56:28PM -0700, Paul E. McKenney wrote: > > > You're missing the point here. b and c could easily be allocated by a > > > function > > > alloc_b() that's in another file. > > > > I am still missing somethin

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Eric Biggers
On Tue, Sep 22, 2020 at 01:56:28PM -0700, Paul E. McKenney wrote: > > You're missing the point here. b and c could easily be allocated by a > > function > > alloc_b() that's in another file. > > I am still missing something. > > If by "allocated" you mean something like kmalloc(), the compiler

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Paul E. McKenney
On Tue, Sep 22, 2020 at 12:09:36PM -0700, Eric Biggers wrote: > On Tue, Sep 22, 2020 at 11:31:00AM -0700, Paul E. McKenney wrote: > > > Also, it's not just the p == &global_variable case. Consider: > > > > > > struct a { struct b *b; }; > > > struct b { ... }; > > > > > > Thread 1: > > > > > >

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Paul E. McKenney
On Tue, Sep 22, 2020 at 11:59:31AM -0700, Eric Biggers wrote: > On Tue, Sep 22, 2020 at 11:42:43AM -0700, Paul E. McKenney wrote: > > On Tue, Sep 22, 2020 at 09:51:36AM +1000, Herbert Xu wrote: > > > On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > > > > > > > > > But this reason

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Eric Biggers
On Tue, Sep 22, 2020 at 11:31:00AM -0700, Paul E. McKenney wrote: > > Also, it's not just the p == &global_variable case. Consider: > > > > struct a { struct b *b; }; > > struct b { ... }; > > > > Thread 1: > > > > /* one-time initialized data shared by all instances of b */ > > static

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Eric Biggers
On Tue, Sep 22, 2020 at 11:42:43AM -0700, Paul E. McKenney wrote: > On Tue, Sep 22, 2020 at 09:51:36AM +1000, Herbert Xu wrote: > > On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > > > > > > > But this reasoning could apply to any data structure that contains > > > > a spin lock,

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Paul E. McKenney
On Tue, Sep 22, 2020 at 09:51:36AM +1000, Herbert Xu wrote: > On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > > > > > But this reasoning could apply to any data structure that contains > > > a spin lock, in particular ones that are dereferenced through RCU. > > > > I lost you o

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-22 Thread Paul E. McKenney
On Mon, Sep 21, 2020 at 04:52:43PM -0700, Eric Biggers wrote: > On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > > On Tue, Sep 22, 2020 at 08:11:04AM +1000, Herbert Xu wrote: > > > On Mon, Sep 21, 2020 at 08:27:14AM -0700, Paul E. McKenney wrote: > > > > On Mon, Sep 21, 2020 at 0

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Eric Biggers
On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > On Tue, Sep 22, 2020 at 08:11:04AM +1000, Herbert Xu wrote: > > On Mon, Sep 21, 2020 at 08:27:14AM -0700, Paul E. McKenney wrote: > > > On Mon, Sep 21, 2020 at 06:19:39PM +1000, Herbert Xu wrote: > > > > On Thu, Sep 17, 2020 at 09:

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Herbert Xu
On Mon, Sep 21, 2020 at 04:26:39PM -0700, Paul E. McKenney wrote: > > > But this reasoning could apply to any data structure that contains > > a spin lock, in particular ones that are dereferenced through RCU. > > I lost you on this one. What is special about a spin lock? I don't know, that was

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Paul E. McKenney
On Tue, Sep 22, 2020 at 08:11:04AM +1000, Herbert Xu wrote: > On Mon, Sep 21, 2020 at 08:27:14AM -0700, Paul E. McKenney wrote: > > On Mon, Sep 21, 2020 at 06:19:39PM +1000, Herbert Xu wrote: > > > On Thu, Sep 17, 2020 at 09:58:02AM -0700, Eric Biggers wrote: > > > > > > > > smp_load_acquire() is o

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Herbert Xu
On Mon, Sep 21, 2020 at 08:27:14AM -0700, Paul E. McKenney wrote: > On Mon, Sep 21, 2020 at 06:19:39PM +1000, Herbert Xu wrote: > > On Thu, Sep 17, 2020 at 09:58:02AM -0700, Eric Biggers wrote: > > > > > > smp_load_acquire() is obviously correct, whereas READ_ONCE() is an > > > optimization > > >

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Paul E. McKenney
On Mon, Sep 21, 2020 at 06:19:39PM +1000, Herbert Xu wrote: > On Thu, Sep 17, 2020 at 09:58:02AM -0700, Eric Biggers wrote: > > > > smp_load_acquire() is obviously correct, whereas READ_ONCE() is an > > optimization > > that is difficult to tell whether it's correct or not. For trivial data > > s

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-21 Thread Herbert Xu
On Thu, Sep 17, 2020 at 09:58:02AM -0700, Eric Biggers wrote: > > smp_load_acquire() is obviously correct, whereas READ_ONCE() is an > optimization > that is difficult to tell whether it's correct or not. For trivial data > structures it's "easy" to tell. But whenever there is a->b where b is an

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-17 Thread Eric Biggers
On Thu, Sep 17, 2020 at 05:26:44PM +1000, Herbert Xu wrote: > Eric Biggers wrote: > > From: Eric Biggers > > > > When a CPU selects which CRNG to use, it accesses crng_node_pool without > > a memory barrier. That's wrong, because crng_node_pool can be set by > > another CPU concurrently. Witho

Re: [PATCH] random: use correct memory barriers for crng_node_pool

2020-09-17 Thread Herbert Xu
Eric Biggers wrote: > From: Eric Biggers > > When a CPU selects which CRNG to use, it accesses crng_node_pool without > a memory barrier. That's wrong, because crng_node_pool can be set by > another CPU concurrently. Without a memory barrier, the crng_state that > is used might not appear to b

[PATCH] random: use correct memory barriers for crng_node_pool

2020-09-16 Thread Eric Biggers
From: Eric Biggers When a CPU selects which CRNG to use, it accesses crng_node_pool without a memory barrier. That's wrong, because crng_node_pool can be set by another CPU concurrently. Without a memory barrier, the crng_state that is used might not appear to be fully initialized. There's an