~ubuntu-branches/ubuntu/saucy/qemu/saucy-proposed

« back to all changes in this revision

Viewing changes to kvm-all.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-05-28 08:18:30 UTC
  • mfrom: (1.8.2) (10.1.37 sid)
  • Revision ID: package-import@ubuntu.com-20130528081830-87xl2z9fq516a814
Tags: 1.5.0+dfsg-2ubuntu1
* Merge 1.5.0+dfs-2 from debian unstable.  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
    * 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.
  - Dropped patches:
    * 0001-fix-wrong-output-with-info-chardev-for-tcp-socket.patch
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * gridcentric patch - updated
    * linaro arm patches from qemu-linaro rebasing branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "exec/memory.h"
34
34
#include "exec/address-spaces.h"
35
35
#include "qemu/event_notifier.h"
 
36
#include "trace.h"
36
37
 
37
38
/* This check must be after config-host.h is included */
38
39
#ifdef CONFIG_EVENTFD
109
110
bool kvm_irqfds_allowed;
110
111
bool kvm_msi_via_irqfd_allowed;
111
112
bool kvm_gsi_routing_allowed;
 
113
bool kvm_allowed;
112
114
 
113
115
static const KVMCapabilityInfo kvm_required_capabilites[] = {
114
116
    KVM_CAP_INFO(USER_MEMORY),
500
502
    return ret;
501
503
}
502
504
 
 
505
static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val,
 
506
                                  bool assign, uint32_t size, bool datamatch)
 
507
{
 
508
    int ret;
 
509
    struct kvm_ioeventfd iofd;
 
510
 
 
511
    iofd.datamatch = datamatch ? val : 0;
 
512
    iofd.addr = addr;
 
513
    iofd.len = size;
 
514
    iofd.flags = 0;
 
515
    iofd.fd = fd;
 
516
 
 
517
    if (!kvm_enabled()) {
 
518
        return -ENOSYS;
 
519
    }
 
520
 
 
521
    if (datamatch) {
 
522
        iofd.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH;
 
523
    }
 
524
    if (!assign) {
 
525
        iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
 
526
    }
 
527
 
 
528
    ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &iofd);
 
529
 
 
530
    if (ret < 0) {
 
531
        return -errno;
 
532
    }
 
533
 
 
534
    return 0;
 
535
}
 
536
 
 
537
static int kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint16_t val,
 
538
                                 bool assign, uint32_t size, bool datamatch)
 
539
{
 
540
    struct kvm_ioeventfd kick = {
 
541
        .datamatch = datamatch ? val : 0,
 
542
        .addr = addr,
 
543
        .flags = KVM_IOEVENTFD_FLAG_PIO,
 
544
        .len = size,
 
545
        .fd = fd,
 
546
    };
 
547
    int r;
 
548
    if (!kvm_enabled()) {
 
549
        return -ENOSYS;
 
550
    }
 
551
    if (datamatch) {
 
552
        kick.flags |= KVM_IOEVENTFD_FLAG_DATAMATCH;
 
553
    }
 
554
    if (!assign) {
 
555
        kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
 
556
    }
 
557
    r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
 
558
    if (r < 0) {
 
559
        return r;
 
560
    }
 
561
    return 0;
 
562
}
 
563
 
 
564
 
