|
27 | 27 | #include <linux/syscalls.h> |
28 | 28 | #include <linux/uaccess.h> |
29 | 29 |
|
| 30 | +#ifdef CONFIG_XEN_PV |
| 31 | +#include <xen/xen-ops.h> |
| 32 | +#include <xen/events.h> |
| 33 | +#endif |
| 34 | + |
30 | 35 | #include <asm/desc.h> |
31 | 36 | #include <asm/traps.h> |
32 | 37 | #include <asm/vdso.h> |
|
35 | 40 | #include <asm/nospec-branch.h> |
36 | 41 | #include <asm/io_bitmap.h> |
37 | 42 | #include <asm/syscall.h> |
| 43 | +#include <asm/irq_stack.h> |
38 | 44 |
|
39 | 45 | #define CREATE_TRACE_POINTS |
40 | 46 | #include <trace/events/syscalls.h> |
@@ -680,3 +686,75 @@ void noinstr idtentry_exit_user(struct pt_regs *regs) |
680 | 686 |
|
681 | 687 | prepare_exit_to_usermode(regs); |
682 | 688 | } |
| 689 | + |
| 690 | +#ifdef CONFIG_XEN_PV |
| 691 | +#ifndef CONFIG_PREEMPTION |
| 692 | +/* |
| 693 | + * Some hypercalls issued by the toolstack can take many 10s of |
| 694 | + * seconds. Allow tasks running hypercalls via the privcmd driver to |
| 695 | + * be voluntarily preempted even if full kernel preemption is |
| 696 | + * disabled. |
| 697 | + * |
| 698 | + * Such preemptible hypercalls are bracketed by |
| 699 | + * xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() |
| 700 | + * calls. |
| 701 | + */ |
| 702 | +DEFINE_PER_CPU(bool, xen_in_preemptible_hcall); |
| 703 | +EXPORT_SYMBOL_GPL(xen_in_preemptible_hcall); |
| 704 | + |
| 705 | +/* |
| 706 | + * In case of scheduling the flag must be cleared and restored after |
| 707 | + * returning from schedule as the task might move to a different CPU. |
| 708 | + */ |
| 709 | +static __always_inline bool get_and_clear_inhcall(void) |
| 710 | +{ |
| 711 | + bool inhcall = __this_cpu_read(xen_in_preemptible_hcall); |
| 712 | + |
| 713 | + __this_cpu_write(xen_in_preemptible_hcall, false); |
| 714 | + return inhcall; |
| 715 | +} |
| 716 | + |
| 717 | +static __always_inline void restore_inhcall(bool inhcall) |
| 718 | +{ |
| 719 | + __this_cpu_write(xen_in_preemptible_hcall, inhcall); |
| 720 | +} |
| 721 | +#else |
| 722 | +static __always_inline bool get_and_clear_inhcall(void) { return false; } |
| 723 | +static __always_inline void restore_inhcall(bool inhcall) { } |
| 724 | +#endif |
| 725 | + |
| 726 | +static void __xen_pv_evtchn_do_upcall(void) |
| 727 | +{ |
| 728 | + irq_enter_rcu(); |
| 729 | + inc_irq_stat(irq_hv_callback_count); |
| 730 | + |
| 731 | + xen_hvm_evtchn_do_upcall(); |
| 732 | + |
| 733 | + irq_exit_rcu(); |
| 734 | +} |
| 735 | + |
| 736 | +__visible noinstr void xen_pv_evtchn_do_upcall(struct pt_regs *regs) |
| 737 | +{ |
| 738 | + struct pt_regs *old_regs; |
| 739 | + bool inhcall, rcu_exit; |
| 740 | + |
| 741 | + rcu_exit = idtentry_enter_cond_rcu(regs); |
| 742 | + old_regs = set_irq_regs(regs); |
| 743 | + |
| 744 | + instrumentation_begin(); |
| 745 | + run_on_irqstack_cond(__xen_pv_evtchn_do_upcall, NULL, regs); |
| 746 | + instrumentation_begin(); |
| 747 | + |
| 748 | + set_irq_regs(old_regs); |
| 749 | + |
| 750 | + inhcall = get_and_clear_inhcall(); |
| 751 | + if (inhcall && !WARN_ON_ONCE(rcu_exit)) { |
| 752 | + instrumentation_begin(); |
| 753 | + idtentry_exit_cond_resched(regs, true); |
| 754 | + instrumentation_end(); |
| 755 | + restore_inhcall(inhcall); |
| 756 | + } else { |
| 757 | + idtentry_exit_cond_rcu(regs, rcu_exit); |
| 758 | + } |
| 759 | +} |
| 760 | +#endif /* CONFIG_XEN_PV */ |
0 commit comments