Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2942345iog; Mon, 20 Jun 2022 07:59:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tAPLCm7XEFJvrDV3R31H5e+DRK3xq0oYSeIqIjH4j9HZTllyuThJy5o1p0BiTOOUqgiZlv X-Received: by 2002:a17:902:d481:b0:167:770b:67c with SMTP id c1-20020a170902d48100b00167770b067cmr24613402plg.77.1655737147057; Mon, 20 Jun 2022 07:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655737147; cv=none; d=google.com; s=arc-20160816; b=CmBEW8YjvhPJh5w6+T7tpOukranCFuD3QbDL6SgdA+rwjlacln7raIPy1cDhVY9rVv tpAB3/WvgSWMjpogLcc92zO/aFIXJOJ2tY7nTjIf8ZX2gBMJz42J2h4G2xKCgTkz/5/z +GfT8IXqcahiEXYzUnI5aCfdJxnjnB6PN7iSuQVCpI9csmCuYIHAfujdo8dhrKHusRlS UWBOQALzCFTe+sov+0P2cXAAZQJIERs1Pp3HcrFUipDKTXyWkjT5RLuR/OJJiXvK+7ZD gynkh7kUWYus89I6Ookkd1vVksEWWSjaDzvspTrrGQQSopgz+3n+LQtdhfCHcCdO881g gNjw== 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=Ig/boKh/s3BkhpqEmyTTTy/D0HbWmUPfe51JuKwvLOU=; b=gwyJSgLxB3egt59cMcY+zRoa+tf4bXwI9KP3r/8yY/oRM8yIKahVdLMokbfOrRH02A VVDUgcVYev3uJPnCfiDeNl5y5iV1BdkN2NKqWtjDJkliu+6dd2F+Q9E7GsCOsOz6samc QXnUKvrlS4eTe0xf60tfPZI2RXtnK+zTXQtQpvA7VwsFuU0AzTleXWqsFnuruuKsH/B8 G1E1+rrwGeWtT5ek+N7KMl9gpdhEttXrfAoaZ1zRHcS8cQAVfrbB7hS9KgSzC/Rlokhs lxcE+7QxiORSf2ehYlMzJtMLWpyn2sa/EXsRhZvhIu+iubCuY5l1VJYqg+aUrcrCiJst G96w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QdsAwoNV; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020a6548c7000000b0040c9dc657ffsi7198383pgs.225.2022.06.20.07.58.53; Mon, 20 Jun 2022 07:59:07 -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=@linuxfoundation.org header.s=korg header.b=QdsAwoNV; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349177AbiFTNvW (ORCPT + 99 others); Mon, 20 Jun 2022 09:51:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349489AbiFTNsp (ORCPT ); Mon, 20 Jun 2022 09:48:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7BDF38AF; Mon, 20 Jun 2022 06:17:54 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 915636114F; Mon, 20 Jun 2022 13:16:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 830EDC3411B; Mon, 20 Jun 2022 13:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655731017; bh=dYx8PdSREqiQ5TasPNKE71jnKx6CBu7ljjQxcwdD4tw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QdsAwoNVB63Gmr0ikE/NLds+XFDOC3m3YgvEaSdUD6LWr2FFnnKxcYzNMvco3xFj5 9kAlr0vMiMUTVhl/Q9poHk9fZSU6/39MlvQCi0FAtpsifvpkGYGWYadPmnklXP7sSI 8sYJOdAMkPvfbaOfbypgKlmu3MTXDuSkIVm2Vm6c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dominik Brodowski , Theodore Tso , Thomas Gleixner , "Jason A. Donenfeld" Subject: [PATCH 5.4 127/240] random: make random_get_entropy() return an unsigned long Date: Mon, 20 Jun 2022 14:50:28 +0200 Message-Id: <20220620124742.692651357@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620124737.799371052@linuxfoundation.org> References: <20220620124737.799371052@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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-kernel@vger.kernel.org From: "Jason A. Donenfeld" commit b0c3e796f24b588b862b61ce235d3c9417dc8983 upstream. Some implementations were returning type `unsigned long`, while others that fell back to get_cycles() were implicitly returning a `cycles_t` or an untyped constant int literal. That makes for weird and confusing code, and basically all code in the kernel already handled it like it was an `unsigned long`. I recently tried to handle it as the largest type it could be, a `cycles_t`, but doing so doesn't really help with much. Instead let's just make random_get_entropy() return an unsigned long all the time. This also matches the commonly used `arch_get_random_long()` function, so now RDRAND and RDTSC return the same sized integer, which means one can fallback to the other more gracefully. Cc: Dominik Brodowski Cc: Theodore Ts'o Acked-by: Thomas Gleixner Signed-off-by: Jason A. Donenfeld Signed-off-by: Greg Kroah-Hartman --- drivers/char/random.c | 20 +++++++------------- include/linux/timex.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1010,7 +1010,7 @@ int __init rand_initialize(void) */ void add_device_randomness(const void *buf, size_t size) { - cycles_t cycles = random_get_entropy(); + unsigned long cycles = random_get_entropy(); unsigned long flags, now = jiffies; if (crng_init == 0 && size) @@ -1041,8 +1041,7 @@ struct timer_rand_state { */ static void add_timer_randomness(struct timer_rand_state *state, unsigned int num) { - cycles_t cycles = random_get_entropy(); - unsigned long flags, now = jiffies; + unsigned long cycles = random_get_entropy(), now = jiffies, flags; long delta, delta2, delta3; spin_lock_irqsave(&input_pool.lock, flags); @@ -1297,8 +1296,7 @@ static void mix_interrupt_randomness(str void add_interrupt_randomness(int irq) { enum { MIX_INFLIGHT = 1U << 31 }; - cycles_t cycles = random_get_entropy(); - unsigned long now = jiffies; + unsigned long cycles = random_get_entropy(), now = jiffies; struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness); struct pt_regs *regs = get_irq_regs(); unsigned int new_count; @@ -1311,16 +1309,12 @@ void add_interrupt_randomness(int irq) if (cycles == 0) cycles = get_reg(fast_pool, regs); - if (sizeof(cycles) == 8) + if (sizeof(unsigned long) == 8) { irq_data.u64[0] = cycles ^ rol64(now, 32) ^ irq; - else { + irq_data.u64[1] = regs ? instruction_pointer(regs) : _RET_IP_; + } else { irq_data.u32[0] = cycles ^ irq; irq_data.u32[1] = now; - } - - if (sizeof(unsigned long) == 8) - irq_data.u64[1] = regs ? instruction_pointer(regs) : _RET_IP_; - else { irq_data.u32[2] = regs ? instruction_pointer(regs) : _RET_IP_; irq_data.u32[3] = get_reg(fast_pool, regs); } @@ -1367,7 +1361,7 @@ static void entropy_timer(struct timer_l static void try_to_generate_entropy(void) { struct { - cycles_t cycles; + unsigned long cycles; struct timer_list timer; } stack; --- a/include/linux/timex.h +++ b/include/linux/timex.h @@ -75,7 +75,7 @@ * By default we use get_cycles() for this purpose, but individual * architectures may override this in their asm/timex.h header file. */ -#define random_get_entropy() get_cycles() +#define random_get_entropy() ((unsigned long)get_cycles()) #endif /*