Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2394648ioo; Sat, 28 May 2022 12:15:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSjdD42V/GQ4PekyDD3cTk3hlLYguXBmlLjK0Jr7/TbP2fVGw24eWJM95MWqnEYYBCEWrU X-Received: by 2002:a17:90b:4d8d:b0:1e0:4cb0:fae2 with SMTP id oj13-20020a17090b4d8d00b001e04cb0fae2mr14499441pjb.27.1653765342825; Sat, 28 May 2022 12:15:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653765342; cv=none; d=google.com; s=arc-20160816; b=P3h/ALsmiwIMMABpizedZbMyY77yUFGTDDme2zVVIFCRCsj3WFvbAJljajUGl+ZeqD WjOLBYX5JgC9cs9emL070EZ2UM4y1D2koD0BJS5v3UuCZMbeL31Q56LTrRzjfcs4g0tf j3PxcpK8rVI3U99/EOheLIJydaxUmq5SdodOo6bW387seFvEcZr2UEVvEkv4lBfCTWsX pCgtgTZ7AW+Tmd9vW11rNpbgjza8yXJTBvgaYBh0RROgPbRjtn49tx3KqT91gJr+5S59 98M23sanElEQ9jMqYrvKMUktAw25hHZjeTvK6KulcZNf6jorx2lmEEJdIQLLjI4kvmeV EzCw== 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:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GBsq33IG7w/nIU2lbNpbZ3GrPr8LsCxxakp6ynYFGX4=; b=vOaP1awepKJmjaoqtT6YtI0UJ1PbF86CX7OQcUjtTlizqt5rmh0WexY+nSpVlsmDE5 35xTdmx/Zxqs25mbfekpUIyysIFqA+xEqGAAb630coujfJyaAa0FPCRt4ehfEsrjtx6K 6zUz+lUg9R7xrKedcRLxExrzIgkzkMgwulbkwkDHgLpUSUK4XANXffSDXmp+SXiBvqxj /ZrTZh+mkGz/Zx27a9rIzYwFQAr+1V5bzwc6t9uXXICR6V9lxraD6UMZTPJd79p1hLjF mDMLqRo2pyk+5jUlq26gzMMkrcX6gtzbbm/vQlaC+3orxG1XzJ7RdkbpzC3m380LBV4B G+9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DYgErvDz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c7-20020a170902d48700b00161f0c3df9esi11645791plg.593.2022.05.28.12.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 May 2022 12:15:42 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DYgErvDz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A0C6F4738C; Sat, 28 May 2022 11:50:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350063AbiE0Iwr (ORCPT + 99 others); Fri, 27 May 2022 04:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350106AbiE0IwG (ORCPT ); Fri, 27 May 2022 04:52:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 335E85BD1C; Fri, 27 May 2022 01:51:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5D460B823DE; Fri, 27 May 2022 08:51:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 880AFC385A9; Fri, 27 May 2022 08:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653641513; bh=Af/mC/zq4tKhaB0LwhH5Vk0R8nnqO8wO9ms7HejQAZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DYgErvDzI/GSAkU76AwWmsPHxlecKcddPLh6xSnE4zqXlCnz50AY3iMhLsWF0KLbO oVmAS0ZIsMIU/iw9kh6LTXVBaNfEnKw/26O9hDde94mg+wpVKqCKHtWjKuML+lApKR 93WkBrOZZpH94VridXM+JaRQ3El1nxMSLxR6sGJs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Arnd Bergmann , "Maciej W. Rozycki" , Thomas Bogendoerfer , "Jason A. Donenfeld" Subject: [PATCH 5.18 13/47] mips: use fallback for random_get_entropy() instead of just c0 random Date: Fri, 27 May 2022 10:49:53 +0200 Message-Id: <20220527084803.459141602@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220527084801.223648383@linuxfoundation.org> References: <20220527084801.223648383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: "Jason A. Donenfeld" commit 1c99c6a7c3c599a68321b01b9ec243215ede5a68 upstream. For situations in which we don't have a c0 counter register available, we've been falling back to reading the c0 "random" register, which is usually bounded by the amount of TLB entries and changes every other cycle or so. This means it wraps extremely often. We can do better by combining this fast-changing counter with a potentially slower-changing counter from random_get_entropy_fallback() in the more significant bits. This commit combines the two, taking into account that the changing bits are in a different bit position depending on the CPU model. In addition, we previously were falling back to 0 for ancient CPUs that Linux does not support anyway; remove that dead path entirely. Cc: Thomas Gleixner Cc: Arnd Bergmann Tested-by: Maciej W. Rozycki Acked-by: Thomas Bogendoerfer Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- arch/mips/include/asm/timex.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) --- a/arch/mips/include/asm/timex.h +++ b/arch/mips/include/asm/timex.h @@ -76,25 +76,24 @@ static inline cycles_t get_cycles(void) else return 0; /* no usable counter */ } +#define get_cycles get_cycles /* * Like get_cycles - but where c0_count is not available we desperately * use c0_random in an attempt to get at least a little bit of entropy. - * - * R6000 and R6000A neither have a count register nor a random register. - * That leaves no entropy source in the CPU itself. */ 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)) + if (can_use_mips_counter(read_c0_prid())) return read_c0_count(); - else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A)) - return read_c0_random(); + + if (cpu_has_3kex) + c0_random = (read_c0_random() >> 8) & 0x3f; else - return 0; /* no usable register */ + c0_random = read_c0_random() & 0x3f; + return (random_get_entropy_fallback() << 6) | (0x3f - c0_random); } #define random_get_entropy random_get_entropy