Re: [PATCH v3 3/3] iova: defer maple tree erase on GFP_ATOMIC failure

From: Rik van Riel

Date: Wed Jun 10 2026 - 22:28:20 EST


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?
>
Mas_erase() would look cleaner, indeed, and it
looks like the mas_wr_preallocate() call is
safe from atomic context, as well!

Let me give that a try tomorrow.

I'll send a v4 if that cleanup works right.

--
All Rights Reversed.