From patchwork Wed Aug 5 15:53:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 247447 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp684395ilo; Wed, 5 Aug 2020 09:39:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsZwvA5nPrjtKTnB0usVgldZSQqjMWZj6YREkuWlY/uLYvT9SzfL4ZqdQAxlfbW4Ea5hk1 X-Received: by 2002:a17:906:2f17:: with SMTP id v23mr76095eji.343.1596645579524; Wed, 05 Aug 2020 09:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596645579; cv=none; d=google.com; s=arc-20160816; b=EKVMIZPHSZlYco7TaGNrjllt8V4KiX+1k2pn9kn2J50T5a+jEP/EqQ19g4SnPnZ4hs 0E+ZVgRtwbSnPhYCUhXymTBDw3/Eew5COsDyhzsdLcXmqxk9Y9f0u2q9C6imXEXALuN9 zpoa3yMng2UnOaPjmvkBhKGlTJv3j9MUAm1j5k3WFGGF0HkoYOXCVQtqFwHauxE6ixqV hDtQL1/sAchcI6azLEqtr42PHlClqFFcIdhuRv9OOsViOhpiDvYa1PiECt4JJ8dIQWaO T29gtKHeJuRX6eOtvVoYrArvdnEVXFmPf77j13sEwsG9AolZAIvNJHVxiIn5rBlHYXcT bJNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JTmLZY3YaUSQeVTrmJ1iXa5w7QTIY45VHmnwDrPFqcw=; b=puU3wJNNGTc1ryUrOe8WPK5eoUg99kT8i/BSHl4sKcMFLA30PuAfDnRSF2qR+nKM+R jQ/Ug8qQVIoyI+MbS2MYvrWHy3ioTKllk5Awwa1ET4fwN55yKX+JoWNh1MC919g1UbCu wYFHyaonGcLJaWLIkFe2ARFqUY0g7ddwwRDtGM3dRjI80k5eWDyAICHaAD+EsS5XlESC AoQfqPIbznxqaJEeVCyjv9w6blFsYaIHaYEDVVm3/R0keCbhQ18JD9UbXGSzZuaC+CPQ AkxKS0C1B9yX08lGf52Ahx0VyxYXWFIQzW3ZLSlpIEyF0D7H0Jm+M5GMYiMC6IvA/Jhr R7Gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2UfwlHvk; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cn16si1430890edb.505.2020.08.05.09.39.39; Wed, 05 Aug 2020 09:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2UfwlHvk; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727114AbgHEQiy (ORCPT + 15 others); Wed, 5 Aug 2020 12:38:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:50308 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbgHEQgo (ORCPT ); Wed, 5 Aug 2020 12:36:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B30792339F; Wed, 5 Aug 2020 15:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642792; bh=ysS3LGq+470SGw6FYTetlB33DoPN5s8hyLYUhLe+03M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2UfwlHvkookgB6Y2e+b1KMuEgg30sdabQZHiYHQEe2JVaLykjCwTG526jAm4ZymUI XOJbBbSbO7pt6rFjVCjOFd0fro59w03EmlGMNAT32/pdI6/+fpH2Icu7oIGtAy/lKL 51WZYPLX+Kvl4Gmyf2LqR0moaTseHksyBZRxuAf8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Grygorii Strashko , Linus Torvalds Subject: [PATCH 4.19 2/6] ARM: percpu.h: fix build error Date: Wed, 5 Aug 2020 17:53:01 +0200 Message-Id: <20200805153505.599534194@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153505.472594546@linuxfoundation.org> References: <20200805153505.472594546@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Grygorii Strashko commit aa54ea903abb02303bf55855fb51e3fcee135d70 upstream. Fix build error for the case: defined(CONFIG_SMP) && !defined(CONFIG_CPU_V6) config: keystone_defconfig CC arch/arm/kernel/signal.o In file included from ../include/linux/random.h:14, from ../arch/arm/kernel/signal.c:8: ../arch/arm/include/asm/percpu.h: In function ‘__my_cpu_offset’: ../arch/arm/include/asm/percpu.h:29:34: error: ‘current_stack_pointer’ undeclared (first use in this function); did you mean ‘user_stack_pointer’? : "Q" (*(const unsigned long *)current_stack_pointer)); ^~~~~~~~~~~~~~~~~~~~~ user_stack_pointer Fixes: f227e3ec3b5c ("random32: update the net random state on interrupt and activity") Signed-off-by: Grygorii Strashko Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- arch/arm/include/asm/percpu.h | 2 ++ 1 file changed, 2 insertions(+) --- a/arch/arm/include/asm/percpu.h +++ b/arch/arm/include/asm/percpu.h @@ -16,6 +16,8 @@ #ifndef _ASM_ARM_PERCPU_H_ #define _ASM_ARM_PERCPU_H_ +#include + /* * Same as asm-generic/percpu.h, except that we store the per cpu offset * in the TPIDRPRW. TPIDRPRW only exists on V6K and V7 From patchwork Wed Aug 5 15:53:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 266756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03D93C433E0 for ; Wed, 5 Aug 2020 19:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B06A8206F6 for ; Wed, 5 Aug 2020 19:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596655792; bh=gXEwiYtWJrb+EFFUrwnNNz7Jzhi9gU+IQFe3eDUXoAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TRdGYV19jkt50Ug1XJL85T0XhMRIPNjxJfsz6rmVF/eNKGysmUATXbUJqrOgJH9od WvcIEVazWgQRgeVwWkBlU0HnITbDgJ1bK/Uyz9nhMiHf7ZM3+pArgEUE5YE5sdLPfJ jLZQTilLmHyyGXQAF6sn8y24D8qTEwpWR0ZU16vM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727891AbgHET3C (ORCPT ); Wed, 5 Aug 2020 15:29:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:33614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728573AbgHERKf (ORCPT ); Wed, 5 Aug 2020 13:10:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49949233A0; Wed, 5 Aug 2020 15:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642794; bh=gXEwiYtWJrb+EFFUrwnNNz7Jzhi9gU+IQFe3eDUXoAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sZITPTFLCeHQKjrT23J7ffPjt2xFmiIJVVG+6hOb5c75SwVse5FVZHTK9t6BV7xHk PtNBwjnx+BSXWSh0TZiFtZLxTMA5k87EH2HZD8rxQXlYt9yLnqTIRAd+gP0xqu1D+n upkeZLQaryFjLiNAyXbfcEaWxqSADrI8E8J1PDpI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?utf-8?q?Daniel_D=C3=ADaz?= , Kees Cook , Marc Zyngier , Stephen Rothwell , Willy Tarreau , Linus Torvalds Subject: [PATCH 4.19 3/6] random: fix circular include dependency on arm64 after addition of percpu.h Date: Wed, 5 Aug 2020 17:53:02 +0200 Message-Id: <20200805153505.648662836@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153505.472594546@linuxfoundation.org> References: <20200805153505.472594546@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Willy Tarreau commit 1c9df907da83812e4f33b59d3d142c864d9da57f upstream. Daniel Díaz and Kees Cook independently reported that commit f227e3ec3b5c ("random32: update the net random state on interrupt and activity") broke arm64 due to a circular dependency on include files since the addition of percpu.h in random.h. The correct fix would definitely be to move all the prandom32 stuff out of random.h but for backporting, a smaller solution is preferred. This one replaces linux/percpu.h with asm/percpu.h, and this fixes the problem on x86_64, arm64, arm, and mips. Note that moving percpu.h around didn't change anything and that removing it entirely broke differently. When backporting, such options might still be considered if this patch fails to help. [ It turns out that an alternate fix seems to be to just remove the troublesome remove from the arm64 that causes the circular dependency. But we might as well do the whole belt-and-suspenders thing, and minimize inclusion in too. Either will fix the problem, and both are good changes. - Linus ] Reported-by: Daniel Díaz Reported-by: Kees Cook Tested-by: Marc Zyngier Fixes: f227e3ec3b5c Cc: Stephen Rothwell Signed-off-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/random.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/include/linux/random.h +++ b/include/linux/random.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include From patchwork Wed Aug 5 15:53:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 266754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AFFAC433E0 for ; Wed, 5 Aug 2020 20:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E4B82076E for ; Wed, 5 Aug 2020 20:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596657853; bh=h3F50YRu/vJdUAaf8yXaUUqx+mIxdpj9HxIcTXfF7B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=cWcqoTDHu0mgbamZ1BtioEvjJBssrjGXR0NhRnodecUm705PWywCuDL+pfemZCC6N wM3JNuL2RsQm31kBAUA9HNgqCciagMUsUjCCLtEMXQGtYUedCJnQKtRYnmfL4i6BIO eH+DNQ0Hmjbir6Gz6qLzwIYeMdysnsYHbEX3xr9U= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbgHEUD7 (ORCPT ); Wed, 5 Aug 2020 16:03:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:50664 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbgHEQgh (ORCPT ); Wed, 5 Aug 2020 12:36:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DBB22233A2; Wed, 5 Aug 2020 15:53:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642797; bh=h3F50YRu/vJdUAaf8yXaUUqx+mIxdpj9HxIcTXfF7B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEXEy2EwPqjRoexBABNw6w2M8YvntZejUJDXFT196htHUB2EIthsjSeViq3KH0flr 9z2QnW3b7GKefoLyCpY4pVTEG+V0JwuqgNndU7OqgLEkrx8r8pwR2FcFR3ZtlqLe76 sboVOYP5PQGjulFLHNqQg5M1MnxiXJkcFTnRsd6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Rothwell , Emese Revfy , Kees Cook , Willy Tarreau , Linus Torvalds Subject: [PATCH 4.19 4/6] random32: remove net_rand_state from the latent entropy gcc plugin Date: Wed, 5 Aug 2020 17:53:03 +0200 Message-Id: <20200805153505.696556762@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153505.472594546@linuxfoundation.org> References: <20200805153505.472594546@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Linus Torvalds commit 83bdc7275e6206f560d247be856bceba3e1ed8f2 upstream. It turns out that the plugin right now ends up being really unhappy about the change from 'static' to 'extern' storage that happened in commit f227e3ec3b5c ("random32: update the net random state on interrupt and activity"). This is probably a trivial fix for the latent_entropy plugin, but for now, just remove net_rand_state from the list of things the plugin worries about. Reported-by: Stephen Rothwell Cc: Emese Revfy Cc: Kees Cook Cc: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/random.h | 2 +- lib/random32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/include/linux/random.h +++ b/include/linux/random.h @@ -116,7 +116,7 @@ struct rnd_state { __u32 s1, s2, s3, s4; }; -DECLARE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy; +DECLARE_PER_CPU(struct rnd_state, net_rand_state); u32 prandom_u32_state(struct rnd_state *state); void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); --- a/lib/random32.c +++ b/lib/random32.c @@ -48,7 +48,7 @@ static inline void prandom_state_selftes } #endif -DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy; +DEFINE_PER_CPU(struct rnd_state, net_rand_state); /** * prandom_u32_state - seeded pseudo-random number generator. From patchwork Wed Aug 5 15:53:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 266762 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51788C433DF for ; Wed, 5 Aug 2020 16:34:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2790C2245C for ; Wed, 5 Aug 2020 16:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596645285; bh=zApClyEvCppNhat9fuMRUHtb1bwWXZNOK8+1NHVYrR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NpVjJGUFBKBFUpUjtGecFaAYqGmgXJ6v+HWC0YJqRHBhPQ3AWZyZKX5nOiY7tAstY x3MRLLhv2Kw3Ao/GhKuJyaZbPqcfAvv1NYp3DhdOD+0tW26n/h0AkknsVr+R7VzbOD zGJm3qOhaMaiNQII/7dNik6rHlFh2ShkwwMxE4V0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727057AbgHEQen (ORCPT ); Wed, 5 Aug 2020 12:34:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:49790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726878AbgHEQcl (ORCPT ); Wed, 5 Aug 2020 12:32:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 94BB5233A1; Wed, 5 Aug 2020 15:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596642800; bh=zApClyEvCppNhat9fuMRUHtb1bwWXZNOK8+1NHVYrR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yc6XhE5O+wYaD42/Np2rK+8i+BliRalKi7Az/L4f9zntzIQ7vHItDOaqvY/C9EeTP iVUjtd9MGlNLNYQR50EdeR8uEFo9A+amttJgxLg02Cw679GNwDCx/RvMi9tSKdMBpB vi0EBH36s8QKk/aACWEsb4TxEe3Vr96aWz2LGWT4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guenter Roeck , Willy Tarreau , Linus Torvalds Subject: [PATCH 4.19 5/6] random32: move the pseudo-random 32-bit definitions to prandom.h Date: Wed, 5 Aug 2020 17:53:04 +0200 Message-Id: <20200805153505.747319766@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200805153505.472594546@linuxfoundation.org> References: <20200805153505.472594546@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Linus Torvalds commit c0842fbc1b18c7a044e6ff3e8fa78bfa822c7d1a upstream. The addition of percpu.h to the list of includes in random.h revealed some circular dependencies on arm64 and possibly other platforms. This include was added solely for the pseudo-random definitions, which have nothing to do with the rest of the definitions in this file but are still there for legacy reasons. This patch moves the pseudo-random parts to linux/prandom.h and the percpu.h include with it, which is now guarded by _LINUX_PRANDOM_H and protected against recursive inclusion. A further cleanup step would be to remove this from entirely, and make people who use the prandom infrastructure include just the new header file. That's a bit of a churn patch, but grepping for "prandom_" and "next_pseudo_random32" "struct rnd_state" should catch most users. But it turns out that that nice cleanup step is fairly painful, because a _lot_ of code currently seems to depend on the implicit include of , which can currently come in a lot of ways, including such fairly core headfers as . So the "nice cleanup" part may or may never happen. Fixes: 1c9df907da83 ("random: fix circular include dependency on arm64 after addition of percpu.h") Tested-by: Guenter Roeck Acked-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/prandom.h | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/random.h | 66 ++-------------------------------------- 2 files changed, 82 insertions(+), 62 deletions(-) --- /dev/null +++ b/include/linux/prandom.h @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * include/linux/prandom.h + * + * Include file for the fast pseudo-random 32-bit + * generation. + */ +#ifndef _LINUX_PRANDOM_H +#define _LINUX_PRANDOM_H + +#include +#include + +u32 prandom_u32(void); +void prandom_bytes(void *buf, size_t nbytes); +void prandom_seed(u32 seed); +void prandom_reseed_late(void); + +struct rnd_state { + __u32 s1, s2, s3, s4; +}; + +DECLARE_PER_CPU(struct rnd_state, net_rand_state); + +u32 prandom_u32_state(struct rnd_state *state); +void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); +void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state); + +#define prandom_init_once(pcpu_state) \ + DO_ONCE(prandom_seed_full_state, (pcpu_state)) + +/** + * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) + * @ep_ro: right open interval endpoint + * + * Returns a pseudo-random number that is in interval [0, ep_ro). Note + * that the result depends on PRNG being well distributed in [0, ~0U] + * u32 space. Here we use maximally equidistributed combined Tausworthe + * generator, that is, prandom_u32(). This is useful when requesting a + * random index of an array containing ep_ro elements, for example. + * + * Returns: pseudo-random number in interval [0, ep_ro) + */ +static inline u32 prandom_u32_max(u32 ep_ro) +{ + return (u32)(((u64) prandom_u32() * ep_ro) >> 32); +} + +/* + * Handle minimum values for seeds + */ +static inline u32 __seed(u32 x, u32 m) +{ + return (x < m) ? x + m : x; +} + +/** + * 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. + */ +static inline void prandom_seed_state(struct rnd_state *state, u64 seed) +{ + u32 i = (seed >> 32) ^ (seed << 10) ^ seed; + + state->s1 = __seed(i, 2U); + state->s2 = __seed(i, 8U); + state->s3 = __seed(i, 16U); + state->s4 = __seed(i, 128U); +} + +/* Pseudo random number generator from numerical recipes. */ +static inline u32 next_pseudo_random32(u32 seed) +{ + return seed * 1664525 + 1013904223; +} + +#endif --- a/include/linux/random.h +++ b/include/linux/random.h @@ -9,7 +9,6 @@ #include #include -#include #include @@ -107,63 +106,12 @@ declare_get_random_var_wait(long) unsigned long randomize_page(unsigned long start, unsigned long range); -u32 prandom_u32(void); -void prandom_bytes(void *buf, size_t nbytes); -void prandom_seed(u32 seed); -void prandom_reseed_late(void); - -struct rnd_state { - __u32 s1, s2, s3, s4; -}; - -DECLARE_PER_CPU(struct rnd_state, net_rand_state); - -u32 prandom_u32_state(struct rnd_state *state); -void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes); -void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state); - -#define prandom_init_once(pcpu_state) \ - DO_ONCE(prandom_seed_full_state, (pcpu_state)) - -/** - * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro) - * @ep_ro: right open interval endpoint - * - * Returns a pseudo-random number that is in interval [0, ep_ro). Note - * that the result depends on PRNG being well distributed in [0, ~0U] - * u32 space. Here we use maximally equidistributed combined Tausworthe - * generator, that is, prandom_u32(). This is useful when requesting a - * random index of an array containing ep_ro elements, for example. - * - * Returns: pseudo-random number in interval [0, ep_ro) - */ -static inline u32 prandom_u32_max(u32 ep_ro) -{ - return (u32)(((u64) prandom_u32() * ep_ro) >> 32); -} - /* - * Handle minimum values for seeds - */ -static inline u32 __seed(u32 x, u32 m) -{ - return (x < m) ? x + m : x; -} - -/** - * 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. + * This is designed to be standalone for just prandom + * users, but for now we include it from + * for legacy reasons. */ -static inline void prandom_seed_state(struct rnd_state *state, u64 seed) -{ - u32 i = (seed >> 32) ^ (seed << 10) ^ seed; - - state->s1 = __seed(i, 2U); - state->s2 = __seed(i, 8U); - state->s3 = __seed(i, 16U); - state->s4 = __seed(i, 128U); -} +#include #ifdef CONFIG_ARCH_RANDOM # include @@ -194,10 +142,4 @@ static inline bool arch_has_random_seed( } #endif -/* Pseudo random number generator from numerical recipes. */ -static inline u32 next_pseudo_random32(u32 seed) -{ - return seed * 1664525 + 1013904223; -} - #endif /* _LINUX_RANDOM_H */