Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/udelay: make udelay have busy loop semantics

When using systemtap it was observed that our udelay implementation is
rather suboptimal if being called from a kprobe handler installed by
systemtap.

The problem observed when a kprobe was installed on lock_acquired().
When the probe was hit the kprobe handler did call udelay, which set
up an (internal) timer and reenabled interrupts (only the clock comparator
interrupt) and waited for the interrupt.
This is an optimization to avoid that the cpu is busy looping while waiting
that enough time passes. The problem is that the interrupt handler still
does call irq_enter()/irq_exit() which then again can lead to a deadlock,
since some accounting functions may take locks as well.

If one of these locks is the same, which caused lock_acquired() to be
called, we have a nice deadlock.

This patch reworks the udelay code for the interrupts disabled case to
immediately leave the low level interrupt handler when the clock
comparator interrupt happens. That way no C code is being called and the
deadlock cannot happen anymore.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Reviewed-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Heiko Carstens and committed by
Martin Schwidefsky
db7e007f 0c5a69f4

+35 -17
+2
arch/s390/include/asm/idle.h
··· 24 24 extern struct device_attribute dev_attr_idle_count; 25 25 extern struct device_attribute dev_attr_idle_time_us; 26 26 27 + void psw_idle(struct s390_idle_data *, unsigned long); 28 + 27 29 #endif /* _S390_IDLE_H */
+13
arch/s390/include/asm/irq.h
··· 96 96 IRQ_SUBCLASS_SERVICE_SIGNAL = 9, 97 97 }; 98 98 99 + #define CR0_IRQ_SUBCLASS_MASK \ 100 + ((1UL << (63 - 30)) /* Warning Track */ | \ 101 + (1UL << (63 - 48)) /* Malfunction Alert */ | \ 102 + (1UL << (63 - 49)) /* Emergency Signal */ | \ 103 + (1UL << (63 - 50)) /* External Call */ | \ 104 + (1UL << (63 - 52)) /* Clock Comparator */ | \ 105 + (1UL << (63 - 53)) /* CPU Timer */ | \ 106 + (1UL << (63 - 54)) /* Service Signal */ | \ 107 + (1UL << (63 - 57)) /* Interrupt Key */ | \ 108 + (1UL << (63 - 58)) /* Measurement Alert */ | \ 109 + (1UL << (63 - 59)) /* Timing Alert */ | \ 110 + (1UL << (63 - 62))) /* IUCV */ 111 + 99 112 void irq_subclass_register(enum irq_subclass subclass); 100 113 void irq_subclass_unregister(enum irq_subclass subclass); 101 114
+2
arch/s390/include/asm/processor.h
··· 15 15 #define CIF_ASCE 1 /* user asce needs fixup / uaccess */ 16 16 #define CIF_NOHZ_DELAY 2 /* delay HZ disable for a tick */ 17 17 #define CIF_FPU 3 /* restore vector registers */ 18 + #define CIF_IGNORE_IRQ 4 /* ignore interrupt (for udelay) */ 18 19 19 20 #define _CIF_MCCK_PENDING (1<<CIF_MCCK_PENDING) 20 21 #define _CIF_ASCE (1<<CIF_ASCE) 21 22 #define _CIF_NOHZ_DELAY (1<<CIF_NOHZ_DELAY) 22 23 #define _CIF_FPU (1<<CIF_FPU) 24 + #define _CIF_IGNORE_IRQ (1<<CIF_IGNORE_IRQ) 23 25 24 26 #ifndef __ASSEMBLY__ 25 27
+4
arch/s390/kernel/entry.S
··· 563 563 stmg %r8,%r9,__PT_PSW(%r11) 564 564 mvc __PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID 565 565 xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11) 566 + TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ 567 + jo .Lio_restore 566 568 TRACE_IRQS_OFF 567 569 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) 568 570 .Lio_loop: ··· 740 738 mvc __PT_INT_PARM(4,%r11),__LC_EXT_PARAMS 741 739 mvc __PT_INT_PARM_LONG(8,%r11),0(%r1) 742 740 xc __PT_FLAGS(8,%r11),__PT_FLAGS(%r11) 741 + TSTMSK __LC_CPU_FLAGS,_CIF_IGNORE_IRQ 742 + jo .Lio_restore 743 743 TRACE_IRQS_OFF 744 744 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) 745 745 lgr %r2,%r11 # pass pointer to pt_regs
-1
arch/s390/kernel/entry.h
··· 16 16 void mcck_int_handler(void); 17 17 void restart_int_handler(void); 18 18 void restart_call_handler(void); 19 - void psw_idle(struct s390_idle_data *, unsigned long); 20 19 21 20 asmlinkage long do_syscall_trace_enter(struct pt_regs *regs); 22 21 asmlinkage void do_syscall_trace_exit(struct pt_regs *regs);
+14 -16
arch/s390/lib/delay.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/irqflags.h> 14 14 #include <linux/interrupt.h> 15 + #include <linux/irq.h> 15 16 #include <asm/vtimer.h> 16 17 #include <asm/div64.h> 18 + #include <asm/idle.h> 17 19 18 20 void __delay(unsigned long loops) 19 21 { ··· 32 30 33 31 static void __udelay_disabled(unsigned long long usecs) 34 32 { 35 - unsigned long cr0, cr6, new; 36 - u64 clock_saved, end; 33 + unsigned long cr0, cr0_new, psw_mask; 34 + struct s390_idle_data idle; 35 + u64 end; 37 36 38 37 end = get_tod_clock() + (usecs << 12); 39 - clock_saved = local_tick_disable(); 40 38 __ctl_store(cr0, 0, 0); 41 - __ctl_store(cr6, 6, 6); 42 - new = (cr0 & 0xffff00e0) | 0x00000800; 43 - __ctl_load(new , 0, 0); 44 - new = 0; 45 - __ctl_load(new, 6, 6); 46 - lockdep_off(); 47 - do { 48 - set_clock_comparator(end); 49 - enabled_wait(); 50 - } while (get_tod_clock_fast() < end); 51 - lockdep_on(); 39 + cr0_new = cr0 & ~CR0_IRQ_SUBCLASS_MASK; 40 + cr0_new |= (1UL << (63 - 52)); /* enable clock comparator irq */ 41 + __ctl_load(cr0_new, 0, 0); 42 + psw_mask = __extract_psw() | PSW_MASK_EXT | PSW_MASK_WAIT; 43 + set_clock_comparator(end); 44 + set_cpu_flag(CIF_IGNORE_IRQ); 45 + psw_idle(&idle, psw_mask); 46 + clear_cpu_flag(CIF_IGNORE_IRQ); 47 + set_clock_comparator(S390_lowcore.clock_comparator); 52 48 __ctl_load(cr0, 0, 0); 53 - __ctl_load(cr6, 6, 6); 54 - local_tick_enable(clock_saved); 55 49 } 56 50 57 51 static void __udelay_enabled(unsigned long long usecs)