]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
Merge tag 'kvm-s390-next-20150331' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 Apr 2015 16:10:03 +0000 (18:10 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 7 Apr 2015 16:10:03 +0000 (18:10 +0200)
Features and fixes for 4.1 (kvm/next)

1. Assorted changes
1.1 allow more feature bits for the guest
1.2 Store breaking event address on program interrupts

2. Interrupt handling rework
2.1 Fix copy_to_user while holding a spinlock (cc stable)
2.2 Rework floating interrupts to follow the priorities
2.3 Allow to inject all local interrupts via new ioctl
2.4 allow to get/set the full local irq state, e.g. for migration
    and introspection

1  2 
Documentation/virtual/kvm/api.txt
include/uapi/linux/kvm.h
virt/kvm/kvm_main.c

index 57d25fdd3d7ec344e21ec94d609d7200fcca0ab5,18fb7630e2ad34b90e6d671f2b25a7095071b73b..bc9f6fe44e27614c2f26f155385fe0d5d13d2e3b
@@@ -997,7 -997,7 +997,7 @@@ for vm-wide capabilities
  4.38 KVM_GET_MP_STATE
  
  Capability: KVM_CAP_MP_STATE
 -Architectures: x86, s390
 +Architectures: x86, s390, arm, arm64
  Type: vcpu ioctl
  Parameters: struct kvm_mp_state (out)
  Returns: 0 on success; -1 on error
@@@ -1011,7 -1011,7 +1011,7 @@@ uniprocessor guests)
  
  Possible values are:
  
 - - KVM_MP_STATE_RUNNABLE:        the vcpu is currently running [x86]
 + - KVM_MP_STATE_RUNNABLE:        the vcpu is currently running [x86,arm/arm64]
   - KVM_MP_STATE_UNINITIALIZED:   the vcpu is an application processor (AP)
                                   which has not yet received an INIT signal [x86]
   - KVM_MP_STATE_INIT_RECEIVED:   the vcpu has received an INIT signal, and is
                                   is waiting for an interrupt [x86]
   - KVM_MP_STATE_SIPI_RECEIVED:   the vcpu has just received a SIPI (vector
                                   accessible via KVM_GET_VCPU_EVENTS) [x86]
 - - KVM_MP_STATE_STOPPED:         the vcpu is stopped [s390]
 + - KVM_MP_STATE_STOPPED:         the vcpu is stopped [s390,arm/arm64]
   - KVM_MP_STATE_CHECK_STOP:      the vcpu is in a special error state [s390]
   - KVM_MP_STATE_OPERATING:       the vcpu is operating (running or halted)
                                   [s390]
@@@ -1031,15 -1031,11 +1031,15 @@@ On x86, this ioctl is only useful afte
  in-kernel irqchip, the multiprocessing state must be maintained by userspace on
  these architectures.
  
 +For arm/arm64:
 +
 +The only states that are valid are KVM_MP_STATE_STOPPED and
 +KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
  
  4.39 KVM_SET_MP_STATE
  
  Capability: KVM_CAP_MP_STATE
 -Architectures: x86, s390
 +Architectures: x86, s390, arm, arm64
  Type: vcpu ioctl
  Parameters: struct kvm_mp_state (in)
  Returns: 0 on success; -1 on error
@@@ -1051,10 -1047,6 +1051,10 @@@ On x86, this ioctl is only useful afte
  in-kernel irqchip, the multiprocessing state must be maintained by userspace on
  these architectures.
  
 +For arm/arm64:
 +
 +The only states that are valid are KVM_MP_STATE_STOPPED and
 +KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
  
  4.40 KVM_SET_IDENTITY_MAP_ADDR
  
