Revision ea375f9a

b/exec.c
512 512

  
513 513
#if defined(CPU_SAVE_VERSION) && !defined(CONFIG_USER_ONLY)
514 514

  
515
static void cpu_common_pre_save(void *opaque)
516
{
517
    CPUState *env = opaque;
518

  
519
    cpu_synchronize_state(env);
520
}
521

  
522
static int cpu_common_pre_load(void *opaque)
523
{
524
    CPUState *env = opaque;
525

  
526
    cpu_synchronize_state(env);
527
    return 0;
528
}
529

  
530 515
static int cpu_common_post_load(void *opaque, int version_id)
531 516
{
532 517
    CPUState *env = opaque;
......
544 529
    .version_id = 1,
545 530
    .minimum_version_id = 1,
546 531
    .minimum_version_id_old = 1,
547
    .pre_save = cpu_common_pre_save,
548
    .pre_load = cpu_common_pre_load,
549 532
    .post_load = cpu_common_post_load,
550 533
    .fields      = (VMStateField []) {
551 534
        VMSTATE_UINT32(halted, CPUState),
b/hw/apic.c
938 938
    APICState *s = opaque;
939 939
    int bsp;
940 940

  
941
    cpu_synchronize_state(s->cpu_env);
942

  
943 941
    bsp = cpu_is_bsp(s->cpu_env);
944 942
    s->apicbase = 0xfee00000 |
945 943
        (bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
b/hw/ppc_newworld.c
167 167
        envs[i] = env;
168 168
    }
169 169

  
170
    /* Make sure all register sets take effect */
171
    cpu_synchronize_state(env);
172

  
173 170
    /* allocate RAM */
174 171
    ram_offset = qemu_ram_alloc(ram_size);
175 172
    cpu_register_physical_memory(0, ram_size, ram_offset);
b/hw/ppc_oldworld.c
165 165
        envs[i] = env;
166 166
    }
167 167

  
168
    /* Make sure all register sets take effect */
169
    cpu_synchronize_state(env);
170

  
171 168
    /* allocate RAM */
172 169
    if (ram_size > (2047 << 20)) {
173 170
        fprintf(stderr,
b/hw/s390-virtio.c
185 185
            exit(1);
186 186
        }
187 187

  
188
        cpu_synchronize_state(env);
189 188
        env->psw.addr = KERN_IMAGE_START;
190 189
        env->psw.mask = 0x0000000180000000ULL;
191 190
    }
b/kvm-all.c
156 156
    CPUState *env = opaque;
157 157

  
158 158
    kvm_arch_reset_vcpu(env);
159
    if (kvm_arch_put_registers(env)) {
160
        fprintf(stderr, "Fatal: kvm vcpu reset failed\n");
161
        abort();
162
    }
163 159
}
164 160

  
165 161
int kvm_irqchip_in_kernel(void)
......
214 210
    if (ret == 0) {
215 211
        qemu_register_reset(kvm_reset_vcpu, env);
216 212
        kvm_arch_reset_vcpu(env);
217
        ret = kvm_arch_put_registers(env);
218 213
    }
219 214
err:
220 215
    return ret;
......
753 748
    }
754 749
}
755 750

  
751
void kvm_cpu_synchronize_post_reset(CPUState *env)
752
{
753
    kvm_arch_put_registers(env, KVM_PUT_RESET_STATE);
754
    env->kvm_vcpu_dirty = 0;
755
}
756

  
757
void kvm_cpu_synchronize_post_init(CPUState *env)
758
{
759
    kvm_arch_put_registers(env, KVM_PUT_FULL_STATE);
760
    env->kvm_vcpu_dirty = 0;
761
}
762

  
756 763
int kvm_cpu_exec(CPUState *env)
757 764
{
758 765
    struct kvm_run *run = env->kvm_run;
......
770 777
#endif
771 778

  
772 779
        if (env->kvm_vcpu_dirty) {
773
            kvm_arch_put_registers(env);
780
            kvm_arch_put_registers(env, KVM_PUT_RUNTIME_STATE);
774 781
            env->kvm_vcpu_dirty = 0;
775 782
        }
776 783

  
b/kvm.h
82 82

  
83 83
int kvm_arch_get_registers(CPUState *env);
84 84

  
85
int kvm_arch_put_registers(CPUState *env);
85
/* state subset only touched by the VCPU itself during runtime */
86
#define KVM_PUT_RUNTIME_STATE   1
87
/* state subset modified during VCPU reset */
88
#define KVM_PUT_RESET_STATE     2
89
/* full state set, modified during initialization or on vmload */
90
#define KVM_PUT_FULL_STATE      3
91

  
92
int kvm_arch_put_registers(CPUState *env, int level);
86 93

  
87 94
int kvm_arch_init(KVMState *s, int smp_cpus);
88 95

  
......
126 133
uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function,
127 134
                                      int reg);
128 135
void kvm_cpu_synchronize_state(CPUState *env);
136
void kvm_cpu_synchronize_post_reset(CPUState *env);
137
void kvm_cpu_synchronize_post_init(CPUState *env);
129 138

  
130 139
/* generic hooks - to be moved/refactored once there are more users */
131 140

  
......
136 145
    }
