LKML Archive on
help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <>
Cc:,,,,, "Luis R. Rodriguez" <>,
	Andy Lutomirski <>,
	Borislav Petkov <>,
	Thomas Gleixner <>,
	Ingo Molnar <>, "H. Peter Anvin" <>,
	Masami Hiramatsu <>,
	Jan Beulich <>
Subject: [PATCH v5 2/2] x86/xen: allow privcmd hypercalls to be preempted on 64-bit
Date: Mon, 26 Jan 2015 17:51:07 -0800	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

From: "Luis R. Rodriguez" <>

Xen has support for splitting heavy work work into a series
of hypercalls, called multicalls, and preempting them through
what Xen calls continuation [0]. Despite this though without
CONFIG_PREEMPT preemption won't happen, without preemption
a system can become pretty useless on heavy handed hypercalls.
Such is the case for example when creating a > 50 GiB HVM guest,
we can get softlockups [1] with:.

kernel: [  802.084335] BUG: soft lockup - CPU#1 stuck for 22s! [xend:31351]

The softlock up triggers on the TASK_UNINTERRUPTIBLE hanger check
(default 120 seconds), on the Xen side in this particular case
this happens when the following Xen hypervisor code is used:

xc_domain_set_pod_target() -->
  do_memory_op() -->
    arch_memory_op() -->
	-- long delay (real or emulated) --

This happens on arch_memory_op() on the XENMEM_set_pod_target memory
op even though arch_memory_op() can handle continuation via
hypercall_create_continuation() for example.

Machines over 50 GiB of memory are on high demand and hard to come
by so to help replicate this sort of issue long delays on select
hypercalls have been emulated in order to be able to test this on
smaller machines [2].

On one hand this issue can be considered as expected given that
CONFIG_PREEMPT=n is used however we have forced voluntary preemption
precedent practices in the kernel even for CONFIG_PREEMPT=n through
the usage of cond_resched() sprinkled in many places. To address
this issue with Xen hypercalls though we need to find a way to aid
to the schedular in the middle of hypercalls. We are motivated to
address this issue on CONFIG_PREEMPT=n as otherwise the system becomes
rather unresponsive for long periods of time; in the worst case, at least
only currently by emulating long delays on select io disk bound
hypercalls, this can lead to filesystem corruption if the delay happens
for example on SCHEDOP_remote_shutdown (when we call 'xl <domain> shutdown').

We can address this problem by trying to check if we should schedule
on the xen timer in the middle of a hypercall on the return from the
timer interrupt. We want to be careful to not always force voluntary
preemption though so to do this we only selectively enable preemption
on very specific xen hypercalls.

This enables hypercall preemption by selectively forcing checks for
voluntary preempting only on ioctl initiated private hypercalls
where we know some folks have run into reported issues [1].


Based on original work by: David Vrabel <>
Suggested-by: Andy Lutomirski <>
Cc: Andy Lutomirski <>
Cc: Borislav Petkov <>
Cc: David Vrabel <>
Cc: Thomas Gleixner <>
Cc: Ingo Molnar <>
Cc: "H. Peter Anvin" <>
Cc: Steven Rostedt <>
Cc: Masami Hiramatsu <>
Cc: Jan Beulich <>
Reviewed-by: Andy Lutomirski <>
Signed-off-by: Luis R. Rodriguez <>
 arch/x86/kernel/entry_64.S       |  2 ++
 drivers/xen/events/events_base.c | 14 ++++++++++++++
 include/xen/events.h             |  1 +
 3 files changed, 17 insertions(+)

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 9ebaf63..ee28733 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1198,6 +1198,8 @@ ENTRY(xen_do_hypervisor_callback)   # do_hypervisor_callback(struct *pt_regs)
 	popq %rsp
 	decl PER_CPU_VAR(irq_count)
+	movq %rsp, %rdi  /* pass pt_regs as first argument */
+	call xen_end_upcall
 	jmp  error_exit
diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
index b4bca2d..bf207f2 100644
--- a/drivers/xen/events/events_base.c
+++ b/drivers/xen/events/events_base.c
@@ -32,6 +32,8 @@
 #include <linux/slab.h>
 #include <linux/irqnr.h>
 #include <linux/pci.h>
+#include <linux/sched.h>
+#include <linux/kprobes.h>
 #ifdef CONFIG_X86
 #include <asm/desc.h>
@@ -1243,6 +1245,18 @@ void xen_evtchn_do_upcall(struct pt_regs *regs)
+ * Some hypercalls issued by the toolstack can take many 10s of
+ * seconds. Allow tasks running hypercalls via the privcmd driver to be
+ * voluntarily preempted even if full kernel preemption is disabled.
+ */
+void xen_end_upcall(struct pt_regs *regs)
+	if (xen_is_preemptible_hypercall(regs))
+		_cond_resched();
 void xen_hvm_evtchn_do_upcall(void)
diff --git a/include/xen/events.h b/include/xen/events.h
index 5321cd9..f08df87 100644
--- a/include/xen/events.h
+++ b/include/xen/events.h
@@ -95,6 +95,7 @@ void xen_hvm_callback_vector(void);
 extern int xen_have_vector_callback;
 int xen_set_callback_via(uint64_t via);
 void xen_evtchn_do_upcall(struct pt_regs *regs);
+void xen_end_upcall(struct pt_regs *regs);
 void xen_hvm_evtchn_do_upcall(void);
 /* Bind a pirq for a physical interrupt to an irq. */

  parent reply	other threads:[~2015-01-27  1:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-27  1:51 [PATCH v5 0/2] x86/xen: add xen hypercall preemption Luis R. Rodriguez
2015-01-27  1:51 ` [PATCH v5 1/2] xen: add xen_is_preemptible_hypercall() Luis R. Rodriguez
2015-02-03 11:05   ` [Xen-devel] " David Vrabel
2015-02-03 18:03     ` Luis R. Rodriguez
2015-01-27  1:51 ` Luis R. Rodriguez [this message]
2015-01-27  8:35   ` [PATCH v5 2/2] x86/xen: allow privcmd hypercalls to be preempted on 64-bit Jan Beulich
2015-01-27 10:01     ` [Xen-devel] " Andrew Cooper
2015-01-27 10:06     ` David Vrabel
2015-01-27 20:12       ` Luis R. Rodriguez
2015-01-29 20:35       ` Luis R. Rodriguez
2015-02-03  0:24         ` Luis R. Rodriguez
2015-02-03  9:58           ` David Vrabel
2015-02-05 12:47 ` [Xen-devel] [PATCH v5 0/2] x86/xen: add xen hypercall preemption David Vrabel
2015-02-05 18:15   ` Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v5 2/2] x86/xen: allow privcmd hypercalls to be preempted on 64-bit' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).