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]
Date:	Thu, 12 May 2016 14:14:52 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Borislav Petkov <bp@...e.de>
Cc:	"H. Peter Anvin" <hpa@...or.com>, Brian Gerst <brgerst@...il.com>,
	x86-ml <x86@...nel.org>, Denys Vlasenko <dvlasenk@...hat.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Dmitry Vyukov <dvyukov@...gle.com>,
	Andi Kleen <andi@...stfloor.org>, zengzhaoxiu@....com,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Kees Cook <keescook@...omium.org>,
	Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>,
	Andy Lutomirski <luto@...capital.net>
Subject: Re: [PATCH -v2] x86/hweight: Get rid of the special calling
 convention

On Thu, May 12, 2016 at 01:57:38PM +0200, Borislav Petkov wrote:
> #ifdef CONFIG_X86_32
> # define PUSH_DX        "pushl %%edx\n\t"
> # define POP_DX         "popl %%edx\n\t"
> #else
> # define PUSH_DX        "pushq %%rdx\n\t"
> # define POP_DX         "popq %%rdx\n\t"
> #endif
> 
> unsigned int __sw_hweight32(unsigned int w)
> {
>         asm volatile(PUSH_DX
>                      "movl %[w], %%edx\n\t"                     /* w -> t */
>                      "shrl %%edx\n\t"                           /* t >> 1 */
>                      "andl $0x55555555, %%edx\n\t"              /* t & 0x55555555 */
>                      "subl %%edx, %[w]\n"                       /* w -= t */
>                      "\n\t"
>                      "movl %[w], %%edx\n\t"                     /* w -> t */
>                      "shrl $2, %[w]\n\t"                        /* w_tmp >> 2 */
>                      "andl $0x33333333, %%edx\n\t"              /* t & 0x33333333 */
>                      "andl $0x33333333, %[w]\n\t"               /* w_tmp & 0x33333333 */
>                      "addl %%edx, %[w]\n"                       /* w = w_tmp + t */
>                      "\n\t"
>                      "movl %[w], %%edx\n\t"                     /* w -> t */
>                      "shrl $4, %%edx\n\t"                       /* t >> 4 */
>                      "addl %%edx, %[w]\n\t"                     /* w_tmp += t */
>                      "andl  $0x0f0f0f0f, %[w]\n\t"              /* w_tmp &= 0x0f0f0f0f */
>                      "imull $0x01010101, %[w], %[w]\n\t"        /* w_tmp *= 0x01010101 */
>                      "shrl $24, %[w]\n\t"                       /* w = w_tmp >> 24 */
>                      POP_DX
>                      : [w] "+r" (w));
> 
>         return w;
> }

But this is a C function, with C calling convention. You're now assuming
GCC doesn't clobber anything with its prologue/epilogue.

I think hpa meant to put it in an .S file and avoid all that.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