From: Jason Gunthorpe <jgg@ziepe.ca>
To: Matthew Wilcox <willy@infradead.org>
Cc: "xiaofeng.yan" <xiaofeng.yan2012@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
dledford@redhat.com, oulijun@huawei.com, yanxiaofeng7@jd.com
Subject: Re: [PATCH 2/2] infiniband: Modify the reference to xa_store_irq() because the parameter of this function has changed
Date: Wed, 4 Nov 2020 17:34:00 -0400 [thread overview]
Message-ID: <20201104213400.GX36674@ziepe.ca> (raw)
In-Reply-To: <20201104193036.GD17076@casper.infradead.org>
On Wed, Nov 04, 2020 at 07:30:36PM +0000, Matthew Wilcox wrote:
> On Wed, Nov 04, 2020 at 02:58:43PM -0400, Jason Gunthorpe wrote:
> > > static void cm_finalize_id(struct cm_id_private *cm_id_priv)
> > > {
> > > xa_store_irq(&cm.local_id_table, cm_local_id(cm_id_priv->id.local_id),
> > > - cm_id_priv, GFP_KERNEL);
> > > + cm_id_priv);
> > > }
> >
> > This one is almost a bug, the entry is preallocated with NULL though:
> >
> > ret = xa_alloc_cyclic_irq(&cm.local_id_table, &id, NULL, xa_limit_32b,
> > &cm.local_id_next, GFP_KERNEL);
> >
> > so it should never allocate here:
> >
> > static int cm_req_handler(struct cm_work *work)
> > {
> > spin_lock_irq(&cm_id_priv->lock);
> > cm_finalize_id(cm_id_priv);
>
> Uhm. I think you want a different debugging check from this. The actual
> bug here is that you'll get back from calling cm_finalize_id() with
> interrupts enabled.
Ooh, that is just no fun too :\
Again surprised some lockdep didn't catch wrongly nesting irq locks
> Can you switch to xa_store(), or do we need an
> xa_store_irqsave()?
Yes, it looks like there is no reason for this, all users of the
xarray are from sleeping contexts, so it shouldn't need the IRQ
version.. I made a patch for this thanks
The cm_id_priv->lock is probably also not needing to be irq either,
but that is much harder to tell for sure
> > Still, woops.
> >
> > Matt, maybe a might_sleep is deserved in here someplace?
> >
> > @@ -1534,6 +1534,8 @@ void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp)
> > XA_STATE(xas, xa, index);
> > void *curr;
> >
> > + might_sleep_if(gfpflags_allow_blocking(gfp));
> > +
> > if (WARN_ON_ONCE(xa_is_advanced(entry)))
> > return XA_ERROR(-EINVAL);
> > if (xa_track_free(xa) && !entry)
> >
> > And similar in the other places that conditionally call __xas_nomem()
> > ?
But this debugging would still catch the wrong nesting of a GFP_KERNEL
inside a spinlock, you don't like it?
> > I also still wish there was a proper 'xa store in already allocated
> > but null' idiom - I remember you thought about using gfp flags == 0 at
> > one point.
>
> An xa_replace(), perhaps?
Make sense.. But I've also done this with cmpxchg. A magic GFP flag,
as you tried to do with 0, is appealing in many ways
Jason
next prev parent reply other threads:[~2020-11-04 21:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 2:32 [PATCH 1/2] [xarry]:Fixed an issue with memory allocated using the GFP_KERNEL flag in spinlocks xiaofeng.yan
2020-11-04 2:32 ` [PATCH 2/2] infiniband: Modify the reference to xa_store_irq() because the parameter of this function has changed xiaofeng.yan
2020-11-04 18:58 ` Jason Gunthorpe
2020-11-04 19:30 ` Matthew Wilcox
2020-11-04 21:34 ` Jason Gunthorpe [this message]
2020-11-04 2:36 ` [PATCH 1/2] [xarry]:Fixed an issue with memory allocated using the GFP_KERNEL flag in spinlocks Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201104213400.GX36674@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=dledford@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oulijun@huawei.com \
--cc=willy@infradead.org \
--cc=xiaofeng.yan2012@gmail.com \
--cc=yanxiaofeng7@jd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).