[PATCH RT 1/8] random: Make it work on rt

2012-10-11 Thread Steven Rostedt
From: Thomas Gleixner 

Delegate the random insertion to the forced threaded interrupt
handler. Store the return IP of the hard interrupt handler in the irq
descriptor and feed it into the random generator as a source of
entropy.

Signed-off-by: Thomas Gleixner 
Cc: stable...@vger.kernel.org
Signed-off-by: Steven Rostedt 
---
 drivers/char/random.c   |   10 ++
 include/linux/irqdesc.h |1 +
 include/linux/random.h  |2 +-
 kernel/irq/handle.c |7 +--
 kernel/irq/manage.c |6 ++
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d38af32..66c8a0f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -767,18 +767,16 @@ EXPORT_SYMBOL_GPL(add_input_randomness);
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness);
 
-void add_interrupt_randomness(int irq, int irq_flags)
+void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
 {
struct entropy_store*r;
struct fast_pool*fast_pool = &__get_cpu_var(irq_randomness);
-   struct pt_regs  *regs = get_irq_regs();
unsigned long   now = jiffies;
__u32   input[4], cycles = get_cycles();
 
input[0] = cycles ^ jiffies;
input[1] = irq;
-   if (regs) {
-   __u64 ip = instruction_pointer(regs);
+   if (ip) {
input[2] = ip;
input[3] = ip >> 32;
}
@@ -792,7 +790,11 @@ void add_interrupt_randomness(int irq, int irq_flags)
fast_pool->last = now;
 
r = nonblocking_pool.initialized ? _pool : _pool;
+#ifndef CONFIG_PREEMPT_RT_FULL
__mix_pool_bytes(r, _pool->pool, sizeof(fast_pool->pool), NULL);
+#else
+   mix_pool_bytes(r, _pool->pool, sizeof(fast_pool->pool), NULL);
+#endif
/*
 * If we don't have a valid cycle counter, and we see
 * back-to-back timer interrupts, then skip giving credit for
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index f1e2527..5f4f091 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -53,6 +53,7 @@ struct irq_desc {
unsigned intirq_count;  /* For detecting broken IRQs */
unsigned long   last_unhandled; /* Aging timer for unhandled 
count */
unsigned intirqs_unhandled;
+   u64 random_ip;
raw_spinlock_t  lock;
struct cpumask  *percpu_enabled;
 #ifdef CONFIG_SMP
diff --git a/include/linux/random.h b/include/linux/random.h
index 29e217a..3995b33 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -53,7 +53,7 @@ extern void rand_initialize_irq(int irq);
 extern void add_device_randomness(const void *, unsigned int);
 extern void add_input_randomness(unsigned int type, unsigned int code,
 unsigned int value);
-extern void add_interrupt_randomness(int irq, int irq_flags);
+extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
 
 extern void get_random_bytes(void *buf, int nbytes);
 extern void get_random_bytes_arch(void *buf, int nbytes);
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index a768885..f6b91bc 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -116,6 +116,8 @@ static void irq_wake_thread(struct irq_desc *desc, struct 
irqaction *action)
 irqreturn_t
 handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
 {
+   struct pt_regs *regs = get_irq_regs();
+   u64 ip = regs ? instruction_pointer(regs) : 0;
irqreturn_t retval = IRQ_NONE;
unsigned int flags = 0, irq = desc->irq_data.irq;
 
@@ -157,8 +159,9 @@ handle_irq_event_percpu(struct irq_desc *desc, struct 
irqaction *action)
} while (action);
 
 #ifndef CONFIG_PREEMPT_RT_FULL
-   /* FIXME: Can we unbreak that ? */
-   add_interrupt_randomness(irq, flags);
+   add_interrupt_randomness(irq, flags, ip);
+#else
+   desc->random_ip = ip;
 #endif
 
if (!noirqdebug)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 87dc053..2204340 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -816,6 +816,12 @@ static int irq_thread(void *data)
action_ret = handler_fn(desc, action);
if (!noirqdebug)
note_interrupt(action->irq, desc, action_ret);
+#ifdef CONFIG_PREEMPT_RT_FULL
+   migrate_disable();
+   add_interrupt_randomness(action->irq, 0,
+desc->random_ip ^ (u64) 
action);
+   migrate_enable();
+#endif
}
 
wake = atomic_dec_and_test(>threads_active);
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  

[PATCH RT 1/8] random: Make it work on rt

2012-10-11 Thread Steven Rostedt
From: Thomas Gleixner t...@linutronix.de

Delegate the random insertion to the forced threaded interrupt
handler. Store the return IP of the hard interrupt handler in the irq
descriptor and feed it into the random generator as a source of
entropy.

Signed-off-by: Thomas Gleixner t...@linutronix.de
Cc: stable...@vger.kernel.org
Signed-off-by: Steven Rostedt rost...@goodmis.org
---
 drivers/char/random.c   |   10 ++
 include/linux/irqdesc.h |1 +
 include/linux/random.h  |2 +-
 kernel/irq/handle.c |7 +--
 kernel/irq/manage.c |6 ++
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index d38af32..66c8a0f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -767,18 +767,16 @@ EXPORT_SYMBOL_GPL(add_input_randomness);
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness);
 
