Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3045814rwb; Wed, 30 Nov 2022 14:40:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4aN2IyDRDhC4xBpUGDfSvNRLYQJg+MTgXo2Ox2jm1cV0pcl+fLpbESEDdGFBjzJyW0M71q X-Received: by 2002:a63:1b52:0:b0:476:cba9:eba4 with SMTP id b18-20020a631b52000000b00476cba9eba4mr41546166pgm.350.1669848024618; Wed, 30 Nov 2022 14:40:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669848024; cv=none; d=google.com; s=arc-20160816; b=mPxHAd9Lbpek+KQIPgsMYVS3qOQdglrWLwuJQ0Ohj5jf/lL8mN+69Ui+0YZLwXactJ u/h4LubVUQaq1ot2aNDRUAAuxuemlIapkYTb8H+7kP+PgfPdj296H1jfQHnu6BGzu8yo tjVV2xA2/slt1h9xg6lY5GLEoQCmhocnxuBHeho5DSDrMaz4sSkCkx7kdxbVWfnK+/mE PRHxLL240xD7cbopJ+VbGy8c4rhwp9Jij8QNaRJlAWO6ka/Bg19UcA4Ivyw0Egu1qTLx XVy85jbiqDsKKcG6aiM36iVTnT8/F7K6F1cOTiVKWcfDFi6UariOHcaK3My4Ynhp7FmW jDQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=f/91FuAQgchGDs/NDm5IkL057Wg/ZNBZPdjPFQuvD+0=; b=cm1gty2Jw36szu/LknuYBoE4u1EvwRKgdSqxiRy+Qz5TIN9NUCyuwR8s/yaXZ9SJB/ LgIIrrirMhngACjHuhVon3HFpgct4+qKbpK14P1+Da0cdpCfmVLtWaNC5ABwygfSnBLs FklvyFXyCSbUnMVkpspn6lHGgjuG9We1i6RDK9oNehm8RDgwDD+Lijp+syx/bW2lxnl5 Oz4/pnVm51qHgX+8e6wxfXBlZ/0tL6/CpXo4cJOzLOE3+YdPsHmAvkw9W8rKnxtV9ltR rvSrh6VCKTRIPasvvDb/3Dol2CK9bfo0QkyWJNJ9g/tBeWVrEK51PXKc9EsgiP+xkbFV BtGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a170902e74300b001897276ce03si2666798plf.489.2022.11.30.14.40.10; Wed, 30 Nov 2022 14:40:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbiK3Wjq convert rfc822-to-8bit (ORCPT + 99 others); Wed, 30 Nov 2022 17:39:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbiK3Wjp (ORCPT ); Wed, 30 Nov 2022 17:39:45 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C00498E593 for ; Wed, 30 Nov 2022 14:39:43 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-50-6YXDDUj9OhOl-PdOYMK1rg-1; Wed, 30 Nov 2022 22:39:39 +0000 X-MC-Unique: 6YXDDUj9OhOl-PdOYMK1rg-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 30 Nov 2022 22:39:38 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.044; Wed, 30 Nov 2022 22:39:38 +0000 From: David Laight To: 'Thomas Gleixner' , "Jason A. Donenfeld" , "linux-kernel@vger.kernel.org" , "patches@lists.linux.dev" CC: "Jason A. Donenfeld" , "linux-crypto@vger.kernel.org" , "linux-api@vger.kernel.org" , "x86@kernel.org" , "Greg Kroah-Hartman" , Adhemerval Zanella Netto , Carlos O'Donell , "Florian Weimer" , Arnd Bergmann , Christian Brauner Subject: RE: [PATCH v10 1/4] random: add vgetrandom_alloc() syscall Thread-Topic: [PATCH v10 1/4] random: add vgetrandom_alloc() syscall Thread-Index: AQHZBD5MKfvjUBqLyk+xAMt8s9EHVq5YDxQQ Date: Wed, 30 Nov 2022 22:39:38 +0000 Message-ID: <310b91f650424d338e56794b8861a088@AcuMS.aculab.com> References: <20221129210639.42233-1-Jason@zx2c4.com> <20221129210639.42233-2-Jason@zx2c4.com> <87cz95v2q2.ffs@tglx> In-Reply-To: <87cz95v2q2.ffs@tglx> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Thomas Gleixner > Sent: 29 November 2022 22:02 > > Jason! > > On Tue, Nov 29 2022 at 22:06, Jason A. Donenfeld wrote: > > + > > +/******************************************************************** > > + * > > + * vDSO support helpers. > > + * > > + * The actual vDSO function is defined over in lib/vdso/getrandom.c, > > + * but this section contains the kernel-mode helpers to support that. > > + * > > + ********************************************************************/ > > + > > +#ifdef CONFIG_VGETRANDOM_ALLOC_SYSCALL > > +/** > > + * vgetrandom_alloc - allocate opaque states for use with vDSO getrandom(). > > + * > > + * @num: on input, a pointer to a suggested hint of how many states to > > + * allocate, and on output the number of states actually allocated. > > + * > > + * @size_per_each: the size of each state allocated, so that the caller can > > + * split up the returned allocation into individual states. > > + * > > + * @flags: currently always zero. > > NIT! > > I personally prefer and ask for it in stuff I maintain: > > * @num: On input, a pointer to a suggested hint of how many states to > * allocate, and on output the number of states actually allocated. > * > * @size_per_each: The size of each state allocated, so that the caller can > * split up the returned allocation into individual states. > * > * @flags: Currently always zero. > > But your turf :) > > > + * > > + * The getrandom() vDSO function in userspace requires an opaque state, which > > + * this function allocates by mapping a certain number of special pages into > > + * the calling process. It takes a hint as to the number of opaque states > > + * desired, and provides the caller with the number of opaque states actually > > + * allocated, the size of each one in bytes, and the address of the first > > + * state. > > make W=1 rightfully complains about: > > > + > > drivers/char/random.c:182: warning: bad line: > > > + * Returns a pointer to the first state in the allocation. > > I have serious doubts that this statement is correct. > > Think about this comment and documentation as a boiler plate for the > mandatory man page for a new syscall (hint...) > > > + * > > + */ > > and W=1 also complains rightfully here: > > > +SYSCALL_DEFINE3(vgetrandom_alloc, unsigned int __user *, num, > > + unsigned int __user *, size_per_each, unsigned int, flags) > > drivers/char/random.c:188: warning: expecting prototype for vgetrandom_alloc(). Prototype was for > sys_vgetrandom_alloc() instead > > > +{ > > diff --git a/include/vdso/getrandom.h b/include/vdso/getrandom.h > > new file mode 100644 > > index 000000000000..5f04c8bf4bd4 > > --- /dev/null > > +++ b/include/vdso/getrandom.h > > @@ -0,0 +1,24 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +/* > > + * Copyright (C) 2022 Jason A. Donenfeld . All Rights Reserved. > > + */ > > + > > +#ifndef _VDSO_GETRANDOM_H > > +#define _VDSO_GETRANDOM_H > > + > > +#include > > + > > +struct vgetrandom_state { > > + union { > > + struct { > > + u8 batch[CHACHA_BLOCK_SIZE * 3 / 2]; > > + u32 key[CHACHA_KEY_SIZE / sizeof(u32)]; > > + }; > > + u8 batch_key[CHACHA_BLOCK_SIZE * 2]; > > + }; > > + unsigned long generation; > > + u8 pos; > > + bool in_use; > > +}; > > Again, please make this properly tabular: > > struct vgetrandom_state { > union { > struct { > u8 batch[CHACHA_BLOCK_SIZE * 3 / 2]; > u32 key[CHACHA_KEY_SIZE / sizeof(u32)]; > }; > u8 batch_key[CHACHA_BLOCK_SIZE * 2]; > }; > unsigned long generation; > u8 pos; > bool in_use; > }; > > Plus some kernel doc which explains what this is about. That structure looks horrid - especially for something shared between entities. The 'unsigned long' should be either u32 or u64. There is 'hidden' padding at the end. If 'pos' is an index into something (longer name would be better) then there is no reason to squeeze the value into 1 byte - it doesn't save anything and might make things bigger. (I think Jason might have blocked my emails, he doesn't like critisicism/feedback.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)