[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables
From: |
Stefan Hajnoczi |
Subject: |
Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables |
Date: |
Tue, 26 Oct 2021 14:22:10 +0100 |
On Mon, Oct 25, 2021 at 05:27:29PM -0600, Warner Losh wrote:
> On Mon, Oct 25, 2021 at 10:18 AM Richard Henderson <
> richard.henderson@linaro.org> wrote:
>
> > On 10/25/21 7:07 AM, Stefan Hajnoczi wrote:
> > > This is a preview of how we can solve the coroutines TLS problem.
> > Coroutines
> > > re-entered from another thread sometimes see stale TLS values. This
> > happens
> > > because compilers may cache values across yield points, so a value from
> > the
> > > previous thread will be used when the coroutine is re-entered in another
> > > thread.
> >
> > I'm not thrilled by this, but I guess it does work.
> >
> > It could be worthwhile to add some inline asm instead for specific hosts
> > -- one
> > instruction instead of an out-of-line call.
> >
> >
> > > Serge Guelton developed this technique, see the first patch for details.
> > I'm
> > > submitting it for discussion before I go ahead with a full conversion of
> > the
> > > source tree.
> > >
> > > Todo:
> > > - Convert all uses of __thread
> > > - Extend checkpatch.pl to reject code that uses __thread
> >
> > Absolutely not. *Perhaps* one or two tls variables which are accessible
> > by coroutines,
> > but there are plenty that have absolutely no relation. Especially
> > everything related to
> > user-only execution.
> >
>
> I had the same worry. I'd also worry that the hoops that are jumped through
> for
> coroutines would somehow conflict with the low-level user-only execution
> environment. I mean, it should be fine, but I know I'd be cranky if I traced
> obscure regressions to being forced to use this construct...
I have the opposite worry:
If "safe" TLS variables are opt-in then we'll likely have obscure bugs
when code changes to access a TLS variable that was previously never
accessed from a coroutine. There is no compiler error and no way to
detect this. When it happens debugging it is painful.
That's why I think all __thread variables should be converted.
Stefan
signature.asc
Description: PGP signature
- Re: [RFC 1/2] tls: add macros for coroutine-safe TLS variables, (continued)
Re: [RFC 1/2] tls: add macros for coroutine-safe TLS variables, Richard Henderson, 2021/10/25
[RFC 2/2] util/async: replace __thread with QEMU TLS macros, Stefan Hajnoczi, 2021/10/25
Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Philippe Mathieu-Daudé, 2021/10/25
Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Richard Henderson, 2021/10/25
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Warner Losh, 2021/10/25
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables,
Stefan Hajnoczi <=
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Richard Henderson, 2021/10/26
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Stefan Hajnoczi, 2021/10/26
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Richard Henderson, 2021/10/26
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Thomas Huth, 2021/10/26
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Richard Henderson, 2021/10/26
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Kevin Wolf, 2021/10/27
- Re: [RFC 0/2] tls: add macros for coroutine-safe TLS variables, Stefan Hajnoczi, 2021/10/27