From: Tim Deegan <tim@xen.org>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Keir Fraser <keir@xen.org>, Jan Beulich <jbeulich@suse.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: Recursive locking in Xen (in reference to NMI/MCE path audit)
Date: Thu, 6 Dec 2012 10:39:03 +0000 [thread overview]
Message-ID: <20121206103903.GH82725@ocelot.phlegethon.org> (raw)
In-Reply-To: <50BF91CD.8020103@citrix.com>
At 18:26 +0000 on 05 Dec (1354731981), Andrew Cooper wrote:
> Hello,
>
> While auditing the NMI/MCE paths, I have encountered some issues with
> recursive locking in Xen, discovered by the misuse of the console_lock
> intermittently as a regular lock and as a recursive lock.
>
> The comment in spinlock.h is unclear as to whether mixing recursive and
> non recursive calls on the same spinlock is valid. If the calls are
> genuinely not valid, then surely regular spinlocks and recursive
> spinlocks should be separate types to let the compiler work for us.
Seems like a good idea.
> If mixing calls are valid, then there appear to be problems with nesting
> recursive and regular calls, as either ordering of spin_lock and
> spin_lock_recursive will deadlock.
Yes. But paths that know they will not need to recurse can safely use
the non-recursive lock op. The shadow code used to do this sort of
thing (with a better failure mode) to explicitly catch recursive paths
that weren't intended.
> As a result, I am wondering which of the above to fix?
>
> There are very few users of recursive locks (domain lock, domain
> page_alloc lock, mm (pod and paging) locks and console lock). The
> console and page_alloc locks appear to have mixed callers, while the
> domain and mm locks appear to have strictly recursive callers.
Please don't touch the mm locks! Any code that uses them in NMI or MCE
handlers is in a bad way already. :)
> It seems to me that either we need to make the two locks different
> types, or use ASSERT()s to ensure we dont next spin_lock() and
> spin_lock_recursive() calls.
I'd be happy with different types, unless there are cases where we care
about the speed of extra operations on the page_alloc or domain locks.
> In addition to the above problems, I find myself needing to implement
> spin_lock_recursive_irq{,save,restore}() variants. The implementations
> themselves are not too hard to do, but I did wonder whether we might
> want to have extra ASSERT()s to remove potential deadlock scenarios from
> the NMI/MCE paths. The ASSERT()s would have to be along the lines of
> "assert this is exclusively a recursive lock" or "assert this is a
> per-cpu regular spinlock which is never referenced outside of this
> specific NMI/MCE path". The possible implementation of these
> pseudo-asserts would differ depending on the outcome of the query.
Have you looked at the existing lock debugging that Keir put in to do
exactly this for normal vs IRQ? Can it be trivially extended?
Tim.
prev parent reply other threads:[~2012-12-06 10:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-05 18:26 Recursive locking in Xen (in reference to NMI/MCE path audit) Andrew Cooper
2012-12-06 10:39 ` Tim Deegan [this message]
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=20121206103903.GH82725@ocelot.phlegethon.org \
--to=tim@xen.org \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=keir@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).