Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp776090ybb; Sat, 28 Mar 2020 09:47:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs9WPhgQVdCL5QyZT6S6lfaauf7fej7GTHa8r9j1fkbQTkn4APa4WOOCsXQ2hKEgWwkZCGd X-Received: by 2002:aca:a895:: with SMTP id r143mr2778877oie.150.1585414068114; Sat, 28 Mar 2020 09:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585414068; cv=none; d=google.com; s=arc-20160816; b=PX8UbCRp86gIvu2ne7OMZzgQDyi1X0SfjWJUOTKNv3+vRTIYLZujrSq/p2/q67B0Na VyiJgL06sIqU++ZRUz6Ep1ngOEUMBW3DhknQF6gAwm/q3Yfmzh7y8lseXLL70tysfYIM oaz2WFCyCgZxnFW+Mj6q59chaKbhpD/XVcTqsw6wzoTlxL98fJOSrwMhA7nEdpHIPz6p 2Kza9qx2dnVNzpYAUnMW42pO1GhuZaYsuNio7t51bDiva41SKHFwwtlXFATSmv2ykTGE Z1x7YDlJrbC75TkgmRrePHqwMTCcdOEb02xJVgCPNT6qvnszdPQ7O4RlkFyXqkj0FiWS fKug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:message-id; bh=PsWOctyalPaDBsVaycz7t0V4+lsBDcOCmJykFMzyUJo=; b=Ofqy+EbZMTJAJZzGHyywcwqIWviIHLNOAwfmF2lb6keUoZcso5Wz82WKMeEIO/oEg3 xUGybK2vXcJOiWB7UtthQD73Ycy435suDh8ndlwfX9HwcgIKGAue24tKia6uaBu0wBmu tSxqViA9h5nhTVTUzilvqNfExcVdvh3UlPfLTRb0USr2Hwi8hmxwA5Apqdmp7maxGirt CGEuc8pQ8kxDT3zvN33wxKmW7q4KsEyuvHamAtBKGfpRImQ8EowOlcvvn2xsZG8sJtNs dfkYc1ROpX4K6CXPaMonsaYi3+1+5UKbEI2wQbMnooaN9ay2K7/kKRrevTSKC1LDKcfL gkfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b22si4331160ooe.7.2020.03.28.09.47.35; Sat, 28 Mar 2020 09:47:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727733AbgC1Qpm (ORCPT + 99 others); Sat, 28 Mar 2020 12:45:42 -0400 Received: from mx.sdf.org ([205.166.94.20]:50006 "EHLO mx.sdf.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbgC1Qnd (ORCPT ); Sat, 28 Mar 2020 12:43:33 -0400 Received: from sdf.org (IDENT:lkml@sdf.lonestar.org [205.166.94.16]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 02SGhGdv020471 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sat, 28 Mar 2020 16:43:16 GMT Received: (from lkml@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 02SGhF9R022227; Sat, 28 Mar 2020 16:43:15 GMT Message-Id: <202003281643.02SGhF9R022227@sdf.org> From: George Spelvin Date: Thu, 3 Oct 2019 07:10:40 -0400 Subject: [RFC PATCH v1 23/50] prandom_seed_state(): Change to 32-bit seed type. To: linux-kernel@vger.kernel.org, lkml@sdf.org Cc: Daniel Borkmann , Stephen Hemminger , Hannes Frederic Sowa Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It only uses 32 bits of the seed anyway, and the vast majority of callers pass in 32-bit values. The only exceptions are: * Several self-tests used a fixed seed of 3141592653589793238ULL. Changed to 3141592653. * arch/x86/mm/kaslr.c uses a seed from kaslr_get_random_long(). It's already well-mixed, so truncating it is no worse than the previous xor-folding. (We could use the folded equivalent 32-bit seed for the self-tests, but we just changed the PRNG algorithm, so the self-tests will change across these commits anyway.) Signed-off-by: George Spelvin Cc: Daniel Borkmann Cc: Stephen Hemminger Cc: Hannes Frederic Sowa --- include/linux/random.h | 9 +++------ lib/interval_tree_test.c | 2 +- lib/rbtree_test.c | 2 +- lib/test_bpf.c | 2 +- lib/test_parman.c | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/linux/random.h b/include/linux/random.h index 4a325f5cf298f..7956063253261 100644 --- a/include/linux/random.h +++ b/include/linux/random.h @@ -210,14 +210,11 @@ void prandom_seed_early(struct rnd_state *state, u32 seed, bool); /** * prandom_seed_state - set seed for prandom_u32_state(). * @state: pointer to state structure to receive the seed. - * @seed: arbitrary 64-bit value to use as a seed. - * (only 32 bits are actually used) + * @seed: arbitrary 32-bit value to use as a seed. */ -static inline void prandom_seed_state(struct rnd_state *state, u64 seed) +static inline void prandom_seed_state(struct rnd_state *state, u32 seed) { - u32 i = (seed >> 32) ^ (seed << 10) ^ seed; - - prandom_seed_early(state, i, false); + prandom_seed_early(state, seed, false); } #ifdef CONFIG_ARCH_RANDOM diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index 8c129c8c638b9..149bca1edbf0d 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c @@ -79,7 +79,7 @@ static int interval_tree_test_init(void) printk(KERN_ALERT "interval tree insert/remove"); - prandom_seed_state(&rnd, 3141592653589793238ULL); + prandom_seed_state(&rnd, 3141592653); init(); time1 = get_cycles(); diff --git a/lib/rbtree_test.c b/lib/rbtree_test.c index 41ae3c7570d39..129b653e6d702 100644 --- a/lib/rbtree_test.c +++ b/lib/rbtree_test.c @@ -251,7 +251,7 @@ static int __init rbtree_test_init(void) printk(KERN_ALERT "rbtree testing"); - prandom_seed_state(&rnd, 3141592653589793238ULL); + prandom_seed_state(&rnd, 3141592653); init(); time1 = get_cycles(); diff --git a/lib/test_bpf.c b/lib/test_bpf.c index cecb230833bed..76697e24ee206 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -134,7 +134,7 @@ static int bpf_fill_maxinsns3(struct bpf_test *self) if (!insn) return -ENOMEM; - prandom_seed_state(&rnd, 3141592653589793238ULL); + prandom_seed_state(&rnd, 3141592653); for (i = 0; i < len - 1; i++) { __u32 k = prandom_u32_state(&rnd); diff --git a/lib/test_parman.c b/lib/test_parman.c index 35e32243693c9..9db1fe1b45083 100644 --- a/lib/test_parman.c +++ b/lib/test_parman.c @@ -131,7 +131,7 @@ static const struct parman_ops test_parman_lsort_ops = { static void test_parman_rnd_init(struct test_parman *test_parman) { - prandom_seed_state(&test_parman->rnd, 3141592653589793238ULL); + prandom_seed_state(&test_parman->rnd, 3141592653); } static u32 test_parman_rnd_get(struct test_parman *test_parman) -- 2.26.0