diff options
author | Theodore Ts'o <tytso@mit.edu> | 2012-07-04 16:19:30 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-08-15 15:04:13 -0400 |
commit | 1edbd889fa5c0343d817ae6fe44ab95870a096b4 (patch) | |
tree | 0da600b6cfae97a78895185200f9284e4fae1d86 | |
parent | efe6c422db90b8303bfaf7fc2131bb2824a06c39 (diff) |
random: add tracepoints for easier debugging and verification
commit 00ce1db1a634746040ace24c09a4e3a7949a3145 upstream.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/char/random.c | 26 | ||||
-rw-r--r-- | include/trace/events/random.h | 134 |
2 files changed, 156 insertions, 4 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index f4dc6d81889..e70701ec3b0 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -266,6 +266,9 @@ | |||
266 | #include <asm/irq_regs.h> | 266 | #include <asm/irq_regs.h> |
267 | #include <asm/io.h> | 267 | #include <asm/io.h> |
268 | 268 | ||
269 | #define CREATE_TRACE_POINTS | ||
270 | #include <trace/events/random.h> | ||
271 | |||
269 | /* | 272 | /* |
270 | * Configuration information | 273 | * Configuration information |
271 | */ | 274 | */ |
@@ -478,8 +481,8 @@ static __u32 const twist_table[8] = { | |||
478 | * it's cheap to do so and helps slightly in the expected case where | 481 | * it's cheap to do so and helps slightly in the expected case where |
479 | * the entropy is concentrated in the low-order bits. | 482 | * the entropy is concentrated in the low-order bits. |
480 | */ | 483 | */ |
481 | static void __mix_pool_bytes(struct entropy_store *r, const void *in, | 484 | static void _mix_pool_bytes(struct entropy_store *r, const void *in, |
482 | int nbytes, __u8 out[64]) | 485 | int nbytes, __u8 out[64]) |
483 | { | 486 | { |
484 | unsigned long i, j, tap1, tap2, tap3, tap4, tap5; | 487 | unsigned long i, j, tap1, tap2, tap3, tap4, tap5; |
485 | int input_rotate; | 488 | int input_rotate; |
@@ -531,13 +534,21 @@ static void __mix_pool_bytes(struct entropy_store *r, const void *in, | |||
531 | ((__u32 *)out)[j] = r->pool[(i - j) & wordmask]; | 534 | ((__u32 *)out)[j] = r->pool[(i - j) & wordmask]; |
532 | } | 535 | } |
533 | 536 | ||
534 | static void mix_pool_bytes(struct entropy_store *r, const void *in, | 537 | static void __mix_pool_bytes(struct entropy_store *r, const void *in, |
535 | int nbytes, __u8 out[64]) | 538 | int nbytes, __u8 out[64]) |
536 | { | 539 | { |
540 | trace_mix_pool_bytes_nolock(r->name, nbytes, _RET_IP_); | ||
541 | _mix_pool_bytes(r, in, nbytes, out); | ||
542 | } | ||
543 | |||
544 | static void mix_pool_bytes(struct entropy_store *r, const void *in, | ||
545 | int nbytes, __u8 out[64]) | ||
546 | { | ||
537 | unsigned long flags; | 547 | unsigned long flags; |
538 | 548 | ||
549 | trace_mix_pool_bytes(r->name, nbytes, _RET_IP_); | ||
539 | spin_lock_irqsave(&r->lock, flags); | 550 | spin_lock_irqsave(&r->lock, flags); |
540 | __mix_pool_bytes(r, in, nbytes, out); | 551 | _mix_pool_bytes(r, in, nbytes, out); |
541 | spin_unlock_irqrestore(&r->lock, flags); | 552 | spin_unlock_irqrestore(&r->lock, flags); |
542 | } | 553 | } |
543 | 554 | ||
@@ -585,6 +596,7 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits) | |||
585 | retry: | 596 | retry: |
586 | entropy_count = orig = ACCESS_ONCE(r->entropy_count); | 597 | entropy_count = orig = ACCESS_ONCE(r->entropy_count); |
587 | entropy_count += nbits; | 598 | entropy_count += nbits; |
599 | |||
588 | if (entropy_count < 0) { | 600 | if (entropy_count < 0) { |
589 | DEBUG_ENT("negative entropy/overflow\n"); | 601 | DEBUG_ENT("negative entropy/overflow\n"); |
590 | entropy_count = 0; | 602 | entropy_count = 0; |
@@ -599,6 +611,9 @@ retry: | |||
599 | r->initialized = 1; | 611 | r->initialized = 1; |
600 | } | 612 | } |
601 | 613 | ||
614 | trace_credit_entropy_bits(r->name, nbits, entropy_count, | ||
615 | r->entropy_total, _RET_IP_); | ||
616 | |||
602 | /* should we wake readers? */ | 617 | /* should we wake readers? */ |
603 | if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) { | 618 | if (r == &input_pool && entropy_count >= random_read_wakeup_thresh) { |
604 | wake_up_interruptible(&random_read_wait); | 619 | wake_up_interruptible(&random_read_wait); |
@@ -971,6 +986,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, | |||
971 | ssize_t ret = 0, i; | 986 | ssize_t ret = 0, i; |
972 | __u8 tmp[EXTRACT_SIZE]; | 987 | __u8 tmp[EXTRACT_SIZE]; |
973 | 988 | ||
989 | trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_); | ||
974 | xfer_secondary_pool(r, nbytes); | 990 | xfer_secondary_pool(r, nbytes); |
975 | nbytes = account(r, nbytes, min, reserved); | 991 | nbytes = account(r, nbytes, min, reserved); |
976 | 992 | ||
@@ -1005,6 +1021,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, | |||
1005 | ssize_t ret = 0, i; | 1021 | ssize_t ret = 0, i; |
1006 | __u8 tmp[EXTRACT_SIZE]; | 1022 | __u8 tmp[EXTRACT_SIZE]; |
1007 | 1023 | ||
1024 | trace_extract_entropy_user(r->name, nbytes, r->entropy_count, _RET_IP_); | ||
1008 | xfer_secondary_pool(r, nbytes); | 1025 | xfer_secondary_pool(r, nbytes); |
1009 | nbytes = account(r, nbytes, 0, 0); | 1026 | nbytes = account(r, nbytes, 0, 0); |
1010 | 1027 | ||
@@ -1062,6 +1079,7 @@ void get_random_bytes_arch(void *buf, int nbytes) | |||
1062 | { | 1079 | { |
1063 | char *p = buf; | 1080 | char *p = buf; |
1064 | 1081 | ||
1082 | trace_get_random_bytes(nbytes, _RET_IP_); | ||
1065 | while (nbytes) { | 1083 | while (nbytes) { |
1066 | unsigned long v; | 1084 | unsigned long v; |
1067 | int chunk = min(nbytes, (int)sizeof(unsigned long)); | 1085 | int chunk = min(nbytes, (int)sizeof(unsigned long)); |
diff --git a/include/trace/events/random.h b/include/trace/events/random.h new file mode 100644 index 00000000000..422df19de73 --- /dev/null +++ b/include/trace/events/random.h | |||
@@ -0,0 +1,134 @@ | |||
1 | #undef TRACE_SYSTEM | ||
2 | #define TRACE_SYSTEM random | ||
3 | |||
4 | #if !defined(_TRACE_RANDOM_H) || defined(TRACE_HEADER_MULTI_READ) | ||
5 | #define _TRACE_RANDOM_H | ||
6 | |||
7 | #include <linux/writeback.h> | ||
8 | #include <linux/tracepoint.h> | ||
9 | |||
10 | DECLARE_EVENT_CLASS(random__mix_pool_bytes, | ||
11 | TP_PROTO(const char *pool_name, int bytes, unsigned long IP), | ||
12 | |||
13 | TP_ARGS(pool_name, bytes, IP), | ||
14 | |||
15 | TP_STRUCT__entry( | ||
16 | __field( const char *, pool_name ) | ||
17 | __field( int, bytes ) | ||
18 | __field(unsigned long, IP ) | ||
19 | ), | ||
20 | |||
21 | TP_fast_assign( | ||
22 | __entry->pool_name = pool_name; | ||
23 | __entry->bytes = bytes; | ||
24 | __entry->IP = IP; | ||
25 | ), | ||
26 | |||
27 | TP_printk("%s pool: bytes %d caller %pF", | ||
28 | __entry->pool_name, __entry->bytes, (void *)__entry->IP) | ||
29 | ); | ||
30 | |||
31 | DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes, | ||
32 | TP_PROTO(const char *pool_name, int bytes, unsigned long IP), | ||
33 | |||
34 | TP_ARGS(pool_name, bytes, IP) | ||
35 | ); | ||
36 | |||
37 | DEFINE_EVENT(random__mix_pool_bytes, mix_pool_bytes_nolock, | ||
38 | TP_PROTO(const char *pool_name, int bytes, unsigned long IP), | ||
39 | |||
40 | TP_ARGS(pool_name, bytes, IP) | ||
41 | ); | ||
42 | |||
43 | TRACE_EVENT(credit_entropy_bits, | ||
44 | TP_PROTO(const char *pool_name, int bits, int entropy_count, | ||
45 | int entropy_total, unsigned long IP), | ||
46 | |||
47 | TP_ARGS(pool_name, bits, entropy_count, entropy_total, IP), | ||
48 | |||
49 | TP_STRUCT__entry( | ||
50 | __field( const char *, pool_name ) | ||
51 | __field( int, bits ) | ||
52 | __field( int, entropy_count ) | ||
53 | __field( int, entropy_total ) | ||
54 | __field(unsigned long, IP ) | ||
55 | ), | ||
56 | |||
57 | TP_fast_assign( | ||
58 | __entry->pool_name = pool_name; | ||
59 | __entry->bits = bits; | ||
60 | __entry->entropy_count = entropy_count; | ||
61 | __entry->entropy_total = entropy_total; | ||
62 | __entry->IP = IP; | ||
63 | ), | ||
64 | |||
65 | TP_printk("%s pool: bits %d entropy_count %d entropy_total %d " | ||
66 | "caller %pF", __entry->pool_name, __entry->bits, | ||
67 | __entry->entropy_count, __entry->entropy_total, | ||
68 | (void *)__entry->IP) | ||
69 | ); | ||
70 | |||
71 | TRACE_EVENT(get_random_bytes, | ||
72 | TP_PROTO(int nbytes, unsigned long IP), | ||
73 | |||
74 | TP_ARGS(nbytes, IP), | ||
75 | |||
76 | TP_STRUCT__entry( | ||
77 | __field( int, nbytes ) | ||
78 | __field(unsigned long, IP ) | ||
79 | ), | ||
80 | |||
81 | TP_fast_assign( | ||
82 | __entry->nbytes = nbytes; | ||
83 | __entry->IP = IP; | ||
84 | ), | ||
85 | |||
86 | TP_printk("nbytes %d caller %pF", __entry->nbytes, (void *)__entry->IP) | ||
87 | ); | ||
88 | |||
89 | DECLARE_EVENT_CLASS(random__extract_entropy, | ||
90 | TP_PROTO(const char *pool_name, int nbytes, int entropy_count, | ||
91 | unsigned long IP), | ||
92 | |||
93 | TP_ARGS(pool_name, nbytes, entropy_count, IP), | ||
94 | |||
95 | TP_STRUCT__entry( | ||
96 | __field( const char *, pool_name ) | ||
97 | __field( int, nbytes ) | ||
98 | __field( int, entropy_count ) | ||
99 | __field(unsigned long, IP ) | ||
100 | ), | ||
101 | |||
102 | TP_fast_assign( | ||
103 | __entry->pool_name = pool_name; | ||
104 | __entry->nbytes = nbytes; | ||
105 | __entry->entropy_count = entropy_count; | ||
106 | __entry->IP = IP; | ||
107 | ), | ||
108 | |||
109 | TP_printk("%s pool: nbytes %d entropy_count %d caller %pF", | ||
110 | __entry->pool_name, __entry->nbytes, __entry->entropy_count, | ||
111 | (void *)__entry->IP) | ||
112 | ); | ||
113 | |||
114 | |||
115 | DEFINE_EVENT(random__extract_entropy, extract_entropy, | ||
116 | TP_PROTO(const char *pool_name, int nbytes, int entropy_count, | ||
117 | unsigned long IP), | ||
118 | |||
119 | TP_ARGS(pool_name, nbytes, entropy_count, IP) | ||
120 | ); | ||
121 | |||
122 | DEFINE_EVENT(random__extract_entropy, extract_entropy_user, | ||
123 | TP_PROTO(const char *pool_name, int nbytes, int entropy_count, | ||
124 | unsigned long IP), | ||
125 | |||
126 | TP_ARGS(pool_name, nbytes, entropy_count, IP) | ||
127 | ); | ||
128 | |||
129 | |||
130 | |||
131 | #endif /* _TRACE_RANDOM_H */ | ||
132 | |||
133 | /* This part must be outside protection */ | ||
134 | #include <trace/define_trace.h> | ||