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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200506180924.tdn3zc7a3yte7kvv@treble>
Date:   Wed, 6 May 2020 13:09:24 -0500
From:   Josh Poimboeuf <jpoimboe@...hat.com>
To:     Peter Zijlstra <peterz@...radead.org>
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, pbonzini@...hat.com,
        mathieu.desnoyers@...icios.com
Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call()

On Wed, May 06, 2020 at 07:58:52PM +0200, Peter Zijlstra wrote:
> On Wed, May 06, 2020 at 12:24:55PM -0500, Josh Poimboeuf wrote:
> > On Fri, May 01, 2020 at 10:29:03PM +0200, Peter Zijlstra wrote:
> > > +++ b/arch/x86/include/asm/static_call.h
> > > @@ -30,4 +30,14 @@
> > >  	    ".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \
> > >  	    ".popsection					\n")
> > >  
> > > +#define ARCH_DEFINE_STATIC_CALL_RETTRAMP(name)				\
> > > +	asm(".pushsection .static_call.text, \"ax\"		\n"	\
> > > +	    ".align 4						\n"	\
> > > +	    ".globl " STATIC_CALL_TRAMP_STR(name) "		\n"	\
> > > +	    STATIC_CALL_TRAMP_STR(name) ":			\n"	\
> > > +	    "	ret; nop; nop; nop; nop;			\n"	\
> > > +	    ".type " STATIC_CALL_TRAMP_STR(name) ", @function	\n"	\
> > > +	    ".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \
> > > +	    ".popsection					\n")
> > > +
> > 
> > The boilerplate in these two trampoline macros is identical except for
> > the actual instructions, maybe there could be a shared
> > __ARCH_DEFINE_STATIC_CALL_TRAMP(name, insns) macro which does most of
> > the dirty work.
> 
> I'm afraid that'll just make it less readable :/

#define __ARCH_DEFINE_STATIC_CALL_TRAMP(name, insns)			\
	asm(".pushsection .static_call.text, \"ax\"		\n"	\
	    ".align 4						\n"	\
	    ".globl " STATIC_CALL_TRAMP_STR(name) "		\n"	\
	    STATIC_CALL_TRAMP_STR(name) ":			\n"	\
	    insns "						\n"	\
	    ".type " STATIC_CALL_TRAMP_STR(name) ", @function	\n"	\
	    ".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \
	    ".popsection					\n")

#define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func)			\
	__ARCH_DEFINE_STATIC_CALL_TRAMP(name, "jmp.d32 " # func)

#define ARCH_DEFINE_STATIC_CALL_RETTRAMP(name, func)			\
	__ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; nop; nop; nop; nop")

I like it.  Makes it easy to see the differences between the tramps.

> > >  #endif /* _ASM_STATIC_CALL_H */
> > > --- a/arch/x86/kernel/static_call.c
> > > +++ b/arch/x86/kernel/static_call.c
> > > @@ -4,19 +4,41 @@
> > >  #include <linux/bug.h>
> > >  #include <asm/text-patching.h>
> > >  
> > > -static void __static_call_transform(void *insn, u8 opcode, void *func)
> > > +enum insn_type {
> > > +	call = 0, /* site call */
> > > +	nop = 1,  /* site cond-call */
> > > +	jmp = 2,  /* tramp / site tail-call */
> > > +	ret = 3,  /* tramp / site cond-tail-call */
> > > +};
> > 
> > The lowercase enums threw me for a loop, I thought they were variables a
> > few times.  Starting a new enum trend? :-)
> 
> I can UPPERCASE them I suppose, not sure where this came from.

Just thought UPPERCASE was the standard... lowercase looks confusingly
like variables when referenced.

-- 
Josh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