qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug
@ 2016-12-26 21:24 Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 1/3] trace: Lock vCPU list when initializing dynamic tracing state Lluís Vilanova
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lluís Vilanova @ 2016-12-26 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

The vCPU list needs to be locked to avoid memory corruption with concurrent
hot-(un)plugs, and per-vCPU events need to be disabled during vCPU hot-unplug.

Also adds event "guest_cpu_exit" to track vCPU hot-unplugging.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---


Lluís Vilanova (3):
      trace: Lock vCPU list when initializing dynamic tracing state
      trace: Fix dynamic event state on vCPU hot-unplug
      trace: Add event "guest_cpu_exit"


 qom/cpu.c              |    2 ++
 trace-events           |    6 ++++++
 trace/control-target.c |   11 ++++++++++-
 trace/control.c        |   19 +++++++++++++++++++
 trace/control.h        |    8 ++++++++
 5 files changed, 45 insertions(+), 1 deletion(-)


To: qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 1/3] trace: Lock vCPU list when initializing dynamic tracing state
  2016-12-26 21:24 [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Lluís Vilanova
@ 2016-12-26 21:24 ` Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 2/3] trace: Fix dynamic event state on vCPU hot-unplug Lluís Vilanova
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Lluís Vilanova @ 2016-12-26 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

Fixes potential corruption when a vCPU is hot-(un)plugged while
initializing the current one.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 trace/control-target.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/trace/control-target.c b/trace/control-target.c
index 7ebf6e0bcb..e2e138a3f0 100644
--- a/trace/control-target.c
+++ b/trace/control-target.c
@@ -79,7 +79,7 @@ void trace_event_set_vcpu_state_dynamic(CPUState *vcpu,
     }
 }
 
-static bool adding_first_cpu(void)
+static bool adding_first_cpu1(void)
 {
     CPUState *cpu;
     size_t count = 0;
@@ -92,6 +92,15 @@ static bool adding_first_cpu(void)
     return true;
 }
 
+static bool adding_first_cpu(void)
+{
+    bool res;
+    cpu_list_lock();
+    res = adding_first_cpu1();
+    cpu_list_unlock();
+    return res;
+}
+
 void trace_init_vcpu(CPUState *vcpu)
 {
     TraceEventIter iter;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 2/3] trace: Fix dynamic event state on vCPU hot-unplug
  2016-12-26 21:24 [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 1/3] trace: Lock vCPU list when initializing dynamic tracing state Lluís Vilanova
@ 2016-12-26 21:24 ` Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 3/3] trace: Add event "guest_cpu_exit" Lluís Vilanova
  2017-01-09 16:38 ` [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Lluís Vilanova @ 2016-12-26 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

We need to disable per-vCPU events on a vCPU that is hot-unplugged to
keep the dynamic event state global counters consistent.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 qom/cpu.c       |    2 ++
 trace/control.c |   16 ++++++++++++++++
 trace/control.h |    8 ++++++++
 3 files changed, 26 insertions(+)

diff --git a/qom/cpu.c b/qom/cpu.c
index 03d9190f8c..93e41056d9 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -348,6 +348,8 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)
 {
     CPUState *cpu = CPU(dev);
+    /* NOTE: latest generic point before the cpu is fully unrealized */
+    trace_fini_vcpu(cpu);
     cpu_exec_unrealizefn(cpu);
 }
 
diff --git a/trace/control.c b/trace/control.c
index 1a7bee6ddc..cb79bb17ec 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -259,6 +259,22 @@ void trace_init_file(const char *file)
 #endif
 }
 
+void trace_fini_vcpu(CPUState *vcpu)
+{
+    TraceEventIter iter;
+    TraceEvent *ev;
+
+    trace_event_iter_init(&iter, NULL);
+    while ((ev = trace_event_iter_next(&iter)) != NULL) {
+        if (trace_event_is_vcpu(ev) &&
+            trace_event_get_state_static(ev) &&
+            trace_event_get_vcpu_state_dynamic(vcpu, ev)) {
+            /* must disable to affect the global counter */
+            trace_event_set_vcpu_state_dynamic(vcpu, ev, false);
+        }
+    }
+}
+
 bool trace_init_backends(void)
 {
 #ifdef CONFIG_TRACE_SIMPLE
diff --git a/trace/control.h b/trace/control.h
index ccaeac8552..4ea53e2986 100644
--- a/trace/control.h
+++ b/trace/control.h
@@ -202,6 +202,14 @@ void trace_init_file(const char *file);
 void trace_init_vcpu(CPUState *vcpu);
 
 /**
+ * trace_fini_vcpu:
+ * @vcpu: Removed vCPU.
+ *
+ * Disable dynamic event state for a hot-unplugged vCPU.
+ */
+void trace_fini_vcpu(CPUState *vcpu);
+
+/**
  * trace_list_events:
  *
  * List all available events.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH 3/3] trace: Add event "guest_cpu_exit"
  2016-12-26 21:24 [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 1/3] trace: Lock vCPU list when initializing dynamic tracing state Lluís Vilanova
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 2/3] trace: Fix dynamic event state on vCPU hot-unplug Lluís Vilanova
@ 2016-12-26 21:24 ` Lluís Vilanova
  2017-01-09 16:38 ` [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Lluís Vilanova @ 2016-12-26 21:24 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

Signals the hot-unplugging of a virtual (guest) CPU.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 trace-events    |    6 ++++++
 trace/control.c |    3 +++
 2 files changed, 9 insertions(+)

diff --git a/trace-events b/trace-events
index f74e1d3d22..f3894f5b38 100644
--- a/trace-events
+++ b/trace-events
@@ -135,6 +135,12 @@ memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t
 # Targets: all
 vcpu guest_cpu_enter(void)
 
+# Hot-unplug a virtual (guest) CPU
+#
+# Mode: user, softmmu
+# Targets: all
+vcpu guest_cpu_exit(void)
+
 # Reset the state of a virtual (guest) CPU
 #
 # Mode: user, softmmu
diff --git a/trace/control.c b/trace/control.c
index cb79bb17ec..56a2632584 100644
--- a/trace/control.c
+++ b/trace/control.c
@@ -26,6 +26,7 @@
 #include "qemu/error-report.h"
 #include "qemu/config-file.h"
 #include "monitor/monitor.h"
+#include "trace.h"
 
 int trace_events_enabled_count;
 
@@ -264,6 +265,8 @@ void trace_fini_vcpu(CPUState *vcpu)
     TraceEventIter iter;
     TraceEvent *ev;
 
+    trace_guest_cpu_exit(vcpu);
+
     trace_event_iter_init(&iter, NULL);
     while ((ev = trace_event_iter_next(&iter)) != NULL) {
         if (trace_event_is_vcpu(ev) &&

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug
  2016-12-26 21:24 [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Lluís Vilanova
                   ` (2 preceding siblings ...)
  2016-12-26 21:24 ` [Qemu-devel] [PATCH 3/3] trace: Add event "guest_cpu_exit" Lluís Vilanova
@ 2017-01-09 16:38 ` Stefan Hajnoczi
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2017-01-09 16:38 UTC (permalink / raw)
  To: Lluís Vilanova; +Cc: qemu-devel

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