@@@ -1975,25 -1967,15 +1975,25 @@@ registers, find a list below
    MIPS  | KVM_REG_MIPS_CP0_STATUS       | 32
    MIPS  | KVM_REG_MIPS_CP0_CAUSE        | 32
    MIPS  | KVM_REG_MIPS_CP0_EPC          | 64
 +  MIPS  | KVM_REG_MIPS_CP0_PRID         | 32
    MIPS  | KVM_REG_MIPS_CP0_CONFIG       | 32
    MIPS  | KVM_REG_MIPS_CP0_CONFIG1      | 32
    MIPS  | KVM_REG_MIPS_CP0_CONFIG2      | 32
    MIPS  | KVM_REG_MIPS_CP0_CONFIG3      | 32
 +  MIPS  | KVM_REG_MIPS_CP0_CONFIG4      | 32
 +  MIPS  | KVM_REG_MIPS_CP0_CONFIG5      | 32
    MIPS  | KVM_REG_MIPS_CP0_CONFIG7      | 32
    MIPS  | KVM_REG_MIPS_CP0_ERROREPC     | 64
    MIPS  | KVM_REG_MIPS_COUNT_CTL        | 64
    MIPS  | KVM_REG_MIPS_COUNT_RESUME     | 64
    MIPS  | KVM_REG_MIPS_COUNT_HZ         | 64
 +  MIPS  | KVM_REG_MIPS_FPR_32(0..31)    | 32
 +  MIPS  | KVM_REG_MIPS_FPR_64(0..31)    | 64
 +  MIPS  | KVM_REG_MIPS_VEC_128(0..31)   | 128
 +  MIPS  | KVM_REG_MIPS_FCR_IR           | 32
 +  MIPS  | KVM_REG_MIPS_FCR_CSR          | 32
 +  MIPS  | KVM_REG_MIPS_MSA_IR           | 32
 +  MIPS  | KVM_REG_MIPS_MSA_CSR          | 32
  
  ARM registers are mapped using the lower 32 bits.  The upper 16 of that
  is the register group type, or coprocessor number:
@@@ -2047,25 -2029,6 +2047,25 @@@ patterns depending on whether they're 3
  MIPS KVM control registers (see above) have the following id bit patterns:
    0x7030 0000 0002 <reg:16>
  
 +MIPS FPU registers (see KVM_REG_MIPS_FPR_{32,64}() above) have the following
 +id bit patterns depending on the size of the register being accessed. They are
 +always accessed according to the current guest FPU mode (Status.FR and
 +Config5.FRE), i.e. as the guest would see them, and they become unpredictable
 +if the guest FPU mode is changed. MIPS SIMD Architecture (MSA) vector
 +registers (see KVM_REG_MIPS_VEC_128() above) have similar patterns as they
 +overlap the FPU registers:
 +  0x7020 0000 0003 00 <0:3> <reg:5> (32-bit FPU registers)
 +  0x7030 0000 0003 00 <0:3> <reg:5> (64-bit FPU registers)
 +  0x7040 0000 0003 00 <0:3> <reg:5> (128-bit MSA vector registers)
 +
 +MIPS FPU control registers (see KVM_REG_MIPS_FCR_{IR,CSR} above) have the
 +following id bit patterns:
 +  0x7020 0000 0003 01 <0:3> <reg:5>
 +
 +MIPS MSA control registers (see KVM_REG_MIPS_MSA_{IR,CSR} above) have the
 +following id bit patterns:
 +  0x7020 0000 0003 02 <0:3> <reg:5>
 +
  
  4.69 KVM_GET_ONE_REG
  
@@@ -2271,7 -2234,7 +2271,7 @@@ into the hash PTE second double word)
  4.75 KVM_IRQFD
  
  Capability: KVM_CAP_IRQFD
 -Architectures: x86 s390
 +Architectures: x86 s390 arm arm64
  Type: vm ioctl
  Parameters: struct kvm_irqfd (in)
  Returns: 0 on success, -1 on error
@@@ -2297,10 -2260,6 +2297,10 @@@ Note that closing the resamplefd is no
  irqfd.  The KVM_IRQFD_FLAG_RESAMPLE is only necessary on assignment
  and need not be specified with KVM_IRQFD_FLAG_DEASSIGN.
  
 +On ARM/ARM64, the gsi field in the kvm_irqfd struct specifies the Shared
 +Peripheral Interrupt (SPI) index, such that the GIC interrupt ID is
 +given by gsi + 32.
 +
  4.76 KVM_PPC_ALLOCATE_HTAB
  
  Capability: KVM_CAP_PPC_ALLOC_HTAB
@@@ -2861,6 -2820,123 +2861,123 @@@ single frame starting at start_gfn for 
  Note: If any architecturally invalid key value is found in the given data then
  the ioctl will return -EINVAL.
  
