From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Tim Deegan <tim@xen.org>, Ian Campbell <Ian.Campbell@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v2 1/2] x86/traps: Prevent interleaving of concurrent cpu state dumps
Date: Thu, 11 Feb 2016 10:52:51 +0000 [thread overview]
Message-ID: <1455187972-30566-1-git-send-email-andrew.cooper3@citrix.com> (raw)
If two cpus enter show_execution_state() concurrently, the resulting console
output interleaved, and of no help debugging the situation further.
As calls to these locations are rare and usually important, it is acceptable
to serialise them. These codepaths are also on the terminal error paths, so
the console lock must be the lock used for serialisation, to allow
console_force_unlock() to function properly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Tim Deegan <tim@xen.org>
CC: Ian Campbell <Ian.Campbell@citrix.com>
v2: Use the console lock rather than a local lock to allow
console_force_unlock() to function correctly on terminal error paths.
---
xen/arch/x86/traps.c | 12 ++++++++++++
xen/drivers/char/console.c | 16 ++++++++++++++++
xen/include/xen/console.h | 2 ++
3 files changed, 30 insertions(+)
diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c
index d19250a..ab7deee 100644
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -416,12 +416,19 @@ void show_stack_overflow(unsigned int cpu, const struct cpu_user_regs *regs)
void show_execution_state(const struct cpu_user_regs *regs)
{
+ /* Prevent interleaving of output. */
+ unsigned long flags = console_lock_recursive_irqsave();
+
show_registers(regs);
show_stack(regs);
+
+ console_unlock_recursive_irqrestore(flags);
}
void vcpu_show_execution_state(struct vcpu *v)
{
+ unsigned long flags;
+
printk("*** Dumping Dom%d vcpu#%d state: ***\n",
v->domain->domain_id, v->vcpu_id);
@@ -433,10 +440,15 @@ void vcpu_show_execution_state(struct vcpu *v)
vcpu_pause(v); /* acceptably dangerous */
+ /* Prevent interleaving of output. */
+ flags = console_lock_recursive_irqsave();
+
vcpu_show_registers(v);
if ( guest_kernel_mode(v, &v->arch.user_regs) )
show_guest_stack(v, &v->arch.user_regs);
+ console_unlock_recursive_irqrestore(flags);
+
vcpu_unpause(v);
}
diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index e0083f1..f4f6141 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -865,6 +865,22 @@ void console_end_log_everything(void)
atomic_dec(&print_everything);
}
+unsigned long console_lock_recursive_irqsave(void)
+{
+ unsigned long flags;
+
+ local_irq_save(flags);
+ spin_lock_recursive(&console_lock);
+
+ return flags;
+}
+
+void console_unlock_recursive_irqrestore(unsigned long flags)
+{
+ spin_unlock_recursive(&console_lock);
+ local_irq_restore(flags);
+}
+
void console_force_unlock(void)
{
watchdog_disable();
diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h
index c7fd9ca..ea06fd8 100644
--- a/xen/include/xen/console.h
+++ b/xen/include/xen/console.h
@@ -21,6 +21,8 @@ int console_has(const char *device);
int fill_console_start_info(struct dom0_vga_console_info *);
+unsigned long console_lock_recursive_irqsave(void);
+void console_unlock_recursive_irqrestore(unsigned long flags);
void console_force_unlock(void);
void console_start_sync(void);
--
2.1.4
next reply other threads:[~2016-02-11 10:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-11 10:52 Andrew Cooper [this message]
2016-02-11 10:52 ` [PATCH v2 2/2] x86/traps: Dump instruction stream in show_execution_state() Andrew Cooper
2016-02-11 11:16 ` Jan Beulich
2016-02-11 12:12 ` Andrew Cooper
2016-02-11 12:52 ` Jan Beulich
2016-02-11 13:41 ` Andrew Cooper
2016-02-11 13:55 ` Jan Beulich
2016-02-11 14:33 ` [PATCH v3 " Andrew Cooper
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455187972-30566-1-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=JBeulich@suse.com \
--cc=tim@xen.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).