From: Jason Gunthorpe <jgg@ziepe.ca>
To: Rik van Riel <riel@surriel.com>, "Liam R. Howlett" <liam@infradead.org>
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
robin.murphy@arm.com, joro@8bytes.org, will@kernel.org,
iommu@lists.linux.dev, kyle@mcmartin.ca,
Rik van Riel <riel@meta.com>
Subject: Re: [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure
Date: Fri, 12 Jun 2026 13:48:52 -0300 [thread overview]
Message-ID: <20260612164852.GL1066031@ziepe.ca> (raw)
In-Reply-To: <61d51d4b5779d80145ceb38e9632a7cc8a79dbec.camel@surriel.com>
On Fri, Jun 12, 2026 at 12:02:55PM -0400, Rik van Riel wrote:
> On Tue, 2026-06-09 at 10:04 -0300, Jason Gunthorpe wrote:
> > On Tue, Jun 02, 2026 at 11:35:48PM -0400, Rik van Riel wrote:
> > > +/*
> > > + * Remove an IOVA entry from the maple tree. Returns true on
> > > success.
> > > + * On failure (maple tree node allocation under GFP_ATOMIC
> > > failed),
> > > + * returns false — the entry remains in the tree and the caller
> > > must
> > > + * not free the struct iova.
> > > + */
> > > +static bool remove_iova(struct iova_domain *iovad, struct iova
> > > *iova)
> > > {
> > > MA_STATE(mas, &iovad->mtree, iova->pfn_lo, iova->pfn_hi);
> > >
> > > @@ -165,7 +175,36 @@ static void remove_iova(struct iova_domain
> > > *iovad, struct iova *iova)
> > > if (iova->pfn_lo < iovad->dma_32bit_pfn)
> > > iovad->max32_alloc_size = iovad->dma_32bit_pfn;
> > >
> > > - mas_store_gfp(&mas, NULL, GFP_ATOMIC);
> > > + if (mas_store_gfp(&mas, NULL, GFP_ATOMIC))
> > > + return false;
> >
> > But why does it use mas_store(NULL) instead of mas_erase()? I thought
> > the iova alloc/free has to be pair wise, we don't split allocations?
> >
> I just looked into this some more, and I was
> confused earlier this week.
>
> The mas_erase() function calls mas_nomem(mas, GFP_KERNEL),
> which is not safe to call while holding a spinlock.
Oh, the kdoc doesn't say that, it doesn't return any error code if it
can't allocate memory, and not a single caller checks for erase
failures.
I assumed internally it "somehow worked out" even though there are
allocations in the callchains..
This is probably a better question for Liam? Can mtree_erase actually
fail ENOMEM? Is it safe to call it in an atomic context?
Jason
next prev parent reply other threads:[~2026-06-12 16:48 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 3:35 [PATCH v3 0/3] iova: use maple tree for O(log n) allocation Rik van Riel
2026-06-03 3:35 ` [PATCH v3 1/3] iova: convert from rbtree to maple tree Rik van Riel
2026-06-17 19:55 ` Liam R. Howlett
2026-06-19 3:47 ` Rik van Riel
2026-06-03 3:35 ` [PATCH v3 2/3] iova: add KUnit test suite Rik van Riel
2026-06-03 3:35 ` [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure Rik van Riel
2026-06-09 13:04 ` Jason Gunthorpe
2026-06-11 2:22 ` Rik van Riel
2026-06-12 16:02 ` Rik van Riel
2026-06-12 16:48 ` Jason Gunthorpe [this message]
2026-06-12 17:23 ` Rik van Riel
2026-06-12 18:03 ` Jason Gunthorpe
2026-06-12 18:44 ` Liam R. Howlett
2026-06-15 11:56 ` Jason Gunthorpe
2026-06-17 17:45 ` Liam R. Howlett
2026-06-17 18:04 ` Jason Gunthorpe
2026-06-18 14:50 ` Liam R. Howlett
2026-06-18 15:24 ` Jason Gunthorpe
2026-06-18 17:27 ` Liam R. Howlett
2026-06-18 17:30 ` Rik van Riel
2026-06-18 19:13 ` Liam R. Howlett
2026-06-19 12:08 ` Jason Gunthorpe
2026-06-30 18:39 ` Liam R. Howlett
2026-06-19 3:51 ` Rik van Riel
2026-06-19 4:54 ` Liam R. Howlett
2026-06-19 12:13 ` Jason Gunthorpe
2026-06-19 18:54 ` Rik van Riel
2026-06-21 0:08 ` Ashok Raj
2026-06-21 1:53 ` Rik van Riel
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=20260612164852.GL1066031@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=kernel-team@meta.com \
--cc=kyle@mcmartin.ca \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@meta.com \
--cc=riel@surriel.com \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/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).