netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: Simplify skb_tx_hash()
@ 2009-02-18  5:32 Krishna Kumar
  2009-02-18  6:53 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Krishna Kumar @ 2009-02-18  5:32 UTC (permalink / raw)
  To: netdev; +Cc: davem, Krishna Kumar

From: Krishna Kumar <krkumar2@in.ibm.com>

The initialization of skb_tx_hashrnd is moved so that it gets called
after "random" driver is initialized. Random numbers generated at this
point are different across 3 immediate reboots:
	(reboot1) Random number: 0xd52f08b6
	(reboot2) Random number: 0x8beeef46
	(reboot3) Random number: 0x7d60a4b6

Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>
---

 net/core/dev.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff -ruNp net-next-2.6.org/net/core/dev.c net-next-2.6.new/net/core/dev.c
--- net-next-2.6.org/net/core/dev.c	2009-02-17 18:57:15.000000000 +0530
+++ net-next-2.6.new/net/core/dev.c	2009-02-17 19:00:23.000000000 +0530
@@ -1745,17 +1745,11 @@ out_kfree_skb:
 }
 
 static u32 skb_tx_hashrnd;
-static int skb_tx_hashrnd_initialized = 0;
 
 static u16 skb_tx_hash(struct net_device *dev, struct sk_buff *skb)
 {
 	u32 hash;
 
-	if (unlikely(!skb_tx_hashrnd_initialized)) {
-		get_random_bytes(&skb_tx_hashrnd, 4);
-		skb_tx_hashrnd_initialized = 1;
-	}
-
 	if (skb_rx_queue_recorded(skb)) {
 		hash = skb_get_rx_queue(skb);
 	} else if (skb->sk && skb->sk->sk_hash) {
@@ -5291,6 +5285,14 @@ out:
 
 subsys_initcall(net_dev_init);
 
+static int __init initialize_hashrnd(void)
+{
+	get_random_bytes(&skb_tx_hashrnd, sizeof(skb_tx_hashrnd));
+	return 0;
+}
+
+late_initcall_sync(initialize_hashrnd);
+
 EXPORT_SYMBOL(__dev_get_by_index);
 EXPORT_SYMBOL(__dev_get_by_name);
 EXPORT_SYMBOL(__dev_remove_pack);

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

* Re: [PATCH] net: Simplify skb_tx_hash()
  2009-02-18  5:32 [PATCH] net: Simplify skb_tx_hash() Krishna Kumar
@ 2009-02-18  6:53 ` David Miller
  2009-02-18  7:27   ` Krishna Kumar2
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2009-02-18  6:53 UTC (permalink / raw)
  To: krkumar2; +Cc: netdev

From: Krishna Kumar <krkumar2@in.ibm.com>
Date: Wed, 18 Feb 2009 11:02:11 +0530

> From: Krishna Kumar <krkumar2@in.ibm.com>
> 
> The initialization of skb_tx_hashrnd is moved so that it gets called
> after "random" driver is initialized. Random numbers generated at this
> point are different across 3 immediate reboots:
> 	(reboot1) Random number: 0xd52f08b6
> 	(reboot2) Random number: 0x8beeef46
> 	(reboot3) Random number: 0x7d60a4b6
> 
> Signed-off-by: Krishna Kumar <krkumar2@in.ibm.com>

Well, two questions:

1) How in the world are you getting a packet transmitted
   before the random driver initializes?

2) How can an initcall be more random than when the first
   packet is transmitted by the system?

A patch like this needs justification, so in your commit
logs you shouldn't just list out mechanically what your
patch is doing, but rather explain "why".

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

* Re: [PATCH] net: Simplify skb_tx_hash()
  2009-02-18  6:53 ` David Miller
@ 2009-02-18  7:27   ` Krishna Kumar2
  2009-02-18  7:41     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Krishna Kumar2 @ 2009-02-18  7:27 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Hi Dave,

> David Miller <davem@davemloft.net>
> 1) How in the world are you getting a packet transmitted
>    before the random driver initializes?

(I am not sure I understood the question) Since the device is
activated after late_initcalls startup sequence (during /etc/rc
stage), no packets should get sent out before that. In any case,
packets can be sent out earlier since skb_tx_hashrnd is set to 0.

> 2) How can an initcall be more random than when the first
>    packet is transmitted by the system?

initcall doesn't give more random, sorry if my mail suggested that any
where. I merely mentioned that the numbers generated at this stage are
different at 3 successive boots (as is the case for the existing code)
and hence is not broken by giving the same random numbers at each boot.

> A patch like this needs justification, so in your commit
> logs you shouldn't just list out mechanically what your
> patch is doing, but rather explain "why".

Please let me know if I should give a better text for justification?

Thanks,

- KK


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

* Re: [PATCH] net: Simplify skb_tx_hash()
  2009-02-18  7:27   ` Krishna Kumar2
@ 2009-02-18  7:41     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2009-02-18  7:41 UTC (permalink / raw)
  To: krkumar2; +Cc: netdev

From: Krishna Kumar2 <krkumar2@in.ibm.com>
Date: Wed, 18 Feb 2009 12:57:23 +0530

> > David Miller <davem@davemloft.net>
> > A patch like this needs justification, so in your commit
> > logs you shouldn't just list out mechanically what your
> > patch is doing, but rather explain "why".
> 
> Please let me know if I should give a better text for justification?

Even after reading all of this I still don't understand why
you're making the change.

Is it to eliminate the comparison every packet in skb_tx_hash()?

If so, say that in the commit message so nobody has to
guess.  Saying just "simplify" doesn't express that at all.


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

end of thread, other threads:[~2009-02-18  7:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-18  5:32 [PATCH] net: Simplify skb_tx_hash() Krishna Kumar
2009-02-18  6:53 ` David Miller
2009-02-18  7:27   ` Krishna Kumar2
2009-02-18  7:41     ` 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).