Thomas Gleixner | 5fca9e5c | 2019-05-24 12:03:55 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
David Vrabel | fdfd811 | 2015-02-19 15:23:17 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Preemptible hypercalls |
| 4 | * |
| 5 | * Copyright (C) 2014 Citrix Systems R&D ltd. |
David Vrabel | fdfd811 | 2015-02-19 15:23:17 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/sched.h> |
| 9 | #include <xen/xen-ops.h> |
| 10 | |
Thomas Gleixner | d4a3dcb | 2019-10-15 21:18:09 +0200 | [diff] [blame] | 11 | #ifndef CONFIG_PREEMPTION |
David Vrabel | fdfd811 | 2015-02-19 15:23:17 +0000 | [diff] [blame] | 12 | |
| 13 | /* |
| 14 | * Some hypercalls issued by the toolstack can take many 10s of |
| 15 | * seconds. Allow tasks running hypercalls via the privcmd driver to |
| 16 | * be voluntarily preempted even if full kernel preemption is |
| 17 | * disabled. |
| 18 | * |
| 19 | * Such preemptible hypercalls are bracketed by |
| 20 | * xen_preemptible_hcall_begin() and xen_preemptible_hcall_end() |
| 21 | * calls. |
| 22 | */ |
| 23 | |
| 24 | DEFINE_PER_CPU(bool, xen_in_preemptible_hcall); |
| 25 | EXPORT_SYMBOL_GPL(xen_in_preemptible_hcall); |
| 26 | |
| 27 | asmlinkage __visible void xen_maybe_preempt_hcall(void) |
| 28 | { |
| 29 | if (unlikely(__this_cpu_read(xen_in_preemptible_hcall) |
Konstantin Khlebnikov | 0fa2f5c | 2015-07-15 12:52:01 +0300 | [diff] [blame] | 30 | && need_resched())) { |
David Vrabel | fdfd811 | 2015-02-19 15:23:17 +0000 | [diff] [blame] | 31 | /* |
| 32 | * Clear flag as we may be rescheduled on a different |
| 33 | * cpu. |
| 34 | */ |
| 35 | __this_cpu_write(xen_in_preemptible_hcall, false); |
| 36 | _cond_resched(); |
| 37 | __this_cpu_write(xen_in_preemptible_hcall, true); |
| 38 | } |
| 39 | } |
Thomas Gleixner | d4a3dcb | 2019-10-15 21:18:09 +0200 | [diff] [blame] | 40 | #endif /* CONFIG_PREEMPTION */ |