+ 4.92 KVM_S390_IRQ
+ Capability: KVM_CAP_S390_INJECT_IRQ
+ Architectures: s390
+ Type: vcpu ioctl
+ Parameters: struct kvm_s390_irq (in)
+ Returns: 0 on success, -1 on error
+ Errors:
+   EINVAL: interrupt type is invalid
+           type is KVM_S390_SIGP_STOP and flag parameter is invalid value
+           type is KVM_S390_INT_EXTERNAL_CALL and code is bigger
+             than the maximum of VCPUs
+   EBUSY:  type is KVM_S390_SIGP_SET_PREFIX and vcpu is not stopped
+           type is KVM_S390_SIGP_STOP and a stop irq is already pending
+           type is KVM_S390_INT_EXTERNAL_CALL and an external call interrupt
+             is already pending
+ Allows to inject an interrupt to the guest.
+ Using struct kvm_s390_irq as a parameter allows
+ to inject additional payload which is not
+ possible via KVM_S390_INTERRUPT.
+ Interrupt parameters are passed via kvm_s390_irq:
+ struct kvm_s390_irq {
+       __u64 type;
+       union {
+               struct kvm_s390_io_info io;
+               struct kvm_s390_ext_info ext;
+               struct kvm_s390_pgm_info pgm;
+               struct kvm_s390_emerg_info emerg;
+               struct kvm_s390_extcall_info extcall;
+               struct kvm_s390_prefix_info prefix;
+               struct kvm_s390_stop_info stop;
+               struct kvm_s390_mchk_info mchk;
+               char reserved[64];
+       } u;
+ };
+ type can be one of the following:
+ KVM_S390_SIGP_STOP - sigp stop; parameter in .stop
+ KVM_S390_PROGRAM_INT - program check; parameters in .pgm
+ KVM_S390_SIGP_SET_PREFIX - sigp set prefix; parameters in .prefix
+ KVM_S390_RESTART - restart; no parameters
+ KVM_S390_INT_CLOCK_COMP - clock comparator interrupt; no parameters
+ KVM_S390_INT_CPU_TIMER - CPU timer interrupt; no parameters
+ KVM_S390_INT_EMERGENCY - sigp emergency; parameters in .emerg
+ KVM_S390_INT_EXTERNAL_CALL - sigp external call; parameters in .extcall
+ KVM_S390_MCHK - machine check interrupt; parameters in .mchk
+ Note that the vcpu ioctl is asynchronous to vcpu execution.
+ 4.94 KVM_S390_GET_IRQ_STATE
+ Capability: KVM_CAP_S390_IRQ_STATE
+ Architectures: s390
+ Type: vcpu ioctl
+ Parameters: struct kvm_s390_irq_state (out)
+ Returns: >= number of bytes copied into buffer,
+          -EINVAL if buffer size is 0,
+          -ENOBUFS if buffer size is too small to fit all pending interrupts,
+          -EFAULT if the buffer address was invalid
+ This ioctl allows userspace to retrieve the complete state of all currently
+ pending interrupts in a single buffer. Use cases include migration
+ and introspection. The parameter structure contains the address of a
+ userspace buffer and its length:
+ struct kvm_s390_irq_state {
+       __u64 buf;
+       __u32 flags;
+       __u32 len;
+       __u32 reserved[4];
+ };
+ Userspace passes in the above struct and for each pending interrupt a
+ struct kvm_s390_irq is copied to the provided buffer.
+ If -ENOBUFS is returned the buffer provided was too small and userspace
+ may retry with a bigger buffer.
+ 4.95 KVM_S390_SET_IRQ_STATE
+ Capability: KVM_CAP_S390_IRQ_STATE
+ Architectures: s390
+ Type: vcpu ioctl
+ Parameters: struct kvm_s390_irq_state (in)
+ Returns: 0 on success,
+          -EFAULT if the buffer address was invalid,
+          -EINVAL for an invalid buffer length (see below),
+          -EBUSY if there were already interrupts pending,
+          errors occurring when actually injecting the
+           interrupt. See KVM_S390_IRQ.
+ This ioctl allows userspace to set the complete state of all cpu-local
+ interrupts currently pending for the vcpu. It is intended for restoring
+ interrupt state after a migration. The input parameter is a userspace buffer
+ containing a struct kvm_s390_irq_state:
+ struct kvm_s390_irq_state {
+       __u64 buf;
+       __u32 len;
+       __u32 pad;
+ };
+ The userspace memory referenced by buf contains a struct kvm_s390_irq
+ for each interrupt to be injected into the guest.
+ If one of the interrupts could not be injected for some reason the
+ ioctl aborts.
+ len must be a multiple of sizeof(struct kvm_s390_irq). It must be > 0
+ and it must not exceed (max_vcpus + 32) * sizeof(struct kvm_s390_irq),
+ which is the maximum number of possibly pending cpu-local interrupts.
  5. The kvm_run structure
  ------------------------
  
