lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 26 Mar 2013 12:30:11 -0400
From:	"J. Bruce Fields" <bfields@...ldses.org>
To:	Tejun Heo <tj@...nel.org>
Cc:	Jeff Layton <jlayton@...hat.com>, akpm@...ux-foundation.org,
	linux-kernel@...r.kernel.org, rusty@...tcorp.com.au,
	skinsbursky@...allels.com, ebiederm@...ssion.com,
	jmorris@...ei.org, axboe@...nel.dk
Subject: Re: [PATCHSET] idr: implement idr_alloc() and convert existing users

On Tue, Mar 26, 2013 at 08:26:53AM -0700, Tejun Heo wrote:
> Hello, Jeff.
> 
> On Tue, Mar 26, 2013 at 11:19:36AM -0400, Jeff Layton wrote:
> > +/**
> > + * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion
> > + * @idr: the (initialized) idr
> > + * @ptr: pointer to be associated with the new id
> > + * @start: the minimum id (inclusive)
> > + * @end: the maximum id (exclusive, <= 0 for max)
> > + * @cur: ptr to current position in the range (typically, last allocated + 1)
> > + * @gfp_mask: memory allocation flags
> > + *
> > + * Essentially the same as idr_alloc, but prefers to allocate progressively
> > + * higher ids if it can. If the "cur" counter wraps, then it will start again
> > + * at the "start" end of the range and allocate one that has already been used.
> > + */
> > +int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, int *cur,
> > +			gfp_t gfp_mask)
> > +{
> > +	int id;
> > +
> > +	id = idr_alloc(idr, ptr, *cur, end, gfp_mask);
> > +	if (id == -ENOSPC)
> > +		id = idr_alloc(idr, ptr, start, end, gfp_mask);
> > +
> > +	if (likely(id >= 0))
> > +		*cur = id + 1;
> > +	return id;
> > +}
> 
> Wouldn't it be better if idr itself could remember the last position?
> Also, @start/@end should always be honored even if, say, @start moves
> above the last position.  Other than that, yeah.

The old nfsd stateid code just generated stateid's from a counter,
something like:

	static u32 counter;
	return counter++;

and then stuck them in a hash table.  Which had the obvious bug with
(very unlikely, absent malice) collisions on wraparound.

I probably should have ignored idr and just made the obvious fix:

	static u32 counter;

	while (!id_exists_in_hash(counter))
		counter++;
	return counter;

So maybe we should just go back to that.  And possibly choose some
better data structure.

The only requirements are that at a given moment in time id's should be
unique, and that we should make some effort to avoid reusing them
immediately.

I don't know what other "cyclic" idr users need.

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