[PATCH] nvme: fix SRCU protection of nvme_ns_head list
Paul E. McKenney
paulmck at kernel.org
Mon Nov 21 06:57:39 PST 2022
On Mon, Nov 21, 2022 at 11:43:33AM +0200, Sagi Grimberg wrote:
>
> > > > sector_t capacity = get_capacity(head->disk);
> > > > int node;
> > > > + int srcu_idx;
> > > > + srcu_idx = srcu_read_lock(&head->srcu);
> > > > list_for_each_entry_rcu(ns, &head->list, siblings) {
> > > > if (capacity != get_capacity(ns->disk))
> > > > clear_bit(NVME_NS_READY, &ns->flags);
> > > > }
> > > > + srcu_read_unlock(&head->srcu, srcu_idx);
> > >
> > > I don't think you need srcu here, rcu_read_lock/unlock is sufficient.
> >
> > So the code obviously does not sleep. But I wonder if anything speaks
> > against mixing SRCU and RCU protection for the same list?
>
> I am not an expert, but the point of (s)rcu_synchronize to fence the
> reader critical section isn't it? so if the reader doesn't sleep, the
> existing rcu_synchronize should be sufficient.
Just in case you need to mix RCU and SRCU readers, so that you need
to wait for both types of readers, but need to avoid the latency of
back-to-back waits, you can overlap the waits like this:
void call_my_srrcu(struct rcu_head *head, rcu_callback_t func)
{
call_srcu(&my_srcu, head, func);
}
...
synchronize_rcu_mult(call_rcu, call_my_srrcu);
Thanx, Paul
More information about the Linux-nvme
mailing list