diff options
author | Eric Dumazet <edumazet@google.com> | 2012-08-08 17:13:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-08-09 19:17:03 -0400 |
commit | a399a8053164ec8bcb06fed52be9941a26ecde11 (patch) | |
tree | c60402a77d08c82630d63e972d32b038919b827f /net/ipv4 | |
parent | 79cda75a107da0d49732b5cb642b456264dd7e0e (diff) |
time: jiffies_delta_to_clock_t() helper to the rescue
Various /proc/net files sometimes report crazy timer values, expressed
in clock_t units.
This happens when an expired timer delta (expires - jiffies) is passed
to jiffies_to_clock_t().
This function has an overflow in :
return div_u64((u64)x * TICK_NSEC, NSEC_PER_SEC / USER_HZ);
commit cbbc719fccdb8cb (time: Change jiffies_to_clock_t() argument type
to unsigned long) only got around the problem.
As we cant output negative values in /proc/net/tcp without breaking
various tools, I suggest adding a jiffies_delta_to_clock_t() wrapper
that caps the negative delta to a 0 value.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Maciej Żenczykowski <maze@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: hank <pyu@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r-- | net/ipv4/igmp.c | 7 | ||||
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 13 |
2 files changed, 10 insertions, 10 deletions
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 6699f23e6f55..0b5580c69f2d 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -2435,6 +2435,8 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v) | |||
2435 | struct ip_mc_list *im = (struct ip_mc_list *)v; | 2435 | struct ip_mc_list *im = (struct ip_mc_list *)v; |
2436 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); | 2436 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); |
2437 | char *querier; | 2437 | char *querier; |
2438 | long delta; | ||
2439 | |||
2438 | #ifdef CONFIG_IP_MULTICAST | 2440 | #ifdef CONFIG_IP_MULTICAST |
2439 | querier = IGMP_V1_SEEN(state->in_dev) ? "V1" : | 2441 | querier = IGMP_V1_SEEN(state->in_dev) ? "V1" : |
2440 | IGMP_V2_SEEN(state->in_dev) ? "V2" : | 2442 | IGMP_V2_SEEN(state->in_dev) ? "V2" : |
@@ -2448,11 +2450,12 @@ static int igmp_mc_seq_show(struct seq_file *seq, void *v) | |||
2448 | state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); | 2450 | state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); |
2449 | } | 2451 | } |
2450 | 2452 | ||
2453 | delta = im->timer.expires - jiffies; | ||
2451 | seq_printf(seq, | 2454 | seq_printf(seq, |
2452 | "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", | 2455 | "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", |
2453 | im->multiaddr, im->users, | 2456 | im->multiaddr, im->users, |
2454 | im->tm_running, im->tm_running ? | 2457 | im->tm_running, |
2455 | jiffies_to_clock_t(im->timer.expires-jiffies) : 0, | 2458 | im->tm_running ? jiffies_delta_to_clock_t(delta) : 0, |
2456 | im->reporter); | 2459 | im->reporter); |
2457 | } | 2460 | } |
2458 | return 0; | 2461 | return 0; |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 42b2a6a73092..c660d2c19a2b 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -2385,7 +2385,7 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req, | |||
2385 | struct seq_file *f, int i, int uid, int *len) | 2385 | struct seq_file *f, int i, int uid, int *len) |
2386 | { | 2386 | { |
2387 | const struct inet_request_sock *ireq = inet_rsk(req); | 2387 | const struct inet_request_sock *ireq = inet_rsk(req); |
2388 | int ttd = req->expires - jiffies; | 2388 | long delta = req->expires - jiffies; |
2389 | 2389 | ||
2390 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" | 2390 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" |
2391 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n", | 2391 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n", |
@@ -2397,7 +2397,7 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req, | |||
2397 | TCP_SYN_RECV, | 2397 | TCP_SYN_RECV, |
2398 | 0, 0, /* could print option size, but that is af dependent. */ | 2398 | 0, 0, /* could print option size, but that is af dependent. */ |
2399 | 1, /* timers active (only the expire timer) */ | 2399 | 1, /* timers active (only the expire timer) */ |
2400 | jiffies_to_clock_t(ttd), | 2400 | jiffies_delta_to_clock_t(delta), |
2401 | req->retrans, | 2401 | req->retrans, |
2402 | uid, | 2402 | uid, |
2403 | 0, /* non standard timer */ | 2403 | 0, /* non standard timer */ |
@@ -2448,7 +2448,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len) | |||
2448 | tp->write_seq - tp->snd_una, | 2448 | tp->write_seq - tp->snd_una, |
2449 | rx_queue, | 2449 | rx_queue, |
2450 | timer_active, | 2450 | timer_active, |
2451 | jiffies_to_clock_t(timer_expires - jiffies), | 2451 | jiffies_delta_to_clock_t(timer_expires - jiffies), |
2452 | icsk->icsk_retransmits, | 2452 | icsk->icsk_retransmits, |
2453 | sock_i_uid(sk), | 2453 | sock_i_uid(sk), |
2454 | icsk->icsk_probes_out, | 2454 | icsk->icsk_probes_out, |
@@ -2467,10 +2467,7 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw, | |||
2467 | { | 2467 | { |
2468 | __be32 dest, src; | 2468 | __be32 dest, src; |
2469 | __u16 destp, srcp; | 2469 | __u16 destp, srcp; |
2470 | int ttd = tw->tw_ttd - jiffies; | 2470 | long delta = tw->tw_ttd - jiffies; |
2471 | |||
2472 | if (ttd < 0) | ||
2473 | ttd = 0; | ||
2474 | 2471 | ||
2475 | dest = tw->tw_daddr; | 2472 | dest = tw->tw_daddr; |
2476 | src = tw->tw_rcv_saddr; | 2473 | src = tw->tw_rcv_saddr; |
@@ -2480,7 +2477,7 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw, | |||
2480 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" | 2477 | seq_printf(f, "%4d: %08X:%04X %08X:%04X" |
2481 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n", | 2478 | " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n", |
2482 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, | 2479 | i, src, srcp, dest, destp, tw->tw_substate, 0, 0, |
2483 | 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, | 2480 | 3, jiffies_delta_to_clock_t(delta), 0, 0, 0, 0, |
2484 | atomic_read(&tw->tw_refcnt), tw, len); | 2481 | atomic_read(&tw->tw_refcnt), tw, len); |
2485 | } | 2482 | } |
2486 | 2483 | ||