Re: [PATCH v2] Fixes a race in iopt_unmap_iova_range
From: Sina Hassani
Date: Tue Apr 07 2026 - 18:09:04 EST
Friendly ping
On Mon, Apr 6, 2026 at 6:40 PM Sina Hassani <sina@xxxxxxxxxx> wrote:
>
> On Mon, Apr 6, 2026 at 6:27 PM Jason Gunthorpe <jgg@xxxxxxxx> wrote:
> >
> > On Mon, Apr 06, 2026 at 06:17:24PM -0700, Sina Hassani wrote:
> > > On Mon, Apr 6, 2026 at 6:12 PM Jason Gunthorpe <jgg@xxxxxxxx> wrote:
> > > >
> > > > On Mon, Apr 06, 2026 at 04:07:01PM -0700, Sina Hassani wrote:
> > > >
> > > > > io_pagetable *iopt, unsigned long start,
> > > > > unmapped_bytes += area_last - area_first + 1;
> > > > >
> > > > > down_write(&iopt->iova_rwsem);
> > > > > +
> > > > > + /* Do not reconsider things already unmapped in case of
> > > > > + * concurrent allocation */
> > > > > + start = area_last + 1;
> > > >
> > > > area_last can be ULONG_MAX so this literally overflows to 0. It is why
> > > > I formed the suggestion I gave as I did
> > > >
> > > Yes, in which case the if (start < area_last) that follows will catch
> > > it. Are you suggesting I compare against ULONG_MAX instead?
> >
> > iommufd does not have any overflows to 0 and rely on it tricks like
> > this. You should just compare to the existing iteration last
> >
> Just to confirm that I understand correctly, like this?
>
> + if (area_last >= last) {
> + break;
> +. } else {
> +. start = area_last + 1;
> + }
>
> > Jason