137 146
}
138 147

  
148
static inline void cpu_synchronize_post_reset(CPUState *env)
149
{
150
    if (kvm_enabled()) {
151
        kvm_cpu_synchronize_post_reset(env);
152
    }
153
}
154

  
155
static inline void cpu_synchronize_post_init(CPUState *env)
156
{
157
    if (kvm_enabled()) {
158
        kvm_cpu_synchronize_post_init(env);
159
    }
160
}
161

  
139 162
#endif
b/savevm.c
1345 1345
{
1346 1346
    SaveStateEntry *se;
1347 1347

  
1348
    cpu_synchronize_all_states();
1349

  
1348 1350
    QTAILQ_FOREACH(se, &savevm_handlers, entry) {
1349 1351
        if (se->save_live_state == NULL)
1350 1352
            continue;
......
1545 1547
        }
1546 1548
    }
1547 1549

  
1550
    cpu_synchronize_all_post_init();
1551

  
1548 1552
    ret = 0;
1549 1553

  
1550 1554
out:
b/sysemu.h
58 58
void do_delvm(Monitor *mon, const QDict *qdict);
59 59
void do_info_snapshots(Monitor *mon);
60 60

  
61
void cpu_synchronize_all_states(void);
62
void cpu_synchronize_all_post_reset(void);
63
void cpu_synchronize_all_post_init(void);
64

  
61 65
void qemu_announce_self(void);
62 66

  
63 67
void main_loop_wait(int timeout);
b/target-i386/kvm.c
883 883
    return ret;
884 884
}
885 885

  
886
int kvm_arch_put_registers(CPUState *env)
886
int kvm_arch_put_registers(CPUState *env, int level)
887 887
{
888 888
    int ret;
889 889

  
b/target-i386/machine.c
321 321
    CPUState *env = opaque;
322 322
    int i;
323 323

  
324
    cpu_synchronize_state(env);
325

  
326 324
    /* FPU */
327 325
    env->fpus_vmstate = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
328 326
    env->fptag_vmstate = 0;
......
337 335
#endif
338 336
}
339 337

  
340
static int cpu_pre_load(void *opaque)
341
{
342
    CPUState *env = opaque;
343

  
344
    cpu_synchronize_state(env);
345
    return 0;
346
}
347

  
348 338
static int cpu_post_load(void *opaque, int version_id)
349 339
{
350 340
    CPUState *env = opaque;
......
373 363
    .minimum_version_id = 3,
374 364
    .minimum_version_id_old = 3,
375 365
    .pre_save = cpu_pre_save,
376
    .pre_load = cpu_pre_load,
377 366
    .post_load = cpu_post_load,
378 367
    .fields      = (VMStateField []) {
379 368
        VMSTATE_UINTTL_ARRAY(regs, CPUState, CPU_NB_REGS),
b/target-ppc/kvm.c
73 73
{
74 74
}
75 75

  
76
int kvm_arch_put_registers(CPUState *env)
76
int kvm_arch_put_registers(CPUState *env, int level)
77 77
{
78 78
    struct kvm_regs regs;
79 79
    int ret;
b/target-ppc/machine.c
7 7
    CPUState *env = (CPUState *)opaque;
8 8
    unsigned int i, j;
9 9

  
10
    cpu_synchronize_state(env);
11

  
12 10
    for (i = 0; i < 32; i++)
13 11
        qemu_put_betls(f, &env->gpr[i]);
14 12
#if !defined(TARGET_PPC64)
......
96 94
    CPUState *env = (CPUState *)opaque;
97 95
    unsigned int i, j;
98 96

  
99
    cpu_synchronize_state(env);
100

  
101 97
    for (i = 0; i < 32; i++)
102 98
        qemu_get_betls(f, &env->gpr[i]);
103 99
#if !defined(TARGET_PPC64)
b/target-s390x/kvm.c
91 91
    /* FIXME: add code to reset vcpu. */
92 92
}
93 93

  
94
int kvm_arch_put_registers(CPUState *env)
94
int kvm_arch_put_registers(CPUState *env, int level)
95 95
{
96 96
    struct kvm_regs regs;
97 97
    int ret;
......
296 296

  
297 297
    cpu_synchronize_state(env);
298 298
    r = s390_virtio_hypercall(env);
299
    kvm_arch_put_registers(env);
300 299

  
301 300
    return r;
302 301
}
b/vl.c
3002 3002
    qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
3003 3003
}
3004 3004

  
3005
void cpu_synchronize_all_states(void)
3006
{
3007
    CPUState *cpu;
3008

  
3009
    for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
3010
        cpu_synchronize_state(cpu);
3011
    }
3012
}
3013

  
3014
void cpu_synchronize_all_post_reset(void)
3015
{
3016
    CPUState *cpu;
3017

  
3018
    for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
3019
        cpu_synchronize_post_reset(cpu);
3020
    }
3021
}
3022

  
3023
void cpu_synchronize_all_post_init(void)
3024
{
3025
    CPUState *cpu;
3026

  
3027
    for (cpu = first_cpu; cpu; cpu = cpu->next_cpu) {
3028
        cpu_synchronize_post_init(cpu);
3029
    }
3030
}
3031

  
3005 3032
struct vm_change_state_entry {
3006 3033
    VMChangeStateHandler *cb;
3007 3034
    void *opaque;
......
3143 3170
    QTAILQ_FOREACH_SAFE(re, &reset_handlers, entry, nre) {
3144 3171
        re->func(re->opaque);
3145 3172
    }
3173
    cpu_synchronize_all_post_reset();
3146 3174
}
3147 3175

  
3148 3176
void qemu_system_reset_request(void)
......
5928 5956
    machine->init(ram_size, boot_devices,
5929 5957
                  kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
5930 5958

  
5959
    cpu_synchronize_all_post_init();
5931 5960

  
5932 5961
#ifndef _WIN32
5933 5962
    /* must be after terminal init, SDL library changes signal handlers */

Also available in: Unified diff