@@@ -3334,31 -3410,6 +3451,31 @@@ Parameters: non
  This capability enables the in-kernel irqchip for s390. Please refer to
  "4.24 KVM_CREATE_IRQCHIP" for details.
  
 +6.9 KVM_CAP_MIPS_FPU
 +
 +Architectures: mips
 +Target: vcpu
 +Parameters: args[0] is reserved for future use (should be 0).
 +
 +This capability allows the use of the host Floating Point Unit by the guest. It
 +allows the Config1.FP bit to be set to enable the FPU in the guest. Once this is
 +done the KVM_REG_MIPS_FPR_* and KVM_REG_MIPS_FCR_* registers can be accessed
 +(depending on the current guest FPU register mode), and the Status.FR,
 +Config5.FRE bits are accessible via the KVM API and also from the guest,
 +depending on them being supported by the FPU.
 +
 +6.10 KVM_CAP_MIPS_MSA
 +
 +Architectures: mips
 +Target: vcpu
 +Parameters: args[0] is reserved for future use (should be 0).
 +
 +This capability allows the use of the MIPS SIMD Architecture (MSA) by the guest.
 +It allows the Config3.MSAP bit to be set to enable the use of MSA by the guest.
 +Once this is done the KVM_REG_MIPS_VEC_* and KVM_REG_MIPS_MSA_* registers can be
 +accessed, and the Config5.MSAEn bit is accessible via the KVM API and also from
 +the guest.
 +
  7. Capabilities that can be enabled on VMs
  ------------------------------------------
  
diff --combined include/uapi/linux/kvm.h
index 05a2083f7a28b711a42d691bab2b8a68f466b7ec,c045c725e521c0a63989a167aa47d32b666d71d0..f574d7be7631e5795f26a8934391b8b6f1473f8e
@@@ -558,6 -558,13 +558,13 @@@ struct kvm_s390_irq 
        } u;
  };
  
+ struct kvm_s390_irq_state {
+       __u64 buf;
+       __u32 flags;
+       __u32 len;
+       __u32 reserved[4];
+ };
  /* for KVM_SET_GUEST_DEBUG */
  
  #define KVM_GUESTDBG_ENABLE           0x00000001
@@@ -802,8 -809,8 +809,10 @@@ struct kvm_ppc_smmu_info 
  #define KVM_CAP_S390_MEM_OP 108
  #define KVM_CAP_S390_USER_STSI 109
  #define KVM_CAP_S390_SKEYS 110
 +#define KVM_CAP_MIPS_FPU 111
 +#define KVM_CAP_MIPS_MSA 112
+ #define KVM_CAP_S390_INJECT_IRQ 113
+ #define KVM_CAP_S390_IRQ_STATE 114
  
  #ifdef KVM_CAP_IRQ_ROUTING
  
@@@ -1184,6 -1191,11 +1193,11 @@@ struct kvm_s390_ucas_mapping 
  /* Available with KVM_CAP_S390_SKEYS */
  #define KVM_S390_GET_SKEYS      _IOW(KVMIO, 0xb2, struct kvm_s390_skeys)
  #define KVM_S390_SET_SKEYS      _IOW(KVMIO, 0xb3, struct kvm_s390_skeys)
+ /* Available with KVM_CAP_S390_INJECT_IRQ */
+ #define KVM_S390_IRQ              _IOW(KVMIO,  0xb4, struct kvm_s390_irq)
+ /* Available with KVM_CAP_S390_IRQ_STATE */
+ #define KVM_S390_SET_IRQ_STATE          _IOW(KVMIO, 0xb5, struct kvm_s390_irq_state)
+ #define KVM_S390_GET_IRQ_STATE          _IOW(KVMIO, 0xb6, struct kvm_s390_irq_state)
  
  #define KVM_DEV_ASSIGN_ENABLE_IOMMU   (1 << 0)
  #define KVM_DEV_ASSIGN_PCI_2_3                (1 << 1)
diff --combined virt/kvm/kvm_main.c
index efe59ae64dc301714c21deba532c60bf152311ae,34310a8d24b9300c2f19b9f530b018e854fb05af..0d06b7b63e9544a923d332f4474f1fab055d98a7
@@@ -16,7 -16,7 +16,7 @@@
   *
   */
  
 -#include "iodev.h"
 +#include <kvm/iodev.h>
  
  #include <linux/kvm_host.h>
  #include <linux/kvm.h>
  MODULE_AUTHOR("Qumranet");
  MODULE_LICENSE("GPL");
  
 -unsigned int halt_poll_ns = 0;
 +static unsigned int halt_poll_ns;
  module_param(halt_poll_ns, uint, S_IRUGO | S_IWUSR);
  
  /*
   * Ordering of locks:
   *
 - *            kvm->lock --> kvm->slots_lock --> kvm->irq_lock
 + *    kvm->lock --> kvm->slots_lock --> kvm->irq_lock
   */
  
  DEFINE_SPINLOCK(kvm_lock);