On Mon, Dec 26, 2016 at 10:24:29PM +0100, Lluís Vilanova wrote:
> The vCPU list needs to be locked to avoid memory corruption with concurrent
> hot-(un)plugs, and per-vCPU events need to be disabled during vCPU hot-unplug.
> 
> Also adds event "guest_cpu_exit" to track vCPU hot-unplugging.
> 
> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
> 
> 
> Lluís Vilanova (3):
>       trace: Lock vCPU list when initializing dynamic tracing state
>       trace: Fix dynamic event state on vCPU hot-unplug
>       trace: Add event "guest_cpu_exit"
> 
> 
>  qom/cpu.c              |    2 ++
>  trace-events           |    6 ++++++
>  trace/control-target.c |   11 ++++++++++-
>  trace/control.c        |   19 +++++++++++++++++++
>  trace/control.h        |    8 ++++++++
>  5 files changed, 45 insertions(+), 1 deletion(-)
> 
> 
> To: qemu-devel@nongnu.org
> Cc: Stefan Hajnoczi <stefanha@redhat.com>

Thanks, applied to my tracing tree:
https://github.com/stefanha/qemu/commits/tracing

Stefan

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-10 14:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-26 21:24 [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Lluís Vilanova
2016-12-26 21:24 ` [Qemu-devel] [PATCH 1/3] trace: Lock vCPU list when initializing dynamic tracing state Lluís Vilanova
2016-12-26 21:24 ` [Qemu-devel] [PATCH 2/3] trace: Fix dynamic event state on vCPU hot-unplug Lluís Vilanova
2016-12-26 21:24 ` [Qemu-devel] [PATCH 3/3] trace: Add event "guest_cpu_exit" Lluís Vilanova
2017-01-09 16:38 ` [Qemu-devel] [PATCH 0/3] trace: Fix event tracing during vCPU hot-unplug Stefan Hajnoczi

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).