* [Qemu-devel] [PATCH v2 1/4] target-i386: Rename optimize_flags_init()
2015-09-18 19:38 [Qemu-devel] [PATCH v2 0/4] target-i386: Remove side-effects from X86CPU::instance_init Eduardo Habkost
@ 2015-09-18 19:38 ` Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 2/4] target-i386: Move TCG initialization check to tcg_x86_init() Eduardo Habkost
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2015-09-18 19:38 UTC (permalink / raw)
To: qemu-devel
Cc: zhugh.fnst, tangchen, chen.fan.fnst, isimatu.yasuaki,
Paolo Bonzini, Gu Zheng, Igor Mammedov, anshul.makkar,
Andreas Färber
Rename the function so that the reason for its existence is clearer: it
does x86-specific initialization of TCG structures.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-i386/cpu.c | 2 +-
target-i386/cpu.h | 2 +-
target-i386/translate.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 21f7b99..22c0f5b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3074,7 +3074,7 @@ static void x86_cpu_initfn(Object *obj)
/* init various static tables used in TCG mode */
if (tcg_enabled() && !inited) {
inited = 1;
- optimize_flags_init();
+ tcg_x86_init();
}
}
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 737a68e..4e48cf2 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -1236,7 +1236,7 @@ static inline target_long lshift(target_long x, int n)
#define ST1 ST(1)
/* translate.c */
-void optimize_flags_init(void);
+void tcg_x86_init(void);
#include "exec/cpu-all.h"
#include "svm.h"
diff --git a/target-i386/translate.c b/target-i386/translate.c
index 8b35de1..e6e60e5 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7789,7 +7789,7 @@ static target_ulong disas_insn(CPUX86State *env, DisasContext *s,
return s->pc;
}
-void optimize_flags_init(void)
+void tcg_x86_init(void)
{
static const char reg_names[CPU_NB_REGS][4] = {
#ifdef TARGET_X86_64
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] target-i386: Move TCG initialization check to tcg_x86_init()
2015-09-18 19:38 [Qemu-devel] [PATCH v2 0/4] target-i386: Remove side-effects from X86CPU::instance_init Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 1/4] target-i386: Rename optimize_flags_init() Eduardo Habkost
@ 2015-09-18 19:38 ` Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 3/4] target-i386: Move TCG initialization to realize time Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize Eduardo Habkost
3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2015-09-18 19:38 UTC (permalink / raw)
To: qemu-devel
Cc: zhugh.fnst, tangchen, chen.fan.fnst, isimatu.yasuaki,
Paolo Bonzini, Gu Zheng, Igor Mammedov, anshul.makkar,
Andreas Färber
Instead of requiring cpu.c to check if TCG was already initialized,
simply let the function be called multiple times.
Suggested-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-i386/cpu.c | 4 +---
target-i386/translate.c | 6 ++++++
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 22c0f5b..f054a69 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -3021,7 +3021,6 @@ static void x86_cpu_initfn(Object *obj)
X86CPUClass *xcc = X86_CPU_GET_CLASS(obj);
CPUX86State *env = &cpu->env;
FeatureWord w;
- static int inited;
cs->env_ptr = env;
cpu_exec_init(cs, &error_abort);
@@ -3072,8 +3071,7 @@ static void x86_cpu_initfn(Object *obj)
x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
/* init various static tables used in TCG mode */
- if (tcg_enabled() && !inited) {
- inited = 1;
+ if (tcg_enabled()) {
tcg_x86_init();
}
}
diff --git a/target-i386/translate.c b/target-i386/translate.c
index e6e60e5..8ed3902 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7821,6 +7821,12 @@ void tcg_x86_init(void)
#endif
};
int i;
+ static bool initialized = false;
+
+ if (initialized) {
+ return;
+ }
+ initialized = true;
cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
cpu_cc_op = tcg_global_mem_new_i32(TCG_AREG0,
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] target-i386: Move TCG initialization to realize time
2015-09-18 19:38 [Qemu-devel] [PATCH v2 0/4] target-i386: Remove side-effects from X86CPU::instance_init Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 1/4] target-i386: Rename optimize_flags_init() Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 2/4] target-i386: Move TCG initialization check to tcg_x86_init() Eduardo Habkost
@ 2015-09-18 19:38 ` Eduardo Habkost
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize Eduardo Habkost
3 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2015-09-18 19:38 UTC (permalink / raw)
To: qemu-devel
Cc: zhugh.fnst, tangchen, chen.fan.fnst, isimatu.yasuaki,
Paolo Bonzini, Gu Zheng, Igor Mammedov, anshul.makkar,
Andreas Färber
QOM instance_init functions are not supposed to have any side-effects,
as new objects may be created at any moment for querying property
information (see qmp_device_list_properties()).
Move TCG initialization to realize time so it won't be called when just
doing object_new() on a X86CPU subclass.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Now the inited/tcg_initialized variable doesn't exist anymore
* Move tcg_x86_init() call after basic parameter validation inside
realizefn
---
target-i386/cpu.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f054a69..2e5a303 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2832,6 +2832,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
goto out;
}
+ if (tcg_enabled()) {
+ tcg_x86_init();
+ }
+
#ifndef CONFIG_USER_ONLY
qemu_register_reset(x86_cpu_machine_reset_cb, cpu);
@@ -3069,11 +3073,6 @@ static void x86_cpu_initfn(Object *obj)
}
x86_cpu_load_def(cpu, xcc->cpu_def, &error_abort);
-
- /* init various static tables used in TCG mode */
- if (tcg_enabled()) {
- tcg_x86_init();
- }
}
static int64_t x86_cpu_get_arch_id(CPUState *cs)
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize
2015-09-18 19:38 [Qemu-devel] [PATCH v2 0/4] target-i386: Remove side-effects from X86CPU::instance_init Eduardo Habkost
` (2 preceding siblings ...)
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 3/4] target-i386: Move TCG initialization to realize time Eduardo Habkost
@ 2015-09-18 19:38 ` Eduardo Habkost
2015-09-21 5:41 ` Bharata B Rao
3 siblings, 1 reply; 7+ messages in thread
From: Eduardo Habkost @ 2015-09-18 19:38 UTC (permalink / raw)
To: qemu-devel
Cc: zhugh.fnst, tangchen, chen.fan.fnst, isimatu.yasuaki,
Paolo Bonzini, Gu Zheng, Igor Mammedov, anshul.makkar,
Andreas Färber
QOM instance_init functions are not supposed to have any side-effects,
as new objects may be created at any moment for querying property
information (see qmp_device_list_properties()).
Calling cpu_exec_init() also affects QEMU's ability to handle errors
during CPU creation, as some actions done by cpu_exec_init() can't be
reverted.
Move cpu_exec_init() call to realize so a simple object_new() won't
trigger it, and so that it is called after some basic validation of CPU
parameters.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Call cpu_exec_init() after basic parameter validation
---
target-i386/cpu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 2e5a303..19d1525 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2832,6 +2832,8 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
goto out;
}
+ cpu_exec_init(cs, &error_abort);
+
if (tcg_enabled()) {
tcg_x86_init();
}
@@ -3027,7 +3029,6 @@ static void x86_cpu_initfn(Object *obj)
FeatureWord w;
cs->env_ptr = env;
- cpu_exec_init(cs, &error_abort);
object_property_add(obj, "family", "int",
x86_cpuid_version_get_family,
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize
2015-09-18 19:38 ` [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize Eduardo Habkost
@ 2015-09-21 5:41 ` Bharata B Rao
2015-09-21 14:15 ` Eduardo Habkost
0 siblings, 1 reply; 7+ messages in thread
From: Bharata B Rao @ 2015-09-21 5:41 UTC (permalink / raw)
To: Eduardo Habkost
Cc: Zhu Guihua, qemu-devel@nongnu.org, tangchen, Gu Zheng,
isimatu yasuaki, Igor Mammedov, ChenFan, Paolo Bonzini,
Anshul Makkar, Andreas Färber
On Sat, Sep 19, 2015 at 1:08 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> QOM instance_init functions are not supposed to have any side-effects,
> as new objects may be created at any moment for querying property
> information (see qmp_device_list_properties()).
>
> Calling cpu_exec_init() also affects QEMU's ability to handle errors
> during CPU creation, as some actions done by cpu_exec_init() can't be
> reverted.
>
> Move cpu_exec_init() call to realize so a simple object_new() won't
> trigger it, and so that it is called after some basic validation of CPU
> parameters.
Since you are moving cpu_exec_init() to realize, does it make sense to
define unrealize and call cpu_exec_exit() from it ?
Regards,
Bharata.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] target-i386: Call cpu_exec_init() on realize
2015-09-21 5:41 ` Bharata B Rao
@ 2015-09-21 14:15 ` Eduardo Habkost
0 siblings, 0 replies; 7+ messages in thread
From: Eduardo Habkost @ 2015-09-21 14:15 UTC (permalink / raw)
To: Bharata B Rao
Cc: Zhu Guihua, qemu-devel@nongnu.org, tangchen, Gu Zheng,
isimatu yasuaki, Igor Mammedov, ChenFan, Paolo Bonzini,
Anshul Makkar, Andreas Färber
On Mon, Sep 21, 2015 at 11:11:47AM +0530, Bharata B Rao wrote:
> On Sat, Sep 19, 2015 at 1:08 AM, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > QOM instance_init functions are not supposed to have any side-effects,
> > as new objects may be created at any moment for querying property
> > information (see qmp_device_list_properties()).
> >
> > Calling cpu_exec_init() also affects QEMU's ability to handle errors
> > during CPU creation, as some actions done by cpu_exec_init() can't be
> > reverted.
> >
> > Move cpu_exec_init() call to realize so a simple object_new() won't
> > trigger it, and so that it is called after some basic validation of CPU
> > parameters.
>
> Since you are moving cpu_exec_init() to realize, does it make sense to
> define unrealize and call cpu_exec_exit() from it ?
It does make sense. But it needs to be done more carefully because
currently cpu_exec_exit() is likely to make QEMU crash, and calling it
from unrealize would make the crash triggerable using a QMP qom-set
command.
--
Eduardo
^ permalink raw reply [flat|nested] 7+ messages in thread