]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0152-x86-stackprotector-Avoid-random-pool-on-rt.patch
rt_patches: required rebase due to printk change
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0152-x86-stackprotector-Avoid-random-pool-on-rt.patch
1 From d67af1e3e3d8d20feeaef3b02c7004a5807bd36b Mon Sep 17 00:00:00 2001
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Thu, 16 Dec 2010 14:25:18 +0100
4 Subject: [PATCH 152/366] x86: stackprotector: Avoid random pool on rt
5
6 CPU bringup calls into the random pool to initialize the stack
7 canary. During boot that works nicely even on RT as the might sleep
8 checks are disabled. During CPU hotplug the might sleep checks
9 trigger. Making the locks in random raw is a major PITA, so avoid the
10 call on RT is the only sensible solution. This is basically the same
11 randomness which we get during boot where the random pool has no
12 entropy and we rely on the TSC randomnness.
13
14 Reported-by: Carsten Emde <carsten.emde@osadl.org>
15 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
16 ---
17  arch/x86/include/asm/stackprotector.h | 9 ++++++++-
18  1 file changed, 8 insertions(+), 1 deletion(-)
19
20 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
21 index 58505f0..02fa396 100644
22 --- a/arch/x86/include/asm/stackprotector.h
23 +++ b/arch/x86/include/asm/stackprotector.h
24 @@ -59,7 +59,7 @@
25   */
26  static __always_inline void boot_init_stack_canary(void)
27  {
28 -       u64 canary;
29 +       u64 uninitialized_var(canary);
30         u64 tsc;
31  
32  #ifdef CONFIG_X86_64
33 @@ -70,8 +70,15 @@ static __always_inline void boot_init_stack_canary(void)
34          * of randomness. The TSC only matters for very early init,
35          * there it already has some randomness on most systems. Later
36          * on during the bootup the random pool has true entropy too.
37 +        *
38 +        * For preempt-rt we need to weaken the randomness a bit, as
39 +        * we can't call into the random generator from atomic context
40 +        * due to locking constraints. We just leave canary
41 +        * uninitialized and use the TSC based randomness on top of it.
42          */
43 +#ifndef CONFIG_PREEMPT_RT_FULL
44         get_random_bytes(&canary, sizeof(canary));
45 +#endif
46         tsc = rdtsc();
47         canary += tsc + (tsc << 32UL);
48  
49 -- 
50 1.9.1
51