-void add_interrupt_randomness(int irq, int irq_flags)
+void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
 {
struct entropy_store*r;
struct fast_pool*fast_pool = __get_cpu_var(irq_randomness);
-   struct pt_regs  *regs = get_irq_regs();
unsigned long   now = jiffies;
__u32   input[4], cycles = get_cycles();
 
input[0] = cycles ^ jiffies;
input[1] = irq;
-   if (regs) {
-   __u64 ip = instruction_pointer(regs);
+   if (ip) {
input[2] = ip;
input[3] = ip  32;
}
@@ -792,7 +790,11 @@ void add_interrupt_randomness(int irq, int irq_flags)
fast_pool-last = now;
 
r = nonblocking_pool.initialized ? input_pool : nonblocking_pool;
+#ifndef CONFIG_PREEMPT_RT_FULL
__mix_pool_bytes(r, fast_pool-pool, sizeof(fast_pool-pool), NULL);
+#else
+   mix_pool_bytes(r, fast_pool-pool, sizeof(fast_pool-pool), NULL);
+#endif
/*
 * If we don't have a valid cycle counter, and we see
 * back-to-back timer interrupts, then skip giving credit for
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index f1e2527..5f4f091 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -53,6 +53,7 @@ struct irq_desc {
unsigned intirq_count;  /* For detecting broken IRQs */
unsigned long   last_unhandled; /* Aging timer for unhandled 
count */
unsigned intirqs_unhandled;
+   u64 random_ip;
raw_spinlock_t  lock;
struct cpumask  *percpu_enabled;
 #ifdef CONFIG_SMP
diff --git a/include/linux/random.h b/include/linux/random.h
index 29e217a..3995b33 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -53,7 +53,7 @@ extern void rand_initialize_irq(int irq);
 extern void add_device_randomness(const void *, unsigned int);
 extern void add_input_randomness(unsigned int type, unsigned int code,
 unsigned int value);
-extern void add_interrupt_randomness(int irq, int irq_flags);
+extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
 
 extern void get_random_bytes(void *buf, int nbytes);
 extern void get_random_bytes_arch(void *buf, int nbytes);
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index a768885..f6b91bc 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -116,6 +116,8 @@ static void irq_wake_thread(struct irq_desc *desc, struct 
irqaction *action)
 irqreturn_t
 handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
 {
+   struct pt_regs *regs = get_irq_regs();
+   u64 ip = regs ? instruction_pointer(regs) : 0;
irqreturn_t retval = IRQ_NONE;
unsigned int flags = 0, irq = desc-irq_data.irq;
 
@@ -157,8 +159,9 @@ handle_irq_event_percpu(struct irq_desc *desc, struct 
irqaction *action)
} while (action);
 
 #ifndef CONFIG_PREEMPT_RT_FULL
-   /* FIXME: Can we unbreak that ? */
-   add_interrupt_randomness(irq, flags);
+   add_interrupt_randomness(irq, flags, ip);
+#else
+   desc-random_ip = ip;
 #endif
 
if (!noirqdebug)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 87dc053..2204340 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -816,6 +816,12 @@ static int irq_thread(void *data)
action_ret = handler_fn(desc, action);
if (!noirqdebug)
note_interrupt(action-irq, desc, action_ret);
+#ifdef CONFIG_PREEMPT_RT_FULL
+   migrate_disable();
+   add_interrupt_randomness(action-irq, 0,
+desc-random_ip ^ (u64) 
action);
+   migrate_enable();
+#endif
}
 
wake = atomic_dec_and_test(desc-threads_active);
-- 
1.7.10.4


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to 

[PATCH RT 1/8] random: Make it work on rt

2012-10-10 Thread Steven Rostedt
From: Thomas Gleixner 

Delegate the random insertion to the forced threaded interrupt
handler. Store the return IP of the hard interrupt handler in the irq
descriptor and feed it into the random generator as a source of
entropy.

Signed-off-by: Thomas Gleixner 
Cc: stable...@vger.kernel.org
Signed-off-by: Steven Rostedt 
---
 drivers/char/random.c   |   10 ++
 include/linux/irqdesc.h |1 +
 include/linux/random.h  |2 +-
 kernel/irq/handle.c |7 +--
 kernel/irq/manage.c |6 ++
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index feae549..f786798 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -745,18 +745,16 @@ EXPORT_SYMBOL_GPL(add_input_randomness);
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness);
 
