[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YbeOjq20FCdzcK1Q@elver.google.com>
Date: Mon, 13 Dec 2021 19:18:54 +0100
From: Marco Elver <elver@...gle.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>,
Will Deacon <will@...nel.org>,
Boqun Feng <boqun.feng@...il.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
the arch/x86 maintainers <x86@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Kees Cook <keescook@...omium.org>,
Christoph Hellwig <hch@...radead.org>,
Jens Axboe <axboe@...nel.dk>
Subject: Re: [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@...radead.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
Powered by blists - more mailing lists