~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to target-s390x/kvm.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
/* #define DEBUG_KVM */
41
41
 
42
42
#ifdef DEBUG_KVM
43
 
#define dprintf(fmt, ...) \
 
43
#define DPRINTF(fmt, ...) \
44
44
    do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
45
45
#else
46
 
#define dprintf(fmt, ...) \
 
46
#define DPRINTF(fmt, ...) \
47
47
    do { } while (0)
48
48
#endif
49
49
 
345
345
 
346
346
int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
347
347
{
348
 
    S390CPU *cpu = S390_CPU(cs);
349
 
    CPUS390XState *env = &cpu->env;
350
348
    static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01};
351
349
 
352
 
    if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) ||
353
 
        cpu_memory_rw_debug(env, bp->pc, (uint8_t *)diag_501, 4, 1)) {
 
350
    if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) ||
 
351
        cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)diag_501, 4, 1)) {
354
352
        return -EINVAL;
355
353
    }
356
354
    return 0;
358
356
 
359
357
int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
360
358
{
361
 
    S390CPU *cpu = S390_CPU(cs);
362
 
    CPUS390XState *env = &cpu->env;
363
359
    uint8_t t[4];
364
360
    static const uint8_t diag_501[] = {0x83, 0x24, 0x05, 0x01};
365
361
 
366
 
    if (cpu_memory_rw_debug(env, bp->pc, t, 4, 0)) {
 
362
    if (cpu_memory_rw_debug(cs, bp->pc, t, 4, 0)) {
367
363
        return -EINVAL;
368
364
    } else if (memcmp(t, diag_501, 4)) {
369
365
        return -EINVAL;
370
 
    } else if (cpu_memory_rw_debug(env, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) {
 
366
    } else if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 1, 1)) {
371
367
        return -EINVAL;
372
368
    }
373
369
 
450
446
    uint64_t code;
451
447
    int r = 0;
452
448
 
453
 
    cpu_synchronize_state(env);
 
449
    cpu_synchronize_state(CPU(cpu));
454
450
    sccb = env->regs[ipbh0 & 0xf];
455
451
    code = env->regs[(ipbh0 & 0xf0) >> 4];
456
452
 
469
465
    int r = 0;
470
466
    int no_cc = 0;
471
467
    CPUS390XState *env = &cpu->env;
472
 
    CPUState *cs = ENV_GET_CPU(env);
 
468
    CPUState *cs = CPU(cpu);
473
469
 
474
470
    if (ipa0 != 0xb2) {
475
471
        /* Not handled for now. */
532
528
        no_cc = 1;
533
529
        r = ioinst_handle_sal(env, env->regs[1]);
534
530
        break;
 
531
    case PRIV_SIGA:
 
532
        /* Not provided, set CC = 3 for subchannel not operational */
 
533
        r = 3;
 
534
        break;
535
535
    default:
536
 
        r = -1;
537
 
        break;
538
 
    }
539
 
 
540
 
    if (r >= 0) {
541
 
        if (!no_cc) {
542
 
            setcc(cpu, r);
543
 
        }
544
 
        r = 0;
545
 
    } else if (r < -1) {
546
 
        r = 0;
547
 
    }
548
 
    return r;
549
 
}
550
 
 
551
 
static int is_ioinst(uint8_t ipa0, uint8_t ipa1, uint8_t ipb)
552
 
{
553
 
    int ret = 0;
554
 
    uint16_t ipa = (ipa0 << 8) | ipa1;
555
 
 
556
 
    switch (ipa) {
557
 
    case IPA0_B2 | PRIV_CSCH:
558
 
    case IPA0_B2 | PRIV_HSCH:
559
 
    case IPA0_B2 | PRIV_MSCH:
560
 
    case IPA0_B2 | PRIV_SSCH:
561
 
    case IPA0_B2 | PRIV_STSCH:
562
 
    case IPA0_B2 | PRIV_TPI:
563
 
    case IPA0_B2 | PRIV_SAL:
564
 
    case IPA0_B2 | PRIV_RSCH:
565
 
    case IPA0_B2 | PRIV_STCRW:
566
 
    case IPA0_B2 | PRIV_STCPS:
567
 
    case IPA0_B2 | PRIV_RCHP:
568
 
    case IPA0_B2 | PRIV_SCHM:
569
 
    case IPA0_B2 | PRIV_CHSC:
570
 
    case IPA0_B2 | PRIV_SIGA:
571
 
    case IPA0_B2 | PRIV_XSCH:
572
 
    case IPA0_B9 | PRIV_EQBS:
573
 
    case IPA0_EB | PRIV_SQBS:
574
 
        ret = 1;
575
 
        break;
576
 
    }
577
 
 
578
 
    return ret;
 
536
        return -1;
 
537
    }
 
