lkml.org 
[lkml]   [2023]   [Jan]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v13 7/7] x86: vdso: Wire up getrandom() vDSO implementation
On Wed, Dec 21, 2022 at 03:27:04PM -0800, Eric Biggers wrote:
> On Wed, Dec 21, 2022 at 03:23:27PM +0100, Jason A. Donenfeld wrote:
> > diff --git a/arch/x86/entry/vdso/vgetrandom-chacha.S b/arch/x86/entry/vdso/vgetrandom-chacha.S
> > new file mode 100644
> > index 000000000000..91fbb7ac7af4
> > --- /dev/null
> > +++ b/arch/x86/entry/vdso/vgetrandom-chacha.S
> > @@ -0,0 +1,177 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (C) 2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
> > + */
> > +
> > +#include <linux/linkage.h>
> > +#include <asm/frame.h>
> > +
> > +.section .rodata.cst16.CONSTANTS, "aM", @progbits, 16
> > +.align 16
> > +CONSTANTS: .octa 0x6b20657479622d323320646e61707865
> > +.text
>
> For simplicity, maybe leave off the section mergeability stuff and just have
> plain ".section .rodata"?

I guess nothing is going to get merged anyway, so sure, why not.

> It would be worth mentioning in the function comment that none of the xmm
> registers are callee-save. That was not obvious to me. I know that on arm64,
> *kernel* code doesn't need to save/restore NEON registers, so it's not something
> that arch/arm64/crypto/ does. But, it *is* needed in arm64 userspace code. So
> I was worried that something similar would apply to x86_64, but it seems not.

I'll add a comment.

>
> > + /* state1[0,1,2,3] = state1[0,3,2,1] */
> > + pshufd $0x39,state1,state1
> > + /* state2[0,1,2,3] = state2[1,0,3,2] */
> > + pshufd $0x4e,state2,state2
> > + /* state3[0,1,2,3] = state3[2,1,0,3] */
> > + pshufd $0x93,state3,state3
>
> The comments don't match the pshufd constants. The code is correct but the
> comments are not. They should be:

Er, I swapped the endian when writing the comment. The code is fine
though, yea. Fixed, thanks.

> The above sequence of 24 instructions is repeated twice, so maybe it should be a
> macro (".chacha_round"?).

Not really a fan of the indirection when reading for something simple
like this.

Thanks for the review.

Jason

\
 
 \ /
  Last update: 2023-03-26 23:24    [W:0.065 / U:1.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site