42
40
//#define DEBUG_KVM
45
#define dprintf(fmt, ...) \
43
#define DPRINTF(fmt, ...) \
46
44
do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
48
#define dprintf(fmt, ...) \
46
#define DPRINTF(fmt, ...) \
103
102
cap_ppc_watchdog = kvm_check_extension(s, KVM_CAP_PPC_BOOKE_WATCHDOG);
104
103
/* Note: we don't set cap_papr here, because this capability is
105
104
* only activated after this by kvmppc_set_papr() */
105
cap_htab_fd = kvm_check_extension(s, KVM_CAP_PPC_HTAB_FD);
107
107
if (!cap_interrupt_level) {
108
108
fprintf(stderr, "KVM: Couldn't find level irq capability. Expect the "
550
550
reg.addr = (uintptr_t)&fpscr;
551
551
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
553
dprintf("Unable to set FPSCR to KVM: %s\n", strerror(errno));
553
DPRINTF("Unable to set FPSCR to KVM: %s\n", strerror(errno));
565
565
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
567
dprintf("Unable to set %s%d to KVM: %s\n", vsx ? "VSR" : "FPR",
567
DPRINTF("Unable to set %s%d to KVM: %s\n", vsx ? "VSR" : "FPR",
568
568
i, strerror(errno));
576
576
reg.addr = (uintptr_t)&env->vscr;
577
577
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
579
dprintf("Unable to set VSCR to KVM: %s\n", strerror(errno));
579
DPRINTF("Unable to set VSCR to KVM: %s\n", strerror(errno));
585
585
reg.addr = (uintptr_t)&env->avr[i];
586
586
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
588
dprintf("Unable to set VR%d to KVM: %s\n", i, strerror(errno));
588
DPRINTF("Unable to set VR%d to KVM: %s\n", i, strerror(errno));
610
610
reg.addr = (uintptr_t)&fpscr;
611
611
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
613
dprintf("Unable to get FPSCR from KVM: %s\n", strerror(errno));
613
DPRINTF("Unable to get FPSCR from KVM: %s\n", strerror(errno));
616
616
env->fpscr = fpscr;
625
625
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
627
dprintf("Unable to get %s%d from KVM: %s\n",
627
DPRINTF("Unable to get %s%d from KVM: %s\n",
628
628
vsx ? "VSR" : "FPR", i, strerror(errno));
641
641
reg.addr = (uintptr_t)&env->vscr;
642
642
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
644
dprintf("Unable to get VSCR from KVM: %s\n", strerror(errno));
644
DPRINTF("Unable to get VSCR from KVM: %s\n", strerror(errno));
650
650
reg.addr = (uintptr_t)&env->avr[i];
651
651
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
653
dprintf("Unable to get VR%d from KVM: %s\n",
653
DPRINTF("Unable to get VR%d from KVM: %s\n",
654
654
i, strerror(errno));
672
672
reg.addr = (uintptr_t)&env->vpa_addr;
673
673
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
675
dprintf("Unable to get VPA address from KVM: %s\n", strerror(errno));
675
DPRINTF("Unable to get VPA address from KVM: %s\n", strerror(errno));
682
682
reg.addr = (uintptr_t)&env->slb_shadow_addr;
683
683
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
685
dprintf("Unable to get SLB shadow state from KVM: %s\n",
685
DPRINTF("Unable to get SLB shadow state from KVM: %s\n",
686
686
strerror(errno));
692
692
reg.addr = (uintptr_t)&env->dtl_addr;
693
693
ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
695
dprintf("Unable to get dispatch trace log state from KVM: %s\n",
695
DPRINTF("Unable to get dispatch trace log state from KVM: %s\n",
696
696
strerror(errno));
718
718
reg.addr = (uintptr_t)&env->vpa_addr;
719
719
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
721
dprintf("Unable to set VPA address to KVM: %s\n", strerror(errno));
721
DPRINTF("Unable to set VPA address to KVM: %s\n", strerror(errno));
729
729
reg.addr = (uintptr_t)&env->slb_shadow_addr;
730
730
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
732
dprintf("Unable to set SLB shadow state to KVM: %s\n", strerror(errno));
732
DPRINTF("Unable to set SLB shadow state to KVM: %s\n", strerror(errno));
738
738
reg.addr = (uintptr_t)&env->dtl_addr;
739
739
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
741
dprintf("Unable to set dispatch trace log state to KVM: %s\n",
741
DPRINTF("Unable to set dispatch trace log state to KVM: %s\n",
742
742
strerror(errno));
748
748
reg.addr = (uintptr_t)&env->vpa_addr;
749
749
ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
751
dprintf("Unable to set VPA address to KVM: %s\n", strerror(errno));
751
DPRINTF("Unable to set VPA address to KVM: %s\n", strerror(errno));
793
793
for (i = 0;i < 32; i++)
794
794
regs.gpr[i] = env->gpr[i];
797
for (i = 0; i < 8; i++) {
798
regs.cr |= (env->crf[i] & 15) << (4 * (7 - i));
796
801
ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, ®s);
1125
1130
irq = KVM_INTERRUPT_SET;
1127
dprintf("injected interrupt %d\n", irq);
1132
DPRINTF("injected interrupt %d\n", irq);
1128
1133
r = kvm_vcpu_ioctl(cs, KVM_INTERRUPT, &irq);
1130
1135
printf("cpu %d fail inject %x\n", cs->cpu_index, irq);
1188
1193
switch (run->exit_reason) {
1189
1194
case KVM_EXIT_DCR:
1190
1195
if (run->dcr.is_write) {
1191
dprintf("handle dcr write\n");
1196
DPRINTF("handle dcr write\n");
1192
1197
ret = kvmppc_handle_dcr_write(env, run->dcr.dcrn, run->dcr.data);
1194
dprintf("handle dcr read\n");
1199
DPRINTF("handle dcr read\n");
1195
1200
ret = kvmppc_handle_dcr_read(env, run->dcr.dcrn, &run->dcr.data);
1198
1203
case KVM_EXIT_HLT:
1199
dprintf("handle halt\n");
1204
DPRINTF("handle halt\n");
1200
1205
ret = kvmppc_handle_halt(cpu);
1202
1207
#if defined(TARGET_PPC64)
1203
1208
case KVM_EXIT_PAPR_HCALL:
1204
dprintf("handle PAPR hypercall\n");
1209
DPRINTF("handle PAPR hypercall\n");
1205
1210
run->papr_hcall.ret = spapr_hypercall(cpu,
1206
1211
run->papr_hcall.nr,
1207
1212
run->papr_hcall.args);
1559
1564
rma_region = g_new(MemoryRegion, 1);
1560
memory_region_init_ram_ptr(rma_region, name, size, rma);
1565
memory_region_init_ram_ptr(rma_region, NULL, name, size, rma);
1561
1566
vmstate_register_ram_global(rma_region);
1562
1567
memory_region_add_subregion(sysmem, 0, rma_region);
1577
1582
/* Find the largest hardware supported page size that's less than
1578
1583
* or equal to the (logical) backing page size of guest RAM */
1579
kvm_get_smmu_info(ppc_env_get_cpu(first_cpu), &info);
1584
kvm_get_smmu_info(POWERPC_CPU(first_cpu), &info);
1580
1585
rampagesize = getrampagesize();
1581
1586
best_page_shift = 0;
1626
len = (window_size / SPAPR_TCE_PAGE_SIZE) * sizeof(sPAPRTCE);
1631
len = (window_size / SPAPR_TCE_PAGE_SIZE) * sizeof(uint64_t);
1627
1632
/* FIXME: round this up to page size */
1629
1634
table = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
1649
len = (window_size / SPAPR_TCE_PAGE_SIZE)*sizeof(sPAPRTCE);
1654
len = (window_size / SPAPR_TCE_PAGE_SIZE)*sizeof(uint64_t);
1650
1655
if ((munmap(table, len) < 0) ||
1651
1656
(close(fd) < 0)) {
1652
1657
fprintf(stderr, "KVM: Unexpected error removing TCE table: %s",
1793
int kvmppc_get_htab_fd(bool write)
1795
struct kvm_get_htab_fd s = {
1796
.flags = write ? KVM_GET_HTAB_WRITE : 0,
1801
fprintf(stderr, "KVM version doesn't support saving the hash table\n");
1805
return kvm_vm_ioctl(kvm_state, KVM_PPC_GET_HTAB_FD, &s);
1808
int kvmppc_save_htab(QEMUFile *f, int fd, size_t bufsize, int64_t max_ns)
1810
int64_t starttime = qemu_get_clock_ns(rt_clock);
1811
uint8_t buf[bufsize];
1815
rc = read(fd, buf, bufsize);
1817
fprintf(stderr, "Error reading data from KVM HTAB fd: %s\n",
1821
/* Kernel already retuns data in BE format for the file */
1822
qemu_put_buffer(f, buf, rc);
1826
|| ((qemu_get_clock_ns(rt_clock) - starttime) < max_ns)));
1828
return (rc == 0) ? 1 : 0;
1831
int kvmppc_load_htab_chunk(QEMUFile *f, int fd, uint32_t index,
1832
uint16_t n_valid, uint16_t n_invalid)
1834
struct kvm_get_htab_header *buf;
1835
size_t chunksize = sizeof(*buf) + n_valid*HASH_PTE_SIZE_64;
1838
buf = alloca(chunksize);
1839
/* This is KVM on ppc, so this is all big-endian */
1841
buf->n_valid = n_valid;
1842
buf->n_invalid = n_invalid;
1844
qemu_get_buffer(f, (void *)(buf + 1), HASH_PTE_SIZE_64*n_valid);
1846
rc = write(fd, buf, chunksize);
1848
fprintf(stderr, "Error writing KVM hash table: %s\n",
1852
if (rc != chunksize) {
1853
/* We should never get a short write on a single chunk */
1854
fprintf(stderr, "Short write, restoring KVM hash table\n");
1788
1860
bool kvm_arch_stop_on_emulation_error(CPUState *cpu)