538
 
 
539
    if (r >= 0 && !no_cc) {
 
540
        setcc(cpu, r);
 
541
    }
 
542
 
 
543
    return 0;
579
544
}
580
545
 
581
546
static int handle_priv(S390CPU *cpu, struct kvm_run *run,
585
550
    uint16_t ipbh0 = (run->s390_sieic.ipb & 0xffff0000) >> 16;
586
551
    uint8_t ipb = run->s390_sieic.ipb & 0xff;
587
552
 
588
 
    dprintf("KVM: PRIV: %d\n", ipa1);
 
553
    DPRINTF("KVM: PRIV: %d\n", ipa1);
589
554
    switch (ipa1) {
590
555
        case PRIV_SCLP_CALL:
591
556
            r = kvm_sclp_service_call(cpu, run, ipbh0);
592
557
            break;
593
558
        default:
594
 
            if (is_ioinst(ipa0, ipa1, ipb)) {
595
 
                r = kvm_handle_css_inst(cpu, run, ipa0, ipa1, ipb);
596
 
                if (r == -1) {
597
 
                    setcc(cpu, 3);
598
 
                    r = 0;
599
 
                }
600
 
            } else {
601
 
                dprintf("KVM: unknown PRIV: 0x%x\n", ipa1);
602
 
                r = -1;
 
559
            r = kvm_handle_css_inst(cpu, run, ipa0, ipa1, ipb);
 
560
            if (r == -1) {
 
561
                DPRINTF("KVM: unhandled PRIV: 0x%x\n", ipa1);
603
562
            }
604
563
            break;
605
564
    }
607
566
    return r;
608
567
}
609
568
 
610
 
static int handle_hypercall(CPUS390XState *env, struct kvm_run *run)
 
569
static int handle_hypercall(S390CPU *cpu, struct kvm_run *run)
611
570
{
612
 
    CPUState *cs = ENV_GET_CPU(env);
 
571
    CPUState *cs = CPU(cpu);
 
572
    CPUS390XState *env = &cpu->env;
613
573
 
614
574
    kvm_s390_get_registers_partial(cs);
615
575
    cs->kvm_vcpu_dirty = true;
618
578
    return 0;
619
579
}
620
580
 
621
 
static int handle_diag(CPUS390XState *env, struct kvm_run *run, int ipb_code)
 
581
static int handle_diag(S390CPU *cpu, struct kvm_run *run, int ipb_code)
622
582
{
623
583
    int r = 0;
624
584
 
625
585
    switch (ipb_code) {
626
586
        case DIAG_KVM_HYPERCALL:
627
 
            r = handle_hypercall(env, run);
 
587
            r = handle_hypercall(cpu, run);
628
588
            break;
629
589
        case DIAG_KVM_BREAKPOINT:
630
590
            sleep(10);
631
591
            break;
632
592
        default:
633
 
            dprintf("KVM: unknown DIAG: 0x%x\n", ipb_code);
 
593
            DPRINTF("KVM: unknown DIAG: 0x%x\n", ipb_code);
634
594
            r = -1;
635
595
            break;
636
596
    }
643
603
    kvm_s390_interrupt(cpu, KVM_S390_RESTART, 0);
644
604
    s390_add_running_cpu(cpu);
645
605
    qemu_cpu_kick(CPU(cpu));
646
 
    dprintf("DONE: SIGP cpu restart: %p\n", &cpu->env);
 
606
    DPRINTF("DONE: SIGP cpu restart: %p\n", &cpu->env);
647
607
    return 0;
648
608
}
649
609
 
656
616
 
657
617
static int s390_cpu_initial_reset(S390CPU *cpu)
658
618
{
 
619
    CPUState *cs = CPU(cpu);
659
620
    CPUS390XState *env = &cpu->env;
660
621
    int i;
661
622
 
662
623
    s390_del_running_cpu(cpu);
663
 
    if (kvm_vcpu_ioctl(CPU(cpu), KVM_S390_INITIAL_RESET, NULL) < 0) {
 
624
    if (kvm_vcpu_ioctl(cs, KVM_S390_INITIAL_RESET, NULL) < 0) {
664
625
        perror("cannot init reset vcpu");
665
626
    }
666
627
 
667
628
    /* Manually zero out all registers */
668
 
    cpu_synchronize_state(env);
 
629
    cpu_synchronize_state(cs);
669
630
    for (i = 0; i < 16; i++) {
670
631
        env->regs[i] = 0;
671
632
    }
672
633
 
673
 
    dprintf("DONE: SIGP initial reset: %p\n", env);
 
634
    DPRINTF("DONE: SIGP initial reset: %p\n", env);
674
635
    return 0;
675
636
}
676
637
 
685
646
    S390CPU *target_cpu;
686
647
    CPUS390XState *target_env;
687
648
 
688
 
    cpu_synchronize_state(env);
 
649
    cpu_synchronize_state(CPU(cpu));
689
650
 
690
651
    /* get order code */
691
652
    order_code = run->s390_sieic.ipb >> 28;
732
693
    return 0;
733
694
}
734
695
 
735
 
static int handle_instruction(S390CPU *cpu, struct kvm_run *run)
 
696
static void handle_instruction(S390CPU *cpu, struct kvm_run *run)
736
697
{
737
 
    CPUS390XState *env = &cpu->env;
738
698
    unsigned int ipa0 = (run->s390_sieic.ipa & 0xff00);
739
699
    uint8_t ipa1 = run->s390_sieic.ipa & 0x00ff;
740
700
    int ipb_code = (run->s390_sieic.ipb & 0x0fff0000) >> 16;
741
701
    int r = -1;
742
702
 
743
 
    dprintf("handle_instruction 0x%x 0x%x\n", run->s390_sieic.ipa, run->s390_sieic.ipb);
 
703
    DPRINTF("handle_instruction 0x%x 0x%x\n",
 
704
            run->s390_sieic.ipa, run->s390_sieic.ipb);
744
705
    switch (ipa0) {
745
706
    case IPA0_B2:
746
707
    case IPA0_B9:
748
709
        r = handle_priv(cpu, run, ipa0 >> 8, ipa1);
749
710
        break;
750
711
    case IPA0_DIAG:
751
 
        r = handle_diag(env, run, ipb_code);
 
712
        r = handle_diag(cpu, run, ipb_code);
752
713
        break;
753
714
    case IPA0_SIGP:
754
715
        r = handle_sigp(cpu, run, ipa1);
758
719
    if (r < 0) {
759
720
        enter_pgmcheck(cpu, 0x0001);
760
721
    }
761
 
    return 0;
762
722
}
763
723
 
764
724
static bool is_special_wait_psw(CPUState *cs)
774
734
    int icpt_code = run->s390_sieic.icptcode;
775
735
    int r = 0;
776
736
 
777
 
    dprintf("intercept: 0x%x (at 0x%lx)\n", icpt_code,
 
737
    DPRINTF("intercept: 0x%x (at 0x%lx)\n", icpt_code,
778
738
            (long)cs->kvm_run->psw_addr);
779
739
    switch (icpt_code) {
780
740
        case ICPT_INSTRUCTION:
781
 
            r = handle_instruction(cpu, run);
 
741
            handle_instruction(cpu, run);
782
742
            break;
783
743
        case ICPT_WAITPSW:
784
744
            /* disabled wait, since enabled wait is handled in kernel */
928
888
    r = kvm_vcpu_ioctl(CPU(cpu), KVM_ENABLE_CAP, &cap);
929
889
    assert(r == 0);
930
890
}
 
891
 
 
892
void kvm_arch_init_irq_routing(KVMState *s)
 
893
{
 
894
}
 
895
 
 
896
int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch,
 
897
                                    int vq, bool assign)
 
898
{
 
899
    struct kvm_ioeventfd kick = {
 
900
        .flags = KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY |
 
901
        KVM_IOEVENTFD_FLAG_DATAMATCH,
 
902
        .fd = event_notifier_get_fd(notifier),
 
903
        .datamatch = vq,
 
904
        .addr = sch,
 
905
        .len = 8,
 
906
    };
 
907
    if (!kvm_check_extension(kvm_state, KVM_CAP_IOEVENTFD)) {
 
908
        return -ENOSYS;
 
909
    }
 
910
    if (!assign) {
 
911
        kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
 
912
    }
 
913
    return kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
 
914
}