aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-06-04 20:09:35 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-06-04 20:09:35 -0400
commit8b35c3595539782052ebffb5acbfa5c6573b198d (patch)
treea0bf8b97b6102f8cb12a61ce2ee241fa28c7e0ad /arch
parent6f66f9005b66a9a09028f8c85d67600b20a979ec (diff)
parent299018f44ac553dce3caf84df1d14c4764faa279 (diff)
Merge branch 'fixes' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm bugfixes from Gleb Natapov: "The bulk of the fixes is in MIPS KVM kernel<->userspace ABI. MIPS KVM is new for 3.10 and some problems were found with current ABI. It is better to fix them now and do not have a kernel with broken one" * 'fixes' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: Fix race in apic->pending_events processing KVM: fix sil/dil/bpl/spl in the mod/rm fields KVM: Emulate multibyte NOP ARM: KVM: be more thorough when invalidating TLBs ARM: KVM: prevent NULL pointer dereferences with KVM VCPU ioctl mips/kvm: Use ENOIOCTLCMD to indicate unimplemented ioctls. mips/kvm: Fix ABI by moving manipulation of CP0 registers to KVM_{G,S}ET_ONE_REG mips/kvm: Use ARRAY_SIZE() instead of hardcoded constants in kvm_arch_vcpu_ioctl_{s,g}et_regs mips/kvm: Fix name of gpr field in struct kvm_regs. mips/kvm: Fix ABI for use of 64-bit registers. mips/kvm: Fix ABI for use of FPU.
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/kvm/arm.c15
-rw-r--r--arch/arm/kvm/mmu.c41
-rw-r--r--arch/mips/include/asm/kvm_host.h4
-rw-r--r--arch/mips/include/uapi/asm/kvm.h137
-rw-r--r--arch/mips/kvm/kvm_mips.c280
-rw-r--r--arch/mips/kvm/kvm_trap_emul.c50
-rw-r--r--arch/x86/kvm/emulate.c9
-rw-r--r--arch/x86/kvm/lapic.c9
8 files changed, 421 insertions, 124 deletions
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 37d216d814cd..ef1703b9587b 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -492,6 +492,11 @@ static void vcpu_pause(struct kvm_vcpu *vcpu)
492 wait_event_interruptible(*wq, !vcpu->arch.pause); 492 wait_event_interruptible(*wq, !vcpu->arch.pause);
493} 493}
494 494
495static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
496{
497 return vcpu->arch.target >= 0;
498}
499
495/** 500/**
496 * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code 501 * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code
497 * @vcpu: The VCPU pointer 502 * @vcpu: The VCPU pointer
@@ -508,8 +513,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
508 int ret; 513 int ret;
509 sigset_t sigsaved; 514 sigset_t sigsaved;
510 515
511 /* Make sure they initialize the vcpu with KVM_ARM_VCPU_INIT */ 516 if (unlikely(!kvm_vcpu_initialized(vcpu)))
512 if (unlikely(vcpu->arch.target < 0))
513 return -ENOEXEC; 517 return -ENOEXEC;
514 518
515 ret = kvm_vcpu_first_run_init(vcpu); 519 ret = kvm_vcpu_first_run_init(vcpu);
@@ -710,6 +714,10 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
710 case KVM_SET_ONE_REG: 714 case KVM_SET_ONE_REG:
711 case KVM_GET_ONE_REG: { 715 case KVM_GET_ONE_REG: {
712 struct kvm_one_reg reg; 716 struct kvm_one_reg reg;
717
718 if (unlikely(!kvm_vcpu_initialized(vcpu)))
719 return -ENOEXEC;
720
713 if (copy_from_user(&reg, argp, sizeof(reg))) 721 if (copy_from_user(&reg, argp, sizeof(reg)))
714 return -EFAULT; 722 return -EFAULT;
715 if (ioctl == KVM_SET_ONE_REG) 723 if (ioctl == KVM_SET_ONE_REG)
@@ -722,6 +730,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
722 struct kvm_reg_list reg_list; 730 struct kvm_reg_list reg_list;
723 unsigned n; 731 unsigned n;
724 732
733 if (unlikely(!kvm_vcpu_initialized(vcpu)))
734 return -ENOEXEC;
735
725 if (copy_from_user(&reg_list, user_list, sizeof(reg_list))) 736 if (copy_from_user(&reg_list, user_list, sizeof(reg_list)))
726 return -EFAULT; 737 return -EFAULT;
727 n = reg_list.n; 738 n = reg_list.n;
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 965706578f13..84ba67b982c0 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -43,7 +43,14 @@ static phys_addr_t hyp_idmap_vector;
43 43
44static void kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa) 44static void kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa)
45{ 45{
46 kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, kvm, ipa); 46 /*
47 * This function also gets called when dealing with HYP page
48 * tables. As HYP doesn't have an associated struct kvm (and
49 * the HYP page tables are fairly static), we don't do
50 * anything there.
51 */
52 if (kvm)
53 kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, kvm, ipa);
47} 54}
48 55
49static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache, 56static int mmu_topup_memory_cache(struct kvm_mmu_memory_cache *cache,
@@ -78,18 +85,20 @@ static void *mmu_memory_cache_alloc(struct kvm_mmu_memory_cache *mc)
78 return p; 85 return p;
79} 86}
80 87
81static void clear_pud_entry(pud_t *pud) 88static void clear_pud_entry(struct kvm *kvm, pud_t *pud, phys_addr_t addr)
82{ 89{
83 pmd_t *pmd_table = pmd_offset(pud, 0); 90 pmd_t *pmd_table = pmd_offset(pud, 0);
84 pud_clear(pud); 91 pud_clear(pud);
92 kvm_tlb_flush_vmid_ipa(kvm, addr);
85 pmd_free(NULL, pmd_table); 93 pmd_free(NULL, pmd_table);
86 put_page(virt_to_page(pud)); 94 put_page(virt_to_page(pud));
87} 95}
88 96
89static void clear_pmd_entry(pmd_t *pmd) 97static void clear_pmd_entry(struct kvm *kvm, pmd_t *pmd, phys_addr_t addr)
90{ 98{
91 pte_t *pte_table = pte_offset_kernel(pmd, 0); 99 pte_t *pte_table = pte_offset_kernel(pmd, 0);
92 pmd_clear(pmd); 100 pmd_clear(pmd);
101 kvm_tlb_flush_vmid_ipa(kvm, addr);
93 pte_free_kernel(NULL, pte_table); 102 pte_free_kernel(NULL, pte_table);
94 put_page(virt_to_page(pmd)); 103 put_page(virt_to_page(pmd));
95} 104}
@@ -100,11 +109,12 @@ static bool pmd_empty(pmd_t *pmd)
100 return page_count(pmd_page) == 1; 109 return page_count(pmd_page) == 1;
101} 110}
102 111
103static void clear_pte_entry(pte_t *pte) 112static void clear_pte_entry(struct kvm *kvm, pte_t *pte, phys_addr_t addr)
104{ 113{
105 if (pte_present(*pte)) { 114 if (pte_present(*pte)) {
106 kvm_set_pte(pte, __pte(0)); 115 kvm_set_pte(pte, __pte(0));
107 put_page(virt_to_page(pte)); 116 put_page(virt_to_page(pte));
117 kvm_tlb_flush_vmid_ipa(kvm, addr);
108 } 118 }
109} 119}
110 120
@@ -114,7 +124,8 @@ static bool pte_empty(pte_t *pte)
114 return page_count(pte_page) == 1; 124 return page_count(pte_page) == 1;
115} 125}
116 126
117static void unmap_range(pgd_t *pgdp, unsigned long long start, u64 size) 127static void unmap_range(struct kvm *kvm, pgd_t *pgdp,
128 unsigned long long start, u64 size)
118{ 129{
119 pgd_t *pgd; 130 pgd_t *pgd;
120 pud_t *pud; 131 pud_t *pud;
@@ -138,15 +149,15 @@ static void unmap_range(pgd_t *pgdp, unsigned long long start, u64 size)
138 } 149 }
139 150
140 pte = pte_offset_kernel(pmd, addr); 151 pte = pte_offset_kernel(pmd, addr);
141 clear_pte_entry(pte); 152 clear_pte_entry(kvm, pte, addr);
142 range = PAGE_SIZE; 153 range = PAGE_SIZE;
143 154
144 /* If we emptied the pte, walk back up the ladder */ 155 /* If we emptied the pte, walk back up the ladder */
145 if (pte_empty(pte)) { 156 if (pte_empty(pte)) {
146 clear_pmd_entry(pmd); 157 clear_pmd_entry(kvm, pmd, addr);
147 range = PMD_SIZE; 158 range = PMD_SIZE;
148 if (pmd_empty(pmd)) { 159 if (pmd_empty(pmd)) {
149 clear_pud_entry(pud); 160 clear_pud_entry(kvm, pud, addr);
150 range = PUD_SIZE; 161 range = PUD_SIZE;
151 } 162 }
152 } 163 }
@@ -165,14 +176,14 @@ void free_boot_hyp_pgd(void)
165 mutex_lock(&kvm_hyp_pgd_mutex); 176 mutex_lock(&kvm_hyp_pgd_mutex);
166 177
167 if (boot_hyp_pgd) { 178 if (boot_hyp_pgd) {
168 unmap_range(boot_hyp_pgd, hyp_idmap_start, PAGE_SIZE); 179 unmap_range(NULL, boot_hyp_pgd, hyp_idmap_start, PAGE_SIZE);
169 unmap_range(boot_hyp_pgd, TRAMPOLINE_VA, PAGE_SIZE); 180 unmap_range(NULL, boot_hyp_pgd, TRAMPOLINE_VA, PAGE_SIZE);
170 kfree(boot_hyp_pgd); 181 kfree(boot_hyp_pgd);
171 boot_hyp_pgd = NULL; 182 boot_hyp_pgd = NULL;
172 } 183 }
173 184
174 if (hyp_pgd) 185 if (hyp_pgd)
175 unmap_range(hyp_pgd, TRAMPOLINE_VA, PAGE_SIZE); 186 unmap_range(NULL, hyp_pgd, TRAMPOLINE_VA, PAGE_SIZE);
176 187
177 kfree(init_bounce_page); 188 kfree(init_bounce_page);
178 init_bounce_page = NULL; 189 init_bounce_page = NULL;
@@ -200,9 +211,10 @@ void free_hyp_pgds(void)
200 211
201 if (hyp_pgd) { 212 if (hyp_pgd) {
202 for (addr = PAGE_OFFSET; virt_addr_valid(addr); addr += PGDIR_SIZE) 213 for (addr = PAGE_OFFSET; virt_addr_valid(addr); addr += PGDIR_SIZE)
203 unmap_range(hyp_pgd, KERN_TO_HYP(addr), PGDIR_SIZE); 214 unmap_range(NULL, hyp_pgd, KERN_TO_HYP(addr), PGDIR_SIZE);
204 for (addr = VMALLOC_START; is_vmalloc_addr((void*)addr); addr += PGDIR_SIZE) 215 for (addr = VMALLOC_START; is_vmalloc_addr((void*)addr); addr += PGDIR_SIZE)
205 unmap_range(hyp_pgd, KERN_TO_HYP(addr), PGDIR_SIZE); 216 unmap_range(NULL, hyp_pgd, KERN_TO_HYP(addr), PGDIR_SIZE);
217
206 kfree(hyp_pgd); 218 kfree(hyp_pgd);
207 hyp_pgd = NULL; 219 hyp_pgd = NULL;
208 } 220 }
@@ -393,7 +405,7 @@ int kvm_alloc_stage2_pgd(struct kvm *kvm)
393 */ 405 */
394static void unmap_stage2_range(struct kvm *kvm, phys_addr_t start, u64 size) 406static void unmap_stage2_range(struct kvm *kvm, phys_addr_t start, u64 size)
395{ 407{
396 unmap_range(kvm->arch.pgd, start, size); 408 unmap_range(kvm, kvm->arch.pgd, start, size);
397} 409}
398 410
399/** 411/**
@@ -675,7 +687,6 @@ static void handle_hva_to_gpa(struct kvm *kvm,
675static void kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, void *data) 687static void kvm_unmap_hva_handler(struct kvm *kvm, gpa_t gpa, void *data)
676{ 688{
677 unmap_stage2_range(kvm, gpa, PAGE_SIZE); 689 unmap_stage2_range(kvm, gpa, PAGE_SIZE);
678 kvm_tlb_flush_vmid_ipa(kvm, gpa);
679} 690}
680 691
681int kvm_unmap_hva(struct kvm *kvm, unsigned long hva) 692int kvm_unmap_hva(struct kvm *kvm, unsigned long hva)
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h
index 143875c6c95a..4d6fa0bf1305 100644
--- a/arch/mips/include/asm/kvm_host.h
+++ b/arch/mips/include/asm/kvm_host.h
@@ -496,10 +496,6 @@ struct kvm_mips_callbacks {
496 uint32_t cause); 496 uint32_t cause);
497 int (*irq_clear) (struct kvm_vcpu *vcpu, unsigned int priority, 497 int (*irq_clear) (struct kvm_vcpu *vcpu, unsigned int priority,
498 uint32_t cause); 498 uint32_t cause);
499 int (*vcpu_ioctl_get_regs) (struct kvm_vcpu *vcpu,
500 struct kvm_regs *regs);
501 int (*vcpu_ioctl_set_regs) (struct kvm_vcpu *vcpu,
502 struct kvm_regs *regs);
503}; 499};
504extern struct kvm_mips_callbacks *kvm_mips_callbacks; 500extern struct kvm_mips_callbacks *kvm_mips_callbacks;
505int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks); 501int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks);
diff --git a/arch/mips/include/uapi/asm/kvm.h b/arch/mips/include/uapi/asm/kvm.h
index 85789eacbf18..3f424f5217da 100644
--- a/arch/mips/include/uapi/asm/kvm.h
+++ b/arch/mips/include/uapi/asm/kvm.h
@@ -1,55 +1,138 @@
1/* 1/*
2* This file is subject to the terms and conditions of the GNU General Public 2 * This file is subject to the terms and conditions of the GNU General Public
3* License. See the file "COPYING" in the main directory of this archive 3 * License. See the file "COPYING" in the main directory of this archive
4* for more details. 4 * for more details.
5* 5 *
6* Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7* Authors: Sanjay Lal <sanjayl@kymasys.com> 7 * Copyright (C) 2013 Cavium, Inc.
8*/ 8 * Authors: Sanjay Lal <sanjayl@kymasys.com>
9 */
9 10
10#ifndef __LINUX_KVM_MIPS_H 11#ifndef __LINUX_KVM_MIPS_H
11#define __LINUX_KVM_MIPS_H 12#define __LINUX_KVM_MIPS_H
12 13
13#include <linux/types.h> 14#include <linux/types.h>
14 15
15#define __KVM_MIPS 16/*
16 17 * KVM MIPS specific structures and definitions.
17#define N_MIPS_COPROC_REGS 32 18 *
18#define N_MIPS_COPROC_SEL 8 19 * Some parts derived from the x86 version of this file.
20 */
19 21
20/* for KVM_GET_REGS and KVM_SET_REGS */ 22/*
23 * for KVM_GET_REGS and KVM_SET_REGS
24 *
25 * If Config[AT] is zero (32-bit CPU), the register contents are
26 * stored in the lower 32-bits of the struct kvm_regs fields and sign
27 * extended to 64-bits.
28 */
21struct kvm_regs { 29struct kvm_regs {
22 __u32 gprs[32]; 30 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
23 __u32 hi; 31 __u64 gpr[32];
24 __u32 lo; 32 __u64 hi;
25 __u32 pc; 33 __u64 lo;
26 34 __u64 pc;
27 __u32 cp0reg[N_MIPS_COPROC_REGS][N_MIPS_COPROC_SEL];
28};
29
30/* for KVM_GET_SREGS and KVM_SET_SREGS */
31struct kvm_sregs {
32}; 35};
33 36
34/* for KVM_GET_FPU and KVM_SET_FPU */ 37/*
38 * for KVM_GET_FPU and KVM_SET_FPU
39 *
40 * If Status[FR] is zero (32-bit FPU), the upper 32-bits of the FPRs
41 * are zero filled.
42 */
35struct kvm_fpu { 43struct kvm_fpu {
44 __u64 fpr[32];
45 __u32 fir;
46 __u32 fccr;
47 __u32 fexr;
48 __u32 fenr;
49 __u32 fcsr;
50 __u32 pad;
36}; 51};
37 52
53
54/*
55 * For MIPS, we use KVM_SET_ONE_REG and KVM_GET_ONE_REG to access CP0
56 * registers. The id field is broken down as follows:
57 *
58 * bits[2..0] - Register 'sel' index.
59 * bits[7..3] - Register 'rd' index.
60 * bits[15..8] - Must be zero.
61 * bits[63..16] - 1 -> CP0 registers.
62 *
63 * Other sets registers may be added in the future. Each set would
64 * have its own identifier in bits[63..16].
65 *
66 * The addr field of struct kvm_one_reg must point to an aligned
67 * 64-bit wide location. For registers that are narrower than
68 * 64-bits, the value is stored in the low order bits of the location,
69 * and sign extended to 64-bits.
70 *
71 * The registers defined in struct kvm_regs are also accessible, the
72 * id values for these are below.
73 */
74
75#define KVM_REG_MIPS_R0 0
76#define KVM_REG_MIPS_R1 1
77#define KVM_REG_MIPS_R2 2
78#define KVM_REG_MIPS_R3 3
79#define KVM_REG_MIPS_R4 4
80#define KVM_REG_MIPS_R5 5
81#define KVM_REG_MIPS_R6 6
82#define KVM_REG_MIPS_R7 7
83#define KVM_REG_MIPS_R8 8
84#define KVM_REG_MIPS_R9 9
85#define KVM_REG_MIPS_R10 10
86#define KVM_REG_MIPS_R11 11
87#define KVM_REG_MIPS_R12 12
88#define KVM_REG_MIPS_R13 13
89#define KVM_REG_MIPS_R14 14
90#define KVM_REG_MIPS_R15 15
91#define KVM_REG_MIPS_R16 16
92#define KVM_REG_MIPS_R17 17
93#define KVM_REG_MIPS_R18 18
94#define KVM_REG_MIPS_R19 19
95#define KVM_REG_MIPS_R20 20
96#define KVM_REG_MIPS_R21 21
97#define KVM_REG_MIPS_R22 22
98#define KVM_REG_MIPS_R23 23
99#define KVM_REG_MIPS_R24 24
100#define KVM_REG_MIPS_R25 25
101#define KVM_REG_MIPS_R26 26
102#define KVM_REG_MIPS_R27 27
103#define KVM_REG_MIPS_R28 28
104#define KVM_REG_MIPS_R29 29
105#define KVM_REG_MIPS_R30 30
106#define KVM_REG_MIPS_R31 31
107
108#define KVM_REG_MIPS_HI 32
109#define KVM_REG_MIPS_LO 33
110#define KVM_REG_MIPS_PC 34
111
112/*
113 * KVM MIPS specific structures and definitions
114 *
115 */
38struct kvm_debug_exit_arch { 116struct kvm_debug_exit_arch {
117 __u64 epc;
39}; 118};
40 119
41/* for KVM_SET_GUEST_DEBUG */ 120/* for KVM_SET_GUEST_DEBUG */
42struct kvm_guest_debug_arch { 121struct kvm_guest_debug_arch {
43}; 122};
44 123
124/* definition of registers in kvm_run */
125struct kvm_sync_regs {
126};
127
128/* dummy definition */
129struct kvm_sregs {
130};
131
45struct kvm_mips_interrupt { 132struct kvm_mips_interrupt {
46 /* in */ 133 /* in */
47 __u32 cpu; 134 __u32 cpu;
48 __u32 irq; 135 __u32 irq;
49}; 136};
50 137
51/* definition of registers in kvm_run */
52struct kvm_sync_regs {
53};
54
55#endif /* __LINUX_KVM_MIPS_H */ 138#endif /* __LINUX_KVM_MIPS_H */
diff --git a/arch/mips/kvm/kvm_mips.c b/arch/mips/kvm/kvm_mips.c
index e0dad0289797..d934b017f479 100644
--- a/arch/mips/kvm/kvm_mips.c
+++ b/arch/mips/kvm/kvm_mips.c
@@ -195,7 +195,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
195long 195long
196kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) 196kvm_arch_dev_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
197{ 197{
198 return -EINVAL; 198 return -ENOIOCTLCMD;
199} 199}
200 200
201void kvm_arch_free_memslot(struct kvm_memory_slot *free, 201void kvm_arch_free_memslot(struct kvm_memory_slot *free,
@@ -401,7 +401,7 @@ int
401kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 401kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
402 struct kvm_guest_debug *dbg) 402 struct kvm_guest_debug *dbg)
403{ 403{
404 return -EINVAL; 404 return -ENOIOCTLCMD;
405} 405}
406 406
407int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) 407int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
@@ -475,14 +475,223 @@ int
475kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 475kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
476 struct kvm_mp_state *mp_state) 476 struct kvm_mp_state *mp_state)
477{ 477{
478 return -EINVAL; 478 return -ENOIOCTLCMD;
479} 479}
480 480
481int 481int
482kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 482kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
483 struct kvm_mp_state *mp_state) 483 struct kvm_mp_state *mp_state)
484{ 484{
485 return -EINVAL; 485 return -ENOIOCTLCMD;
486}
487
488#define KVM_REG_MIPS_CP0_INDEX (0x10000 + 8 * 0 + 0)
489#define KVM_REG_MIPS_CP0_ENTRYLO0 (0x10000 + 8 * 2 + 0)
490#define KVM_REG_MIPS_CP0_ENTRYLO1 (0x10000 + 8 * 3 + 0)
491#define KVM_REG_MIPS_CP0_CONTEXT (0x10000 + 8 * 4 + 0)
492#define KVM_REG_MIPS_CP0_USERLOCAL (0x10000 + 8 * 4 + 2)
493#define KVM_REG_MIPS_CP0_PAGEMASK (0x10000 + 8 * 5 + 0)
494#define KVM_REG_MIPS_CP0_PAGEGRAIN (0x10000 + 8 * 5 + 1)
495#define KVM_REG_MIPS_CP0_WIRED (0x10000 + 8 * 6 + 0)
496#define KVM_REG_MIPS_CP0_HWRENA (0x10000 + 8 * 7 + 0)
497#define KVM_REG_MIPS_CP0_BADVADDR (0x10000 + 8 * 8 + 0)
498#define KVM_REG_MIPS_CP0_COUNT (0x10000 + 8 * 9 + 0)
499#define KVM_REG_MIPS_CP0_ENTRYHI (0x10000 + 8 * 10 + 0)
500#define KVM_REG_MIPS_CP0_COMPARE (0x10000 + 8 * 11 + 0)
501#define KVM_REG_MIPS_CP0_STATUS (0x10000 + 8 * 12 + 0)
502#define KVM_REG_MIPS_CP0_CAUSE (0x10000 + 8 * 13 + 0)
503#define KVM_REG_MIPS_CP0_EBASE (0x10000 + 8 * 15 + 1)
504#define KVM_REG_MIPS_CP0_CONFIG (0x10000 + 8 * 16 + 0)
505#define KVM_REG_MIPS_CP0_CONFIG1 (0x10000 + 8 * 16 + 1)
506#define KVM_REG_MIPS_CP0_CONFIG2 (0x10000 + 8 * 16 + 2)
507#define KVM_REG_MIPS_CP0_CONFIG3 (0x10000 + 8 * 16 + 3)
508#define KVM_REG_MIPS_CP0_CONFIG7 (0x10000 + 8 * 16 + 7)
509#define KVM_REG_MIPS_CP0_XCONTEXT (0x10000 + 8 * 20 + 0)
510#define KVM_REG_MIPS_CP0_ERROREPC (0x10000 + 8 * 30 + 0)
511
512static u64 kvm_mips_get_one_regs[] = {
513 KVM_REG_MIPS_R0,
514 KVM_REG_MIPS_R1,
515 KVM_REG_MIPS_R2,
516 KVM_REG_MIPS_R3,
517 KVM_REG_MIPS_R4,
518 KVM_REG_MIPS_R5,
519 KVM_REG_MIPS_R6,
520 KVM_REG_MIPS_R7,
521 KVM_REG_MIPS_R8,
522 KVM_REG_MIPS_R9,
523 KVM_REG_MIPS_R10,
524 KVM_REG_MIPS_R11,
525 KVM_REG_MIPS_R12,
526 KVM_REG_MIPS_R13,
527 KVM_REG_MIPS_R14,
528 KVM_REG_MIPS_R15,
529 KVM_REG_MIPS_R16,
530 KVM_REG_MIPS_R17,
531 KVM_REG_MIPS_R18,
532 KVM_REG_MIPS_R19,
533 KVM_REG_MIPS_R20,
534 KVM_REG_MIPS_R21,
535 KVM_REG_MIPS_R22,
536 KVM_REG_MIPS_R23,
537 KVM_REG_MIPS_R24,
538 KVM_REG_MIPS_R25,
539 KVM_REG_MIPS_R26,
540 KVM_REG_MIPS_R27,
541 KVM_REG_MIPS_R28,
542 KVM_REG_MIPS_R29,
543 KVM_REG_MIPS_R30,
544 KVM_REG_MIPS_R31,
545
546 KVM_REG_MIPS_HI,
547 KVM_REG_MIPS_LO,
548 KVM_REG_MIPS_PC,
549
550 KVM_REG_MIPS_CP0_INDEX,
551 KVM_REG_MIPS_CP0_CONTEXT,
552 KVM_REG_MIPS_CP0_PAGEMASK,
553 KVM_REG_MIPS_CP0_WIRED,
554 KVM_REG_MIPS_CP0_BADVADDR,
555 KVM_REG_MIPS_CP0_ENTRYHI,
556 KVM_REG_MIPS_CP0_STATUS,
557 KVM_REG_MIPS_CP0_CAUSE,
558 /* EPC set via kvm_regs, et al. */
559 KVM_REG_MIPS_CP0_CONFIG,
560 KVM_REG_MIPS_CP0_CONFIG1,
561 KVM_REG_MIPS_CP0_CONFIG2,
562 KVM_REG_MIPS_CP0_CONFIG3,
563 KVM_REG_MIPS_CP0_CONFIG7,
564 KVM_REG_MIPS_CP0_ERROREPC
565};
566
567static int kvm_mips_get_reg(struct kvm_vcpu *vcpu,
568 const struct kvm_one_reg *reg)
569{
570 u64 __user *uaddr = (u64 __user *)(long)reg->addr;
571
572 struct mips_coproc *cop0 = vcpu->arch.cop0;
573 s64 v;
574
575 switch (reg->id) {
576 case KVM_REG_MIPS_R0 ... KVM_REG_MIPS_R31:
577 v = (long)vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0];
578 break;
579 case KVM_REG_MIPS_HI:
580 v = (long)vcpu->arch.hi;
581 break;
582 case KVM_REG_MIPS_LO:
583 v = (long)vcpu->arch.lo;
584 break;
585 case KVM_REG_MIPS_PC:
586 v = (long)vcpu->arch.pc;
587 break;
588
589 case KVM_REG_MIPS_CP0_INDEX:
590 v = (long)kvm_read_c0_guest_index(cop0);
591 break;
592 case KVM_REG_MIPS_CP0_CONTEXT:
593 v = (long)kvm_read_c0_guest_context(cop0);
594 break;
595 case KVM_REG_MIPS_CP0_PAGEMASK:
596 v = (long)kvm_read_c0_guest_pagemask(cop0);
597 break;
598 case KVM_REG_MIPS_CP0_WIRED:
599 v = (long)kvm_read_c0_guest_wired(cop0);
600 break;
601 case KVM_REG_MIPS_CP0_BADVADDR:
602 v = (long)kvm_read_c0_guest_badvaddr(cop0);
603 break;
604 case KVM_REG_MIPS_CP0_ENTRYHI:
605 v = (long)kvm_read_c0_guest_entryhi(cop0);
606 break;
607 case KVM_REG_MIPS_CP0_STATUS:
608 v = (long)kvm_read_c0_guest_status(cop0);
609 break;
610 case KVM_REG_MIPS_CP0_CAUSE:
611 v = (long)kvm_read_c0_guest_cause(cop0);
612 break;
613 case KVM_REG_MIPS_CP0_ERROREPC:
614 v = (long)kvm_read_c0_guest_errorepc(cop0);
615 break;
616 case KVM_REG_MIPS_CP0_CONFIG:
617 v = (long)kvm_read_c0_guest_config(cop0);
618 break;
619 case KVM_REG_MIPS_CP0_CONFIG1:
620 v = (long)kvm_read_c0_guest_config1(cop0);
621 break;
622 case KVM_REG_MIPS_CP0_CONFIG2:
623 v = (long)kvm_read_c0_guest_config2(cop0);
624 break;
625 case KVM_REG_MIPS_CP0_CONFIG3:
626 v = (long)kvm_read_c0_guest_config3(cop0);
627 break;
628 case KVM_REG_MIPS_CP0_CONFIG7:
629 v = (long)kvm_read_c0_guest_config7(cop0);
630 break;
631 default:
632 return -EINVAL;
633 }
634 return put_user(v, uaddr);
635}
636
637static int kvm_mips_set_reg(struct kvm_vcpu *vcpu,
638 const struct kvm_one_reg *reg)
639{
640 u64 __user *uaddr = (u64 __user *)(long)reg->addr;
641 struct mips_coproc *cop0 = vcpu->arch.cop0;
642 u64 v;
643
644 if (get_user(v, uaddr) != 0)
645 return -EFAULT;
646
647 switch (reg->id) {
648 case KVM_REG_MIPS_R0:
649 /* Silently ignore requests to set $0 */
650 break;
651 case KVM_REG_MIPS_R1 ... KVM_REG_MIPS_R31:
652 vcpu->arch.gprs[reg->id - KVM_REG_MIPS_R0] = v;
653 break;
654 case KVM_REG_MIPS_HI:
655 vcpu->arch.hi = v;
656 break;
657 case KVM_REG_MIPS_LO:
658 vcpu->arch.lo = v;
659 break;
660 case KVM_REG_MIPS_PC:
661 vcpu->arch.pc = v;
662 break;
663
664 case KVM_REG_MIPS_CP0_INDEX:
665 kvm_write_c0_guest_index(cop0, v);
666 break;
667 case KVM_REG_MIPS_CP0_CONTEXT:
668 kvm_write_c0_guest_context(cop0, v);
669 break;
670 case KVM_REG_MIPS_CP0_PAGEMASK:
671 kvm_write_c0_guest_pagemask(cop0, v);
672 break;
673 case KVM_REG_MIPS_CP0_WIRED:
674 kvm_write_c0_guest_wired(cop0, v);
675 break;
676 case KVM_REG_MIPS_CP0_BADVADDR:
677 kvm_write_c0_guest_badvaddr(cop0, v);
678 break;
679 case KVM_REG_MIPS_CP0_ENTRYHI:
680 kvm_write_c0_guest_entryhi(cop0, v);
681 break;
682 case KVM_REG_MIPS_CP0_STATUS:
683 kvm_write_c0_guest_status(cop0, v);
684 break;
685 case KVM_REG_MIPS_CP0_CAUSE:
686 kvm_write_c0_guest_cause(cop0, v);
687 break;
688 case KVM_REG_MIPS_CP0_ERROREPC:
689 kvm_write_c0_guest_errorepc(cop0, v);
690 break;
691 default:
692 return -EINVAL;
693 }
694 return 0;
486} 695}
487 696
488long 697long
@@ -491,9 +700,38 @@ kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
491 struct kvm_vcpu *vcpu = filp->private_data; 700 struct kvm_vcpu *vcpu = filp->private_data;
492 void __user *argp = (void __user *)arg; 701 void __user *argp = (void __user *)arg;
493 long r; 702 long r;
494 int intr;
495 703
496 switch (ioctl) { 704 switch (ioctl) {
705 case KVM_SET_ONE_REG:
706 case KVM_GET_ONE_REG: {
707 struct kvm_one_reg reg;
708 if (copy_from_user(&reg, argp, sizeof(reg)))
709 return -EFAULT;
710 if (ioctl == KVM_SET_ONE_REG)
711 return kvm_mips_set_reg(vcpu, &reg);
712 else
713 return kvm_mips_get_reg(vcpu, &reg);
714 }
715 case KVM_GET_REG_LIST: {
716 struct kvm_reg_list __user *user_list = argp;
717 u64 __user *reg_dest;
718 struct kvm_reg_list reg_list;
719 unsigned n;
720
721 if (copy_from_user(&reg_list, user_list, sizeof(reg_list)))
722 return -EFAULT;
723 n = reg_list.n;
724 reg_list.n = ARRAY_SIZE(kvm_mips_get_one_regs);
725 if (copy_to_user(user_list, &reg_list, sizeof(reg_list)))
726 return -EFAULT;
727 if (n < reg_list.n)
728 return -E2BIG;
729 reg_dest = user_list->reg;
730 if (copy_to_user(reg_dest, kvm_mips_get_one_regs,
731 sizeof(kvm_mips_get_one_regs)))
732 return -EFAULT;
733 return 0;
734 }
497 case KVM_NMI: 735 case KVM_NMI:
498 /* Treat the NMI as a CPU reset */ 736 /* Treat the NMI as a CPU reset */
499 r = kvm_mips_reset_vcpu(vcpu); 737 r = kvm_mips_reset_vcpu(vcpu);
@@ -505,8 +743,6 @@ kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
505 if (copy_from_user(&irq, argp, sizeof(irq))) 743 if (copy_from_user(&irq, argp, sizeof(irq)))
506 goto out; 744 goto out;
507 745
508 intr = (int)irq.irq;
509
510 kvm_debug("[%d] %s: irq: %d\n", vcpu->vcpu_id, __func__, 746 kvm_debug("[%d] %s: irq: %d\n", vcpu->vcpu_id, __func__,
511 irq.irq); 747 irq.irq);
512 748
@@ -514,7 +750,7 @@ kvm_arch_vcpu_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
514 break; 750 break;
515 } 751 }
516 default: 752 default:
517 r = -EINVAL; 753 r = -ENOIOCTLCMD;
518 } 754 }
519 755
520out: 756out:
@@ -565,7 +801,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
565 801
566 switch (ioctl) { 802 switch (ioctl) {
567 default: 803 default:
568 r = -EINVAL; 804 r = -ENOIOCTLCMD;
569 } 805 }
570 806
571 return r; 807 return r;
@@ -593,13 +829,13 @@ void kvm_arch_exit(void)
593int 829int
594kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 830kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
595{ 831{
596 return -ENOTSUPP; 832 return -ENOIOCTLCMD;
597} 833}
598 834
599int 835int
600kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) 836kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
601{ 837{
602 return -ENOTSUPP; 838 return -ENOIOCTLCMD;
603} 839}
604 840
605int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu) 841int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
@@ -609,12 +845,12 @@ int kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
609 845
610int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 846int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
611{ 847{
612 return -ENOTSUPP; 848 return -ENOIOCTLCMD;
613} 849}
614 850
615int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 851int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
616{ 852{
617 return -ENOTSUPP; 853 return -ENOIOCTLCMD;
618} 854}
619 855
620int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf) 856int kvm_arch_vcpu_fault(struct kvm_vcpu *vcpu, struct vm_fault *vmf)
@@ -627,6 +863,9 @@ int kvm_dev_ioctl_check_extension(long ext)
627 int r; 863 int r;
628 864
629 switch (ext) { 865 switch (ext) {
866 case KVM_CAP_ONE_REG:
867 r = 1;
868 break;
630 case KVM_CAP_COALESCED_MMIO: 869 case KVM_CAP_COALESCED_MMIO:
631 r = KVM_COALESCED_MMIO_PAGE_OFFSET; 870 r = KVM_COALESCED_MMIO_PAGE_OFFSET;
632 break; 871 break;
@@ -635,7 +874,6 @@ int kvm_dev_ioctl_check_extension(long ext)
635 break; 874 break;
636 } 875 }
637 return r; 876 return r;
638
639} 877}
640 878
641int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 879int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
@@ -677,28 +915,28 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
677{ 915{
678 int i; 916 int i;
679 917
680 for (i = 0; i < 32; i++) 918 for (i = 1; i < ARRAY_SIZE(vcpu->arch.gprs); i++)
681 vcpu->arch.gprs[i] = regs->gprs[i]; 919 vcpu->arch.gprs[i] = regs->gpr[i];
682 920 vcpu->arch.gprs[0] = 0; /* zero is special, and cannot be set. */
683 vcpu->arch.hi = regs->hi; 921 vcpu->arch.hi = regs->hi;
684 vcpu->arch.lo = regs->lo; 922 vcpu->arch.lo = regs->lo;
685 vcpu->arch.pc = regs->pc; 923 vcpu->arch.pc = regs->pc;
686 924
687 return kvm_mips_callbacks->vcpu_ioctl_set_regs(vcpu, regs); 925 return 0;
688} 926}
689 927
690int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 928int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
691{ 929{
692 int i; 930 int i;
693 931
694 for (i = 0; i < 32; i++) 932 for (i = 0; i < ARRAY_SIZE(vcpu->arch.gprs); i++)
695 regs->gprs[i] = vcpu->arch.gprs[i]; 933 regs->gpr[i] = vcpu->arch.gprs[i];
696 934
697 regs->hi = vcpu->arch.hi; 935 regs->hi = vcpu->arch.hi;
698 regs->lo = vcpu->arch.lo; 936 regs->lo = vcpu->arch.lo;
699 regs->pc = vcpu->arch.pc; 937 regs->pc = vcpu->arch.pc;
700 938
701 return kvm_mips_callbacks->vcpu_ioctl_get_regs(vcpu, regs); 939 return 0;
702} 940}
703 941
704void kvm_mips_comparecount_func(unsigned long data) 942void kvm_mips_comparecount_func(unsigned long data)
diff --git a/arch/mips/kvm/kvm_trap_emul.c b/arch/mips/kvm/kvm_trap_emul.c
index 466aeef044bd..30d725321db1 100644
--- a/arch/mips/kvm/kvm_trap_emul.c
+++ b/arch/mips/kvm/kvm_trap_emul.c
@@ -345,54 +345,6 @@ static int kvm_trap_emul_handle_break(struct kvm_vcpu *vcpu)
345 return ret; 345 return ret;
346} 346}
347 347
348static int
349kvm_trap_emul_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
350{
351 struct mips_coproc *cop0 = vcpu->arch.cop0;
352
353 kvm_write_c0_guest_index(cop0, regs->cp0reg[MIPS_CP0_TLB_INDEX][0]);
354 kvm_write_c0_guest_context(cop0, regs->cp0reg[MIPS_CP0_TLB_CONTEXT][0]);
355 kvm_write_c0_guest_badvaddr(cop0, regs->cp0reg[MIPS_CP0_BAD_VADDR][0]);
356 kvm_write_c0_guest_entryhi(cop0, regs->cp0reg[MIPS_CP0_TLB_HI][0]);
357 kvm_write_c0_guest_epc(cop0, regs->cp0reg[MIPS_CP0_EXC_PC][0]);
358
359 kvm_write_c0_guest_status(cop0, regs->cp0reg[MIPS_CP0_STATUS][0]);
360 kvm_write_c0_guest_cause(cop0, regs->cp0reg[MIPS_CP0_CAUSE][0]);
361 kvm_write_c0_guest_pagemask(cop0,
362 regs->cp0reg[MIPS_CP0_TLB_PG_MASK][0]);
363 kvm_write_c0_guest_wired(cop0, regs->cp0reg[MIPS_CP0_TLB_WIRED][0]);
364 kvm_write_c0_guest_errorepc(cop0, regs->cp0reg[MIPS_CP0_ERROR_PC][0]);
365
366 return 0;
367}
368
369static int
370kvm_trap_emul_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
371{
372 struct mips_coproc *cop0 = vcpu->arch.cop0;
373
374 regs->cp0reg[MIPS_CP0_TLB_INDEX][0] = kvm_read_c0_guest_index(cop0);
375 regs->cp0reg[MIPS_CP0_TLB_CONTEXT][0] = kvm_read_c0_guest_context(cop0);
376 regs->cp0reg[MIPS_CP0_BAD_VADDR][0] = kvm_read_c0_guest_badvaddr(cop0);
377 regs->cp0reg[MIPS_CP0_TLB_HI][0] = kvm_read_c0_guest_entryhi(cop0);
378 regs->cp0reg[MIPS_CP0_EXC_PC][0] = kvm_read_c0_guest_epc(cop0);
379
380 regs->cp0reg[MIPS_CP0_STATUS][0] = kvm_read_c0_guest_status(cop0);
381 regs->cp0reg[MIPS_CP0_CAUSE][0] = kvm_read_c0_guest_cause(cop0);
382 regs->cp0reg[MIPS_CP0_TLB_PG_MASK][0] =
383 kvm_read_c0_guest_pagemask(cop0);
384 regs->cp0reg[MIPS_CP0_TLB_WIRED][0] = kvm_read_c0_guest_wired(cop0);
385 regs->cp0reg[MIPS_CP0_ERROR_PC][0] = kvm_read_c0_guest_errorepc(cop0);
386
387 regs->cp0reg[MIPS_CP0_CONFIG][0] = kvm_read_c0_guest_config(cop0);
388 regs->cp0reg[MIPS_CP0_CONFIG][1] = kvm_read_c0_guest_config1(cop0);
389 regs->cp0reg[MIPS_CP0_CONFIG][2] = kvm_read_c0_guest_config2(cop0);
390 regs->cp0reg[MIPS_CP0_CONFIG][3] = kvm_read_c0_guest_config3(cop0);
391 regs->cp0reg[MIPS_CP0_CONFIG][7] = kvm_read_c0_guest_config7(cop0);
392
393 return 0;
394}
395
396static int kvm_trap_emul_vm_init(struct kvm *kvm) 348static int kvm_trap_emul_vm_init(struct kvm *kvm)
397{ 349{
398 return 0; 350 return 0;
@@ -471,8 +423,6 @@ static struct kvm_mips_callbacks kvm_trap_emul_callbacks = {
471 .dequeue_io_int = kvm_mips_dequeue_io_int_cb, 423 .dequeue_io_int = kvm_mips_dequeue_io_int_cb,
472 .irq_deliver = kvm_mips_irq_deliver_cb, 424 .irq_deliver = kvm_mips_irq_deliver_cb,
473 .irq_clear = kvm_mips_irq_clear_cb, 425 .irq_clear = kvm_mips_irq_clear_cb,
474 .vcpu_ioctl_get_regs = kvm_trap_emul_ioctl_get_regs,
475 .vcpu_ioctl_set_regs = kvm_trap_emul_ioctl_set_regs,
476}; 426};
477 427
478int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks) 428int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks)
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 8db0010ed150..5953dcea752d 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1240,9 +1240,12 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
1240 ctxt->modrm_seg = VCPU_SREG_DS; 1240 ctxt->modrm_seg = VCPU_SREG_DS;
1241 1241
1242 if (ctxt->modrm_mod == 3) { 1242 if (ctxt->modrm_mod == 3) {
1243 int highbyte_regs = ctxt->rex_prefix == 0;
1244
1243 op->type = OP_REG; 1245 op->type = OP_REG;
1244 op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes; 1246 op->bytes = (ctxt->d & ByteOp) ? 1 : ctxt->op_bytes;
1245 op->addr.reg = decode_register(ctxt, ctxt->modrm_rm, ctxt->d & ByteOp); 1247 op->addr.reg = decode_register(ctxt, ctxt->modrm_rm,
1248 highbyte_regs && (ctxt->d & ByteOp));
1246 if (ctxt->d & Sse) { 1249 if (ctxt->d & Sse) {
1247 op->type = OP_XMM; 1250 op->type = OP_XMM;
1248 op->bytes = 16; 1251 op->bytes = 16;
@@ -3997,7 +4000,8 @@ static const struct opcode twobyte_table[256] = {
3997 DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N, 4000 DI(ImplicitOps | Priv, invd), DI(ImplicitOps | Priv, wbinvd), N, N,
3998 N, D(ImplicitOps | ModRM), N, N, 4001 N, D(ImplicitOps | ModRM), N, N,
3999 /* 0x10 - 0x1F */ 4002 /* 0x10 - 0x1F */
4000 N, N, N, N, N, N, N, N, D(ImplicitOps | ModRM), N, N, N, N, N, N, N, 4003 N, N, N, N, N, N, N, N,
4004 D(ImplicitOps | ModRM), N, N, N, N, N, N, D(ImplicitOps | ModRM),
4001 /* 0x20 - 0x2F */ 4005 /* 0x20 - 0x2F */
4002 DIP(ModRM | DstMem | Priv | Op3264, cr_read, check_cr_read), 4006 DIP(ModRM | DstMem | Priv | Op3264, cr_read, check_cr_read),
4003 DIP(ModRM | DstMem | Priv | Op3264, dr_read, check_dr_read), 4007 DIP(ModRM | DstMem | Priv | Op3264, dr_read, check_dr_read),
@@ -4836,6 +4840,7 @@ twobyte_insn:
4836 case 0x08: /* invd */ 4840 case 0x08: /* invd */
4837 case 0x0d: /* GrpP (prefetch) */ 4841 case 0x0d: /* GrpP (prefetch) */
4838 case 0x18: /* Grp16 (prefetch/nop) */ 4842 case 0x18: /* Grp16 (prefetch/nop) */
4843 case 0x1f: /* nop */
4839 break; 4844 break;
4840 case 0x20: /* mov cr, reg */ 4845 case 0x20: /* mov cr, reg */
4841 ctxt->dst.val = ops->get_cr(ctxt, ctxt->modrm_reg); 4846 ctxt->dst.val = ops->get_cr(ctxt, ctxt->modrm_reg);
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index e1adbb4aca75..0eee2c8b64d1 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1861,11 +1861,14 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
1861{ 1861{
1862 struct kvm_lapic *apic = vcpu->arch.apic; 1862 struct kvm_lapic *apic = vcpu->arch.apic;
1863 unsigned int sipi_vector; 1863 unsigned int sipi_vector;
1864 unsigned long pe;
1864 1865
1865 if (!kvm_vcpu_has_lapic(vcpu)) 1866 if (!kvm_vcpu_has_lapic(vcpu) || !apic->pending_events)
1866 return; 1867 return;
1867 1868
1868 if (test_and_clear_bit(KVM_APIC_INIT, &apic->pending_events)) { 1869 pe = xchg(&apic->pending_events, 0);
1870
1871 if (test_bit(KVM_APIC_INIT, &pe)) {
1869 kvm_lapic_reset(vcpu); 1872 kvm_lapic_reset(vcpu);
1870 kvm_vcpu_reset(vcpu); 1873 kvm_vcpu_reset(vcpu);
1871 if (kvm_vcpu_is_bsp(apic->vcpu)) 1874 if (kvm_vcpu_is_bsp(apic->vcpu))
@@ -1873,7 +1876,7 @@ void kvm_apic_accept_events(struct kvm_vcpu *vcpu)
1873 else 1876 else
1874 vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED; 1877 vcpu->arch.mp_state = KVM_MP_STATE_INIT_RECEIVED;
1875 } 1878 }
1876 if (test_and_clear_bit(KVM_APIC_SIPI, &apic->pending_events) && 1879 if (test_bit(KVM_APIC_SIPI, &pe) &&
1877 vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) { 1880 vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
1878 /* evaluate pending_events before reading the vector */ 1881 /* evaluate pending_events before reading the vector */
1879 smp_rmb(); 1882 smp_rmb();