On Tue, Sep 3, 2019 at 9:45 AM Eric W. Biederman <ebied...@xmission.com> wrote: > > So with a big fat comment explaining why it is safe we could potentially > use RCU_INIT_POINTER. I currently don't see where the appropriate > barriers are so I can not write that comment or with a clear conscious > write the code to use RCU_INIT_POINTER instead of rcu_assign_pointer.
The only difference ends up being that RCU_INIT_POINTER() is just a store, while rcu_assign_pointer() uses a smp_store_release(). (There is some build-time special case code to make rcu_assign_pointer(NULL) avoid the store_release, but that is irrelevant for this discussion). So from a memory ordering standpoint, RCU_INIT_POINTER-vs-rcu_assign_pointer doesn't change what pointer you get (on the other CPU that does the reading), but only whether the stores to behind the pointer have been ordered wrt the reading too. Which no existing case can care about, since it didn't use to have any ordering anyway before this patch series. The individual values read off the thread pointer had their own individual memory ordering rules (ie instead of making the _pointer_ be the serialization point, we have rules for how "p->on_cpu" is ordered wrt the rq lock etc). So one argument for just using RCU_INIT_POINTER is that it's the same ordering that we had before, and then it's up to any users of that pointer to order any accesses to any fields in 'struct task_struct'. Conversely, one argument for using rcu_assign_pointer() is that when we pair it with an RCU read, we get certain ordering guarantees automatically. So _if_ we have fields that change when a process is put on the run-queue, and the RCU users want to read those fields, then the release/acquire semantics might perform better than potential existing smp memory barriers we might have right now. Linus