* [PATCH net-next 1/2] net: make net_get_random_once irqsave
@ 2013-10-23 11:12 Hannes Frederic Sowa
2013-10-23 18:05 ` [PATCH net-next v2 1/2] net: make net_get_random_once irq safe Hannes Frederic Sowa
2013-10-25 23:04 ` [PATCH net-next 1/2] net: make net_get_random_once irqsave David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Hannes Frederic Sowa @ 2013-10-23 11:12 UTC (permalink / raw)
To: netdev; +Cc: davem, edumazet
I initial build a non-irqsave version of net_get_random_once because I
would liked to have the freedom to defer even the extraction process of
get_random_bytes until the nonblocking pool is fully seeded.
I don't think this is a good idea anymore and thus this patch makes
net_get_random_once irqsave. Now someone using net_get_random_once does
not need to care from where it is called.
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
include/linux/net.h | 1 -
net/core/utils.c | 7 ++++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/net.h b/include/linux/net.h
index aca446b..b292a04 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -250,7 +250,6 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
#define ___NET_RANDOM_STATIC_KEY_INIT STATIC_KEY_INIT_FALSE
#endif /* HAVE_JUMP_LABEL */
-/* BE CAREFUL: this function is not interrupt safe */
#define net_get_random_once(buf, nbytes) \
({ \
bool ___ret = false; \
diff --git a/net/core/utils.c b/net/core/utils.c
index bf09371..2f737bf 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -370,16 +370,17 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key)
{
static DEFINE_SPINLOCK(lock);
+ unsigned long flags;
- spin_lock_bh(&lock);
+ spin_lock_irqsave(&lock, flags);
if (*done) {
- spin_unlock_bh(&lock);
+ spin_unlock_irqrestore(&lock, flags);
return false;
}
get_random_bytes(buf, nbytes);
*done = true;
- spin_unlock_bh(&lock);
+ spin_unlock_irqrestore(&lock, flags);
__net_random_once_disable_jump(done_key);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH net-next v2 1/2] net: make net_get_random_once irq safe
2013-10-23 11:12 [PATCH net-next 1/2] net: make net_get_random_once irqsave Hannes Frederic Sowa
@ 2013-10-23 18:05 ` Hannes Frederic Sowa
2013-10-25 23:04 ` [PATCH net-next 1/2] net: make net_get_random_once irqsave David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Hannes Frederic Sowa @ 2013-10-23 18:05 UTC (permalink / raw)
To: netdev, davem, edumazet
I initial build non irq safe version of net_get_random_once because I
would liked to have the freedom to defer even the extraction process of
get_random_bytes until the nonblocking pool is fully seeded.
I don't think this is a good idea anymore and thus this patch makes
net_get_random_once irq safe. Now someone using net_get_random_once does
not need to care from where it is called.
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
---
v2: Reword the commit message only. It looked horribly.
include/linux/net.h | 1 -
net/core/utils.c | 7 ++++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/net.h b/include/linux/net.h
index aca446b..b292a04 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -250,7 +250,6 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
#define ___NET_RANDOM_STATIC_KEY_INIT STATIC_KEY_INIT_FALSE
#endif /* HAVE_JUMP_LABEL */
-/* BE CAREFUL: this function is not interrupt safe */
#define net_get_random_once(buf, nbytes) \
({ \
bool ___ret = false; \
diff --git a/net/core/utils.c b/net/core/utils.c
index bf09371..2f737bf 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -370,16 +370,17 @@ bool __net_get_random_once(void *buf, int nbytes, bool *done,
struct static_key *done_key)
{
static DEFINE_SPINLOCK(lock);
+ unsigned long flags;
- spin_lock_bh(&lock);
+ spin_lock_irqsave(&lock, flags);
if (*done) {
- spin_unlock_bh(&lock);
+ spin_unlock_irqrestore(&lock, flags);
return false;
}
get_random_bytes(buf, nbytes);
*done = true;
- spin_unlock_bh(&lock);
+ spin_unlock_irqrestore(&lock, flags);
__net_random_once_disable_jump(done_key);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next 1/2] net: make net_get_random_once irqsave
2013-10-23 11:12 [PATCH net-next 1/2] net: make net_get_random_once irqsave Hannes Frederic Sowa
2013-10-23 18:05 ` [PATCH net-next v2 1/2] net: make net_get_random_once irq safe Hannes Frederic Sowa
@ 2013-10-25 23:04 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2013-10-25 23:04 UTC (permalink / raw)
To: hannes; +Cc: netdev, edumazet
From: Hannes Frederic Sowa <hannes@stressinduktion.org>
Date: Wed, 23 Oct 2013 13:12:00 +0200
> I initial build a non-irqsave version of net_get_random_once because I
> would liked to have the freedom to defer even the extraction process of
> get_random_bytes until the nonblocking pool is fully seeded.
>
> I don't think this is a good idea anymore and thus this patch makes
> net_get_random_once irqsave. Now someone using net_get_random_once does
> not need to care from where it is called.
>
> Cc: David S. Miller <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-25 23:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 11:12 [PATCH net-next 1/2] net: make net_get_random_once irqsave Hannes Frederic Sowa
2013-10-23 18:05 ` [PATCH net-next v2 1/2] net: make net_get_random_once irq safe Hannes Frederic Sowa
2013-10-25 23:04 ` [PATCH net-next 1/2] net: make net_get_random_once irqsave 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).