Index | Thread | Search

From:
Alexander Bluhm <bluhm@openbsd.org>
Subject:
Re: refcnt: Improve assertion on take
To:
Vitaliy Makkoveev <mvs@openbsd.org>
Cc:
Christian Ludwig <cludwig@genua.de>, tech@openbsd.org
Date:
Fri, 20 Jun 2025 16:10:29 +0200

Download raw body.

Thread
Hi Christian,

Finally I have commited this.  Thanks.

bluhm

On Tue, May 20, 2025 at 03:17:43PM +0000, Vitaliy Makkoveev wrote:
> On Tue, May 20, 2025 at 05:00:42PM +0200, Christian Ludwig wrote:
> > Hi,
> > 
> > This is a resend of https://marc.info/?l=openbsd-tech&m=174043502604444
> > from earlier this year. atomic_inc_int_nv() returns the incremented
> > value. And you can only take a reference if you hold one already.
> > 
> > It passes regress. But more testers are welcome.
> > 
> 
> Makes sense. I already pointed that current assertion will not be
> triggered if we take reference on object with zero refs.
> 
> > 
> >  - Christian
> > 
> > ---
> >  sys/kern/kern_synch.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
> > index 144283d005ac..08e7d165d1bd 100644
> > --- a/sys/kern/kern_synch.c
> > +++ b/sys/kern/kern_synch.c
> > @@ -919,7 +919,7 @@ refcnt_take(struct refcnt *r)
> >  	u_int refs;
> >  
> >  	refs = atomic_inc_int_nv(&r->r_refs);
> > -	KASSERT(refs != 0);
> > +	KASSERT(refs > 1);
> >  	TRACEINDEX(refcnt, r->r_traceidx, r, refs - 1, +1);
> >  	(void)refs;
> >  }
>