@@@ -80,7 -80,7 +80,7 @@@ static DEFINE_RAW_SPINLOCK(kvm_count_lo
  LIST_HEAD(vm_list);
  
  static cpumask_var_t cpus_hardware_enabled;
 -static int kvm_usage_count = 0;
 +static int kvm_usage_count;
  static atomic_t hardware_enable_failed;
  
  struct kmem_cache *kvm_vcpu_cache;
@@@ -539,12 -539,20 +539,12 @@@ void *kvm_kvzalloc(unsigned long size
                return kzalloc(size, GFP_KERNEL);
  }
  
 -void kvm_kvfree(const void *addr)
 -{
 -      if (is_vmalloc_addr(addr))
 -              vfree(addr);
 -      else
 -              kfree(addr);
 -}
 -
  static void kvm_destroy_dirty_bitmap(struct kvm_memory_slot *memslot)
  {
        if (!memslot->dirty_bitmap)
                return;
  
 -      kvm_kvfree(memslot->dirty_bitmap);
 +      kvfree(memslot->dirty_bitmap);
        memslot->dirty_bitmap = NULL;
  }
  
@@@ -880,8 -888,8 +880,8 @@@ int __kvm_set_memory_region(struct kvm 
                 * or moved, memslot will be created.
                 *
                 * validation of sp->gfn happens in:
 -               *      - gfn_to_hva (kvm_read_guest, gfn_to_pfn)
 -               *      - kvm_is_visible_gfn (mmu_check_roots)
 +               *      - gfn_to_hva (kvm_read_guest, gfn_to_pfn)
 +               *      - kvm_is_visible_gfn (mmu_check_roots)
                 */
                kvm_arch_flush_shadow_memslot(kvm, slot);
  
@@@ -1053,11 -1061,9 +1053,11 @@@ int kvm_get_dirty_log_protect(struct kv
                mask = xchg(&dirty_bitmap[i], 0);
                dirty_bitmap_buffer[i] = mask;
  
 -              offset = i * BITS_PER_LONG;
 -              kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot, offset,
 -                                                              mask);
 +              if (mask) {
 +                      offset = i * BITS_PER_LONG;
 +                      kvm_arch_mmu_enable_log_dirty_pt_masked(kvm, memslot,
 +                                                              offset, mask);
 +              }
        }
  
        spin_unlock(&kvm->mmu_lock);
@@@ -1475,6 -1481,7 +1475,6 @@@ struct page *gfn_to_page(struct kvm *kv
  
        return kvm_pfn_to_page(pfn);
  }
 -
  EXPORT_SYMBOL_GPL(gfn_to_page);
  
  void kvm_release_page_clean(struct page *page)
@@@ -1510,7 -1517,6 +1510,7 @@@ void kvm_set_pfn_dirty(pfn_t pfn
  {
        if (!kvm_is_reserved_pfn(pfn)) {
                struct page *page = pfn_to_page(pfn);
 +
                if (!PageReserved(page))
                        SetPageDirty(page);
        }
@@@ -1736,7 -1742,7 +1736,7 @@@ int kvm_clear_guest(struct kvm *kvm, gp
        int offset = offset_in_page(gpa);
        int ret;
  
 -        while ((seg = next_segment(len, offset)) != 0) {
 +      while ((seg = next_segment(len, offset)) != 0) {
                ret = kvm_clear_guest_page(kvm, gfn, offset, seg);
                if (ret < 0)
                        return ret;
@@@ -1794,7 -1800,6 +1794,7 @@@ void kvm_vcpu_block(struct kvm_vcpu *vc
        start = cur = ktime_get();
        if (halt_poll_ns) {
                ktime_t stop = ktime_add_ns(ktime_get(), halt_poll_ns);
 +
                do {
                        /*
                         * This sets KVM_REQ_UNHALT if an interrupt
@@@ -2113,7 -2118,7 +2113,7 @@@ static long kvm_vcpu_ioctl(struct file 
         * Special cases: vcpu ioctls that are asynchronous to vcpu execution,
         * so vcpu_load() would break it.
         */
-       if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_INTERRUPT)
+       if (ioctl == KVM_S390_INTERRUPT || ioctl == KVM_S390_IRQ || ioctl == KVM_INTERRUPT)
                return kvm_arch_vcpu_ioctl(filp, ioctl, arg);
  #endif
  
                        /* The thread running this VCPU changed. */
                        struct pid *oldpid = vcpu->pid;
                        struct pid *newpid = get_task_pid(current, PIDTYPE_PID);
 +
                        rcu_assign_pointer(vcpu->pid, newpid);
                        if (oldpid)
                                synchronize_rcu();
@@@ -2201,7 -2205,7 +2201,7 @@@ out_free1
                if (r)
                        goto out;
                r = -EFAULT;
 -              if (copy_to_user(argp, &mp_state, sizeof mp_state))
 +              if (copy_to_user(argp, &mp_state, sizeof(mp_state)))
                        goto out;
                r = 0;
                break;
                struct kvm_mp_state mp_state;
  
                r = -EFAULT;
 -              if (copy_from_user(&mp_state, argp, sizeof mp_state))
 +              if (copy_from_user(&mp_state, argp, sizeof(mp_state)))
                        goto out;
                r = kvm_arch_vcpu_ioctl_set_mpstate(vcpu, &mp_state);
                break;
                struct kvm_translation tr;
  
                r = -EFAULT;
 -              if (copy_from_user(&tr, argp, sizeof tr))
 +              if (copy_from_user(&tr, argp, sizeof(tr)))
                        goto out;
                r = kvm_arch_vcpu_ioctl_translate(vcpu, &tr);
                if (r)
                        goto out;
                r = -EFAULT;
 -              if (copy_to_user(argp, &tr, sizeof tr))
 +              if (copy_to_user(argp, &tr, sizeof(tr)))
                        goto out;
                r = 0;
                break;
                struct kvm_guest_debug dbg;
  
                r = -EFAULT;
 -              if (copy_from_user(&dbg, argp, sizeof dbg))
 +              if (copy_from_user(&dbg, argp, sizeof(dbg)))
                        goto out;
                r = kvm_arch_vcpu_ioctl_set_guest_debug(vcpu, &dbg);
                break;
                if (argp) {
                        r = -EFAULT;
                        if (copy_from_user(&kvm_sigmask, argp,
 -                                         sizeof kvm_sigmask))
 +                                         sizeof(kvm_sigmask)))
                                goto out;
                        r = -EINVAL;
 -                      if (kvm_sigmask.len != sizeof sigset)
 +                      if (kvm_sigmask.len != sizeof(sigset))
                                goto out;
                        r = -EFAULT;
                        if (copy_from_user(&sigset, sigmask_arg->sigset,
 -                                         sizeof sigset))
 +                                         sizeof(sigset)))
                                goto out;
                        p = &sigset;
                }
@@@ -2317,14 -2321,14 +2317,14 @@@ static long kvm_vcpu_compat_ioctl(struc
                if (argp) {
                        r = -EFAULT;
                        if (copy_from_user(&kvm_sigmask, argp,
 -                                         sizeof kvm_sigmask))
 +                                         sizeof(kvm_sigmask)))
                                goto out;
                        r = -EINVAL;
 -                      if (kvm_sigmask.len != sizeof csigset)
 +                      if (kvm_sigmask.len != sizeof(csigset))
                                goto out;
                        r = -EFAULT;
                        if (copy_from_user(&csigset, sigmask_arg->sigset,
 -                                         sizeof csigset))
 +                                         sizeof(csigset)))
                                goto out;
                        sigset_from_compat(&sigset, &csigset);
                        r = kvm_vcpu_ioctl_set_sigmask(vcpu, &sigset);
@@@ -2520,7 -2524,7 +2520,7 @@@ static long kvm_vm_ioctl(struct file *f
  
                r = -EFAULT;
                if (copy_from_user(&kvm_userspace_mem, argp,
 -                                              sizeof kvm_userspace_mem))
 +                                              sizeof(kvm_userspace_mem)))
                        goto out;
  
                r = kvm_vm_ioctl_set_memory_region(kvm, &kvm_userspace_mem);
                struct kvm_dirty_log log;
  
                r = -EFAULT;
 -              if (copy_from_user(&log, argp, sizeof log))
 +              if (copy_from_user(&log, argp, sizeof(log)))
                        goto out;
                r = kvm_vm_ioctl_get_dirty_log(kvm, &log);
                break;
  #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
        case KVM_REGISTER_COALESCED_MMIO: {
                struct kvm_coalesced_mmio_zone zone;
 +
                r = -EFAULT;
 -              if (copy_from_user(&zone, argp, sizeof zone))
 +              if (copy_from_user(&zone, argp, sizeof(zone)))
                        goto out;
                r = kvm_vm_ioctl_register_coalesced_mmio(kvm, &zone);
                break;
        }
        case KVM_UNREGISTER_COALESCED_MMIO: {
                struct kvm_coalesced_mmio_zone zone;
 +
                r = -EFAULT;
 -              if (copy_from_user(&zone, argp, sizeof zone))
 +              if (copy_from_user(&zone, argp, sizeof(zone)))
                        goto out;
                r = kvm_vm_ioctl_unregister_coalesced_mmio(kvm, &zone);
                break;
                struct kvm_irqfd data;
  
                r = -EFAULT;
 -              if (copy_from_user(&data, argp, sizeof data))
 +              if (copy_from_user(&data, argp, sizeof(data)))
                        goto out;
                r = kvm_irqfd(kvm, &data);
                break;
                struct kvm_ioeventfd data;
  
                r = -EFAULT;
 -              if (copy_from_user(&data, argp, sizeof data))
 +              if (copy_from_user(&data, argp, sizeof(data)))
                        goto out;
                r = kvm_ioeventfd(kvm, &data);
                break;
                struct kvm_msi msi;
  
                r = -EFAULT;
 -              if (copy_from_user(&msi, argp, sizeof msi))
 +              if (copy_from_user(&msi, argp, sizeof(msi)))
                        goto out;
                r = kvm_send_userspace_msi(kvm, &msi);
                break;
                struct kvm_irq_level irq_event;
  
                r = -EFAULT;
 -              if (copy_from_user(&irq_event, argp, sizeof irq_event))
 +              if (copy_from_user(&irq_event, argp, sizeof(irq_event)))
                        goto out;
  
                r = kvm_vm_ioctl_irq_line(kvm, &irq_event,
  
                r = -EFAULT;
                if (ioctl == KVM_IRQ_LINE_STATUS) {
 -                      if (copy_to_user(argp, &irq_event, sizeof irq_event))
 +                      if (copy_to_user(argp, &irq_event, sizeof(irq_event)))
                                goto out;
                }
  
                        goto out_free_irq_routing;
                r = kvm_set_irq_routing(kvm, entries, routing.nr,
                                        routing.flags);
 -      out_free_irq_routing:
 +out_free_irq_routing:
                vfree(entries);
                break;
        }
@@@ -2819,7 -2821,8 +2819,7 @@@ static void hardware_enable_nolock(voi
        if (r) {
                cpumask_clear_cpu(cpu, cpus_hardware_enabled);
                atomic_inc(&hardware_enable_failed);
 -              printk(KERN_INFO "kvm: enabling virtualization on "
 -                               "CPU%d failed\n", cpu);
 +              pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu);
        }
  }
  
@@@ -2895,12 -2898,12 +2895,12 @@@ static int kvm_cpu_hotplug(struct notif
        val &= ~CPU_TASKS_FROZEN;
        switch (val) {
        case CPU_DYING:
 -              printk(KERN_INFO "kvm: disabling virtualization on CPU%d\n",
 +              pr_info("kvm: disabling virtualization on CPU%d\n",
                       cpu);
                hardware_disable();
                break;
        case CPU_STARTING:
 -              printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n",
 +              pr_info("kvm: enabling virtualization on CPU%d\n",
                       cpu);
                hardware_enable();
                break;
@@@ -2917,7 -2920,7 +2917,7 @@@ static int kvm_reboot(struct notifier_b
         *
         * And Intel TXT required VMX off for all cpu when system shutdown.
         */
 -      printk(KERN_INFO "kvm: exiting hardware virtualization\n");
 +      pr_info("kvm: exiting hardware virtualization\n");
        kvm_rebooting = true;
        on_each_cpu(hardware_disable_nolock, NULL, 1);
        return NOTIFY_OK;
@@@ -2941,7 -2944,7 +2941,7 @@@ static void kvm_io_bus_destroy(struct k
  }
  
  static inline int kvm_io_bus_cmp(const struct kvm_io_range *r1,
 -                                 const struct kvm_io_range *r2)
 +                               const struct kvm_io_range *r2)
  {
        if (r1->addr < r2->addr)
                return -1;
@@@ -2994,7 -2997,7 +2994,7 @@@ static int kvm_io_bus_get_first_dev(str
        return off;
  }
  
 -static int __kvm_io_bus_write(struct kvm_io_bus *bus,
 +static int __kvm_io_bus_write(struct kvm_vcpu *vcpu, struct kvm_io_bus *bus,
                              struct kvm_io_range *range, const void *val)
  {
        int idx;
  
        while (idx < bus->dev_count &&
                kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
 -              if (!kvm_iodevice_write(bus->range[idx].dev, range->addr,
 +              if (!kvm_iodevice_write(vcpu, bus->range[idx].dev, range->addr,
                                        range->len, val))
                        return idx;
                idx++;
  }
  
  /* kvm_io_bus_write - called under kvm->slots_lock */
 -int kvm_io_bus_write(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 +int kvm_io_bus_write(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
                     int len, const void *val)
  {
        struct kvm_io_bus *bus;
                .len = len,
        };
  
 -      bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
 -      r = __kvm_io_bus_write(bus, &range, val);
 +      bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
 +      r = __kvm_io_bus_write(vcpu, bus, &range, val);
        return r < 0 ? r : 0;
  }
  
  /* kvm_io_bus_write_cookie - called under kvm->slots_lock */
 -int kvm_io_bus_write_cookie(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 -                          int len, const void *val, long cookie)
 +int kvm_io_bus_write_cookie(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx,
 +                          gpa_t addr, int len, const void *val, long cookie)
  {
        struct kvm_io_bus *bus;
        struct kvm_io_range range;
                .len = len,
        };
  
 -      bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
 +      bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
  
        /* First try the device referenced by cookie. */
        if ((cookie >= 0) && (cookie < bus->dev_count) &&
            (kvm_io_bus_cmp(&range, &bus->range[cookie]) == 0))
 -              if (!kvm_iodevice_write(bus->range[cookie].dev, addr, len,
 +              if (!kvm_iodevice_write(vcpu, bus->range[cookie].dev, addr, len,
                                        val))
                        return cookie;
  
         * cookie contained garbage; fall back to search and return the
         * correct cookie value.
         */
 -      return __kvm_io_bus_write(bus, &range, val);
 +      return __kvm_io_bus_write(vcpu, bus, &range, val);
  }
  
 -static int __kvm_io_bus_read(struct kvm_io_bus *bus, struct kvm_io_range *range,
 -                           void *val)
 +static int __kvm_io_bus_read(struct kvm_vcpu *vcpu, struct kvm_io_bus *bus,
 +                           struct kvm_io_range *range, void *val)
  {
        int idx;
  
  
        while (idx < bus->dev_count &&
                kvm_io_bus_cmp(range, &bus->range[idx]) == 0) {
 -              if (!kvm_iodevice_read(bus->range[idx].dev, range->addr,
 +              if (!kvm_iodevice_read(vcpu, bus->range[idx].dev, range->addr,
                                       range->len, val))
                        return idx;
                idx++;
  EXPORT_SYMBOL_GPL(kvm_io_bus_write);
  
  /* kvm_io_bus_read - called under kvm->slots_lock */
 -int kvm_io_bus_read(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr,
 +int kvm_io_bus_read(struct kvm_vcpu *vcpu, enum kvm_bus bus_idx, gpa_t addr,
                    int len, void *val)
  {
        struct kvm_io_bus *bus;
                .len = len,
        };
  
 -      bus = srcu_dereference(kvm->buses[bus_idx], &kvm->srcu);
 -      r = __kvm_io_bus_read(bus, &range, val);
 +      bus = srcu_dereference(vcpu->kvm->buses[bus_idx], &vcpu->kvm->srcu);
 +      r = __kvm_io_bus_read(vcpu, bus, &range, val);
        return r < 0 ? r : 0;
  }
  
@@@ -3265,7 -3268,6 +3265,7 @@@ struct kvm_vcpu *preempt_notifier_to_vc
  static void kvm_sched_in(struct preempt_notifier *pn, int cpu)
  {
        struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
 +
        if (vcpu->preempted)
                vcpu->preempted = false;
  
@@@ -3347,7 -3349,7 +3347,7 @@@ int kvm_init(void *opaque, unsigned vcp
  
        r = misc_register(&kvm_dev);
        if (r) {
 -              printk(KERN_ERR "kvm: misc device register failed\n");
 +              pr_err("kvm: misc device register failed\n");
                goto out_unreg;
        }
  
  
        r = kvm_init_debug();
        if (r) {
 -              printk(KERN_ERR "kvm: create debugfs files failed\n");
 +              pr_err("kvm: create debugfs files failed\n");
                goto out_undebugfs;
        }