Skip to content

Commit dfa9c2a

Browse files
committed
Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging
- Migration and linuxboot fixes for 2.2 regressions - valgrind/KVM support - small i386 patches - PCI SD host controller support - malloc/free cleanups from Markus (x86/scsi) - IvyBridge model - XSAVES support for KVM - initial patches from record/replay # gpg: Signature made Mon 15 Dec 2014 16:35:08 GMT using RSA key ID 78C7AE83 # gpg: Good signature from "Paolo Bonzini <[email protected]>" # gpg: aka "Paolo Bonzini <[email protected]>" # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * remotes/bonzini/tags/for-upstream: (47 commits) sdhci: Support SDHCI devices on PCI sdhci: Define SDHCI PCI ids sdhci: Add "sysbus" to sdhci QOM types and methods sdhci: Remove class "virtual" methods sdhci: Set a default frequency clock serial: only resample THR interrupt on rising edge of IER.THRI serial: update LSR on enabling/disabling FIFOs serial: clean up THRE/TEMT handling serial: reset thri_pending on IER writes with THRI=0 linuxboot: fix loading old kernels kvm/apic: fix 2.2->2.1 migration target-i386: add Ivy Bridge CPU model target-i386: add f16c and rdrand to Haswell and Broadwell target-i386: add VME to all CPUs pc: add 2.3 machine types i386: do not cross the pages boundaries in replay mode cpus: make icount warp behave well with respect to stop/cont timer: introduce new QEMU_CLOCK_VIRTUAL_RT clock cpu-exec: invalidate nocache translation if they are interrupted icount: introduce cpu_get_icount_raw ... Signed-off-by: Peter Maydell <[email protected]>
2 parents 5460075 + 224d10f commit dfa9c2a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+604
-263
lines changed

cpu-exec.c

+12-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, uint8_t *tb_ptr)
168168
}
169169
#endif /* DEBUG_DISAS */
170170

171+
cpu->can_do_io = 0;
171172
next_tb = tcg_qemu_tb_exec(env, tb_ptr);
173+
cpu->can_do_io = 1;
172174
trace_exec_tb_exit((void *) (next_tb & ~TB_EXIT_MASK),
173175
next_tb & TB_EXIT_MASK);
174176

@@ -202,14 +204,19 @@ static void cpu_exec_nocache(CPUArchState *env, int max_cycles,
202204
{
203205
CPUState *cpu = ENV_GET_CPU(env);
204206
TranslationBlock *tb;
207+
target_ulong pc = orig_tb->pc;
208+
target_ulong cs_base = orig_tb->cs_base;
209+
uint64_t flags = orig_tb->flags;
205210

206211
/* Should never happen.
207212
We only end up here when an existing TB is too long. */
208213
if (max_cycles > CF_COUNT_MASK)
209214
max_cycles = CF_COUNT_MASK;
210215

211-
tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base, orig_tb->flags,
212-
max_cycles);
216+
/* tb_gen_code can flush our orig_tb, invalidate it now */
217+
tb_phys_invalidate(orig_tb, -1);
218+
tb = tb_gen_code(cpu, pc, cs_base, flags,
219+
max_cycles | CF_NOCACHE);
213220
cpu->current_tb = tb;
214221
/* execute the generated code */
215222
trace_exec_tb_nocache(tb, tb->pc);
@@ -353,7 +360,6 @@ int cpu_exec(CPUArchState *env)
353360
}
354361

355362
cc->cpu_exec_enter(cpu);
356-
cpu->exception_index = -1;
357363

358364
/* Calculate difference between guest clock and host clock.
359365
* This delay includes the delay of the last cycle, so
@@ -373,6 +379,7 @@ int cpu_exec(CPUArchState *env)
373379
if (ret == EXCP_DEBUG) {
374380
cpu_handle_debug_exception(env);
375381
}
382+
cpu->exception_index = -1;
376383
break;
377384
} else {
378385
#if defined(CONFIG_USER_ONLY)
@@ -383,6 +390,7 @@ int cpu_exec(CPUArchState *env)
383390
cc->do_interrupt(cpu);
384391
#endif
385392
ret = cpu->exception_index;
393+
cpu->exception_index = -1;
386394
break;
387395
#else
388396
cc->do_interrupt(cpu);
@@ -537,6 +545,7 @@ int cpu_exec(CPUArchState *env)
537545
cpu = current_cpu;
538546
env = cpu->env_ptr;
539547
cc = CPU_GET_CLASS(cpu);
548+
cpu->can_do_io = 1;
540549
#ifdef TARGET_I386
541550
x86_cpu = X86_CPU(cpu);
542551
#endif

cpus.c

+26-14
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,26 @@ typedef struct TimersState {
136136

137137
static TimersState timers_state;
138138

139-
/* Return the virtual CPU time, based on the instruction counter. */
140-
static int64_t cpu_get_icount_locked(void)
139+
int64_t cpu_get_icount_raw(void)
141140
{
142141
int64_t icount;
143142
CPUState *cpu = current_cpu;
144143

145144
icount = timers_state.qemu_icount;
146145
if (cpu) {
147146
if (!cpu_can_do_io(cpu)) {
148-
fprintf(stderr, "Bad clock read\n");
147+
fprintf(stderr, "Bad icount read\n");
148+
exit(1);
149149
}
150150
icount -= (cpu->icount_decr.u16.low + cpu->icount_extra);
151151
}
152+
return icount;
153+
}
154+
155+
/* Return the virtual CPU time, based on the instruction counter. */
156+
static int64_t cpu_get_icount_locked(void)
157+
{
158+
int64_t icount = cpu_get_icount_raw();
152159
return timers_state.qemu_icount_bias + cpu_icount_to_ns(icount);
153160
}
154161

