[PATCH V2 1/2] nvme-core: use xarray for ctrl ns tracking
Keith Busch
kbusch at kernel.org
Wed Jul 1 12:44:47 EDT 2020
On Wed, Jul 01, 2020 at 03:12:35PM +0200, Christoph Hellwig wrote:
> [willy: a comment/request on the xa_load API below]
>
> On Tue, Jun 30, 2020 at 07:25:16PM -0700, Chaitanya Kulkarni wrote:
> >
> > + rcu_read_lock();
> > + do {
> > + ns = xas_load(&xas);
> > + if (xa_is_zero(ns))
> > + ns = NULL;
> > + } while (xas_retry(&xas, ns));
> > + ns = ns && kref_get_unless_zero(&ns->kref) ? ns : NULL;
> > + rcu_read_unlock();
>
> This looks pretty weird, but I think the problem is one in the xarray
> API, as for the typical lookup pattern we'd want an xa_load with
> external RCU locking:
>
> rcu_read_lock();
> ns = xa_load_rcu(&ctrl->namespaces, nsid);
> if (ns && !kref_get_unless_zero(&ns->kref))
> ns = NULL;
> rcu_read_unlock();
>
> instead of duplicating this fairly arcane loop in all kinds of callers.
Is it not safe to use external RCU locking with the existing xa_load()?
The rcu_read_lock() api says nested read-side critical sections are
fine.
More information about the Linux-nvme
mailing list