lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200503125813.GL3762@hirez.programming.kicks-ass.net>
Date:   Sun, 3 May 2020 14:58:13 +0200
From:   Peter Zijlstra <peterz@...radead.org>
To:     Rasmus Villemoes <linux@...musvillemoes.dk>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org, rostedt@...dmis.org,
        mhiramat@...nel.org, bristot@...hat.com, jbaron@...mai.com,
        torvalds@...ux-foundation.org, tglx@...utronix.de,
        mingo@...nel.org, namit@...are.com, hpa@...or.com, luto@...nel.org,
        ard.biesheuvel@...aro.org, jpoimboe@...hat.com,
        pbonzini@...hat.com, mathieu.desnoyers@...icios.com
Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call()

On Sat, May 02, 2020 at 03:08:00PM +0200, Rasmus Villemoes wrote:
> On 01/05/2020 22.29, Peter Zijlstra wrote:
> > Extend the static_call infrastructure to optimize the following common
> > pattern:
> > 
> > 	if (func_ptr)
> > 		func_ptr(args...)
> > 
> > +
> >  #define static_call(name)	__static_call(name)
> > +#define static_cond_call(name)	(void)__static_call(name)
> >  
> > +
> >  #define static_call(name)	__static_call(name)
> > +#define static_cond_call(name)	(void)__static_call(name)
> >  
> 
> > +#define static_cond_call(name)						\
> > +	if (STATIC_CALL_KEY(name).func)					\
> > +		((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
> > +
> 
> This addresses neither the READ_ONCE issue nor the fact that,

> AFAICT,
> the semantics of
> 
>   static_cond_call(foo)(i++)
> 
> will depend on CONFIG_HAVE_STATIC_CALL.

True.

So there is something utterly terrible we can do to address both:


void __static_call_nop(void)
{
}

#define __static_cond_call(name) \
({ \
	void *func = READ_ONCE(STATIC_CALL_KEY(name).func); \
	if (!func) \
		func = &__static_call_nop; \
	(typeof(STATIC_CALL_TRAMP(name))*)func; \
})

#define static_cond_call(name) (void)__static_cond_call(name)


This gets us into Undefined Behaviour territory, but it ought to work.

It adds the READ_ONCE(), and it cures the argument evaluation issue.

> Also, I'd have appreciated being
> cc'ed on new revisions instead of stumbling on it by chance.

Sorry, my bad, I forgot about that :-/. I rushed to repost, and simply
forgot a few things.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