@@ -345,7 +352,7 @@ static void icount_warp_rt(void *opaque)
345352

346353
seqlock_write_lock(&timers_state.vm_clock_seqlock);
347354
if (runstate_is_running()) {
348-
int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
355+
int64_t clock = cpu_get_clock_locked();
349356
int64_t warp_delta;
350357

351358
warp_delta = clock - vm_clock_warp_start;
@@ -354,9 +361,8 @@ static void icount_warp_rt(void *opaque)
354361
* In adaptive mode, do not let QEMU_CLOCK_VIRTUAL run too
355362
* far ahead of real time.
356363
*/
357-
int64_t cur_time = cpu_get_clock_locked();
358364
int64_t cur_icount = cpu_get_icount_locked();
359-
int64_t delta = cur_time - cur_icount;
365+
int64_t delta = clock - cur_icount;
360366
warp_delta = MIN(warp_delta, delta);
361367
}
362368
timers_state.qemu_icount_bias += warp_delta;
@@ -419,7 +425,7 @@ void qemu_clock_warp(QEMUClockType type)
419425
}
420426

421427
/* We want to use the earliest deadline from ALL vm_clocks */
422-
clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
428+
clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
423429
deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL);
424430
if (deadline < 0) {
425431
return;
@@ -437,8 +443,8 @@ void qemu_clock_warp(QEMUClockType type)
437443
* sleep in icount mode if there is a pending QEMU_CLOCK_VIRTUAL
438444
* timer; rather time could just advance to the next QEMU_CLOCK_VIRTUAL
439445
* event. Instead, we do stop VCPUs and only advance QEMU_CLOCK_VIRTUAL
440-
* after some e"real" time, (related to the time left until the next
441-
* event) has passed. The QEMU_CLOCK_REALTIME timer will do this.
446+
* after some "real" time, (related to the time left until the next
447+
* event) has passed. The QEMU_CLOCK_VIRTUAL_RT clock will do this.
442448
* This avoids that the warps are visible externally; for example,
443449
* you will not be sending network packets continuously instead of
444450
* every 100ms.
@@ -512,8 +518,8 @@ void configure_icount(QemuOpts *opts, Error **errp)
512518
return;
513519
}
514520
icount_align_option = qemu_opt_get_bool(opts, "align", false);
515-
icount_warp_timer = timer_new_ns(QEMU_CLOCK_REALTIME,
516-
icount_warp_rt, NULL);
521+
icount_warp_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
522+
icount_warp_rt, NULL);
517523
if (strcmp(option, "auto") != 0) {
518524
errno = 0;
519525
icount_time_shift = strtol(option, &rem_str, 0);
@@ -537,10 +543,10 @@ void configure_icount(QemuOpts *opts, Error **errp)
537543
the virtual time trigger catches emulated time passing too fast.
538544
Realtime triggers occur even when idle, so use them less frequently
539545
than VM triggers. */
540-
icount_rt_timer = timer_new_ms(QEMU_CLOCK_REALTIME,
541-
icount_adjust_rt, NULL);
546+
icount_rt_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_RT,
547+
icount_adjust_rt, NULL);
542548
timer_mod(icount_rt_timer,
543-
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
549+
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) + 1000);
544550
icount_vm_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
545551
icount_adjust_vm, NULL);
546552
timer_mod(icount_vm_timer,
@@ -934,6 +940,8 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)
934940
qemu_mutex_lock(&qemu_global_mutex);
935941
qemu_thread_get_self(cpu->thread);
936942
cpu->thread_id = qemu_get_thread_id();
943+
cpu->exception_index = -1;
944+
cpu->can_do_io = 1;
937945
current_cpu = cpu;
938946

