* [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer
@ 2013-11-12 22:45 Daniel Borkmann
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
2013-11-14 21:06 ` [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer David Miller
0 siblings, 2 replies; 6+ messages in thread
From: Daniel Borkmann @ 2013-11-12 22:45 UTC (permalink / raw)
To: davem; +Cc: netdev, Hannes Frederic Sowa
We only call that in functions annotated with __init, so add __init
prefix in prandom_start_seed_timer() as well, so that the kernel can
make use of this hint and we can possibly free up resources after it's
usage. And since it's an internal function rename it to
__prandom_start_seed_timer().
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
lib/random32.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/random32.c b/lib/random32.c
index 82da4f4..4f9d5df 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -222,7 +222,7 @@ static void __prandom_timer(unsigned long dontcare)
add_timer(&seed_timer);
}
-static void prandom_start_seed_timer(void)
+static void __init __prandom_start_seed_timer(void)
{
set_timer_slack(&seed_timer, HZ);
seed_timer.expires = jiffies + 40 * HZ;
@@ -270,7 +270,7 @@ void prandom_reseed_late(void)
static int __init prandom_reseed(void)
{
__prandom_reseed(false);
- prandom_start_seed_timer();
+ __prandom_start_seed_timer();
return 0;
}
late_initcall(prandom_reseed);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer
2013-11-12 22:45 [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer Daniel Borkmann
@ 2013-11-12 22:45 ` Daniel Borkmann
2013-11-12 23:35 ` Stephen Hemminger
2013-11-14 21:07 ` David Miller
2013-11-14 21:06 ` [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer David Miller
1 sibling, 2 replies; 6+ messages in thread
From: Daniel Borkmann @ 2013-11-12 22:45 UTC (permalink / raw)
To: davem; +Cc: netdev, Hannes Frederic Sowa
Use msecs_to_jiffies, for these calculations as different HZ
considerations are taken into account for conversion of the timer
shot, and also it makes the code more readable.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
lib/random32.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/random32.c b/lib/random32.c
index 4f9d5df..1e5b2df 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
static void __prandom_timer(unsigned long dontcare)
{
u32 entropy;
+ unsigned long expires;
get_random_bytes(&entropy, sizeof(entropy));
prandom_seed(entropy);
+
/* reseed every ~60 seconds, in [40 .. 80) interval with slack */
- seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
+ expires = 40 + (prandom_u32() % 40);
+ seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
+
add_timer(&seed_timer);
}
static void __init __prandom_start_seed_timer(void)
{
set_timer_slack(&seed_timer, HZ);
- seed_timer.expires = jiffies + 40 * HZ;
+ seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
add_timer(&seed_timer);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
@ 2013-11-12 23:35 ` Stephen Hemminger
2013-11-12 23:47 ` Hannes Frederic Sowa
2013-11-14 21:07 ` David Miller
1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2013-11-12 23:35 UTC (permalink / raw)
To: Daniel Borkmann; +Cc: davem, netdev, Hannes Frederic Sowa
On Tue, 12 Nov 2013 23:45:42 +0100
Daniel Borkmann <dborkman@redhat.com> wrote:
> Use msecs_to_jiffies, for these calculations as different HZ
> considerations are taken into account for conversion of the timer
> shot, and also it makes the code more readable.
>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> ---
> lib/random32.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/lib/random32.c b/lib/random32.c
> index 4f9d5df..1e5b2df 100644
> --- a/lib/random32.c
> +++ b/lib/random32.c
> @@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
> static void __prandom_timer(unsigned long dontcare)
> {
> u32 entropy;
> + unsigned long expires;
>
> get_random_bytes(&entropy, sizeof(entropy));
> prandom_seed(entropy);
> +
> /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
> - seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
> + expires = 40 + (prandom_u32() % 40);
> + seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
> +
> add_timer(&seed_timer);
> }
>
> static void __init __prandom_start_seed_timer(void)
> {
> set_timer_slack(&seed_timer, HZ);
> - seed_timer.expires = jiffies + 40 * HZ;
> + seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
> add_timer(&seed_timer);
> }
>
Some questions:
1. What is the point of using msecs_to_jiffies? the older code already handled
differing HZ?
2. Why the magic 40-80 sec range? What about platforms with very low entropy
you will end up draining it faster.
3. I prefer using mod_timer rather than setting expires and call add_timer
4. You should also use round_jiffies to save power by making the wakeup on a second
boundary.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer
2013-11-12 23:35 ` Stephen Hemminger
@ 2013-11-12 23:47 ` Hannes Frederic Sowa
0 siblings, 0 replies; 6+ messages in thread
From: Hannes Frederic Sowa @ 2013-11-12 23:47 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Daniel Borkmann, davem, netdev
On Tue, Nov 12, 2013 at 03:35:12PM -0800, Stephen Hemminger wrote:
> On Tue, 12 Nov 2013 23:45:42 +0100
> Daniel Borkmann <dborkman@redhat.com> wrote:
>
> > Use msecs_to_jiffies, for these calculations as different HZ
> > considerations are taken into account for conversion of the timer
> > shot, and also it makes the code more readable.
> >
> > Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> > Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
> > ---
> > lib/random32.c | 8 ++++++--
> > 1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/random32.c b/lib/random32.c
> > index 4f9d5df..1e5b2df 100644
> > --- a/lib/random32.c
> > +++ b/lib/random32.c
> > @@ -214,18 +214,22 @@ static DEFINE_TIMER(seed_timer, __prandom_timer, 0, 0);
> > static void __prandom_timer(unsigned long dontcare)
> > {
> > u32 entropy;
> > + unsigned long expires;
> >
> > get_random_bytes(&entropy, sizeof(entropy));
> > prandom_seed(entropy);
> > +
> > /* reseed every ~60 seconds, in [40 .. 80) interval with slack */
> > - seed_timer.expires = jiffies + (40 * HZ + (prandom_u32() % (40 * HZ)));
> > + expires = 40 + (prandom_u32() % 40);
> > + seed_timer.expires = jiffies + msecs_to_jiffies(expires * MSEC_PER_SEC);
> > +
> > add_timer(&seed_timer);
> > }
> >
> > static void __init __prandom_start_seed_timer(void)
> > {
> > set_timer_slack(&seed_timer, HZ);
> > - seed_timer.expires = jiffies + 40 * HZ;
> > + seed_timer.expires = jiffies + msecs_to_jiffies(40 * MSEC_PER_SEC);
> > add_timer(&seed_timer);
> > }
> >
>
> Some questions:
> 1. What is the point of using msecs_to_jiffies? the older code already handled
> differing HZ?
The change is not that important. It seemed a bit more readable. We could
certainly drop that.
> 2. Why the magic 40-80 sec range? What about platforms with very low entropy
> you will end up draining it faster.
Daniel and me had a discussion about that. I originally had it even lower and
Daniel warned about that. The current window seemd fine to me as we don't want
to have a too big window where one could probe ports if an attacker could find
a bias in the PRNG. Do you have a suggestion?
> 3. I prefer using mod_timer rather than setting expires and call add_timer
I wanted the BUG_ON in add_timer in the code path so we can make sure no
two timers are running concurrently. Would be no problem to change that.
> 4. You should also use round_jiffies to save power by making the wakeup on a second
> boundary.
We already apply slack when initializing the timer:
static void prandom_start_seed_timer(void)
{
set_timer_slack(&seed_timer, HZ);
seed_timer.expires = jiffies + 40 * HZ;
add_timer(&seed_timer);
}
It thus does get rounded by apply_slack in mod_timer.
Greetings,
Hannes
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer
2013-11-12 22:45 [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer Daniel Borkmann
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
@ 2013-11-14 21:06 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2013-11-14 21:06 UTC (permalink / raw)
To: dborkman; +Cc: netdev, hannes
From: Daniel Borkmann <dborkman@redhat.com>
Date: Tue, 12 Nov 2013 23:45:41 +0100
> We only call that in functions annotated with __init, so add __init
> prefix in prandom_start_seed_timer() as well, so that the kernel can
> make use of this hint and we can possibly free up resources after it's
> usage. And since it's an internal function rename it to
> __prandom_start_seed_timer().
>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
2013-11-12 23:35 ` Stephen Hemminger
@ 2013-11-14 21:07 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2013-11-14 21:07 UTC (permalink / raw)
To: dborkman; +Cc: netdev, hannes
From: Daniel Borkmann <dborkman@redhat.com>
Date: Tue, 12 Nov 2013 23:45:42 +0100
> Use msecs_to_jiffies, for these calculations as different HZ
> considerations are taken into account for conversion of the timer
> shot, and also it makes the code more readable.
>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-11-14 21:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-12 22:45 [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer Daniel Borkmann
2013-11-12 22:45 ` [PATCH 2/2] random32: use msecs_to_jiffies for reseed timer Daniel Borkmann
2013-11-12 23:35 ` Stephen Hemminger
2013-11-12 23:47 ` Hannes Frederic Sowa
2013-11-14 21:07 ` David Miller
2013-11-14 21:06 ` [PATCH 1/2] random32: add __init prefix to prandom_start_seed_timer David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).