All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] init: call time_init() before rand_initialize()
@ 2022-05-05  0:31 Jason A. Donenfeld
  2022-05-07 19:26 ` Andrew Morton
  2022-05-13 21:18 ` [PATCH] " Stafford Horne
  0 siblings, 2 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-05-05  0:31 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jason A. Donenfeld, Stafford Horne, Andrew Morton

Currently time_init() is called before rand_initialize(), but
rand_initialize() makes use of the timer on various platforms, and
sometimes this timer needs to be initialized by time_init() first. In
order to not return zero, reverse the order of these two calls. The
block doing random initialization was right before time_init() before,
so changing the order shouldn't have any complicated effects.

Cc: Stafford Horne <shorne@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
Andrew - this file has no formal maintainer, but you've signed the most
commits, so I'm CC'ing you. This has some interactions with my
random.git tree, so unless there are objections, I'll queue it up there.
-Jason

 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 98182c3c2c4b..e37ec99cf56d 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1035,6 +1035,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	softirq_init();
 	timekeeping_init();
 	kfence_init();
+	time_init();
 
 	/*
 	 * For best initial stack canary entropy, prepare it after:
@@ -1049,7 +1050,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	add_device_randomness(command_line, strlen(command_line));
 	boot_init_stack_canary();
 
-	time_init();
 	perf_event_init();
 	profile_init();
 	call_function_init();
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: call time_init() before rand_initialize()
  2022-05-05  0:31 [PATCH] init: call time_init() before rand_initialize() Jason A. Donenfeld
@ 2022-05-07 19:26 ` Andrew Morton
  2022-05-07 21:09   ` Jason A. Donenfeld
  2022-05-13 21:18 ` [PATCH] " Stafford Horne
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2022-05-07 19:26 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-kernel, Stafford Horne

On Thu,  5 May 2022 02:31:14 +0200 "Jason A. Donenfeld" <Jason@zx2c4.com> wrote:

> Currently time_init() is called before rand_initialize(), but

You mean "after"!  Changelog was really confusing until I went and
looked at the code.

> rand_initialize() makes use of the timer on various platforms, and
> sometimes this timer needs to be initialized by time_init() first. In
> order to not return zero, 

return zero from what?

> reverse the order of these two calls. The
> block doing random initialization was right before time_init() before,
> so changing the order shouldn't have any complicated effects.

I hope you're right.  Moving these things around tends to fix one thing
and break another.

> Andrew - this file has no formal maintainer, but you've signed the most
> commits, so I'm CC'ing you. This has some interactions with my
> random.git tree, so unless there are objections, I'll queue it up there.

No probs.  Plenty of testing in linux-next, please.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: call time_init() before rand_initialize()
  2022-05-07 19:26 ` Andrew Morton
@ 2022-05-07 21:09   ` Jason A. Donenfeld
  2022-05-08  0:20     ` [PATCH v2] " Jason A. Donenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-05-07 21:09 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Stafford Horne

Hi Andrew,

On Sat, May 07, 2022 at 12:26:53PM -0700, Andrew Morton wrote:
> On Thu,  5 May 2022 02:31:14 +0200 "Jason A. Donenfeld" <Jason@zx2c4.com> wrote:
> 
> > Currently time_init() is called before rand_initialize(), but
> 
> You mean "after"!  Changelog was really confusing until I went and
> looked at the code.

Oh dear, yes. Will fix that.

> 
> > rand_initialize() makes use of the timer on various platforms, and
> > sometimes this timer needs to be initialized by time_init() first. In
> > order to not return zero, 
> 
> return zero from what?

random_get_entropy_fallback(). I'll fix that in the commit message.

> > reverse the order of these two calls. The
> > block doing random initialization was right before time_init() before,
> > so changing the order shouldn't have any complicated effects.
> 
> I hope you're right.  Moving these things around tends to fix one thing
> and break another.

I hope so too. Reading the platform code for every arch I can't see
where breakage would be. Nothing in the time init functions relies on
the rng being available, and actually, the rng is already quasi
functional before the call to rand_initialize(), so I think it should be
good. Nonetheless:

> No probs.  Plenty of testing in linux-next, please.

Exactly this. Plus the CI on build.wireguard.com and such is churning on
it on a variety of different archs.

Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] init: call time_init() before rand_initialize()
  2022-05-07 21:09   ` Jason A. Donenfeld
@ 2022-05-08  0:20     ` Jason A. Donenfeld
  0 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-05-08  0:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jason A. Donenfeld, Andrew Morton, Stafford Horne

Currently time_init() is called after rand_initialize(), but
rand_initialize() makes use of the timer on various platforms, and
sometimes this timer needs to be initialized by time_init() first. In
order for random_get_entropy() to not return zero during early boot when
it's potentially used as an entropy source, reverse the order of these
two calls. The block doing random initialization was right before
time_init() before, so changing the order shouldn't have any complicated
effects.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Stafford Horne <shorne@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
Changes v1->v2:
- Clarified commit message; code remains the same.

This lives in random.git and will be in linux-next for testing.

 init/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/init/main.c b/init/main.c
index 98182c3c2c4b..e37ec99cf56d 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1035,6 +1035,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	softirq_init();
 	timekeeping_init();
 	kfence_init();
+	time_init();
 
 	/*
 	 * For best initial stack canary entropy, prepare it after:
@@ -1049,7 +1050,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
 	add_device_randomness(command_line, strlen(command_line));
 	boot_init_stack_canary();
 
-	time_init();
 	perf_event_init();
 	profile_init();
 	call_function_init();
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] init: call time_init() before rand_initialize()
  2022-05-05  0:31 [PATCH] init: call time_init() before rand_initialize() Jason A. Donenfeld
  2022-05-07 19:26 ` Andrew Morton
@ 2022-05-13 21:18 ` Stafford Horne
  1 sibling, 0 replies; 5+ messages in thread
From: Stafford Horne @ 2022-05-13 21:18 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-kernel, Andrew Morton

On Thu, May 05, 2022 at 02:31:14AM +0200, Jason A. Donenfeld wrote:
> Currently time_init() is called before rand_initialize(), but
> rand_initialize() makes use of the timer on various platforms, and
> sometimes this timer needs to be initialized by time_init() first. In
> order to not return zero, reverse the order of these two calls. The
> block doing random initialization was right before time_init() before,
> so changing the order shouldn't have any complicated effects.
> 
> Cc: Stafford Horne <shorne@gmail.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

I was thinking along the same lines when I looked into the OpenRISC issue
that we fixed discussed here:

 - https://lore.kernel.org/all/Ym27sFdFZEt5QV0i@antec/

Though, I was not sure as to any dependency issues caused by changing the
order.  Having it in -next and testing for a while should be able to
bring out any bug.

As for this patch:

Reviewed-by: Stafford Horne <shorne@gmail.com>

> ---
> Andrew - this file has no formal maintainer, but you've signed the most
> commits, so I'm CC'ing you. This has some interactions with my
> random.git tree, so unless there are objections, I'll queue it up there.
> -Jason
> 
>  init/main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/init/main.c b/init/main.c
> index 98182c3c2c4b..e37ec99cf56d 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -1035,6 +1035,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
>  	softirq_init();
>  	timekeeping_init();
>  	kfence_init();
> +	time_init();
>  
>  	/*
>  	 * For best initial stack canary entropy, prepare it after:
> @@ -1049,7 +1050,6 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
>  	add_device_randomness(command_line, strlen(command_line));
>  	boot_init_stack_canary();
>  
> -	time_init();
>  	perf_event_init();
>  	profile_init();
>  	call_function_init();
> -- 
> 2.35.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-13 21:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05  0:31 [PATCH] init: call time_init() before rand_initialize() Jason A. Donenfeld
2022-05-07 19:26 ` Andrew Morton
2022-05-07 21:09   ` Jason A. Donenfeld
2022-05-08  0:20     ` [PATCH v2] " Jason A. Donenfeld
2022-05-13 21:18 ` [PATCH] " Stafford Horne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.