939947
r = kvm_init_vcpu(cpu);
@@ -974,6 +982,8 @@ static void *qemu_dummy_cpu_thread_fn(void *arg)
974982
qemu_mutex_lock_iothread();
975983
qemu_thread_get_self(cpu->thread);
976984
cpu->thread_id = qemu_get_thread_id();
985+
cpu->exception_index = -1;
986+
cpu->can_do_io = 1;
977987

978988
sigemptyset(&waitset);
979989
sigaddset(&waitset, SIG_IPI);
@@ -1016,6 +1026,8 @@ static void *qemu_tcg_cpu_thread_fn(void *arg)
10161026
CPU_FOREACH(cpu) {
10171027
cpu->thread_id = qemu_get_thread_id();
10181028
cpu->created = true;
1029+
cpu->exception_index = -1;
1030+
cpu->can_do_io = 1;
10191031
}
10201032
qemu_cond_signal(&qemu_cpu_cond);
10211033

default-configs/pci.mak

+2
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ CONFIG_IPACK=y
3030
CONFIG_WDT_IB6300ESB=y
3131
CONFIG_PCI_TESTDEV=y
3232
CONFIG_NVME_PCI=y
33+
CONFIG_SD=y
34+
CONFIG_SDHCI=y

docs/specs/pci-ids.txt

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ PCI devices (other than virtio):
4444
1b36:0002 PCI serial port (16550A) adapter (docs/specs/pci-serial.txt)
4545
1b36:0003 PCI Dual-port 16550A adapter (docs/specs/pci-serial.txt)
4646
1b36:0004 PCI Quad-port 16550A adapter (docs/specs/pci-serial.txt)
47+
1b36:0005 PCI test device (docs/specs/pci-testdev.txt)
48+
1b36:0006 PCI SD Card Host Controller Interface (SDHCI)
4749

4850
All these devices are documented in docs/specs.
4951

hw/char/serial.c

+40-18
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,23 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque)
224224
SerialState *s = opaque;
225225

226226
do {
227+
assert(!(s->lsr & UART_LSR_TEMT));
227228
if (s->tsr_retry <= 0) {
229+
assert(!(s->lsr & UART_LSR_THRE));
230+
228231
if (s->fcr & UART_FCR_FE) {
229-
if (fifo8_is_empty(&s->xmit_fifo)) {
230-
return FALSE;
231-
}
232+
assert(!fifo8_is_empty(&s->xmit_fifo));
232233
s->tsr = fifo8_pop(&s->xmit_fifo);
233234
if (!s->xmit_fifo.num) {
234235
s->lsr |= UART_LSR_THRE;
235236
}
236-
} else if ((s->lsr & UART_LSR_THRE)) {
237-
return FALSE;
238237
} else {
239238
s->tsr = s->thr;
240239
s->lsr |= UART_LSR_THRE;
241-
s->lsr &= ~UART_LSR_TEMT;
240+
}
241+
if ((s->lsr & UART_LSR_THRE) && !s->thr_ipending) {
242+
s->thr_ipending = 1;
243+
serial_update_irq(s);
242244
}
243245
}
244246

@@ -256,17 +258,13 @@ static gboolean serial_xmit(GIOChannel *chan, GIOCondition cond, void *opaque)
256258
} else {
257259
s->tsr_retry = 0;
258260
}
261+
259262
/* Transmit another byte if it is already available. It is only
260263
possible when FIFO is enabled and not empty. */
261-
} while ((s->fcr & UART_FCR_FE) && !fifo8_is_empty(&s->xmit_fifo));
264+
} while (!(s->lsr & UART_LSR_THRE));
262265

263266
s->last_xmit_ts = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
264-
265-
if (s->lsr & UART_LSR_THRE) {
266-
s->lsr |= UART_LSR_TEMT;
267-
s->thr_ipending = 1;
268-
serial_update_irq(s);
269-
}
267+
s->lsr |= UART_LSR_TEMT;
270268

