Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp2666086imi; Mon, 25 Jul 2022 05:03:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtWHHyHHNgkAsoXThYuyH8pc2bqoLFAPQRndKPDI6aGe34yFMuKELrxkwzNJn/8/x/CVdS X-Received: by 2002:a05:620a:1459:b0:6b6:5f61:1fdf with SMTP id i25-20020a05620a145900b006b65f611fdfmr2378827qkl.746.1658750629244; Mon, 25 Jul 2022 05:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658750629; cv=none; d=google.com; s=arc-20160816; b=TqLV8gI/qAYZRuHoW+XtCjPJDZNWc+5HeaO0GIzAvSGbYtOK9yHOqOBQDHTr8B+Dhv 7s5fL7DJYHXUPsx/zAinEf2vMU90fo1915Whf97PUiBsXHr0Jea0P0HNXi2O8zhTstKV JAkz+ZSq8mgWrDDeoWSGOC7WTVjyFfmQycoPcoN+33FDwJ9ov1acjKrLWxDsxhCPxJxg 84+9GysLBvSifPb31mt74JRYQtY4CM+KS7pu4t7f2KjcBJ21v4niC1jLDoUG6qTy7Yzv v0UWcwDgUhP/lY6v7y7O3F02EyGajJqspiRAAliiorpmpCpHxBtpjxTgDGOj+SRsYwnt yyVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature; bh=j/9WpKQ5QRClT7V7QGV66k1XiLQwCz29JU6f+PwSms0=; b=lnRYJAt2t/U52//38H/fms9E6IurjUDm2fIEpFdvWiX/1BjBHnX1C4IhZ1G1qg4fur bBnsT0jrAwyj80Ns5yZEuluk1mNIOg6llQOY3emmrjLWXKiTG50eofVFDcGmAjxzObR8 H60G+rj2HNIiT0rcuR7FmK9a/RB2y0GtTETP30HQPH3JidbpbgCrK/c1R9s3kw6Xitkg FNP8TJWKb6wXwccG1/dNvZREBap0+DNo0fM2U4jBP+6o8xIeckJhWYSlFm2S8QvPcFpz G6GnhWiSZt2cEccH8o1a7vf4ZGjSGpOVz3CYL7/VetAqRobf01hR/4EM2fTpd0r949EF zhLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=vi0ewQ2z; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a672201000000b0034bb8362b00si1310438vsi.647.2022.07.25.05.03.31; Mon, 25 Jul 2022 05:03:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=vi0ewQ2z; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235030AbiGYLZn (ORCPT + 99 others); Mon, 25 Jul 2022 07:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234703AbiGYLZj (ORCPT ); Mon, 25 Jul 2022 07:25:39 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E9BD13F9A; Mon, 25 Jul 2022 04:25:38 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0AD2F2005D; Mon, 25 Jul 2022 11:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1658748337; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j/9WpKQ5QRClT7V7QGV66k1XiLQwCz29JU6f+PwSms0=; b=vi0ewQ2zMuHdDXWDXkxY4Z8OFRChESV8dWBtQRzR57H+dvD1TuDR0AbNqSzvb+zyJWnUMi IdY7qN3loqmmaycThy99JASd+S9BRzPI7SlBd7VlYEQz75cz6kzlUfiSFp+Xfwz4x5WZHS NKYjNv+1Fbl7kQy5zoDSpDqmakaB9X0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1658748337; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j/9WpKQ5QRClT7V7QGV66k1XiLQwCz29JU6f+PwSms0=; b=bcug884lC8Iy4aI8HxMtEHjkxobfKamSnFyZxNcVCZlaqgLZUufdinpWxmolPhaC++vbxQ 0xmUfO2USHdIuxBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F0CBD13ABB; Mon, 25 Jul 2022 11:25:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EGvHOrB93mKhRQAAMHmgww (envelope-from ); Mon, 25 Jul 2022 11:25:36 +0000 Date: Mon, 25 Jul 2022 13:25:36 +0200 From: Borislav Petkov To: "Jason A. Donenfeld" Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, x86@kernel.org, Will Deacon , Alexander Gordeev , Thomas Gleixner , "H . Peter Anvin" , Catalin Marinas , Heiko Carstens , Johannes Berg , Mark Rutland , Harald Freudenberger , Michael Ellerman Subject: Re: [PATCH v3] random: handle archrandom with multiple longs Message-ID: References: <20220719130207.147536-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220719130207.147536-1-Jason@zx2c4.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-kernel@vger.kernel.org On Tue, Jul 19, 2022 at 03:02:07PM +0200, Jason A. Donenfeld wrote: > The archrandom interface was originally designed for x86, which supplies > RDRAND/RDSEED for receiving random words into registers, resulting in > one function to generate an int and another to generate a long. However, > other architectures don't follow this. > > On arm64, the SMCCC TRNG interface can return between 1 and 3 longs. On > s390, the CPACF TRNG interface can return arbitrary amounts, with 32 > longs having the same cost as one. On UML, the os_getrandom() interface > can return arbitrary amounts. > > So change the api signature to take a "max_longs" parameter designating > the maximum number of longs requested, and then return the number of > longs generated. > > Since callers need to check this return value and loop anyway, each arch > implementation does not bother implementing its own loop to try again to > fill the maximum number of longs. Additionally, all existing callers > pass in a constant max_longs parameter. Taken together, these two things > mean that the codegen doesn't really change much for one-word-at-a-time > platforms, while performance is greatly improved on platforms such as > s390. > > Cc: Will Deacon > Cc: Alexander Gordeev > Cc: Thomas Gleixner > Cc: H. Peter Anvin > Cc: Catalin Marinas > Cc: Borislav Petkov > Cc: Heiko Carstens > Cc: Johannes Berg > Cc: Mark Rutland > Cc: Harald Freudenberger > Acked-by: Michael Ellerman > Signed-off-by: Jason A. Donenfeld > --- > arch/arm64/include/asm/archrandom.h | 102 ++++++++++++-------------- > arch/arm64/kernel/kaslr.c | 2 +- > arch/powerpc/include/asm/archrandom.h | 30 ++------ > arch/powerpc/kvm/book3s_hv.c | 2 +- > arch/s390/include/asm/archrandom.h | 29 ++------ > arch/um/include/asm/archrandom.h | 21 ++---- > arch/x86/include/asm/archrandom.h | 41 +---------- > arch/x86/kernel/espfix_64.c | 2 +- > drivers/char/random.c | 45 ++++++++---- > include/asm-generic/archrandom.h | 18 +---- > include/linux/random.h | 12 +-- > 11 files changed, 116 insertions(+), 188 deletions(-) Acked-by: Borislav Petkov # for x86 Thx. -- Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH GF: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman (HRB 36809, AG Nürnberg)