Re: [PATCH v8 15/19] locking/rwsem: Adaptive disabling of reader optimistic spinning

From: Peter Zijlstra
Date: Thu Jun 06 2019 - 04:16:02 EST


On Thu, Jun 06, 2019 at 10:03:15AM +0200, Peter Zijlstra wrote:
> On Wed, Jun 05, 2019 at 01:52:15PM -0700, Linus Torvalds wrote:
> > On Wed, Jun 5, 2019 at 1:19 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > Urgh, that's another things that's been on the TODO list for a long long
> > > time, write code to verify the alignment of allocations :/ I'm
> > > suspecting quite a lot of that goes wrong all over the place.
> >
> > On x86, we only guarantee 8-byte alignment from things like kmalloc(), iirc.
>
> Oh sure, and I'm not proposing to change that. I was more thinking of
> having a GCC plugin that verifies, for every ptr assignment:
>
> ptr = foo;

To better qualify: 'for every ptr assignment that includes a type cast',
and since allocators return 'void *' and (typically/eventually) assign
to a typed pointer, that would be the place to check.

This avoids having to instrument every single pointer assignment.

> that the actual alignment maches:
>
> assert(!(uintptr_t)ptr % __alignof(*ptr));
>
> That would catch bugs like:
>
> struct bar {
> int ponies;
> int peaches __smp_cacheline_aligned;
> };
>
> struct bar *barp = kmalloc(sizeof(barp, GFP_KERNEL);
>
> Blatantly violating alignment can't be right; either the alignment
> constraints put on the data structures are not important and they should
> be fixed, or we should respect them and fix the allocation, either way,
> we should not silently violate things like we do today.
>
>