Re: [PATCH v4 12/22] lib/stackdepot: use read/write lock

From: Marco Elver
Date: Sat Jan 13 2024 - 04:31:09 EST


On Sat, 13 Jan 2024 at 10:23, Marco Elver <elver@xxxxxxxxxx> wrote:
>
> On Sat, 13 Jan 2024 at 10:19, Andi Kleen <ak@xxxxxxxxxxxxxxx> wrote:
> >
> > On Sat, Jan 13, 2024 at 10:12:21AM +0100, Marco Elver wrote:
> > > On Sat, 13 Jan 2024 at 02:24, Andi Kleen <ak@xxxxxxxxxxxxxxx> wrote:
> > > >
> > > > On Fri, Jan 12, 2024 at 11:15:05PM +0100, Marco Elver wrote:
> > > > > + /*
> > > > > + * Stack traces of size 0 are never saved, and we can simply use
> > > > > + * the size field as an indicator if this is a new unused stack
> > > > > + * record in the freelist.
> > > > > + */
> > > > > + stack->size = 0;
> > > >
> > > > I would use WRITE_ONCE here too, at least for TSan.
> > >
> > > This is written with the pool_lock held.
> >
> > ...which doesn't help because the readers don't take it?
>
> This function is only refilling the freelist. Readers don't see it yet
> because it's in none of the hash table buckets. The freelist is only
> ever accessed under the lock.
>
> Once an entry is allocated from the freelist, its size is overwritten
> with something non-zero (since it then contains a stack trace). Those
> updates are released into the right hash table bucket with
> list_add_rcu() (which implies a release).
>
> Am I missing something else?

FWIW, the current version (draft) of this can be found here:
https://git.kernel.org/pub/scm/linux/kernel/git/melver/linux.git/log/?h=kasan/dev
I'll send the 2 patches next week - they should apply cleanly on
current mainline.

Thanks,
-- Marco