lkml.org 
[lkml]   [2021]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 8/9] atomic,x86: Alternative atomic_*_overflow() scheme
On Mon, Dec 13, 2021 at 10:11AM -0800, Linus Torvalds wrote:
> On Mon, Dec 13, 2021 at 8:43 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > So Marco was expressing doubt about this exact interface for the
> > atomic_*_overflow() functions, since it's extremely easy to get the
> > whole ATOMIC_OVERFLOW_OFFSET thing wrong.
>
> I missed that discussion (maybe it was on irc? Or maybe I just get too
> much email).
>
> Anyway, my preferred solution would simply be to make the ref-counting
> atomics use a different type.
>
> Voilà, problem solved. You can't really misuse them by mistake,
> because you can't access it by mistake.
>
> Sure, it could be a wrapper around 'atomic_t' on architectures that
> end up using the generic fallback, so it might be as simple as
>
> typedef atomic_t atomic_ref_t;
>
> in some asm-generic implementation, although I suspect that you'd want
> type safety even there, and do
>
> typedef struct { atomic_t atomic_val; } atomic_ref_t;
>
> But then on x86 - and other architectures that might prefer to use
> that offset trick because they have flags - I'm not sure it even makes
> sense to have anything to do with 'atomic_t' at all, since there would
> basically be zero overlap with the regular atomic operations (partly
> due to the offset, but partly simply because the 'ref' operations are
> simply different).
>
> (Wrt naming: I do think this is more about the "ref" part than the
> "overflow" part - thus I'd suggest the "atomic_ref_t" rather than your
> ofl naming).

I'm still genuinely worried about this:

> 2. Yet another potentially larger issue is if some code
> kmalloc()s some structs containing refcount_t, and relies on
> GFP_ZERO (kzalloc()) to initialize their data assuming that a
> freshly initialized refcount_t contains 0.

Even with everything properly wrapped up in atomic_ref_t, it's not going
to prevent mis-initialization via kzalloc() and friends.

I think C won't let us design that misuse out of existence.

Thanks,
-- Marco

\
 
 \ /
  Last update: 2021-12-13 19:19    [W:0.775 / U:0.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site