Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1862590pxb; Sun, 17 Apr 2022 01:22:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2VU5kTKuPW4EHrOHWYX5Gy7vKUkB0qhJ+snuMZptQGcM4qCN9MGEfNgYqaju7byfLi+A4 X-Received: by 2002:a17:907:1b1d:b0:6e4:b5fc:e8e6 with SMTP id mp29-20020a1709071b1d00b006e4b5fce8e6mr4960795ejc.215.1650183765370; Sun, 17 Apr 2022 01:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650183765; cv=none; d=google.com; s=arc-20160816; b=BOIowQL/euGrF5xbgA0PDYMmicnqCqR1hW+Gr4wNcEydyN+uf3dFQNYe9lpfUQ9qcT mp4ldJEvPuR2oWfKbEdi5N0iQFFOnkfir1gUZb7+FHYHupYm5WTWz12MNJ0v726Qz/S7 rYWpQU7GmzWZgQThVsvm30IobsukP5yVjRCTLxFwzHMMiT3vLucDlPFSLegi6Nau5Zp0 QMQ7vanfiCGw74Cmzu4lrNn5JreJx/pMEXfDJmvWg4aKzO0rMWVSX48nDAzJ48/P7Bs9 Y6WqaVnvfwikpx4z5zGX6BcAeoFt4ByvZFxznnYkfOSYUqJxJf+f5mGrWVaXe9Y8qcQK KxCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date; bh=ln+hCvRTzYdSJkoPHk0V+ClX1sRDFXxqnL0Mhy1Hr3k=; b=f5g1bELRw/kX4i8nM/YgC7OZfwrdAuKsFdP5kdBVUFypWDJtNKlMeUr+XXTR9f0KfM /Sdo09XOrOvR/7eVFV9/2A2NzfjU4QjTYYkVWAeiO24eNKC/cvf6zznbiRWUhp2xns0C nW9f6+zjXGWACffymBY7xTREw0gVuPrFmq+pr8Y9uPhewgRvqWyxL+Lel8Hcg9+xvUuS M/xdlZQl4n/HznTYsgGxptq02OS/aDJxh2uVsnTTFkwoqKrGLHHyD1AvSLADKAfXtowH GtBtngeZjU4d1YiwF+H8WEl8AH9YL04NpWpzOzS5zggpxxe2ambFmI9INlNv8wQXiUFh Fdzg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a50d615000000b0041f0ddd61f6si4438279edi.561.2022.04.17.01.22.00; Sun, 17 Apr 2022 01:22:45 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232307AbiDPOr3 (ORCPT + 99 others); Sat, 16 Apr 2022 10:47:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232287AbiDPOr2 (ORCPT ); Sat, 16 Apr 2022 10:47:28 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A6E1516598; Sat, 16 Apr 2022 07:44:55 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id EDBF792009E; Sat, 16 Apr 2022 16:44:53 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id E02D092009C; Sat, 16 Apr 2022 15:44:53 +0100 (BST) Date: Sat, 16 Apr 2022 15:44:53 +0100 (BST) From: "Maciej W. Rozycki" To: "Jason A. Donenfeld" cc: Thomas Bogendoerfer , LKML , Linux Crypto Mailing List , Thomas Gleixner , Arnd Bergmann , Theodore Ts'o , Dominik Brodowski , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Paul Walmsley , Palmer Dabbelt , Albert Ou , "David S . Miller" , Richard Weinberger , Anton Ivanov , Johannes Berg , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Chris Zankel , Max Filippov , John Stultz , Stephen Boyd , Dinh Nguyen , linux-arm-kernel , linux-m68k , "open list:BROADCOM NVRAM DRIVER" , linux-riscv , sparclinux , linux-um@lists.infradead.org, X86 ML , linux-xtensa@linux-xtensa.org Subject: Re: [PATCH v4 04/11] mips: use fallback for random_get_entropy() instead of zero In-Reply-To: Message-ID: References: <20220413115411.21489-1-Jason@zx2c4.com> <20220413115411.21489-5-Jason@zx2c4.com> <20220413122546.GA11860@alpha.franken.de> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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-crypto@vger.kernel.org Hi Jason, > > There are two variants only of the CP0 Random register that we can ever > > encounter, as it's been de-facto standardised in early 1990s already and > > then written down in the MIPSr1 architecture specification ~2000. So I > > think it may make sense to actually handle them both explictitly with > > individual calculations, possibly conditionalised on a CONFIG setting or > > `cpu_has_3kex', because kernels that support the two variants of the MMU > > architecture are mutually incompatible. > > Okay, I can give this a shot, but this certainly isn't my forté. It > may ultimately wind up being simpler for you to just send some code of > what you envision for this, but if I understand your idea correctly, > what you're saying is something like: > > static inline unsigned long random_get_entropy(void) > { > unsigned int prid = read_c0_prid(); > unsigned int imp = prid & PRID_IMP_MASK; > unsigned int c0_random; > > if (can_use_mips_counter(prid)) > return read_c0_count(); > > if (cpu_has_3kex) > c0_random = (read_c0_random() >> 8) & 0x3f; > else > c0_random = read_c0_random() & 0x3f; > return (random_get_entropy_fallback() << 6) | (0x3f - c0_random); > } > > What do you think of that? Some tweak I'm missing? It certainly looks good to me. Do you have a way I could verify how this function performs? If so, then I could put it through my systems as I can cover all the cases handled here. Any improvements I previously discussed can then be made locally in the MIPS port as follow-up changes. > > Isn't it going to be an issue for an entropy source that the distribution > > of values obtained from the CP0 Random bit-field is not even, that is some > > values from the 6-bit range will never appear? > > It's the same situation without inverting the order: instead of some > bits on the top never happening, some bits on the bottom never happen > instead. In general, counters don't form uniform distributions anyway, > since the lower bits change faster, and neither are they independent, > since one sample in large part depends on the previous. This is just > sort of the nature of the beast, and the code that calls > random_get_entropy() deals with this appropriately (by, at the moment, > just hashing all the bits). OK then, thanks for your clarification. Maciej