qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Aleksandar Markovic" <amarkovic@wavecomp.com>,
	"Michael Walle" <michael@walle.cc>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Aleksandar Rikalo" <aleksandar.rikalo@rt-rk.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>,
	"Bastian Koppelmann" <kbastian@mail.uni-paderborn.de>
Subject: [PATCH 1/2] cpu: Do not reset a vCPU before it is created
Date: Mon,  9 Mar 2020 13:11:02 +0100	[thread overview]
Message-ID: <20200309121103.20234-2-philmd@redhat.com> (raw)
In-Reply-To: <20200309121103.20234-1-philmd@redhat.com>

cpu_reset() might modify architecture-specific fields allocated
by qemu_init_vcpu(). To avoid bugs similar to the one fixed in
commit 00d0f7cb66 when introducing new architectures, move the
cpu_reset() calls after qemu_init_vcpu().

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 target/cris/cpu.c    | 2 +-
 target/lm32/cpu.c    | 3 +--
 target/m68k/cpu.c    | 2 +-
 target/mips/cpu.c    | 2 +-
 target/sh4/cpu.c     | 2 +-
 target/tilegx/cpu.c  | 2 +-
 target/tricore/cpu.c | 2 +-
 7 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/target/cris/cpu.c b/target/cris/cpu.c
index 17c6712e29..9b8b99840d 100644
--- a/target/cris/cpu.c
+++ b/target/cris/cpu.c
@@ -134,8 +134,8 @@ static void cris_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     ccc->parent_realize(dev, errp);
 }
diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c
index 687bf35e65..56f7b97c8f 100644
--- a/target/lm32/cpu.c
+++ b/target/lm32/cpu.c
@@ -132,9 +132,8 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    cpu_reset(cs);
-
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     lcc->parent_realize(dev, errp);
 }
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index f0653cda2f..51ca62694e 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -247,8 +247,8 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
 
     m68k_cpu_init_gdb(cpu);
 
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     mcc->parent_realize(dev, errp);
 }
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index 6cd6b9650b..553945005f 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -149,8 +149,8 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
 
     cpu_mips_realize_env(&cpu->env);
 
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     mcc->parent_realize(dev, errp);
 }
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 70c8d8170f..2564436719 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -184,8 +184,8 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     scc->parent_realize(dev, errp);
 }
diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c
index cd422a0467..7e9982197f 100644
--- a/target/tilegx/cpu.c
+++ b/target/tilegx/cpu.c
@@ -91,8 +91,8 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     tcc->parent_realize(dev, errp);
 }
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 85bc9f03a1..c5a5d54569 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -94,8 +94,8 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)
     if (tricore_feature(env, TRICORE_FEATURE_131)) {
         set_feature(env, TRICORE_FEATURE_13);
     }
-    cpu_reset(cs);
     qemu_init_vcpu(cs);
+    cpu_reset(cs);
 
     tcc->parent_realize(dev, errp);
 }
-- 
2.21.1



  reply	other threads:[~2020-03-09 12:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 12:11 [PATCH 0/2] cpu: Avoid latent bug calling cpu_reset() on uninitialized vCPU Philippe Mathieu-Daudé
2020-03-09 12:11 ` Philippe Mathieu-Daudé [this message]
2020-03-09 13:08   ` [PATCH 1/2] cpu: Do not reset a vCPU before it is created Laurent Vivier
2020-03-09 13:09   ` Peter Maydell
2020-03-09 13:13     ` Laurent Vivier
2020-03-09 13:18       ` Peter Maydell
2020-03-09 13:28         ` Laurent Vivier
2020-03-09 12:11 ` [PATCH 2/2] cpu: Assert a vCPU is created before resetting it Philippe Mathieu-Daudé
2020-03-09 13:10   ` Peter Maydell
2020-03-09 15:30     ` Philippe Mathieu-Daudé

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=20200309121103.20234-2-philmd@redhat.com \
    --to=philmd@redhat.com \
    --cc=aleksandar.rikalo@rt-rk.com \
    --cc=amarkovic@wavecomp.com \
    --cc=aurelien@aurel32.net \
    --cc=edgar.iglesias@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=laurent@vivier.eu \
    --cc=michael@walle.cc \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).