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

x86/entry/traps: Refactor preemption and interrupt flag handling

Make the preemption and interrupt flag handling more readable by
removing preempt_conditional_sti() and preempt_conditional_cli()
helpers and using preempt_disable() and
preempt_enable_no_resched() instead.

Rename contitional_sti() and conditional_cli() to the more
understandable cond_local_irq_enable() and
cond_local_irq_disable() respectively, while at it.

Suggested-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
[ Boris: massage text. ]
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: H Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1453750913-4781-2-git-send-email-bp@alien8.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Alexander Kuleshov and committed by
Ingo Molnar
d99e1bd1 bb56968a

+19 -28
+19 -28
arch/x86/kernel/traps.c
··· 83 83 DECLARE_BITMAP(used_vectors, NR_VECTORS); 84 84 EXPORT_SYMBOL_GPL(used_vectors); 85 85 86 - static inline void conditional_sti(struct pt_regs *regs) 86 + static inline void cond_local_irq_enable(struct pt_regs *regs) 87 87 { 88 88 if (regs->flags & X86_EFLAGS_IF) 89 89 local_irq_enable(); 90 90 } 91 91 92 - static inline void preempt_conditional_sti(struct pt_regs *regs) 93 - { 94 - preempt_count_inc(); 95 - if (regs->flags & X86_EFLAGS_IF) 96 - local_irq_enable(); 97 - } 98 - 99 - static inline void conditional_cli(struct pt_regs *regs) 92 + static inline void cond_local_irq_disable(struct pt_regs *regs) 100 93 { 101 94 if (regs->flags & X86_EFLAGS_IF) 102 95 local_irq_disable(); 103 - } 104 - 105 - static inline void preempt_conditional_cli(struct pt_regs *regs) 106 - { 107 - if (regs->flags & X86_EFLAGS_IF) 108 - local_irq_disable(); 109 - preempt_count_dec(); 110 96 } 111 97 112 98 void ist_enter(struct pt_regs *regs) ··· 272 286 273 287 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, signr) != 274 288 NOTIFY_STOP) { 275 - conditional_sti(regs); 289 + cond_local_irq_enable(regs); 276 290 do_trap(trapnr, signr, str, regs, error_code, 277 291 fill_trap_info(regs, signr, trapnr, &info)); 278 292 } ··· 354 368 if (notify_die(DIE_TRAP, "bounds", regs, error_code, 355 369 X86_TRAP_BR, SIGSEGV) == NOTIFY_STOP) 356 370 return; 357 - conditional_sti(regs); 371 + cond_local_irq_enable(regs); 358 372 359 373 if (!user_mode(regs)) 360 374 die("bounds", regs, error_code); ··· 429 443 struct task_struct *tsk; 430 444 431 445 RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU"); 432 - conditional_sti(regs); 446 + cond_local_irq_enable(regs); 433 447 434 448 if (v8086_mode(regs)) { 435 449 local_irq_enable(); ··· 503 517 * as we may switch to the interrupt stack. 504 518 */ 505 519 debug_stack_usage_inc(); 506 - preempt_conditional_sti(regs); 520 + preempt_disable(); 521 + cond_local_irq_enable(regs); 507 522 do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL); 508 - preempt_conditional_cli(regs); 523 + cond_local_irq_disable(regs); 524 + preempt_enable_no_resched(); 509 525 debug_stack_usage_dec(); 510 526 exit: 511 527 ist_exit(regs); ··· 636 648 debug_stack_usage_inc(); 637 649 638 650 /* It's safe to allow irq's after DR6 has been saved */ 639 - preempt_conditional_sti(regs); 651 + preempt_disable(); 652 + cond_local_irq_enable(regs); 640 653 641 654 if (v8086_mode(regs)) { 642 655 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code, 643 656 X86_TRAP_DB); 644 - preempt_conditional_cli(regs); 657 + cond_local_irq_disable(regs); 658 + preempt_enable_no_resched(); 645 659 debug_stack_usage_dec(); 646 660 goto exit; 647 661 } ··· 663 673 si_code = get_si_code(tsk->thread.debugreg6); 664 674 if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp) 665 675 send_sigtrap(tsk, regs, error_code, si_code); 666 - preempt_conditional_cli(regs); 676 + cond_local_irq_disable(regs); 677 + preempt_enable_no_resched(); 667 678 debug_stack_usage_dec(); 668 679 669 680 exit: ··· 687 696 688 697 if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, SIGFPE) == NOTIFY_STOP) 689 698 return; 690 - conditional_sti(regs); 699 + cond_local_irq_enable(regs); 691 700 692 701 if (!user_mode(regs)) { 693 702 if (!fixup_exception(regs)) { ··· 734 743 dotraplinkage void 735 744 do_spurious_interrupt_bug(struct pt_regs *regs, long error_code) 736 745 { 737 - conditional_sti(regs); 746 + cond_local_irq_enable(regs); 738 747 } 739 748 740 749 dotraplinkage void ··· 747 756 if (read_cr0() & X86_CR0_EM) { 748 757 struct math_emu_info info = { }; 749 758 750 - conditional_sti(regs); 759 + cond_local_irq_enable(regs); 751 760 752 761 info.regs = regs; 753 762 math_emulate(&info); ··· 756 765 #endif 757 766 fpu__restore(&current->thread.fpu); /* interrupts still off */ 758 767 #ifdef CONFIG_X86_32 759 - conditional_sti(regs); 768 + cond_local_irq_enable(regs); 760 769 #endif 761 770 } 762 771 NOKPROBE_SYMBOL(do_device_not_available);