-void add_interrupt_randomness(int irq, int irq_flags)
+void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
 {
struct entropy_store*r;
struct fast_pool*fast_pool = &__get_cpu_var(irq_randomness);
-   struct pt_regs  *regs = get_irq_regs();
unsigned long   now = jiffies;
__u32   input[4], cycles = get_cycles();
 
input[0] = cycles ^ jiffies;
input[1] = irq;
-   if (regs) {
-   __u64 ip = instruction_pointer(regs);
+   if (ip) {
input[2] = ip;
input[3] = ip >> 32;
}
@@ -770,7 +768,11 @@ void add_interrupt_randomness(int irq, int irq_flags)
fast_pool->last = now;
 
r = nonblocking_pool.initialized ? _pool : _pool;
+#ifndef CONFIG_PREEMPT_RT_FULL
__mix_pool_bytes(r, _pool->pool, sizeof(fast_pool->pool), NULL);
+#else
+   mix_pool_bytes(r, _pool->pool, sizeof(fast_pool->pool), NULL);
+#endif
/*
 * If we don't have a valid cycle counter, and we see
 * back-to-back timer interrupts, then skip giving credit for
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 9a323d1..5bf5add 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -52,6 +52,7 @@ struct irq_desc {
unsigned intirq_count;  /* For detecting broken IRQs */
unsigned long   last_unhandled; /* Aging timer for unhandled 
count */
unsigned intirqs_unhandled;
+   u64 random_ip;
raw_spinlock_t  lock;
struct cpumask  *percpu_enabled;
 #ifdef CONFIG_SMP
diff --git a/include/linux/random.h b/include/linux/random.h
index ac621ce..9ae01e2 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -51,7 +51,7 @@ struct rnd_state {
 extern void add_device_randomness(const void *, unsigned int);
 extern void add_input_randomness(unsigned int type, unsigned int code,
 unsigned int value);
-extern void add_interrupt_randomness(int irq, int irq_flags);
+extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
 
 extern void get_random_bytes(void *buf, int nbytes);
 extern void get_random_bytes_arch(void *buf, int nbytes);
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index 311c4e6..7f50c55 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -132,6 +132,8 @@ static void irq_wake_thread(struct irq_desc *desc, struct 
irqaction *action)
 irqreturn_t
 handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
 {
+   struct pt_regs *regs = get_irq_regs();
+   u64 ip = regs ? instruction_pointer(regs) : 0;
irqreturn_t retval = IRQ_NONE;
unsigned int flags = 0, irq = desc->irq_data.irq;
 
@@ -173,8 +175,9 @@ handle_irq_event_percpu(struct irq_desc *desc, struct 
irqaction *action)
} while (action);
 
 #ifndef CONFIG_PREEMPT_RT_FULL
-   /* FIXME: Can we unbreak that ? */
-   add_interrupt_randomness(irq, flags);
+   add_interrupt_randomness(irq, flags, ip);
+#else
+   desc->random_ip = ip;
 #endif
 
if (!noirqdebug)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index ede56ac..90bf44a 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -814,6 +814,12 @@ static int irq_thread(void *data)
if (!noirqdebug)
note_interrupt(action->irq, desc, action_ret);
 
+#ifdef CONFIG_PREEMPT_RT_FULL
+   migrate_disable();
+   add_interrupt_randomness(action->irq, 0,
+desc->random_ip ^ (u64) action);
+   migrate_enable();
+#endif
wake_threads_waitq(desc);
}
 
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RT 1/8] random: Make it work on rt

2012-10-10 Thread Steven Rostedt
From: Thomas Gleixner t...@linutronix.de

Delegate the random insertion to the forced threaded interrupt
handler. Store the return IP of the hard interrupt handler in the irq
descriptor and feed it into the random generator as a source of
entropy.

Signed-off-by: Thomas Gleixner t...@linutronix.de
Cc: stable...@vger.kernel.org
Signed-off-by: Steven Rostedt rost...@goodmis.org
---
 drivers/char/random.c   |   10 ++
 include/linux/irqdesc.h |1 +
 include/linux/random.h  |2 +-
 kernel/irq/handle.c |7 +--
 kernel/irq/manage.c |6 ++
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index feae549..f786798 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -745,18 +745,16 @@ EXPORT_SYMBOL_GPL(add_input_randomness);
 
 static DEFINE_PER_CPU(struct fast_pool, irq_randomness);
 
-void add_interrupt_randomness(int irq, int irq_flags)
+void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
 {
struct entropy_store*r;
struct fast_pool*fast_pool = __get_cpu_var(irq_randomness);
-   struct pt_regs  *regs = get_irq_regs();
unsigned long   now = jiffies;
__u32   input[4], cycles = get_cycles();
 
input[0] = cycles ^ jiffies;
input[1] = irq;
-   if (regs) {
-   __u64 ip = instruction_pointer(regs);
+   if (ip) {
input[2] = ip;
input[3] = ip  32;
}
@@ -770,7 +768,11 @@ void add_interrupt_randomness(int irq, int irq_flags)
fast_pool-last = now;
 
r = nonblocking_pool.initialized ? input_pool : nonblocking_pool;
+#ifndef CONFIG_PREEMPT_RT_FULL
__mix_pool_bytes(r, fast_pool-pool, sizeof(fast_pool-pool), NULL);
+#else
+   mix_pool_bytes(r, fast_pool-pool, sizeof(fast_pool-pool), NULL);
+#endif
/*
 * If we don't have a valid cycle counter, and we see
 * back-to-back timer interrupts, then skip giving credit for
diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h
index 9a323d1..5bf5add 100644
--- a/include/linux/irqdesc.h
+++ b/include/linux/irqdesc.h
@@ -52,6 +52,7 @@ struct irq_desc {
unsigned intirq_count;  /* For detecting broken IRQs */
unsigned long   last_unhandled; /* Aging timer for unhandled 
count */
unsigned intirqs_unhandled;
+   u64 random_ip;
raw_spinlock_t  lock;
struct cpumask  *percpu_enabled;
 #ifdef CONFIG_SMP
diff --git a/include/linux/random.h b/include/linux/random.h
index ac621ce..9ae01e2 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -51,7 +51,7 @@ struct rnd_state {
 extern void add_device_randomness(const void *, unsigned int);
 extern void add_input_randomness(unsigned int type, unsigned int code,
 unsigned int value);
-extern void add_interrupt_randomness(int irq, int irq_flags);
+extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
 
 extern void get_random_bytes(void *buf, int nbytes);
 extern void get_random_bytes_arch(void *buf, int nbytes);
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
index 311c4e6..7f50c55 100644
--- a/kernel/irq/handle.c
+++ b/kernel/irq/handle.c
@@ -132,6 +132,8 @@ static void irq_wake_thread(struct irq_desc *desc, struct 
irqaction *action)
 irqreturn_t
 handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
 {
+   struct pt_regs *regs = get_irq_regs();
+   u64 ip = regs ? instruction_pointer(regs) : 0;
irqreturn_t retval = IRQ_NONE;
unsigned int flags = 0, irq = desc-irq_data.irq;
 
@@ -173,8 +175,9 @@ handle_irq_event_percpu(struct irq_desc *desc, struct 
irqaction *action)
} while (action);
 
 #ifndef CONFIG_PREEMPT_RT_FULL
-   /* FIXME: Can we unbreak that ? */
-   add_interrupt_randomness(irq, flags);
+   add_interrupt_randomness(irq, flags, ip);
+#else
+   desc-random_ip = ip;
 #endif
 
if (!noirqdebug)
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index ede56ac..90bf44a 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -814,6 +814,12 @@ static int irq_thread(void *data)
if (!noirqdebug)
note_interrupt(action-irq, desc, action_ret);
 
+#ifdef CONFIG_PREEMPT_RT_FULL
+   migrate_disable();
+   add_interrupt_randomness(action-irq, 0,
+desc-random_ip ^ (u64) action);
+   migrate_enable();
+#endif
wake_threads_waitq(desc);
}
 
-- 
1.7.10.4


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/