All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Liu Ping Fan <qemulist@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Stefan Hajnoczi <stefanha@gmail.com>,
	Marcelo Tosatti <mtosatti@redhat.com>,
	qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v6 7/8] memory: introduce tls context to trace nested mmio request issue
Date: Mon, 05 Nov 2012 07:57:50 +0100	[thread overview]
Message-ID: <5097636E.4010901@web.de> (raw)
In-Reply-To: <1352093924-17598-8-git-send-email-qemulist@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2714 bytes --]

On 2012-11-05 06:38, Liu Ping Fan wrote:
> From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> 
> After breaking down big lock, nested MMIO request which not targeting
> at RAM can cause deadlock issue. Supposing the scene: dev_a,b with
> fine-grain locks lockA/B, then ABBA dealock issue can be triggered.
> We fix this by tracing and rejecting such request.
> 
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  exec.c        |   47 +++++++++++++++++++++++++++++++++++++++++++++++
>  qemu-thread.h |    7 +++++++
>  2 files changed, 54 insertions(+), 0 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index fa34ef9..1eb920d 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3442,6 +3442,48 @@ static bool address_space_section_lookup_ref(AddressSpace *as,
>      return safe_ref;
>  }
>  
> +typedef struct ThreadContext {
> +  DispatchType dispatch_type;
> +  unsigned int mmio_req_pending;
> +} ThreadContext;
> +
> +static __thread ThreadContext thread_context = {
          ^^^^^^^^
Again, you will have to work on qemu-tls.h and then use DEFINE_TLS. The
above is not portable.

> +    .dispatch_type = DISPATCH_INIT,
> +    .mmio_req_pending = 0
> +};
> +
> +void qemu_thread_set_dispatch_type(DispatchType type)
> +{
> +    thread_context.dispatch_type = type;
> +}
> +
> +void qemu_thread_reset_dispatch_type(void)
> +{
> +    thread_context.dispatch_type = DISPATCH_INIT;
> +}
> +
> +static void address_space_check_inc_req_pending(MemoryRegionSection *section)
> +{
> +    bool nested = false;
> +
> +    /* currently, only mmio out of big lock, and need this to avoid dead lock */
> +    if (thread_context.dispatch_type == DISPATCH_MMIO) {
> +        nested = ++thread_context.mmio_req_pending > 1 ? true : false;
> +        /* To fix, will filter iommu case */
> +        if (nested && !memory_region_is_ram(section->mr)) {
> +            fprintf(stderr, "mmio: nested target not RAM is not support");
> +            abort();
> +        }
> +    }

This should already take PIO into account, thus all scenarios: If we are
dispatching MMIO or PIO, reject any further requests that are not
targeting RAM.

I don't think we need mmio_req_pending for this. We are not interested
in differentiating between MMIO and PIO, both will be problematic. We
just store the information if a request is going on in the TLS variable
here, not before entering cpu_physical_memory_xxx. And then we can
simply bail out if another non-RAM request is arriving, the nesting
level will never be >1.

And with bailing out I mean warn once + ignore request, not abort().
This would be a needless guest triggerable VM termination.

Jan



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

  reply	other threads:[~2012-11-05  6:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05  5:38 [Qemu-devel] [PATCH v6 0/8] push mmio dispatch out of big lock Liu Ping Fan
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 1/8] atomic: introduce atomic operations Liu Ping Fan
2012-11-12  9:54   ` Paolo Bonzini
2012-11-13  6:48     ` liu ping fan
2012-11-13 10:11       ` Paolo Bonzini
2012-11-14  9:38         ` liu ping fan
2012-11-14  9:47           ` Paolo Bonzini
2012-11-15  7:47             ` liu ping fan
2012-11-15 11:24               ` Paolo Bonzini
2012-11-16  0:03               ` Richard Henderson
2012-11-21  5:58                 ` liu ping fan
2012-11-18 10:04               ` Avi Kivity
2012-11-21  5:57                 ` liu ping fan
2012-11-13 10:11       ` Paolo Bonzini
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 2/8] qom: apply atomic on object's refcount Liu Ping Fan
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 3/8] hotplug: introduce qdev_unplug_complete() to remove device from views Liu Ping Fan
2012-11-12  9:27   ` Paolo Bonzini
2012-11-13  6:12     ` liu ping fan
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 4/8] pci: remove pci device from mem view when unplug Liu Ping Fan
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 5/8] memory: introduce local lock for address space Liu Ping Fan
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 6/8] memory: make mmio dispatch able to be out of biglock Liu Ping Fan
2012-11-05  6:45   ` Jan Kiszka
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 7/8] memory: introduce tls context to trace nested mmio request issue Liu Ping Fan
2012-11-05  6:57   ` Jan Kiszka [this message]
2012-11-05  5:38 ` [Qemu-devel] [PATCH v6 8/8] vcpu: push mmio dispatcher out of big lock Liu Ping Fan
2012-11-05  7:00 ` [Qemu-devel] [PATCH v6 0/8] push mmio dispatch " Jan Kiszka
2012-11-09  6:23   ` liu ping fan
2012-11-09  8:15     ` Jan Kiszka

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=5097636E.4010901@web.de \
    --to=jan.kiszka@web.de \
    --cc=anthony@codemonkey.ws \
    --cc=avi@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemulist@gmail.com \
    --cc=stefanha@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.