503
565
static int kvm_check_many_ioeventfds(void)
504
566
{
505
567
    /* Userspace can use ioeventfd for io notification.  This requires a host
517
579
        if (ioeventfds[i] < 0) {
518
580
            break;
519
581
        }
520
 
        ret = kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, true);
 
582
        ret = kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, true, 2, true);
521
583
        if (ret < 0) {
522
584
            close(ioeventfds[i]);
523
585
            break;
528
590
    ret = i == ARRAY_SIZE(ioeventfds);
529
591
 
530
592
    while (i-- > 0) {
531
 
        kvm_set_ioeventfd_pio_word(ioeventfds[i], 0, i, false);
 
593
        kvm_set_ioeventfd_pio(ioeventfds[i], 0, i, false, 2, true);
532
594
        close(ioeventfds[i]);
533
595
    }
534
596
    return ret;
748
810
    int fd = event_notifier_get_fd(e);
749
811
    int r;
750
812
 
751
 
    assert(match_data && section->size <= 8);
752
 
 
753
813
    r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
754
 
                               data, true, section->size);
 
814
                               data, true, section->size, match_data);
755
815
    if (r < 0) {
756
816
        abort();
757
817
    }
766
826
    int r;
767
827
 
768
828
    r = kvm_set_ioeventfd_mmio(fd, section->offset_within_address_space,
769
 
                               data, false, section->size);
 
829
                               data, false, section->size, match_data);
770
830
    if (r < 0) {
771
831
        abort();
772
832
    }
780
840
    int fd = event_notifier_get_fd(e);
781
841
    int r;
782
842
 
783
 
    assert(match_data && section->size == 2);
784
 
 
785
 
    r = kvm_set_ioeventfd_pio_word(fd, section->offset_within_address_space,
786
 
                                   data, true);
 
843
    r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
 
844
                              data, true, section->size, match_data);
787
845
    if (r < 0) {
788
846
        abort();
789
847
    }
798
856
    int fd = event_notifier_get_fd(e);
799
857
    int r;
800
858
 
801
 
    r = kvm_set_ioeventfd_pio_word(fd, section->offset_within_address_space,
802
 
                                   data, false);
 
859
    r = kvm_set_ioeventfd_pio(fd, section->offset_within_address_space,
 
860
                              data, false, section->size, match_data);
803
861
    if (r < 0) {
804
862
        abort();
805
863
    }
826
884
    .priority = 10,
827
885
};
828
886
 
829
 
static void kvm_handle_interrupt(CPUArchState *env, int mask)
 
887
static void kvm_handle_interrupt(CPUState *cpu, int mask)
830
888
{
831
 
    CPUState *cpu = ENV_GET_CPU(env);
832
 
 
833
 
    env->interrupt_request |= mask;
 
889
    cpu->interrupt_request |= mask;
834
890
 
835
891
    if (!qemu_cpu_is_self(cpu)) {
836
892
        qemu_cpu_kick(cpu);
1512
1568
    }
1513
1569
}
1514
1570
 
1515
 
void kvm_cpu_synchronize_post_reset(CPUArchState *env)
 
1571
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
1516
1572
{
1517
 
    CPUState *cpu = ENV_GET_CPU(env);
1518
 
 
1519
1573
    kvm_arch_put_registers(cpu, KVM_PUT_RESET_STATE);
1520
1574
    cpu->kvm_vcpu_dirty = false;
1521
1575
}
1522
1576
 
1523
 
void kvm_cpu_synchronize_post_init(CPUArchState *env)
 
1577
void kvm_cpu_synchronize_post_init(CPUState *cpu)
1524
1578
{
1525
 
    CPUState *cpu = ENV_GET_CPU(env);
1526
 
 
1527
1579
    kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE);
1528
1580
    cpu->kvm_vcpu_dirty = false;
1529
1581
}
1537
1589
    DPRINTF("kvm_cpu_exec()\n");
1538
1590
 
1539
1591
    if (kvm_arch_process_async_events(cpu)) {
1540
 
        env->exit_request = 0;
 
1592
        cpu->exit_request = 0;
1541
1593
        return EXCP_HLT;
1542
1594
    }
1543
1595
 
1548
1600
        }
1549
1601
 
1550
1602
        kvm_arch_pre_run(cpu, run);
1551
 
        if (env->exit_request) {
 
1603
        if (cpu->exit_request) {
1552
1604
            DPRINTF("interrupt exit requested\n");
1553
1605
            /*
1554
1606
             * KVM requires us to reenter the kernel after IO exits to complete
1575
1627
            abort();
1576
1628
        }
1577
1629
 
 
1630
        trace_kvm_run_exit(cpu->cpu_index, run->exit_reason);
1578
1631
        switch (run->exit_reason) {
1579
1632
        case KVM_EXIT_IO:
1580
1633
            DPRINTF("handle_io\n");
1622
1675
        vm_stop(RUN_STATE_INTERNAL_ERROR);
1623
1676
    }
1624
1677
 
1625
 
    env->exit_request = 0;
 
1678
    cpu->exit_request = 0;
1626
1679
    return ret;
1627
1680
}
1628
1681
 
1636
1689
    arg = va_arg(ap, void *);
1637
1690
    va_end(ap);
1638
1691
 
 
1692
    trace_kvm_ioctl(type, arg);
1639
1693
    ret = ioctl(s->fd, type, arg);
1640
1694
    if (ret == -1) {
1641
1695
        ret = -errno;
1653
1707
    arg = va_arg(ap, void *);
1654
1708
    va_end(ap);
1655
1709
 
 
1710
    trace_kvm_vm_ioctl(type, arg);
1656
1711
    ret = ioctl(s->vmfd, type, arg);
1657
1712
    if (ret == -1) {
1658
1713
        ret = -errno;
1670
1725
    arg = va_arg(ap, void *);
1671
1726
    va_end(ap);
1672
1727
 
 
1728
    trace_kvm_vcpu_ioctl(cpu->cpu_index, type, arg);
1673
1729
    ret = ioctl(cpu->kvm_fd, type, arg);
1674
1730
    if (ret == -1) {
1675
1731
        ret = -errno;
1734
1790
    return kvm_state->intx_set_mask;
1735
1791
}
1736
1792
 
1737
 
void *kvm_vmalloc(ram_addr_t size)
 
1793
void *kvm_ram_alloc(ram_addr_t size)
1738
1794
{
1739
1795
#ifdef TARGET_S390X
1740
1796
    void *mem;
1741
1797
 
1742
 
    mem = kvm_arch_vmalloc(size);
 
1798
    mem = kvm_arch_ram_alloc(size);
1743
1799
    if (mem) {
1744
1800
        return mem;
1745
1801
    }
1746
1802
#endif
1747
 
    return qemu_vmalloc(size);
 
1803
    return qemu_anon_ram_alloc(size);
1748
1804
}
1749
1805
 
1750
1806
void kvm_setup_guest_memory(void *start, size_t size)
1973
2029
 
1974
2030
    return r;
1975
2031
}
1976
 
 
1977
 
int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, bool assign,
1978
 
                           uint32_t size)
1979
 
{
1980
 
    int ret;
1981
 
    struct kvm_ioeventfd iofd;
1982
 
 
1983
 
    iofd.datamatch = val;
1984
 
    iofd.addr = addr;
1985
 
    iofd.len = size;
1986
 
    iofd.flags = KVM_IOEVENTFD_FLAG_DATAMATCH;
1987
 
    iofd.fd = fd;
1988
 
 
1989
 
    if (!kvm_enabled()) {
1990
 
        return -ENOSYS;
1991
 
    }
1992
 
 
1993
 
    if (!assign) {
1994
 
        iofd.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
1995
 
    }
1996
 
 
1997
 
    ret = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &iofd);
1998
 
 
1999
 
    if (ret < 0) {
2000
 
        return -errno;
2001
 
    }
2002
 
 
2003
 
    return 0;
2004
 
}
2005
 
 
2006
 
int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)
2007
 
{
2008
 
    struct kvm_ioeventfd kick = {
2009
 
        .datamatch = val,
2010
 
        .addr = addr,
2011
 
        .len = 2,
2012
 
        .flags = KVM_IOEVENTFD_FLAG_DATAMATCH | KVM_IOEVENTFD_FLAG_PIO,
2013
 
        .fd = fd,
2014
 
    };
2015
 
    int r;
2016
 
    if (!kvm_enabled()) {
2017
 
        return -ENOSYS;
2018
 
    }
2019
 
    if (!assign) {
2020
 
        kick.flags |= KVM_IOEVENTFD_FLAG_DEASSIGN;
2021
 
    }
2022
 
    r = kvm_vm_ioctl(kvm_state, KVM_IOEVENTFD, &kick);
2023
 
    if (r < 0) {
2024
 
        return r;
2025
 
    }
2026
 
    return 0;
2027
 
}
2028
 
 
2029
2032
int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
2030
2033
{
2031
2034
    return kvm_arch_on_sigbus_vcpu(cpu, code, addr);