Re: [PATCH v4 28/39] unwind_user/deferred: Add deferred unwinding interface
From: Peter Zijlstra
Date: Thu Jan 23 2025 - 16:58:34 EST
On Thu, Jan 23, 2025 at 10:30:56AM -0800, Josh Poimboeuf wrote:
> On Thu, Jan 23, 2025 at 09:17:18AM +0100, Peter Zijlstra wrote:
> > On Wed, Jan 22, 2025 at 02:51:27PM -0800, Josh Poimboeuf wrote:
> > > On Wed, Jan 22, 2025 at 03:16:16PM +0100, Peter Zijlstra wrote:
> > > The ctx_ctr is always incremented before calling this, so 0 isn't a
> > > valid cookie.
> >
> > Right, so that's the problem. You're considering 0 an invalid cookie,
> > but ctx_to_cookie(0, 1<<48) will be a 0 cookie.
> >
> > That thing *will* wrap.
>
> Well, yes, after N years of sustained very high syscall activity on CPU
> 0, with stack tracing enabled, in which multiple tracer unwind requests
> happen to occur in the same entry context where ctx_ctr wrapped, one of
> the tracers might get an invalid cookie.
>
> I can double-increment the counter when it's (1UL << 48) - 1). Or use
> some other bit for "cookie valid".
Right, steal one bit from counter and make it always 1. 47 bit wrap
around should be fine.