271269
return FALSE;
272270
}
@@ -323,10 +321,10 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
323321
fifo8_pop(&s->xmit_fifo);
324322
}
325323
fifo8_push(&s->xmit_fifo, s->thr);
326-
s->lsr &= ~UART_LSR_TEMT;
327324
}
328325
s->thr_ipending = 0;
329326
s->lsr &= ~UART_LSR_THRE;
327+
s->lsr &= ~UART_LSR_TEMT;
330328
serial_update_irq(s);
331329
if (s->tsr_retry <= 0) {
332330
serial_xmit(NULL, G_IO_OUT, s);
@@ -338,10 +336,12 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
338336
s->divider = (s->divider & 0x00ff) | (val << 8);
339337
serial_update_parameters(s);
340338
} else {
339+
uint8_t changed = (s->ier ^ val) & 0x0f;
341340
s->ier = val & 0x0f;
342341
/* If the backend device is a real serial port, turn polling of the modem
343-
status lines on physical port on or off depending on UART_IER_MSI state */
344-
if (s->poll_msl >= 0) {
342+
* status lines on physical port on or off depending on UART_IER_MSI state.
343+
*/
344+
if ((changed & UART_IER_MSI) && s->poll_msl >= 0) {
345345
if (s->ier & UART_IER_MSI) {
346346
s->poll_msl = 1;
347347
serial_update_msl(s);
@@ -350,8 +350,27 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
350350
s->poll_msl = 0;
351351
}
352352
}
353-
if (s->lsr & UART_LSR_THRE) {
354-
s->thr_ipending = 1;
353+
354+
/* Turning on the THRE interrupt on IER can trigger the interrupt
355+
* if LSR.THRE=1, even if it had been masked before by reading IIR.
356+
* This is not in the datasheet, but Windows relies on it. It is
357+
* unclear if THRE has to be resampled every time THRI becomes
358+
* 1, or only on the rising edge. Bochs does the latter, and Windows
359+
* always toggles IER to all zeroes and back to all ones, so do the
360+
* same.
361+
*
362+
* If IER.THRI is zero, thr_ipending is not used. Set it to zero
363+
* so that the thr_ipending subsection is not migrated.
364+
*/
365+
if (changed & UART_IER_THRI) {
366+
if ((s->ier & UART_IER_THRI) && (s->lsr & UART_LSR_THRE)) {
367+
s->thr_ipending = 1;
368+
} else {
369+
s->thr_ipending = 0;
370+
}
371+
}
372+
373+
if (changed) {
355374
serial_update_irq(s);
356375
}
357376
}
@@ -365,12 +384,15 @@ static void serial_ioport_write(void *opaque, hwaddr addr, uint64_t val,
365384
/* FIFO clear */
366385

367386
if (val & UART_FCR_RFR) {
387+
s->lsr &= ~(UART_LSR_DR | UART_LSR_BI);
368388
timer_del(s->fifo_timeout_timer);
369389
s->timeout_ipending = 0;
370390
fifo8_reset(&s->recv_fifo);
371391
}
372392

373393
if (val & UART_FCR_XFR) {
394+
s->lsr |= UART_LSR_THRE;
395+
s->thr_ipending = 1;
374396
fifo8_reset(&s->xmit_fifo);
375397
}
376398

hw/i386/kvm/apic.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,15 @@ static const MemoryRegionOps kvm_apic_io_ops = {
171171
.endianness = DEVICE_NATIVE_ENDIAN,
172172
};
173173

174-
static void kvm_apic_realize(DeviceState *dev, Error **errp)
174+
static void kvm_apic_reset(APICCommonState *s)
175175
{
176-
APICCommonState *s = APIC_COMMON(dev);
177-
178176
/* Not used by KVM, which uses the CPU mp_state instead. */
179177
s->wait_for_sipi = 0;
178+
}
179+
180+
static void kvm_apic_realize(DeviceState *dev, Error **errp)
181+
{
182+
APICCommonState *s = APIC_COMMON(dev);
180183

181184
memory_region_init_io(&s->io_memory, NULL, &kvm_apic_io_ops, s, "kvm-apic-msi",
182185
APIC_SPACE_SIZE);
@@ -191,6 +194,7 @@ static void kvm_apic_class_init(ObjectClass *klass, void *data)
191194
APICCommonClass *k = APIC_COMMON_CLASS(klass);
192195

193196
k->realize = kvm_apic_realize;
197+
k->reset = kvm_apic_reset;
194198
k->set_base = kvm_apic_set_base;
195199
k->set_tpr = kvm_apic_set_tpr;
196200
k->get_tpr = kvm_apic_get_tpr;

hw/i386/kvm/clock.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void kvmclock_vm_state_change(void *opaque, int running,
8888
int ret;
8989

9090
if (running) {
91-
struct kvm_clock_data data;
91+
struct kvm_clock_data data = {};
9292
uint64_t time_at_migration = kvmclock_current_nsec(s);
9393

9494
s->clock_valid = false;
@@ -99,7 +99,6 @@ static void kvmclock_vm_state_change(void *opaque, int running,
9999
}
100100

101101
data.clock = s->clock;
102-
data.flags = 0;
103102
ret = kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, &data);
104103
if (ret < 0) {
105104
fprintf(stderr, "KVM_SET_CLOCK failed: %s\n", strerror(ret));

hw/i386/kvm/i8254.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void kvm_pit_get(PITCommonState *pit)
138138
static void kvm_pit_put(PITCommonState *pit)
139139
{
140140
KVMPITState *s = KVM_PIT(pit);
141-
struct kvm_pit_state2 kpit;
141+
struct kvm_pit_state2 kpit = {};
142142
struct kvm_pit_channel_state *kchan;
143143
struct PITChannelState *sc;
144144
int i, ret;

0 commit comments

Comments
 (0)