History

Merge tag 'kvm-4.3-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm

Pull kvm updates from Paolo Bonzini: "A very small release for x86 and s390 KVM. - s390: timekeeping changes, cleanups and fixes - x86: support for Hyper-V MSRs to report crashes, and a bunch of cleanups. One interesting feature that was planned for 4.3 (emulating the local APIC in kernel while keeping the IOAPIC and 8254 in userspace) had to be delayed because Intel complained about my reading of the manual" * tag 'kvm-4.3-1' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (42 commits) x86/kvm: Rename VMX's segment access rights defines KVM: x86/vPMU: Fix unnecessary signed extension for AMD PERFCTRn kvm: x86: Fix error handling in the function kvm_lapic_sync_from_vapic KVM: s390: Fix assumption that kvm_set_irq_routing is always run successfully KVM: VMX: drop ept misconfig check KVM: MMU: fully check zero bits for sptes KVM: MMU: introduce is_shadow_zero_bits_set() KVM: MMU: introduce the framework to check zero bits on sptes KVM: MMU: split reset_rsvds_bits_mask_ept KVM: MMU: split reset_rsvds_bits_mask KVM: MMU: introduce rsvd_bits_validate KVM: MMU: move FNAME(is_rsvd_bits_set) to mmu.c KVM: MMU: fix validation of mmio page fault KVM: MTRR: Use default type for non-MTRR-covered gfn before WARN_ON KVM: s390: host STP toleration for VMs KVM: x86: clean/fix memory barriers in irqchip_in_kernel KVM: document memory barriers for kvm->vcpus/kvm->online_vcpus KVM: x86: remove unnecessary memory barriers for shared MSRs KVM: move code related to KVM_SET_BOOT_CPU_ID to x86 KVM: s390: log capability enablement and vm attribute changes ...

Linus Torvalds committed 11 years ago

Commit 44e98ed2 parents 64291f7 4d283ec35 files · +1084 −825Browse files

Unified · Split

35 files
  1. Documentation/s390/00-INDEX +0 −2
  2. Documentation/s390/kvm.txt +0 −125
  3. Documentation/virtual/kvm/api.txt +5 −0
  4. arch/s390/include/asm/etr.h +3 −0
  5. arch/s390/include/asm/kvm_host.h +3 −1
  6. arch/s390/kernel/time.c +13 −3
  7. arch/s390/kvm/diag.c +11 −2
  8. arch/s390/kvm/guestdbg.c +35 −0
  9. arch/s390/kvm/interrupt.c +51 −47
  10. arch/s390/kvm/kvm-s390.c +95 −19
  11. arch/s390/kvm/kvm-s390.h +9 −2
  12. arch/s390/kvm/priv.c +15 −13
  13. arch/s390/kvm/sigp.c +5 −8
  14. arch/s390/kvm/trace-s390.h +19 −14
  15. arch/x86/include/asm/kvm_host.h +35 −8
  16. arch/x86/include/asm/vmx.h +24 −23
  17. arch/x86/include/uapi/asm/vmx.h +2 −0
  18. arch/x86/kvm/Makefile +3 −1
  19. arch/x86/kvm/hyperv.c +377 −0
  20. arch/x86/kvm/hyperv.h +32 −0
  21. arch/x86/kvm/i8259.c +5 −10
  22. arch/x86/kvm/irq.h +4 −4
  23. arch/x86/kvm/lapic.c +3 −2
  24. arch/x86/kvm/lapic.h +1 −1
  25. arch/x86/kvm/mmu.c +171 −114
  26. arch/x86/kvm/mmu.h +3 −1
  27. arch/x86/kvm/paging_tmpl.h +2 −11
  28. arch/x86/kvm/pmu_amd.c +0 −2
  29. arch/x86/kvm/svm.c +9 −7
  30. arch/x86/kvm/vmx.c +82 −99
  31. arch/x86/kvm/x86.c +47 −276
  32. arch/x86/kvm/x86.h +5 −0
  33. include/linux/kvm_host.h +8 −16
  34. include/uapi/linux/kvm.h +2 −0
  35. virt/kvm/kvm_main.c +5 −14
Documentation/s390/00-INDEX+0−2
@@ -16,8 +16,6 @@ Debugging390.txt · 15 unmodified lines
1616 - hints for debugging on s390 systems.
1717 driver-model.txt
1818 - information on s390 devices and the driver model.
19−kvm.txt
20− - ioctl calls to /dev/kvm on s390.
2119 monreader.txt
2220 - information on accessing the z/VM monitor stream from Linux.
2321 qeth.txt
Documentation/s390/kvm.txt+0−125
@@ -1,125 +0,0 @@
1−*** BIG FAT WARNING ***
2−The kvm module is currently in EXPERIMENTAL state for s390. This means that
3−the interface to the module is not yet considered to remain stable. Thus, be
4−prepared that we keep breaking your userspace application and guest
5−compatibility over and over again until we feel happy with the result. Make sure
6−your guest kernel, your host kernel, and your userspace launcher are in a
7−consistent state.
8−
9−This Documentation describes the unique ioctl calls to /dev/kvm, the resulting
10−kvm-vm file descriptors, and the kvm-vcpu file descriptors that differ from x86.
11−
12−1. ioctl calls to /dev/kvm
13−KVM does support the following ioctls on s390 that are common with other
14−architectures and do behave the same:
15−KVM_GET_API_VERSION
16−KVM_CREATE_VM (*) see note
17−KVM_CHECK_EXTENSION
18−KVM_GET_VCPU_MMAP_SIZE
19−
20−Notes:
21−* KVM_CREATE_VM may fail on s390, if the calling process has multiple
22−threads and has not called KVM_S390_ENABLE_SIE before.
23−
24−In addition, on s390 the following architecture specific ioctls are supported:
25−ioctl: KVM_S390_ENABLE_SIE
26−args: none
27−see also: include/linux/kvm.h
28−This call causes the kernel to switch on PGSTE in the user page table. This
29−operation is needed in order to run a virtual machine, and it requires the
30−calling process to be single-threaded. Note that the first call to KVM_CREATE_VM
31−will implicitly try to switch on PGSTE if the user process has not called
32−KVM_S390_ENABLE_SIE before. User processes that want to launch multiple threads
33−before creating a virtual machine have to call KVM_S390_ENABLE_SIE, or will
34−observe an error calling KVM_CREATE_VM. Switching on PGSTE is a one-time
35−operation, is not reversible, and will persist over the entire lifetime of
36−the calling process. It does not have any user-visible effect other than a small
37−performance penalty.
38−
39−2. ioctl calls to the kvm-vm file descriptor
40−KVM does support the following ioctls on s390 that are common with other
41−architectures and do behave the same:
42−KVM_CREATE_VCPU
43−KVM_SET_USER_MEMORY_REGION (*) see note
44−KVM_GET_DIRTY_LOG (**) see note
45−
46−Notes:
47−* kvm does only allow exactly one memory slot on s390, which has to start
48− at guest absolute address zero and at a user address that is aligned on any
49− page boundary. This hardware "limitation" allows us to have a few unique
50− optimizations. The memory slot doesn't have to be filled
51− with memory actually, it may contain sparse holes. That said, with different
52− user memory layout this does still allow a large flexibility when
53− doing the guest memory setup.
54−** KVM_GET_DIRTY_LOG doesn't work properly yet. The user will receive an empty
55−log. This ioctl call is only needed for guest migration, and we intend to
56−implement this one in the future.
57−
58−In addition, on s390 the following architecture specific ioctls for the kvm-vm
59−file descriptor are supported:
60−ioctl: KVM_S390_INTERRUPT
61−args: struct kvm_s390_interrupt *
62−see also: include/linux/kvm.h
63−This ioctl is used to submit a floating interrupt for a virtual machine.
64−Floating interrupts may be delivered to any virtual cpu in the configuration.
65−Only some interrupt types defined in include/linux/kvm.h make sense when
66−submitted as floating interrupts. The following interrupts are not considered
67−to be useful as floating interrupts, and a call to inject them will result in
68−-EINVAL error code: program interrupts and interprocessor signals. Valid
69−floating interrupts are:
70−KVM_S390_INT_VIRTIO
71−KVM_S390_INT_SERVICE
72−
73−3. ioctl calls to the kvm-vcpu file descriptor
74−KVM does support the following ioctls on s390 that are common with other
75−architectures and do behave the same:
76−KVM_RUN
77−KVM_GET_REGS
78−KVM_SET_REGS
79−KVM_GET_SREGS
80−KVM_SET_SREGS
81−KVM_GET_FPU
82−KVM_SET_FPU
83−
84−In addition, on s390 the following architecture specific ioctls for the
85−kvm-vcpu file descriptor are supported:
86−ioctl: KVM_S390_INTERRUPT
87−args: struct kvm_s390_interrupt *
88−see also: include/linux/kvm.h
89−This ioctl is used to submit an interrupt for a specific virtual cpu.
90−Only some interrupt types defined in include/linux/kvm.h make sense when
91−submitted for a specific cpu. The following interrupts are not considered
92−to be useful, and a call to inject them will result in -EINVAL error code:
93−service processor calls and virtio interrupts. Valid interrupt types are:
94−KVM_S390_PROGRAM_INT
95−KVM_S390_SIGP_STOP
96−KVM_S390_RESTART
97−KVM_S390_SIGP_SET_PREFIX
98−KVM_S390_INT_EMERGENCY
99−
100−ioctl: KVM_S390_STORE_STATUS
101−args: unsigned long
102−see also: include/linux/kvm.h
103−This ioctl stores the state of the cpu at the guest real address given as
104−argument, unless one of the following values defined in include/linux/kvm.h
105−is given as argument:
106−KVM_S390_STORE_STATUS_NOADDR - the CPU stores its status to the save area in
107−absolute lowcore as defined by the principles of operation
108−KVM_S390_STORE_STATUS_PREFIXED - the CPU stores its status to the save area in
109−its prefix page just like the dump tool that comes with zipl. This is useful
110−to create a system dump for use with lkcdutils or crash.
111−
112−ioctl: KVM_S390_SET_INITIAL_PSW
113−args: struct kvm_s390_psw *
114−see also: include/linux/kvm.h
115−This ioctl can be used to set the processor status word (psw) of a stopped cpu
116−prior to running it with KVM_RUN. Note that this call is not required to modify
117−the psw during sie intercepts that fall back to userspace because struct kvm_run
118−does contain the psw, and this value is evaluated during reentry of KVM_RUN
119−after the intercept exit was recognized.
120−
121−ioctl: KVM_S390_INITIAL_RESET
122−args: none
123−see also: include/linux/kvm.h
124−This ioctl can be used to perform an initial cpu reset as defined by the
125−principles of operation. The target cpu has to be in stopped state.
Documentation/virtual/kvm/api.txt+5−0
@@ -3277,6 +3277,7 @@ should put the acknowledged interrupt vector into the 'epr' field. · 3276 unmodified lines
32773277 struct {
32783278 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
32793279 #define KVM_SYSTEM_EVENT_RESET 2
3280+#define KVM_SYSTEM_EVENT_CRASH 3
32803281 __u32 type;
32813282 __u64 flags;
32823283 } system_event;
@@ -3296,6 +3297,10 @@ Valid values for 'type' are: · 13 unmodified lines
32963297 KVM_SYSTEM_EVENT_RESET -- the guest has requested a reset of the VM.
32973298 As with SHUTDOWN, userspace can choose to ignore the request, or
32983299 to schedule the reset to occur in the future and may call KVM_RUN again.
3300+ KVM_SYSTEM_EVENT_CRASH -- the guest crash occurred and the guest
3301+ has requested a crash condition maintenance. Userspace can choose
3302+ to ignore the request, or to gather VM memory core dump and/or
3303+ reset/shutdown of the VM.
32993304
33003305 /* Fix the size of the union. */
33013306 char padding[256];
arch/s390/include/asm/etr.h+3−0
@@ -214,6 +214,9 @@ static inline int etr_ptff(void *ptff_block, unsigned int func) · 213 unmodified lines
214214 void etr_switch_to_local(void);
215215 void etr_sync_check(void);
216216
217+/* notifier for syncs */
218+extern struct atomic_notifier_head s390_epoch_delta_notifier;
219+
217220 /* STP interruption parameter */
218221 struct stp_irq_parm {
219222 unsigned int _pad0 : 14;
arch/s390/include/asm/kvm_host.h+3−1
@@ -258,6 +258,9 @@ struct kvm_vcpu_stat { · 257 unmodified lines
258258 u32 diagnose_10;
259259 u32 diagnose_44;
260260 u32 diagnose_9c;
261+ u32 diagnose_258;
262+ u32 diagnose_308;
263+ u32 diagnose_500;
261264 };
262265
263266 #define PGM_OPERATION 0x01
@@ -630,7 +633,6 @@ extern char sie_exit; · 366 unmodified lines
630633
631634 static inline void kvm_arch_hardware_disable(void) {}
632635 static inline void kvm_arch_check_processor_compat(void *rtn) {}
633−static inline void kvm_arch_exit(void) {}
634636 static inline void kvm_arch_sync_events(struct kvm *kvm) {}
635637 static inline void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) {}
636638 static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {}
arch/s390/kernel/time.c+13−3
@@ -58,6 +58,9 @@ EXPORT_SYMBOL_GPL(sched_clock_base_cc); · 57 unmodified lines
5858
5959 static DEFINE_PER_CPU(struct clock_event_device, comparators);
6060
61+ATOMIC_NOTIFIER_HEAD(s390_epoch_delta_notifier);
62+EXPORT_SYMBOL(s390_epoch_delta_notifier);
63+
6164 /*
6265 * Scheduler clock - returns current time in nanosec units.
6366 */
@@ -752,7 +755,7 @@ static void clock_sync_cpu(struct clock_sync_data *sync) · 688 unmodified lines
752755 static int etr_sync_clock(void *data)
753756 {
754757 static int first;
755− unsigned long long clock, old_clock, delay, delta;
758+ unsigned long long clock, old_clock, clock_delta, delay, delta;
756759 struct clock_sync_data *etr_sync;
757760 struct etr_aib *sync_port, *aib;
758761 int port;
@@ -789,6 +792,9 @@ static int etr_sync_clock(void *data) · 30 unmodified lines
789792 delay = (unsigned long long)
790793 (aib->edf2.etv - sync_port->edf2.etv) << 32;
791794 delta = adjust_time(old_clock, clock, delay);
795+ clock_delta = clock - old_clock;
796+ atomic_notifier_call_chain(&s390_epoch_delta_notifier, 0,
797+ &clock_delta);
792798 etr_sync->fixup_cc = delta;
793799 fixup_clock_comparator(delta);
794800 /* Verify that the clock is properly set. */
@@ -1526,7 +1532,7 @@ void stp_island_check(void) · 731 unmodified lines
15261532 static int stp_sync_clock(void *data)
15271533 {
15281534 static int first;
1529− unsigned long long old_clock, delta;
1535+ unsigned long long old_clock, delta, new_clock, clock_delta;
15301536 struct clock_sync_data *stp_sync;
15311537 int rc;
15321538
@@ -1551,7 +1557,11 @@ static int stp_sync_clock(void *data) · 18 unmodified lines
15511557 old_clock = get_tod_clock();
15521558 rc = chsc_sstpc(stp_page, STP_OP_SYNC, 0);
15531559 if (rc == 0) {
1554− delta = adjust_time(old_clock, get_tod_clock(), 0);
1560+ new_clock = get_tod_clock();
1561+ delta = adjust_time(old_clock, new_clock, 0);
1562+ clock_delta = new_clock - old_clock;
1563+ atomic_notifier_call_chain(&s390_epoch_delta_notifier,
1564+ 0, &clock_delta);
15551565 fixup_clock_comparator(delta);
15561566 rc = chsc_sstpi(stp_page, &stp_info,
15571567 sizeof(struct stp_sstpi));
arch/s390/kvm/diag.c+11−2
@@ -27,13 +27,13 @@ static int diag_release_pages(struct kvm_vcpu *vcpu) · 26 unmodified lines
2727
2828 start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
2929 end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
30+ vcpu->stat.diagnose_10++;
3031
3132 if (start & ~PAGE_MASK || end & ~PAGE_MASK || start >= end
3233 || start < 2 * PAGE_SIZE)
3334 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
3435
3536 VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
36− vcpu->stat.diagnose_10++;
3737
3838 /*
3939 * We checked for start >= end above, so lets check for the
@@ -75,6 +75,9 @@ static int __diag_page_ref_service(struct kvm_vcpu *vcpu) · 35 unmodified lines
7575 u16 rx = (vcpu->arch.sie_block->ipa & 0xf0) >> 4;
7676 u16 ry = (vcpu->arch.sie_block->ipa & 0x0f);
7777
78+ VCPU_EVENT(vcpu, 3, "diag page reference parameter block at 0x%llx",
79+ vcpu->run->s.regs.gprs[rx]);
80+ vcpu->stat.diagnose_258++;
7881 if (vcpu->run->s.regs.gprs[rx] & 7)
7982 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
8083 rc = read_guest(vcpu, vcpu->run->s.regs.gprs[rx], rx, &parm, sizeof(parm));
@@ -85,6 +88,9 @@ static int __diag_page_ref_service(struct kvm_vcpu *vcpu) · 4 unmodified lines
8588
8689 switch (parm.subcode) {
8790 case 0: /* TOKEN */
91+ VCPU_EVENT(vcpu, 3, "pageref token addr 0x%llx "
92+ "select mask 0x%llx compare mask 0x%llx",
93+ parm.token_addr, parm.select_mask, parm.compare_mask);
8894 if (vcpu->arch.pfault_token != KVM_S390_PFAULT_TOKEN_INVALID) {
8995 /*
9096 * If the pagefault handshake is already activated,
@@ -114,6 +120,7 @@ static int __diag_page_ref_service(struct kvm_vcpu *vcpu) · 23 unmodified lines
114120 * the cancel, therefore to reduce code complexity, we assume
115121 * all outstanding tokens are already pending.
116122 */
123+ VCPU_EVENT(vcpu, 3, "pageref cancel addr 0x%llx", parm.token_addr);
117124 if (parm.token_addr || parm.select_mask ||
118125 parm.compare_mask || parm.zarch)
119126 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
@@ -174,7 +181,8 @@ static int __diag_ipl_functions(struct kvm_vcpu *vcpu) · 54 unmodified lines
174181 unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
175182 unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff;
176183
177− VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
184+ VCPU_EVENT(vcpu, 3, "diag ipl functions, subcode %lx", subcode);
185+ vcpu->stat.diagnose_308++;
178186 switch (subcode) {
179187 case 3:
180188 vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
@@ -202,6 +210,7 @@ static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu) · 21 unmodified lines
202210 {
203211 int ret;
204212
213+ vcpu->stat.diagnose_500++;
205214 /* No virtio-ccw notification? Get out quickly. */
206215 if (!vcpu->kvm->arch.css_support ||
207216 (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY))
arch/s390/kvm/guestdbg.c+35−0
@@ -473,10 +473,45 @@ static void filter_guest_per_event(struct kvm_vcpu *vcpu) · 472 unmodified lines
473473 vcpu->arch.sie_block->iprcc &= ~PGM_PER;
474474 }
475475
476+#define pssec(vcpu) (vcpu->arch.sie_block->gcr[1] & _ASCE_SPACE_SWITCH)
477+#define hssec(vcpu) (vcpu->arch.sie_block->gcr[13] & _ASCE_SPACE_SWITCH)
478+#define old_ssec(vcpu) ((vcpu->arch.sie_block->tecmc >> 31) & 0x1)
479+#define old_as_is_home(vcpu) !(vcpu->arch.sie_block->tecmc & 0xffff)
480+
476481 void kvm_s390_handle_per_event(struct kvm_vcpu *vcpu)
477482 {
483+ int new_as;
484+
478485 if (debug_exit_required(vcpu))
479486 vcpu->guest_debug |= KVM_GUESTDBG_EXIT_PENDING;
480487
481488 filter_guest_per_event(vcpu);
489+
490+ /*
491+ * Only RP, SAC, SACF, PT, PTI, PR, PC instructions can trigger
492+ * a space-switch event. PER events enforce space-switch events
493+ * for these instructions. So if no PER event for the guest is left,
494+ * we might have to filter the space-switch element out, too.
495+ */
496+ if (vcpu->arch.sie_block->iprcc == PGM_SPACE_SWITCH) {
497+ vcpu->arch.sie_block->iprcc = 0;
498+ new_as = psw_bits(vcpu->arch.sie_block->gpsw).as;
499+
500+ /*
501+ * If the AS changed from / to home, we had RP, SAC or SACF
502+ * instruction. Check primary and home space-switch-event
503+ * controls. (theoretically home -> home produced no event)
504+ */
505+ if (((new_as == PSW_AS_HOME) ^ old_as_is_home(vcpu)) &&
506+ (pssec(vcpu) || hssec(vcpu)))
507+ vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH;
508+
509+ /*
510+ * PT, PTI, PR, PC instruction operate on primary AS only. Check
511+ * if the primary-space-switch-event control was or got set.
512+ */
513+ if (new_as == PSW_AS_PRIMARY && !old_as_is_home(vcpu) &&
514+ (pssec(vcpu) || old_ssec(vcpu)))
515+ vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH;
516+ }
482517 }
arch/s390/kvm/interrupt.c+51−47
@@ -30,7 +30,6 @@ · 29 unmodified lines
3030 #define IOINT_SCHID_MASK 0x0000ffff
3131 #define IOINT_SSID_MASK 0x00030000
3232 #define IOINT_CSSID_MASK 0x03fc0000
33−#define IOINT_AI_MASK 0x04000000
3433 #define PFAULT_INIT 0x0600
3534 #define PFAULT_DONE 0x0680
3635 #define VIRTIO_PARAM 0x0d00
@@ -72,9 +71,13 @@ static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) · 35 unmodified lines
7271
7372 static int ckc_irq_pending(struct kvm_vcpu *vcpu)
7473 {
74+ preempt_disable();
7575 if (!(vcpu->arch.sie_block->ckc <
76− get_tod_clock_fast() + vcpu->arch.sie_block->epoch))
76+ get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) {
77+ preempt_enable();
7778 return 0;
79+ }
80+ preempt_enable();
7881 return ckc_interrupts_enabled(vcpu);
7982 }
8083
@@ -311,8 +314,8 @@ static int __must_check __deliver_pfault_init(struct kvm_vcpu *vcpu) · 230 unmodified lines
311314 li->irq.ext.ext_params2 = 0;
312315 spin_unlock(&li->lock);
313316
314− VCPU_EVENT(vcpu, 4, "interrupt: pfault init parm:%x,parm64:%llx",
315− 0, ext.ext_params2);
317+ VCPU_EVENT(vcpu, 4, "deliver: pfault init token 0x%llx",
318+ ext.ext_params2);
316319 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
317320 KVM_S390_INT_PFAULT_INIT,
318321 0, ext.ext_params2);
@@ -368,7 +371,7 @@ static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu) · 49 unmodified lines
368371 spin_unlock(&fi->lock);
369372
370373 if (deliver) {
371− VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx",
374+ VCPU_EVENT(vcpu, 3, "deliver: machine check mcic 0x%llx",
372375 mchk.mcic);
373376 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
374377 KVM_S390_MCHK,
@@ -403,7 +406,7 @@ static int __must_check __deliver_restart(struct kvm_vcpu *vcpu) · 28 unmodified lines
403406 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
404407 int rc;
405408
406− VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart");
409+ VCPU_EVENT(vcpu, 3, "%s", "deliver: cpu restart");
407410 vcpu->stat.deliver_restart_signal++;
408411 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0);
409412
@@ -427,7 +430,6 @@ static int __must_check __deliver_set_prefix(struct kvm_vcpu *vcpu) · 17 unmodified lines
427430 clear_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs);
428431 spin_unlock(&li->lock);
429432
430− VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x", prefix.address);
431433 vcpu->stat.deliver_prefix_signal++;
432434 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
433435 KVM_S390_SIGP_SET_PREFIX,
@@ -450,7 +452,7 @@ static int __must_check __deliver_emergency_signal(struct kvm_vcpu *vcpu) · 16 unmodified lines
450452 clear_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs);
451453 spin_unlock(&li->lock);
452454
453− VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp emerg");
455+ VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp emerg");
454456 vcpu->stat.deliver_emergency_signal++;
455457 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY,
456458 cpu_addr, 0);
@@ -477,7 +479,7 @@ static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu) · 20 unmodified lines
477479 clear_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs);
478480 spin_unlock(&li->lock);
479481
480− VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call");
482+ VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp ext call");
481483 vcpu->stat.deliver_external_call++;
482484 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
483485 KVM_S390_INT_EXTERNAL_CALL,
@@ -506,7 +508,7 @@ static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) · 22 unmodified lines
506508 memset(&li->irq.pgm, 0, sizeof(pgm_info));
507509 spin_unlock(&li->lock);
508510
509− VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x",
511+ VCPU_EVENT(vcpu, 3, "deliver: program irq code 0x%x, ilc:%d",
510512 pgm_info.code, ilc);
511513 vcpu->stat.deliver_program_int++;
512514 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
@@ -622,7 +624,7 @@ static int __must_check __deliver_service(struct kvm_vcpu *vcpu) · 109 unmodified lines
622624 clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs);
623625 spin_unlock(&fi->lock);
624626
625− VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
627+ VCPU_EVENT(vcpu, 4, "deliver: sclp parameter 0x%x",
626628 ext.ext_params);
627629 vcpu->stat.deliver_service_signal++;
628630 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE,
@@ -651,9 +653,6 @@ static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) · 22 unmodified lines
651653 struct kvm_s390_interrupt_info,
652654 list);
653655 if (inti) {
654− trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
655− KVM_S390_INT_PFAULT_DONE, 0,
656− inti->ext.ext_params2);
657656 list_del(&inti->list);
658657 fi->counters[FIRQ_CNTR_PFAULT] -= 1;
659658 }
@@ -662,6 +661,12 @@ static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) · 2 unmodified lines
662661 spin_unlock(&fi->lock);
663662
664663 if (inti) {
664+ trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
665+ KVM_S390_INT_PFAULT_DONE, 0,
666+ inti->ext.ext_params2);
667+ VCPU_EVENT(vcpu, 4, "deliver: pfault done token 0x%llx",
668+ inti->ext.ext_params2);
669+
665670 rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE,
666671 (u16 *)__LC_EXT_INT_CODE);
667672 rc |= put_guest_lc(vcpu, PFAULT_DONE,
@@ -691,7 +696,7 @@ static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu) · 23 unmodified lines
691696 list);
692697 if (inti) {
693698 VCPU_EVENT(vcpu, 4,
694− "interrupt: virtio parm:%x,parm64:%llx",
699+ "deliver: virtio parm: 0x%x,parm64: 0x%llx",
695700 inti->ext.ext_params, inti->ext.ext_params2);
696701 vcpu->stat.deliver_virtio_interrupt++;
697702 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
@@ -741,7 +746,7 @@ static int __must_check __deliver_io(struct kvm_vcpu *vcpu, · 43 unmodified lines
741746 struct kvm_s390_interrupt_info,
742747 list);
743748 if (inti) {
744− VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type);
749+ VCPU_EVENT(vcpu, 4, "deliver: I/O 0x%llx", inti->type);
745750 vcpu->stat.deliver_io_int++;
746751 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id,
747752 inti->type,
@@ -855,7 +860,9 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) · 107 unmodified lines
855860 goto no_timer;
856861 }
857862
863+ preempt_disable();
858864 now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch;
865+ preempt_enable();
859866 sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
860867
861868 /* underflow */
@@ -864,7 +871,7 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) · 2 unmodified lines
864871
865872 __set_cpu_idle(vcpu);
866873 hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL);
867− VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime);
874+ VCPU_EVENT(vcpu, 4, "enabled wait via clock comparator: %llu ns", sltime);
868875 no_timer:
869876 srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
870877 kvm_vcpu_block(vcpu);
@@ -894,7 +901,9 @@ enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) · 23 unmodified lines
894901 u64 now, sltime;
895902
896903 vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
904+ preempt_disable();
897905 now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch;
906+ preempt_enable();
898907 sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
899908
900909 /*
@@ -968,6 +977,10 @@ static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 67 unmodified lines
968977 {
969978 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
970979
980+ VCPU_EVENT(vcpu, 3, "inject: program irq code 0x%x", irq->u.pgm.code);
981+ trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
982+ irq->u.pgm.code, 0);
983+
971984 li->irq.pgm = irq->u.pgm;
972985 set_bit(IRQ_PEND_PROG, &li->pending_irqs);
973986 return 0;
@@ -978,9 +991,6 @@ int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) · 4 unmodified lines
978991 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
979992 struct kvm_s390_irq irq;
980993
981− VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code);
982− trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, code,
983− 0, 1);
984994 spin_lock(&li->lock);
985995 irq.u.pgm.code = code;
986996 __inject_prog(vcpu, &irq);
@@ -996,10 +1006,6 @@ int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, · 9 unmodified lines
9961006 struct kvm_s390_irq irq;
9971007 int rc;
9981008
999− VCPU_EVENT(vcpu, 3, "inject: prog irq %d (from kernel)",
1000− pgm_info->code);
1001− trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT,
1002− pgm_info->code, 0, 1);
10031009 spin_lock(&li->lock);
10041010 irq.u.pgm = *pgm_info;
10051011 rc = __inject_prog(vcpu, &irq);
@@ -1012,11 +1018,11 @@ static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 6 unmodified lines
10121018 {
10131019 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
10141020
1015− VCPU_EVENT(vcpu, 3, "inject: external irq params:%x, params2:%llx",
1016− irq->u.ext.ext_params, irq->u.ext.ext_params2);
1021+ VCPU_EVENT(vcpu, 4, "inject: pfault init parameter block at 0x%llx",
1022+ irq->u.ext.ext_params2);
10171023 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_PFAULT_INIT,
10181024 irq->u.ext.ext_params,
1019− irq->u.ext.ext_params2, 2);
1025+ irq->u.ext.ext_params2);
10201026
10211027 li->irq.ext = irq->u.ext;
10221028 set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs);
@@ -1045,10 +1051,10 @@ static int __inject_extcall(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 22 unmodified lines
10451051 struct kvm_s390_extcall_info *extcall = &li->irq.extcall;
10461052 uint16_t src_id = irq->u.extcall.code;
10471053
1048− VCPU_EVENT(vcpu, 3, "inject: external call source-cpu:%u",
1054+ VCPU_EVENT(vcpu, 4, "inject: external call source-cpu:%u",
10491055 src_id);
10501056 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EXTERNAL_CALL,
1051− src_id, 0, 2);
1057+ src_id, 0);
10521058
10531059 /* sending vcpu invalid */
10541060 if (src_id >= KVM_MAX_VCPUS ||
@@ -1070,10 +1076,10 @@ static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 15 unmodified lines
10701076 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
10711077 struct kvm_s390_prefix_info *prefix = &li->irq.prefix;
10721078
1073− VCPU_EVENT(vcpu, 3, "inject: set prefix to %x (from user)",
1079+ VCPU_EVENT(vcpu, 3, "inject: set prefix to %x",
10741080 irq->u.prefix.address);
10751081 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_SET_PREFIX,
1076− irq->u.prefix.address, 0, 2);
1082+ irq->u.prefix.address, 0);
10771083
10781084 if (!is_vcpu_stopped(vcpu))
10791085 return -EBUSY;
@@ -1090,7 +1096,7 @@ static int __inject_sigp_stop(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 10 unmodified lines
10901096 struct kvm_s390_stop_info *stop = &li->irq.stop;
10911097 int rc = 0;
10921098
1093− trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0, 2);
1099+ trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0);
10941100
10951101 if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS)
10961102 return -EINVAL;
@@ -1114,8 +1120,8 @@ static int __inject_sigp_restart(struct kvm_vcpu *vcpu, · 17 unmodified lines
11141120 {
11151121 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
11161122
1117− VCPU_EVENT(vcpu, 3, "inject: restart type %llx", irq->type);
1118− trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0, 2);
1123+ VCPU_EVENT(vcpu, 3, "%s", "inject: restart int");
1124+ trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0);
11191125
11201126 set_bit(IRQ_PEND_RESTART, &li->pending_irqs);
11211127 return 0;
@@ -1126,10 +1132,10 @@ static int __inject_sigp_emergency(struct kvm_vcpu *vcpu, · 4 unmodified lines
11261132 {
11271133 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
11281134
1129− VCPU_EVENT(vcpu, 3, "inject: emergency %u\n",
1135+ VCPU_EVENT(vcpu, 4, "inject: emergency from cpu %u",
11301136 irq->u.emerg.code);
11311137 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY,
1132− irq->u.emerg.code, 0, 2);
1138+ irq->u.emerg.code, 0);
11331139
11341140 set_bit(irq->u.emerg.code, li->sigp_emerg_pending);
11351141 set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs);
@@ -1142,10 +1148,10 @@ static int __inject_mchk(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 6 unmodified lines
11421148 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
11431149 struct kvm_s390_mchk_info *mchk = &li->irq.mchk;
11441150
1145− VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx",
1151+ VCPU_EVENT(vcpu, 3, "inject: machine check mcic 0x%llx",
11461152 irq->u.mchk.mcic);
11471153 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0,
1148− irq->u.mchk.mcic, 2);
1154+ irq->u.mchk.mcic);
11491155
11501156 /*
11511157 * Because repressible machine checks can be indicated along with
@@ -1172,9 +1178,9 @@ static int __inject_ckc(struct kvm_vcpu *vcpu) · 20 unmodified lines
11721178 {
11731179 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
11741180
1175− VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CLOCK_COMP);
1181+ VCPU_EVENT(vcpu, 3, "%s", "inject: clock comparator external");
11761182 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP,
1177− 0, 0, 2);
1183+ 0, 0);
11781184
11791185 set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs);
11801186 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
@@ -1185,9 +1191,9 @@ static int __inject_cpu_timer(struct kvm_vcpu *vcpu) · 4 unmodified lines
11851191 {
11861192 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
11871193
1188− VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CPU_TIMER);
1194+ VCPU_EVENT(vcpu, 3, "%s", "inject: cpu timer external");
11891195 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER,
1190− 0, 0, 2);
1196+ 0, 0);
11911197
11921198 set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs);
11931199 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
@@ -1435,20 +1441,20 @@ int kvm_s390_inject_vm(struct kvm *kvm, · 241 unmodified lines
14351441 inti->ext.ext_params2 = s390int->parm64;
14361442 break;
14371443 case KVM_S390_INT_SERVICE:
1438− VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm);
1444+ VM_EVENT(kvm, 4, "inject: sclp parm:%x", s390int->parm);
14391445 inti->ext.ext_params = s390int->parm;
14401446 break;
14411447 case KVM_S390_INT_PFAULT_DONE:
14421448 inti->ext.ext_params2 = s390int->parm64;
14431449 break;
14441450 case KVM_S390_MCHK:
1445− VM_EVENT(kvm, 5, "inject: machine check parm64:%llx",
1451+ VM_EVENT(kvm, 3, "inject: machine check mcic 0x%llx",
14461452 s390int->parm64);
14471453 inti->mchk.cr14 = s390int->parm; /* upper bits are not used */
14481454 inti->mchk.mcic = s390int->parm64;
14491455 break;
14501456 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
1451− if (inti->type & IOINT_AI_MASK)
1457+ if (inti->type & KVM_S390_INT_IO_AI_MASK)
14521458 VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)");
14531459 else
14541460 VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x",
@@ -1535,8 +1541,6 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) · 80 unmodified lines
15351541
15361542 switch (irq->type) {
15371543 case KVM_S390_PROGRAM_INT:
1538− VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)",
1539− irq->u.pgm.code);
15401544 rc = __inject_prog(vcpu, irq);
15411545 break;
15421546 case KVM_S390_SIGP_SET_PREFIX:
arch/s390/kvm/kvm-s390.c+95−19
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 #include <linux/vmalloc.h>
2929 #include <asm/asm-offsets.h>
3030 #include <asm/lowcore.h>
31+#include <asm/etr.h>
3132 #include <asm/pgtable.h>
3233 #include <asm/nmi.h>
3334 #include <asm/switch_to.h>
@@ -108,6 +109,9 @@ struct kvm_stats_debugfs_item debugfs_entries[] = { · 74 unmodified lines
108109 { "diagnose_10", VCPU_STAT(diagnose_10) },
109110 { "diagnose_44", VCPU_STAT(diagnose_44) },
110111 { "diagnose_9c", VCPU_STAT(diagnose_9c) },
112+ { "diagnose_258", VCPU_STAT(diagnose_258) },
113+ { "diagnose_308", VCPU_STAT(diagnose_308) },
114+ { "diagnose_500", VCPU_STAT(diagnose_500) },
111115 { NULL }
112116 };
113117
@@ -124,6 +128,7 @@ unsigned long kvm_s390_fac_list_mask_size(void) · 10 unmodified lines
124128 }
125129
126130 static struct gmap_notifier gmap_notifier;
131+debug_info_t *kvm_s390_dbf;
127132
128133 /* Section: not file related */
129134 int kvm_arch_hardware_enable(void)
@@ -134,24 +139,69 @@ int kvm_arch_hardware_enable(void) · 4 unmodified lines
134139
135140 static void kvm_gmap_notifier(struct gmap *gmap, unsigned long address);
136141
142+/*
143+ * This callback is executed during stop_machine(). All CPUs are therefore
144+ * temporarily stopped. In order not to change guest behavior, we have to
145+ * disable preemption whenever we touch the epoch of kvm and the VCPUs,
146+ * so a CPU won't be stopped while calculating with the epoch.
147+ */
148+static int kvm_clock_sync(struct notifier_block *notifier, unsigned long val,
149+ void *v)
150+{
151+ struct kvm *kvm;
152+ struct kvm_vcpu *vcpu;
153+ int i;
154+ unsigned long long *delta = v;
155+
156+ list_for_each_entry(kvm, &vm_list, vm_list) {
157+ kvm->arch.epoch -= *delta;
158+ kvm_for_each_vcpu(i, vcpu, kvm) {
159+ vcpu->arch.sie_block->epoch -= *delta;
160+ }
161+ }
162+ return NOTIFY_OK;
163+}
164+
165+static struct notifier_block kvm_clock_notifier = {
166+ .notifier_call = kvm_clock_sync,
167+};
168+
137169 int kvm_arch_hardware_setup(void)
138170 {
139171 gmap_notifier.notifier_call = kvm_gmap_notifier;
140172 gmap_register_ipte_notifier(&gmap_notifier);
173+ atomic_notifier_chain_register(&s390_epoch_delta_notifier,
174+ &kvm_clock_notifier);
141175 return 0;
142176 }
143177
144178 void kvm_arch_hardware_unsetup(void)
145179 {
146180 gmap_unregister_ipte_notifier(&gmap_notifier);
181+ atomic_notifier_chain_unregister(&s390_epoch_delta_notifier,
182+ &kvm_clock_notifier);
147183 }
148184
149185 int kvm_arch_init(void *opaque)
150186 {
187+ kvm_s390_dbf = debug_register("kvm-trace", 32, 1, 7 * sizeof(long));
188+ if (!kvm_s390_dbf)
189+ return -ENOMEM;
190+
191+ if (debug_register_view(kvm_s390_dbf, &debug_sprintf_view)) {
192+ debug_unregister(kvm_s390_dbf);
193+ return -ENOMEM;
194+ }
195+
151196 /* Register floating interrupt controller interface. */
152197 return kvm_register_device_ops(&kvm_flic_ops, KVM_DEV_TYPE_FLIC);
153198 }
154199
200+void kvm_arch_exit(void)
201+{
202+ debug_unregister(kvm_s390_dbf);
203+}
204+
155205 /* Section: device related */
156206 long kvm_arch_dev_ioctl(struct file *filp,
157207 unsigned int ioctl, unsigned long arg)
@@ -281,10 +331,12 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) · 123 unmodified lines
281331
282332 switch (cap->cap) {
283333 case KVM_CAP_S390_IRQCHIP:
334+ VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_IRQCHIP");
284335 kvm->arch.use_irqchip = 1;
285336 r = 0;
286337 break;
287338 case KVM_CAP_S390_USER_SIGP:
339+ VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_SIGP");
288340 kvm->arch.user_sigp = 1;
289341 r = 0;
290342 break;
@@ -295,8 +347,11 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) · 4 unmodified lines
295347 r = 0;
296348 } else
297349 r = -EINVAL;
350+ VM_EVENT(kvm, 3, "ENABLE: CAP_S390_VECTOR_REGISTERS %s",
351+ r ? "(not available)" : "(success)");
298352 break;
299353 case KVM_CAP_S390_USER_STSI:
354+ VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_STSI");
300355 kvm->arch.user_stsi = 1;
301356 r = 0;
302357 break;
@@ -314,6 +369,8 @@ static int kvm_s390_get_mem_control(struct kvm *kvm, struct kvm_device_attr *att · 11 unmodified lines
314369 switch (attr->attr) {
315370 case KVM_S390_VM_MEM_LIMIT_SIZE:
316371 ret = 0;
372+ VM_EVENT(kvm, 3, "QUERY: max guest memory: %lu bytes",
373+ kvm->arch.gmap->asce_end);
317374 if (put_user(kvm->arch.gmap->asce_end, (u64 __user *)attr->addr))
318375 ret = -EFAULT;
319376 break;
@@ -330,7 +387,13 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att · 10 unmodified lines
330387 unsigned int idx;
331388 switch (attr->attr) {
332389 case KVM_S390_VM_MEM_ENABLE_CMMA:
390+ /* enable CMMA only for z10 and later (EDAT_1) */
391+ ret = -EINVAL;
392+ if (!MACHINE_IS_LPAR || !MACHINE_HAS_EDAT1)
393+ break;
394+
333395 ret = -EBUSY;
396+ VM_EVENT(kvm, 3, "%s", "ENABLE: CMMA support");
334397 mutex_lock(&kvm->lock);
335398 if (atomic_read(&kvm->online_vcpus) == 0) {
336399 kvm->arch.use_cmma = 1;
@@ -339,6 +402,11 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att · 2 unmodified lines
339402 mutex_unlock(&kvm->lock);
340403 break;
341404 case KVM_S390_VM_MEM_CLR_CMMA:
405+ ret = -EINVAL;
406+ if (!kvm->arch.use_cmma)
407+ break;
408+
409+ VM_EVENT(kvm, 3, "%s", "RESET: CMMA states");
342410 mutex_lock(&kvm->lock);
343411 idx = srcu_read_lock(&kvm->srcu);
344412 s390_reset_cmma(kvm->arch.gmap->mm);
@@ -374,6 +442,7 @@ static int kvm_s390_set_mem_control(struct kvm *kvm, struct kvm_device_attr *att · 29 unmodified lines
374442 }
375443 }
376444 mutex_unlock(&kvm->lock);
445+ VM_EVENT(kvm, 3, "SET: max guest memory: %lu bytes", new_limit);
377446 break;
378447 }
379448 default:
@@ -400,22 +469,26 @@ static int kvm_s390_vm_set_crypto(struct kvm *kvm, struct kvm_device_attr *attr) · 20 unmodified lines
400469 kvm->arch.crypto.crycb->aes_wrapping_key_mask,
401470 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
402471 kvm->arch.crypto.aes_kw = 1;
472+ VM_EVENT(kvm, 3, "%s", "ENABLE: AES keywrapping support");
403473 break;
404474 case KVM_S390_VM_CRYPTO_ENABLE_DEA_KW:
405475 get_random_bytes(
406476 kvm->arch.crypto.crycb->dea_wrapping_key_mask,
407477 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
408478 kvm->arch.crypto.dea_kw = 1;
479+ VM_EVENT(kvm, 3, "%s", "ENABLE: DEA keywrapping support");
409480 break;
410481 case KVM_S390_VM_CRYPTO_DISABLE_AES_KW:
411482 kvm->arch.crypto.aes_kw = 0;
412483 memset(kvm->arch.crypto.crycb->aes_wrapping_key_mask, 0,
413484 sizeof(kvm->arch.crypto.crycb->aes_wrapping_key_mask));
485+ VM_EVENT(kvm, 3, "%s", "DISABLE: AES keywrapping support");
414486 break;
415487 case KVM_S390_VM_CRYPTO_DISABLE_DEA_KW:
416488 kvm->arch.crypto.dea_kw = 0;
417489 memset(kvm->arch.crypto.crycb->dea_wrapping_key_mask, 0,
418490 sizeof(kvm->arch.crypto.crycb->dea_wrapping_key_mask));
491+ VM_EVENT(kvm, 3, "%s", "DISABLE: DEA keywrapping support");
419492 break;
420493 default:
421494 mutex_unlock(&kvm->lock);
@@ -440,6 +513,7 @@ static int kvm_s390_set_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) · 18 unmodified lines
440513
441514 if (gtod_high != 0)
442515 return -EINVAL;
516+ VM_EVENT(kvm, 3, "SET: TOD extension: 0x%x\n", gtod_high);
443517
444518 return 0;
445519 }
@@ -459,12 +533,15 @@ static int kvm_s390_set_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) · 13 unmodified lines
459533 return r;
460534
461535 mutex_lock(&kvm->lock);
536+ preempt_disable();
462537 kvm->arch.epoch = gtod - host_tod;
463538 kvm_s390_vcpu_block_all(kvm);
464539 kvm_for_each_vcpu(vcpu_idx, cur_vcpu, kvm)
465540 cur_vcpu->arch.sie_block->epoch = kvm->arch.epoch;
466541 kvm_s390_vcpu_unblock_all(kvm);
542+ preempt_enable();
467543 mutex_unlock(&kvm->lock);
544+ VM_EVENT(kvm, 3, "SET: TOD base: 0x%llx\n", gtod);
468545 return 0;
469546 }
470547
@@ -496,6 +573,7 @@ static int kvm_s390_get_tod_high(struct kvm *kvm, struct kvm_device_attr *attr) · 25 unmodified lines
496573 if (copy_to_user((void __user *)attr->addr, &gtod_high,
497574 sizeof(gtod_high)))
498575 return -EFAULT;
576+ VM_EVENT(kvm, 3, "QUERY: TOD extension: 0x%x\n", gtod_high);
499577
500578 return 0;
501579 }
@@ -509,9 +587,12 @@ static int kvm_s390_get_tod_low(struct kvm *kvm, struct kvm_device_attr *attr) · 7 unmodified lines
509587 if (r)
510588 return r;
511589
590+ preempt_disable();
512591 gtod = host_tod + kvm->arch.epoch;
592+ preempt_enable();
513593 if (copy_to_user((void __user *)attr->addr, &gtod, sizeof(gtod)))
514594 return -EFAULT;
595+ VM_EVENT(kvm, 3, "QUERY: TOD base: 0x%llx\n", gtod);
515596
516597 return 0;
517598 }
@@ -821,7 +902,9 @@ static long kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args) · 303 unmodified lines
821902 }
822903
823904 /* Enable storage key handling for the guest */
824− s390_enable_skey();
905+ r = s390_enable_skey();
906+ if (r)
907+ goto out;
825908
826909 for (i = 0; i < args->count; i++) {
827910 hva = gfn_to_hva(kvm, args->start_gfn + i);
@@ -879,8 +962,7 @@ long kvm_arch_vm_ioctl(struct file *filp, · 51 unmodified lines
879962 if (kvm->arch.use_irqchip) {
880963 /* Set up dummy routing. */
881964 memset(&routing, 0, sizeof(routing));
882− kvm_set_irq_routing(kvm, &routing, 0, 0);
883− r = 0;
965+ r = kvm_set_irq_routing(kvm, &routing, 0, 0);
884966 }
885967 break;
886968 }
@@ -1043,7 +1125,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · 156 unmodified lines
10431125
10441126 sprintf(debug_name, "kvm-%u", current->pid);
10451127
1046− kvm->arch.dbf = debug_register(debug_name, 8, 2, 8 * sizeof(long));
1128+ kvm->arch.dbf = debug_register(debug_name, 32, 1, 7 * sizeof(long));
10471129 if (!kvm->arch.dbf)
10481130 goto out_err;
10491131
@@ -1086,7 +1168,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · 36 unmodified lines
10861168 mutex_init(&kvm->arch.ipte_mutex);
10871169
10881170 debug_register_view(kvm->arch.dbf, &debug_sprintf_view);
1089− VM_EVENT(kvm, 3, "%s", "vm created");
1171+ VM_EVENT(kvm, 3, "vm created with type %lu", type);
10901172
10911173 if (type & KVM_VM_S390_UCONTROL) {
10921174 kvm->arch.gmap = NULL;
@@ -1103,6 +1185,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · 10 unmodified lines
11031185 kvm->arch.epoch = 0;
11041186
11051187 spin_lock_init(&kvm->arch.start_stop_lock);
1188+ KVM_EVENT(3, "vm 0x%p created by pid %u", kvm, current->pid);
11061189
11071190 return 0;
11081191 out_err:
@@ -1110,6 +1193,7 @@ out_err: · 1 unmodified line
11101193 free_page((unsigned long)kvm->arch.model.fac);
11111194 debug_unregister(kvm->arch.dbf);
11121195 free_page((unsigned long)(kvm->arch.sca));
1196+ KVM_EVENT(3, "creation of vm failed: %d", rc);
11131197 return rc;
11141198 }
11151199
@@ -1131,7 +1215,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) · 15 unmodified lines
11311215 if (kvm_is_ucontrol(vcpu->kvm))
11321216 gmap_free(vcpu->arch.gmap);
11331217
1134− if (kvm_s390_cmma_enabled(vcpu->kvm))
1218+ if (vcpu->kvm->arch.use_cmma)
11351219 kvm_s390_vcpu_unsetup_cmma(vcpu);
11361220 free_page((unsigned long)(vcpu->arch.sie_block));
11371221
@@ -1166,6 +1250,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm) · 28 unmodified lines
11661250 gmap_free(kvm->arch.gmap);
11671251 kvm_s390_destroy_adapters(kvm);
11681252 kvm_s390_clear_float_irqs(kvm);
1253+ KVM_EVENT(3, "vm 0x%p destroyed", kvm);
11691254 }
11701255
11711256 /* Section: vcpu related */
@@ -1264,7 +1349,9 @@ static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu) · 92 unmodified lines
12641349 void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
12651350 {
12661351 mutex_lock(&vcpu->kvm->lock);
1352+ preempt_disable();
12671353 vcpu->arch.sie_block->epoch = vcpu->kvm->arch.epoch;
1354+ preempt_enable();
12681355 mutex_unlock(&vcpu->kvm->lock);
12691356 if (!kvm_is_ucontrol(vcpu->kvm))
12701357 vcpu->arch.gmap = vcpu->kvm->arch.gmap;
@@ -1342,7 +1429,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) · 71 unmodified lines
13421429 }
13431430 vcpu->arch.sie_block->ictl |= ICTL_ISKE | ICTL_SSKE | ICTL_RRBE;
13441431
1345− if (kvm_s390_cmma_enabled(vcpu->kvm)) {
1432+ if (vcpu->kvm->arch.use_cmma) {
13461433 rc = kvm_s390_vcpu_setup_cmma(vcpu);
13471434 if (rc)
13481435 return rc;
@@ -1723,18 +1810,6 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, · 374 unmodified lines
17231810 return rc;
17241811 }
17251812
1726−bool kvm_s390_cmma_enabled(struct kvm *kvm)
1727−{
1728− if (!MACHINE_IS_LPAR)
1729− return false;
1730− /* only enable for z10 and later */
1731− if (!MACHINE_HAS_EDAT1)
1732− return false;
1733− if (!kvm->arch.use_cmma)
1734− return false;
1735− return true;
1736−}
1737−
17381813 static bool ibs_enabled(struct kvm_vcpu *vcpu)
17391814 {
17401815 return atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_IBS;
@@ -2340,6 +2415,7 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, · 599 unmodified lines
23402415 case KVM_CAP_S390_CSS_SUPPORT:
23412416 if (!vcpu->kvm->arch.css_support) {
23422417 vcpu->kvm->arch.css_support = 1;
2418+ VM_EVENT(vcpu->kvm, 3, "%s", "ENABLE: CSS support");
23432419 trace_kvm_s390_enable_css(vcpu->kvm);
23442420 }
23452421 r = 0;
arch/s390/kvm/kvm-s390.h+9−2
@@ -27,6 +27,13 @@ typedef int (*intercept_handler_t)(struct kvm_vcpu *vcpu); · 26 unmodified lines
2727 #define TDB_FORMAT1 1
2828 #define IS_ITDB_VALID(vcpu) ((*(char *)vcpu->arch.sie_block->itdba == TDB_FORMAT1))
2929
30+extern debug_info_t *kvm_s390_dbf;
31+#define KVM_EVENT(d_loglevel, d_string, d_args...)\
32+do { \
33+ debug_sprintf_event(kvm_s390_dbf, d_loglevel, d_string "\n", \
34+ d_args); \
35+} while (0)
36+
3037 #define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\
3138 do { \
3239 debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \
@@ -65,6 +72,8 @@ static inline u32 kvm_s390_get_prefix(struct kvm_vcpu *vcpu) · 32 unmodified lines
6572
6673 static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix)
6774 {
75+ VCPU_EVENT(vcpu, 3, "set prefix of cpu %03u to 0x%x", vcpu->vcpu_id,
76+ prefix);
6877 vcpu->arch.sie_block->prefix = prefix >> GUEST_PREFIX_SHIFT;
6978 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
7079 kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
@@ -217,8 +226,6 @@ void exit_sie(struct kvm_vcpu *vcpu); · 146 unmodified lines
217226 void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu);
218227 int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu);
219228 void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu);
220−/* is cmma enabled */
221−bool kvm_s390_cmma_enabled(struct kvm *kvm);
222229 unsigned long kvm_s390_fac_list_mask_size(void);
223230 extern unsigned long kvm_s390_fac_list_mask[];
224231
arch/s390/kvm/priv.c+15−13
@@ -53,11 +53,14 @@ static int handle_set_clock(struct kvm_vcpu *vcpu) · 52 unmodified lines
5353 kvm_s390_set_psw_cc(vcpu, 3);
5454 return 0;
5555 }
56+ VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val);
5657 val = (val - hostclk) & ~0x3fUL;
5758
5859 mutex_lock(&vcpu->kvm->lock);
60+ preempt_disable();
5961 kvm_for_each_vcpu(i, cpup, vcpu->kvm)
6062 cpup->arch.sie_block->epoch = val;
63+ preempt_enable();
6164 mutex_unlock(&vcpu->kvm->lock);
6265
6366 kvm_s390_set_psw_cc(vcpu, 0);
@@ -98,8 +101,6 @@ static int handle_set_prefix(struct kvm_vcpu *vcpu) · 34 unmodified lines
98101 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
99102
100103 kvm_s390_set_prefix(vcpu, address);
101−
102− VCPU_EVENT(vcpu, 5, "setting prefix to %x", address);
103104 trace_kvm_s390_handle_prefix(vcpu, 1, address);
104105 return 0;
105106 }
@@ -129,7 +130,7 @@ static int handle_store_prefix(struct kvm_vcpu *vcpu) · 23 unmodified lines
129130 if (rc)
130131 return kvm_s390_inject_prog_cond(vcpu, rc);
131132
132− VCPU_EVENT(vcpu, 5, "storing prefix to %x", address);
133+ VCPU_EVENT(vcpu, 3, "STPX: storing prefix 0x%x into 0x%llx", address, operand2);
133134 trace_kvm_s390_handle_prefix(vcpu, 0, address);
134135 return 0;
135136 }
@@ -155,7 +156,7 @@ static int handle_store_cpu_address(struct kvm_vcpu *vcpu) · 19 unmodified lines
155156 if (rc)
156157 return kvm_s390_inject_prog_cond(vcpu, rc);
157158
158− VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", ga);
159+ VCPU_EVENT(vcpu, 3, "STAP: storing cpu address (%u) to 0x%llx", vcpu_id, ga);
159160 trace_kvm_s390_handle_stap(vcpu, ga);
160161 return 0;
161162 }
@@ -167,6 +168,7 @@ static int __skey_check_enable(struct kvm_vcpu *vcpu) · 5 unmodified lines
167168 return rc;
168169
169170 rc = s390_enable_skey();
171+ VCPU_EVENT(vcpu, 3, "%s", "enabling storage keys for guest");
170172 trace_kvm_s390_skey_related_inst(vcpu);
171173 vcpu->arch.sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE | ICTL_RRBE);
172174 return rc;
@@ -370,7 +372,7 @@ static int handle_stfl(struct kvm_vcpu *vcpu) · 197 unmodified lines
370372 &fac, sizeof(fac));
371373 if (rc)
372374 return rc;
373− VCPU_EVENT(vcpu, 5, "store facility list value %x", fac);
375+ VCPU_EVENT(vcpu, 3, "STFL: store facility list 0x%x", fac);
374376 trace_kvm_s390_handle_stfl(vcpu, fac);
375377 return 0;
376378 }
@@ -468,7 +470,7 @@ static int handle_stidp(struct kvm_vcpu *vcpu) · 91 unmodified lines
468470 if (rc)
469471 return kvm_s390_inject_prog_cond(vcpu, rc);
470472
471− VCPU_EVENT(vcpu, 5, "%s", "store cpu id");
473+ VCPU_EVENT(vcpu, 3, "STIDP: store cpu id 0x%llx", stidp_data);
472474 return 0;
473475 }
474476
@@ -521,7 +523,7 @@ static int handle_stsi(struct kvm_vcpu *vcpu) · 46 unmodified lines
521523 ar_t ar;
522524
523525 vcpu->stat.instruction_stsi++;
524− VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
526+ VCPU_EVENT(vcpu, 3, "STSI: fc: %u sel1: %u sel2: %u", fc, sel1, sel2);
525527
526528 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
527529 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
@@ -758,10 +760,10 @@ static int handle_essa(struct kvm_vcpu *vcpu) · 230 unmodified lines
758760 struct gmap *gmap;
759761 int i;
760762
761− VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries);
763+ VCPU_EVENT(vcpu, 4, "ESSA: release %d pages", entries);
762764 gmap = vcpu->arch.gmap;
763765 vcpu->stat.instruction_essa++;
764− if (!kvm_s390_cmma_enabled(vcpu->kvm))
766+ if (!vcpu->kvm->arch.use_cmma)
765767 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
766768
767769 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
@@ -829,7 +831,7 @@ int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) · 61 unmodified lines
829831 if (ga & 3)
830832 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
831833
832− VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
834+ VCPU_EVENT(vcpu, 4, "LCTL: r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
833835 trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, ga);
834836
835837 nr_regs = ((reg3 - reg1) & 0xf) + 1;
@@ -868,7 +870,7 @@ int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu) · 32 unmodified lines
868870 if (ga & 3)
869871 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
870872
871− VCPU_EVENT(vcpu, 5, "stctl r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
873+ VCPU_EVENT(vcpu, 4, "STCTL r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
872874 trace_kvm_s390_handle_stctl(vcpu, 0, reg1, reg3, ga);
873875
874876 reg = reg1;
@@ -902,7 +904,7 @@ static int handle_lctlg(struct kvm_vcpu *vcpu) · 27 unmodified lines
902904 if (ga & 7)
903905 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
904906
905− VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
907+ VCPU_EVENT(vcpu, 4, "LCTLG: r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
906908 trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, ga);
907909
908910 nr_regs = ((reg3 - reg1) & 0xf) + 1;
@@ -940,7 +942,7 @@ static int handle_stctg(struct kvm_vcpu *vcpu) · 31 unmodified lines
940942 if (ga & 7)
941943 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
942944
943− VCPU_EVENT(vcpu, 5, "stctg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga);
945+ VCPU_EVENT(vcpu, 4, "STCTG r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
944946 trace_kvm_s390_handle_stctl(vcpu, 1, reg1, reg3, ga);
945947
946948 reg = reg1;
arch/s390/kvm/sigp.c+5−8
@@ -205,9 +205,6 @@ static int __sigp_set_prefix(struct kvm_vcpu *vcpu, struct kvm_vcpu *dst_vcpu, · 204 unmodified lines
205205 *reg &= 0xffffffff00000000UL;
206206 *reg |= SIGP_STATUS_INCORRECT_STATE;
207207 return SIGP_CC_STATUS_STORED;
208− } else if (rc == 0) {
209− VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x",
210− dst_vcpu->vcpu_id, irq.u.prefix.address);
211208 }
212209
213210 return rc;
@@ -371,7 +368,8 @@ static int handle_sigp_dst(struct kvm_vcpu *vcpu, u8 order_code, · 157 unmodified lines
371368 return rc;
372369 }
373370
374−static int handle_sigp_order_in_user_space(struct kvm_vcpu *vcpu, u8 order_code)
371+static int handle_sigp_order_in_user_space(struct kvm_vcpu *vcpu, u8 order_code,
372+ u16 cpu_addr)
375373 {
376374 if (!vcpu->kvm->arch.user_sigp)
377375 return 0;
@@ -414,9 +412,8 @@ static int handle_sigp_order_in_user_space(struct kvm_vcpu *vcpu, u8 order_code) · 36 unmodified lines
414412 default:
415413 vcpu->stat.instruction_sigp_unknown++;
416414 }
417−
418− VCPU_EVENT(vcpu, 4, "sigp order %u: completely handled in user space",
419− order_code);
415+ VCPU_EVENT(vcpu, 3, "SIGP: order %u for CPU %d handled in userspace",
416+ order_code, cpu_addr);
420417
421418 return 1;
422419 }
@@ -435,7 +432,7 @@ int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu) · 12 unmodified lines
435432 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
436433
437434 order_code = kvm_s390_get_base_disp_rs(vcpu, NULL);
438− if (handle_sigp_order_in_user_space(vcpu, order_code))
435+ if (handle_sigp_order_in_user_space(vcpu, order_code, cpu_addr))
439436 return -EOPNOTSUPP;
440437
441438 if (r1 % 2)
arch/s390/kvm/trace-s390.h+19−14
@@ -105,11 +105,22 @@ TRACE_EVENT(kvm_s390_vcpu_start_stop, · 104 unmodified lines
105105 {KVM_S390_PROGRAM_INT, "program interrupt"}, \
106106 {KVM_S390_SIGP_SET_PREFIX, "sigp set prefix"}, \
107107 {KVM_S390_RESTART, "sigp restart"}, \
108+ {KVM_S390_INT_PFAULT_INIT, "pfault init"}, \
109+ {KVM_S390_INT_PFAULT_DONE, "pfault done"}, \
110+ {KVM_S390_MCHK, "machine check"}, \
111+ {KVM_S390_INT_CLOCK_COMP, "clock comparator"}, \
112+ {KVM_S390_INT_CPU_TIMER, "cpu timer"}, \
108113 {KVM_S390_INT_VIRTIO, "virtio interrupt"}, \
109114 {KVM_S390_INT_SERVICE, "sclp interrupt"}, \
110115 {KVM_S390_INT_EMERGENCY, "sigp emergency"}, \
111116 {KVM_S390_INT_EXTERNAL_CALL, "sigp ext call"}
112117
118+#define get_irq_name(__type) \
119+ (__type > KVM_S390_INT_IO_MAX ? \
120+ __print_symbolic(__type, kvm_s390_int_type) : \
121+ (__type & KVM_S390_INT_IO_AI_MASK ? \
122+ "adapter I/O interrupt" : "subchannel I/O interrupt"))
123+
113124 TRACE_EVENT(kvm_s390_inject_vm,
114125 TP_PROTO(__u64 type, __u32 parm, __u64 parm64, int who),
115126 TP_ARGS(type, parm, parm64, who),
@@ -131,22 +142,19 @@ TRACE_EVENT(kvm_s390_inject_vm, · 15 unmodified lines
131142 TP_printk("inject%s: type:%x (%s) parm:%x parm64:%llx",
132143 (__entry->who == 1) ? " (from kernel)" :
133144 (__entry->who == 2) ? " (from user)" : "",
134− __entry->inttype,
135− __print_symbolic(__entry->inttype, kvm_s390_int_type),
145+ __entry->inttype, get_irq_name(__entry->inttype),
136146 __entry->parm, __entry->parm64)
137147 );
138148
139149 TRACE_EVENT(kvm_s390_inject_vcpu,
140− TP_PROTO(unsigned int id, __u64 type, __u32 parm, __u64 parm64, \
141− int who),
142− TP_ARGS(id, type, parm, parm64, who),
150+ TP_PROTO(unsigned int id, __u64 type, __u32 parm, __u64 parm64),
151+ TP_ARGS(id, type, parm, parm64),
143152
144153 TP_STRUCT__entry(
145154 __field(int, id)
146155 __field(__u32, inttype)
147156 __field(__u32, parm)
148157 __field(__u64, parm64)
149− __field(int, who)
150158 ),
151159
152160 TP_fast_assign(
@@ -154,15 +162,12 @@ TRACE_EVENT(kvm_s390_inject_vcpu, · 1 unmodified line
154162 __entry->inttype = type & 0x00000000ffffffff;
155163 __entry->parm = parm;
156164 __entry->parm64 = parm64;
157− __entry->who = who;
158165 ),
159166
160− TP_printk("inject%s (vcpu %d): type:%x (%s) parm:%x parm64:%llx",
161− (__entry->who == 1) ? " (from kernel)" :
162− (__entry->who == 2) ? " (from user)" : "",
167+ TP_printk("inject (vcpu %d): type:%x (%s) parm:%x parm64:%llx",
163168 __entry->id, __entry->inttype,
164− __print_symbolic(__entry->inttype, kvm_s390_int_type),
165− __entry->parm, __entry->parm64)
169+ get_irq_name(__entry->inttype), __entry->parm,
170+ __entry->parm64)
166171 );
167172
168173 /*
@@ -189,8 +194,8 @@ TRACE_EVENT(kvm_s390_deliver_interrupt, · 20 unmodified lines
189194 TP_printk("deliver interrupt (vcpu %d): type:%x (%s) " \
190195 "data:%08llx %016llx",
191196 __entry->id, __entry->inttype,
192− __print_symbolic(__entry->inttype, kvm_s390_int_type),
193− __entry->data0, __entry->data1)
197+ get_irq_name(__entry->inttype), __entry->data0,
198+ __entry->data1)
194199 );
195200
196201 /*
arch/x86/include/asm/kvm_host.h+35−8
@@ -252,6 +252,11 @@ struct kvm_pio_request { · 251 unmodified lines
252252 int size;
253253 };
254254
255+struct rsvd_bits_validate {
256+ u64 rsvd_bits_mask[2][4];
257+ u64 bad_mt_xwr;
258+};
259+
255260 /*
256261 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
257262 * 32-bit). The kvm_mmu structure abstracts the details of the current mmu
@@ -289,8 +294,15 @@ struct kvm_mmu { · 31 unmodified lines
289294
290295 u64 *pae_root;
291296 u64 *lm_root;
292− u64 rsvd_bits_mask[2][4];
293− u64 bad_mt_xwr;
297+
298+ /*
299+ * check zero bits on shadow page table entries, these
300+ * bits include not only hardware reserved bits but also
301+ * the bits spte never used.
302+ */
303+ struct rsvd_bits_validate shadow_zero_check;
304+
305+ struct rsvd_bits_validate guest_rsvd_check;
294306
295307 /*
296308 * Bitmap: bit set = last pte in walk
@@ -358,6 +370,11 @@ struct kvm_mtrr { · 61 unmodified lines
358370 struct list_head head;
359371 };
360372
373+/* Hyper-V per vcpu emulation context */
374+struct kvm_vcpu_hv {
375+ u64 hv_vapic;
376+};
377+
361378 struct kvm_vcpu_arch {
362379 /*
363380 * rip and regs accesses must go through
@@ -514,8 +531,7 @@ struct kvm_vcpu_arch { · 150 unmodified lines
514531 /* used for guest single stepping over the given code position */
515532 unsigned long singlestep_rip;
516533
517− /* fields used by HYPER-V emulation */
518− u64 hv_vapic;
534+ struct kvm_vcpu_hv hyperv;
519535
520536 cpumask_var_t wbinvd_dirty_mask;
521537
@@ -586,6 +602,17 @@ struct kvm_apic_map { · 64 unmodified lines
586602 struct kvm_lapic *logical_map[16][16];
587603 };
588604
605+/* Hyper-V emulation context */
606+struct kvm_hv {
607+ u64 hv_guest_os_id;
608+ u64 hv_hypercall;
609+ u64 hv_tsc_page;
610+
611+ /* Hyper-v based guest crash (NT kernel bugcheck) parameters */
612+ u64 hv_crash_param[HV_X64_MSR_CRASH_PARAMS];
613+ u64 hv_crash_ctl;
614+};
615+
589616 struct kvm_arch {
590617 unsigned int n_used_mmu_pages;
591618 unsigned int n_requested_mmu_pages;
@@ -645,16 +672,14 @@ struct kvm_arch { · 53 unmodified lines
645672 /* reads protected by irq_srcu, writes by irq_lock */
646673 struct hlist_head mask_notifier_list;
647674
648− /* fields used by HYPER-V emulation */
649− u64 hv_guest_os_id;
650− u64 hv_hypercall;
651− u64 hv_tsc_page;
675+ struct kvm_hv hyperv;
652676
653677 #ifdef CONFIG_KVM_MMU_AUDIT
654678 int audit_point;
655679 #endif
656680
657681 bool boot_vcpu_runs_old_kvmclock;
682+ u32 bsp_vcpu_id;
658683
659684 u64 disabled_quirks;
660685 };
@@ -1203,5 +1228,7 @@ int __x86_set_memory_region(struct kvm *kvm, · 542 unmodified lines
12031228 const struct kvm_userspace_memory_region *mem);
12041229 int x86_set_memory_region(struct kvm *kvm,
12051230 const struct kvm_userspace_memory_region *mem);
1231+bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu);
1232+bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu);
12061233
12071234 #endif /* _ASM_X86_KVM_HOST_H */
arch/x86/include/asm/vmx.h+24−23
@@ -47,6 +47,7 @@ · 46 unmodified lines
4747 #define CPU_BASED_MOV_DR_EXITING 0x00800000
4848 #define CPU_BASED_UNCOND_IO_EXITING 0x01000000
4949 #define CPU_BASED_USE_IO_BITMAPS 0x02000000
50+#define CPU_BASED_MONITOR_TRAP_FLAG 0x08000000
5051 #define CPU_BASED_USE_MSR_BITMAPS 0x10000000
5152 #define CPU_BASED_MONITOR_EXITING 0x20000000
5253 #define CPU_BASED_PAUSE_EXITING 0x40000000
@@ -367,29 +368,29 @@ enum vmcs_field { · 314 unmodified lines
367368 #define TYPE_PHYSICAL_APIC_EVENT (10 << 12)
368369 #define TYPE_PHYSICAL_APIC_INST (15 << 12)
369370
370−/* segment AR */
371−#define SEGMENT_AR_L_MASK (1 << 13)
372−
373−#define AR_TYPE_ACCESSES_MASK 1
374−#define AR_TYPE_READABLE_MASK (1 << 1)
375−#define AR_TYPE_WRITEABLE_MASK (1 << 2)
376−#define AR_TYPE_CODE_MASK (1 << 3)
377−#define AR_TYPE_MASK 0x0f
378−#define AR_TYPE_BUSY_64_TSS 11
379−#define AR_TYPE_BUSY_32_TSS 11
380−#define AR_TYPE_BUSY_16_TSS 3
381−#define AR_TYPE_LDT 2
382−
383−#define AR_UNUSABLE_MASK (1 << 16)
384−#define AR_S_MASK (1 << 4)
385−#define AR_P_MASK (1 << 7)
386−#define AR_L_MASK (1 << 13)
387−#define AR_DB_MASK (1 << 14)
388−#define AR_G_MASK (1 << 15)
389−#define AR_DPL_SHIFT 5
390−#define AR_DPL(ar) (((ar) >> AR_DPL_SHIFT) & 3)
391−
392−#define AR_RESERVD_MASK 0xfffe0f00
371+/* segment AR in VMCS -- these are different from what LAR reports */
372+#define VMX_SEGMENT_AR_L_MASK (1 << 13)
373+
374+#define VMX_AR_TYPE_ACCESSES_MASK 1
375+#define VMX_AR_TYPE_READABLE_MASK (1 << 1)
376+#define VMX_AR_TYPE_WRITEABLE_MASK (1 << 2)
377+#define VMX_AR_TYPE_CODE_MASK (1 << 3)
378+#define VMX_AR_TYPE_MASK 0x0f
379+#define VMX_AR_TYPE_BUSY_64_TSS 11
380+#define VMX_AR_TYPE_BUSY_32_TSS 11
381+#define VMX_AR_TYPE_BUSY_16_TSS 3
382+#define VMX_AR_TYPE_LDT 2
383+
384+#define VMX_AR_UNUSABLE_MASK (1 << 16)
385+#define VMX_AR_S_MASK (1 << 4)
386+#define VMX_AR_P_MASK (1 << 7)
387+#define VMX_AR_L_MASK (1 << 13)
388+#define VMX_AR_DB_MASK (1 << 14)
389+#define VMX_AR_G_MASK (1 << 15)
390+#define VMX_AR_DPL_SHIFT 5
391+#define VMX_AR_DPL(ar) (((ar) >> VMX_AR_DPL_SHIFT) & 3)
392+
393+#define VMX_AR_RESERVD_MASK 0xfffe0f00
393394
394395 #define TSS_PRIVATE_MEMSLOT (KVM_USER_MEM_SLOTS + 0)
395396 #define APIC_ACCESS_PAGE_PRIVATE_MEMSLOT (KVM_USER_MEM_SLOTS + 1)
arch/x86/include/uapi/asm/vmx.h+2−0
@@ -58,6 +58,7 @@ · 57 unmodified lines
5858 #define EXIT_REASON_INVALID_STATE 33
5959 #define EXIT_REASON_MSR_LOAD_FAIL 34
6060 #define EXIT_REASON_MWAIT_INSTRUCTION 36
61+#define EXIT_REASON_MONITOR_TRAP_FLAG 37
6162 #define EXIT_REASON_MONITOR_INSTRUCTION 39
6263 #define EXIT_REASON_PAUSE_INSTRUCTION 40
6364 #define EXIT_REASON_MCE_DURING_VMENTRY 41
@@ -106,6 +107,7 @@ · 42 unmodified lines
106107 { EXIT_REASON_MSR_READ, "MSR_READ" }, \
107108 { EXIT_REASON_MSR_WRITE, "MSR_WRITE" }, \
108109 { EXIT_REASON_MWAIT_INSTRUCTION, "MWAIT_INSTRUCTION" }, \
110+ { EXIT_REASON_MONITOR_TRAP_FLAG, "MONITOR_TRAP_FLAG" }, \
109111 { EXIT_REASON_MONITOR_INSTRUCTION, "MONITOR_INSTRUCTION" }, \
110112 { EXIT_REASON_PAUSE_INSTRUCTION, "PAUSE_INSTRUCTION" }, \
111113 { EXIT_REASON_MCE_DURING_VMENTRY, "MCE_DURING_VMENTRY" }, \
arch/x86/kvm/Makefile+3−1
@@ -12,7 +12,9 @@ kvm-y += $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o \ · 11 unmodified lines
1212 kvm-$(CONFIG_KVM_ASYNC_PF) += $(KVM)/async_pf.o
1313
1414 kvm-y += x86.o mmu.o emulate.o i8259.o irq.o lapic.o \
15− i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o
15+ i8254.o ioapic.o irq_comm.o cpuid.o pmu.o mtrr.o \
16+ hyperv.o
17+
1618 kvm-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += assigned-dev.o iommu.o
1719 kvm-intel-y += vmx.o pmu_intel.o
1820 kvm-amd-y += svm.o pmu_amd.o
arch/x86/kvm/hyperv.c+377−0
@@ -0,0 +1,377 @@
1+/*
2+ * KVM Microsoft Hyper-V emulation
3+ *
4+ * derived from arch/x86/kvm/x86.c
5+ *
6+ * Copyright (C) 2006 Qumranet, Inc.
7+ * Copyright (C) 2008 Qumranet, Inc.
8+ * Copyright IBM Corporation, 2008
9+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
10+ * Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
11+ *
12+ * Authors:
13+ * Avi Kivity <avi@qumranet.com>
14+ * Yaniv Kamay <yaniv@qumranet.com>
15+ * Amit Shah <amit.shah@qumranet.com>
16+ * Ben-Ami Yassour <benami@il.ibm.com>
17+ * Andrey Smetanin <asmetanin@virtuozzo.com>
18+ *
19+ * This work is licensed under the terms of the GNU GPL, version 2. See
20+ * the COPYING file in the top-level directory.
21+ *
22+ */
23+
24+#include "x86.h"
25+#include "lapic.h"
26+#include "hyperv.h"
27+
28+#include <linux/kvm_host.h>
29+#include <trace/events/kvm.h>
30+
31+#include "trace.h"
32+
33+static bool kvm_hv_msr_partition_wide(u32 msr)
34+{
35+ bool r = false;
36+
37+ switch (msr) {
38+ case HV_X64_MSR_GUEST_OS_ID:
39+ case HV_X64_MSR_HYPERCALL:
40+ case HV_X64_MSR_REFERENCE_TSC:
41+ case HV_X64_MSR_TIME_REF_COUNT:
42+ case HV_X64_MSR_CRASH_CTL:
43+ case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
44+ r = true;
45+ break;
46+ }
47+
48+ return r;
49+}
50+
51+static int kvm_hv_msr_get_crash_data(struct kvm_vcpu *vcpu,
52+ u32 index, u64 *pdata)
53+{
54+ struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
55+
56+ if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
57+ return -EINVAL;
58+
59+ *pdata = hv->hv_crash_param[index];
60+ return 0;
61+}
62+
63+static int kvm_hv_msr_get_crash_ctl(struct kvm_vcpu *vcpu, u64 *pdata)
64+{
65+ struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
66+
67+ *pdata = hv->hv_crash_ctl;
68+ return 0;
69+}
70+
71+static int kvm_hv_msr_set_crash_ctl(struct kvm_vcpu *vcpu, u64 data, bool host)
72+{
73+ struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
74+
75+ if (host)
76+ hv->hv_crash_ctl = data & HV_X64_MSR_CRASH_CTL_NOTIFY;
77+
78+ if (!host && (data & HV_X64_MSR_CRASH_CTL_NOTIFY)) {
79+
80+ vcpu_debug(vcpu, "hv crash (0x%llx 0x%llx 0x%llx 0x%llx 0x%llx)\n",
81+ hv->hv_crash_param[0],
82+ hv->hv_crash_param[1],
83+ hv->hv_crash_param[2],
84+ hv->hv_crash_param[3],
85+ hv->hv_crash_param[4]);
86+
87+ /* Send notification about crash to user space */
88+ kvm_make_request(KVM_REQ_HV_CRASH, vcpu);
89+ }
90+
91+ return 0;
92+}
93+
94+static int kvm_hv_msr_set_crash_data(struct kvm_vcpu *vcpu,
95+ u32 index, u64 data)
96+{
97+ struct kvm_hv *hv = &vcpu->kvm->arch.hyperv;
98+
99+ if (WARN_ON_ONCE(index >= ARRAY_SIZE(hv->hv_crash_param)))
100+ return -EINVAL;
101+
102+ hv->hv_crash_param[index] = data;
103+ return 0;
104+}
105+
106+static int kvm_hv_set_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data,
107+ bool host)
108+{
109+ struct kvm *kvm = vcpu->kvm;
110+ struct kvm_hv *hv = &kvm->arch.hyperv;
111+
112+ switch (msr) {
113+ case HV_X64_MSR_GUEST_OS_ID:
114+ hv->hv_guest_os_id = data;
115+ /* setting guest os id to zero disables hypercall page */
116+ if (!hv->hv_guest_os_id)
117+ hv->hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
118+ break;
119+ case HV_X64_MSR_HYPERCALL: {
120+ u64 gfn;
121+ unsigned long addr;
122+ u8 instructions[4];
123+
124+ /* if guest os id is not set hypercall should remain disabled */
125+ if (!hv->hv_guest_os_id)
126+ break;
127+ if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
128+ hv->hv_hypercall = data;
129+ break;
130+ }
131+ gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
132+ addr = gfn_to_hva(kvm, gfn);
133+ if (kvm_is_error_hva(addr))
134+ return 1;
135+ kvm_x86_ops->patch_hypercall(vcpu, instructions);
136+ ((unsigned char *)instructions)[3] = 0xc3; /* ret */
137+ if (__copy_to_user((void __user *)addr, instructions, 4))
138+ return 1;
139+ hv->hv_hypercall = data;
140+ mark_page_dirty(kvm, gfn);
141+ break;
142+ }
143+ case HV_X64_MSR_REFERENCE_TSC: {
144+ u64 gfn;
145+ HV_REFERENCE_TSC_PAGE tsc_ref;
146+
147+ memset(&tsc_ref, 0, sizeof(tsc_ref));
148+ hv->hv_tsc_page = data;
149+ if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
150+ break;
151+ gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
152+ if (kvm_write_guest(
153+ kvm,
154+ gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
155+ &tsc_ref, sizeof(tsc_ref)))
156+ return 1;
157+ mark_page_dirty(kvm, gfn);
158+ break;
159+ }
160+ case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
161+ return kvm_hv_msr_set_crash_data(vcpu,
162+ msr - HV_X64_MSR_CRASH_P0,
163+ data);
164+ case HV_X64_MSR_CRASH_CTL:
165+ return kvm_hv_msr_set_crash_ctl(vcpu, data, host);
166+ default:
167+ vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
168+ msr, data);
169+ return 1;
170+ }
171+ return 0;
172+}
173+
174+static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
175+{
176+ struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
177+
178+ switch (msr) {
179+ case HV_X64_MSR_APIC_ASSIST_PAGE: {
180+ u64 gfn;
181+ unsigned long addr;
182+
183+ if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
184+ hv->hv_vapic = data;
185+ if (kvm_lapic_enable_pv_eoi(vcpu, 0))
186+ return 1;
187+ break;
188+ }
189+ gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
190+ addr = kvm_vcpu_gfn_to_hva(vcpu, gfn);
191+ if (kvm_is_error_hva(addr))
192+ return 1;
193+ if (__clear_user((void __user *)addr, PAGE_SIZE))
194+ return 1;
195+ hv->hv_vapic = data;
196+ kvm_vcpu_mark_page_dirty(vcpu, gfn);
197+ if (kvm_lapic_enable_pv_eoi(vcpu,
198+ gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
199+ return 1;
200+ break;
201+ }
202+ case HV_X64_MSR_EOI:
203+ return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
204+ case HV_X64_MSR_ICR:
205+ return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
206+ case HV_X64_MSR_TPR:
207+ return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
208+ default:
209+ vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
210+ msr, data);
211+ return 1;
212+ }
213+
214+ return 0;
215+}
216+
217+static int kvm_hv_get_msr_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
218+{
219+ u64 data = 0;
220+ struct kvm *kvm = vcpu->kvm;
221+ struct kvm_hv *hv = &kvm->arch.hyperv;
222+
223+ switch (msr) {
224+ case HV_X64_MSR_GUEST_OS_ID:
225+ data = hv->hv_guest_os_id;
226+ break;
227+ case HV_X64_MSR_HYPERCALL:
228+ data = hv->hv_hypercall;
229+ break;
230+ case HV_X64_MSR_TIME_REF_COUNT: {
231+ data =
232+ div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
233+ break;
234+ }
235+ case HV_X64_MSR_REFERENCE_TSC:
236+ data = hv->hv_tsc_page;
237+ break;
238+ case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
239+ return kvm_hv_msr_get_crash_data(vcpu,
240+ msr - HV_X64_MSR_CRASH_P0,
241+ pdata);
242+ case HV_X64_MSR_CRASH_CTL:
243+ return kvm_hv_msr_get_crash_ctl(vcpu, pdata);
244+ default:
245+ vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
246+ return 1;
247+ }
248+
249+ *pdata = data;
250+ return 0;
251+}
252+
253+static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
254+{
255+ u64 data = 0;
256+ struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
257+
258+ switch (msr) {
259+ case HV_X64_MSR_VP_INDEX: {
260+ int r;
261+ struct kvm_vcpu *v;
262+
263+ kvm_for_each_vcpu(r, v, vcpu->kvm) {
264+ if (v == vcpu) {
265+ data = r;
266+ break;
267+ }
268+ }
269+ break;
270+ }
271+ case HV_X64_MSR_EOI:
272+ return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
273+ case HV_X64_MSR_ICR:
274+ return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
275+ case HV_X64_MSR_TPR:
276+ return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
277+ case HV_X64_MSR_APIC_ASSIST_PAGE:
278+ data = hv->hv_vapic;
279+ break;
280+ default:
281+ vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
282+ return 1;
283+ }
284+ *pdata = data;
285+ return 0;
286+}
287+
288+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
289+{
290+ if (kvm_hv_msr_partition_wide(msr)) {
291+ int r;
292+
293+ mutex_lock(&vcpu->kvm->lock);
294+ r = kvm_hv_set_msr_pw(vcpu, msr, data, host);
295+ mutex_unlock(&vcpu->kvm->lock);
296+ return r;
297+ } else
298+ return kvm_hv_set_msr(vcpu, msr, data);
299+}
300+
301+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
302+{
303+ if (kvm_hv_msr_partition_wide(msr)) {
304+ int r;
305+
306+ mutex_lock(&vcpu->kvm->lock);
307+ r = kvm_hv_get_msr_pw(vcpu, msr, pdata);
308+ mutex_unlock(&vcpu->kvm->lock);
309+ return r;
310+ } else
311+ return kvm_hv_get_msr(vcpu, msr, pdata);
312+}
313+
314+bool kvm_hv_hypercall_enabled(struct kvm *kvm)
315+{
316+ return kvm->arch.hyperv.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
317+}
318+
319+int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
320+{
321+ u64 param, ingpa, outgpa, ret;
322+ uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
323+ bool fast, longmode;
324+
325+ /*
326+ * hypercall generates UD from non zero cpl and real mode
327+ * per HYPER-V spec
328+ */
329+ if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
330+ kvm_queue_exception(vcpu, UD_VECTOR);
331+ return 0;
332+ }
333+
334+ longmode = is_64_bit_mode(vcpu);
335+
336+ if (!longmode) {
337+ param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
338+ (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
339+ ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
340+ (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
341+ outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
342+ (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
343+ }
344+#ifdef CONFIG_X86_64
345+ else {
346+ param = kvm_register_read(vcpu, VCPU_REGS_RCX);
347+ ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
348+ outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
349+ }
350+#endif
351+
352+ code = param & 0xffff;
353+ fast = (param >> 16) & 0x1;
354+ rep_cnt = (param >> 32) & 0xfff;
355+ rep_idx = (param >> 48) & 0xfff;
356+
357+ trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
358+
359+ switch (code) {
360+ case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
361+ kvm_vcpu_on_spin(vcpu);
362+ break;
363+ default:
364+ res = HV_STATUS_INVALID_HYPERCALL_CODE;
365+ break;
366+ }
367+
368+ ret = res | (((u64)rep_done & 0xfff) << 32);
369+ if (longmode) {
370+ kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
371+ } else {
372+ kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
373+ kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
374+ }
375+
376+ return 1;
377+}
arch/x86/kvm/hyperv.h+32−0
@@ -0,0 +1,32 @@
1+/*
2+ * KVM Microsoft Hyper-V emulation
3+ *
4+ * derived from arch/x86/kvm/x86.c
5+ *
6+ * Copyright (C) 2006 Qumranet, Inc.
7+ * Copyright (C) 2008 Qumranet, Inc.
8+ * Copyright IBM Corporation, 2008
9+ * Copyright 2010 Red Hat, Inc. and/or its affiliates.
10+ * Copyright (C) 2015 Andrey Smetanin <asmetanin@virtuozzo.com>
11+ *
12+ * Authors:
13+ * Avi Kivity <avi@qumranet.com>
14+ * Yaniv Kamay <yaniv@qumranet.com>
15+ * Amit Shah <amit.shah@qumranet.com>
16+ * Ben-Ami Yassour <benami@il.ibm.com>
17+ * Andrey Smetanin <asmetanin@virtuozzo.com>
18+ *
19+ * This work is licensed under the terms of the GNU GPL, version 2. See
20+ * the COPYING file in the top-level directory.
21+ *
22+ */
23+
24+#ifndef __ARCH_X86_KVM_HYPERV_H__
25+#define __ARCH_X86_KVM_HYPERV_H__
26+
27+int kvm_hv_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host);
28+int kvm_hv_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
29+bool kvm_hv_hypercall_enabled(struct kvm *kvm);
30+int kvm_hv_hypercall(struct kvm_vcpu *vcpu);
31+
32+#endif
arch/x86/kvm/i8259.c+5−10
@@ -651,15 +651,10 @@ fail_unlock: · 650 unmodified lines
651651 return NULL;
652652 }
653653
654−void kvm_destroy_pic(struct kvm *kvm)
654+void kvm_destroy_pic(struct kvm_pic *vpic)
655655 {
656− struct kvm_pic *vpic = kvm->arch.vpic;
657−
658− if (vpic) {
659− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_master);
660− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_slave);
661− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &vpic->dev_eclr);
662− kvm->arch.vpic = NULL;
663− kfree(vpic);
664− }
656+ kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_master);
657+ kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_slave);
658+ kvm_io_bus_unregister_dev(vpic->kvm, KVM_PIO_BUS, &vpic->dev_eclr);
659+ kfree(vpic);
665660 }
arch/x86/kvm/irq.h+4−4
@@ -74,7 +74,7 @@ struct kvm_pic { · 73 unmodified lines
7474 };
7575
7676 struct kvm_pic *kvm_create_pic(struct kvm *kvm);
77−void kvm_destroy_pic(struct kvm *kvm);
77+void kvm_destroy_pic(struct kvm_pic *vpic);
7878 int kvm_pic_read_irq(struct kvm *kvm);
7979 void kvm_pic_update_irq(struct kvm_pic *s);
8080
@@ -85,11 +85,11 @@ static inline struct kvm_pic *pic_irqchip(struct kvm *kvm) · 4 unmodified lines
8585
8686 static inline int irqchip_in_kernel(struct kvm *kvm)
8787 {
88− int ret;
88+ struct kvm_pic *vpic = pic_irqchip(kvm);
8989
90− ret = (pic_irqchip(kvm) != NULL);
90+ /* Read vpic before kvm->irq_routing. */
9191 smp_rmb();
92− return ret;
92+ return vpic != NULL;
9393 }
9494
9595 void kvm_pic_reset(struct kvm_kpic_state *s);
arch/x86/kvm/lapic.c+3−2
@@ -1900,8 +1900,9 @@ void kvm_lapic_sync_from_vapic(struct kvm_vcpu *vcpu) · 1899 unmodified lines
19001900 if (!test_bit(KVM_APIC_CHECK_VAPIC, &vcpu->arch.apic_attention))
19011901 return;
19021902
1903− kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
1904− sizeof(u32));
1903+ if (kvm_read_guest_cached(vcpu->kvm, &vcpu->arch.apic->vapic_cache, &data,
1904+ sizeof(u32)))
1905+ return;
19051906
19061907 apic_set_tpr(vcpu->arch.apic, data & 0xff);
19071908 }
arch/x86/kvm/lapic.h+1−1
@@ -91,7 +91,7 @@ int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data); · 90 unmodified lines
9191
9292 static inline bool kvm_hv_vapic_assist_page_enabled(struct kvm_vcpu *vcpu)
9393 {
94− return vcpu->arch.hv_vapic & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
94+ return vcpu->arch.hyperv.hv_vapic & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE;
9595 }
9696
9797 int kvm_lapic_enable_pv_eoi(struct kvm_vcpu *vcpu, u64 data);
arch/x86/kvm/mmu.c+171−114
@@ -357,12 +357,6 @@ static u64 __get_spte_lockless(u64 *sptep) · 356 unmodified lines
357357 {
358358 return ACCESS_ONCE(*sptep);
359359 }
360−
361−static bool __check_direct_spte_mmio_pf(u64 spte)
362−{
363− /* It is valid if the spte is zapped. */
364− return spte == 0ull;
365−}
366360 #else
367361 union split_spte {
368362 struct {
@@ -478,23 +472,6 @@ retry: · 109 unmodified lines
478472
479473 return spte.spte;
480474 }
481−
482−static bool __check_direct_spte_mmio_pf(u64 spte)
483−{
484− union split_spte sspte = (union split_spte)spte;
485− u32 high_mmio_mask = shadow_mmio_mask >> 32;
486−
487− /* It is valid if the spte is zapped. */
488− if (spte == 0ull)
489− return true;
490−
491− /* It is valid if the spte is being zapped. */
492− if (sspte.spte_low == 0ull &&
493− (sspte.spte_high & high_mmio_mask) == high_mmio_mask)
494− return true;
495−
496− return false;
497−}
498475 #endif
499476
500477 static bool spte_is_locklessly_modifiable(u64 spte)
@@ -3291,54 +3268,89 @@ static gpa_t nonpaging_gva_to_gpa_nested(struct kvm_vcpu *vcpu, gva_t vaddr, · 2790 unmodified lines
32913268 return vcpu->arch.nested_mmu.translate_gpa(vcpu, vaddr, access, exception);
32923269 }
32933270
3294−static bool quickly_check_mmio_pf(struct kvm_vcpu *vcpu, u64 addr, bool direct)
3271+static bool
3272+__is_rsvd_bits_set(struct rsvd_bits_validate *rsvd_check, u64 pte, int level)
32953273 {
3296− if (direct)
3297− return vcpu_match_mmio_gpa(vcpu, addr);
3274+ int bit7 = (pte >> 7) & 1, low6 = pte & 0x3f;
32983275
3299− return vcpu_match_mmio_gva(vcpu, addr);
3276+ return (pte & rsvd_check->rsvd_bits_mask[bit7][level-1]) |
3277+ ((rsvd_check->bad_mt_xwr & (1ull << low6)) != 0);
33003278 }
33013279
3280+static bool is_rsvd_bits_set(struct kvm_mmu *mmu, u64 gpte, int level)
3281+{
3282+ return __is_rsvd_bits_set(&mmu->guest_rsvd_check, gpte, level);
3283+}
33023284
3303−/*
3304− * On direct hosts, the last spte is only allows two states
3305− * for mmio page fault:
3306− * - It is the mmio spte
3307− * - It is zapped or it is being zapped.
3308− *
3309− * This function completely checks the spte when the last spte
3310− * is not the mmio spte.
3311− */
3312−static bool check_direct_spte_mmio_pf(u64 spte)
3285+static bool is_shadow_zero_bits_set(struct kvm_mmu *mmu, u64 spte, int level)
33133286 {
3314− return __check_direct_spte_mmio_pf(spte);
3287+ return __is_rsvd_bits_set(&mmu->shadow_zero_check, spte, level);
33153288 }
33163289
3317−static u64 walk_shadow_page_get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr)
3290+static bool quickly_check_mmio_pf(struct kvm_vcpu *vcpu, u64 addr, bool direct)
3291+{
3292+ if (direct)
3293+ return vcpu_match_mmio_gpa(vcpu, addr);
3294+
3295+ return vcpu_match_mmio_gva(vcpu, addr);
3296+}
3297+
3298+/* return true if reserved bit is detected on spte. */
3299+static bool
3300+walk_shadow_page_get_mmio_spte(struct kvm_vcpu *vcpu, u64 addr, u64 *sptep)
33183301 {
33193302 struct kvm_shadow_walk_iterator iterator;
3320− u64 spte = 0ull;
3303+ u64 sptes[PT64_ROOT_LEVEL], spte = 0ull;
3304+ int root, leaf;
3305+ bool reserved = false;
33213306
33223307 if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
3323− return spte;
3308+ goto exit;
33243309
33253310 walk_shadow_page_lockless_begin(vcpu);
3326− for_each_shadow_entry_lockless(vcpu, addr, iterator, spte)
3311+
3312+ for (shadow_walk_init(&iterator, vcpu, addr), root = iterator.level;
3313+ shadow_walk_okay(&iterator);
3314+ __shadow_walk_next(&iterator, spte)) {
3315+ leaf = iterator.level;
3316+ spte = mmu_spte_get_lockless(iterator.sptep);
3317+
3318+ sptes[leaf - 1] = spte;
3319+
33273320 if (!is_shadow_present_pte(spte))
33283321 break;
3322+
3323+ reserved |= is_shadow_zero_bits_set(&vcpu->arch.mmu, spte,
3324+ leaf);
3325+ }
3326+
33293327 walk_shadow_page_lockless_end(vcpu);
33303328
3331− return spte;
3329+ if (reserved) {
3330+ pr_err("%s: detect reserved bits on spte, addr 0x%llx, dump hierarchy:\n",
3331+ __func__, addr);
3332+ while (root >= leaf) {
3333+ pr_err("------ spte 0x%llx level %d.\n",
3334+ sptes[root - 1], root);
3335+ root--;
3336+ }
3337+ }
3338+exit:
3339+ *sptep = spte;
3340+ return reserved;
33323341 }
33333342
33343343 int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct)
33353344 {
33363345 u64 spte;
3346+ bool reserved;
33373347
33383348 if (quickly_check_mmio_pf(vcpu, addr, direct))
33393349 return RET_MMIO_PF_EMULATE;
33403350
3341− spte = walk_shadow_page_get_mmio_spte(vcpu, addr);
3351+ reserved = walk_shadow_page_get_mmio_spte(vcpu, addr, &spte);
3352+ if (unlikely(reserved))
3353+ return RET_MMIO_PF_BUG;
33423354
33433355 if (is_mmio_spte(spte)) {
33443356 gfn_t gfn = get_mmio_spte_gfn(spte);
@@ -3355,13 +3367,6 @@ int handle_mmio_page_fault_common(struct kvm_vcpu *vcpu, u64 addr, bool direct) · 10 unmodified lines
33553367 return RET_MMIO_PF_EMULATE;
33563368 }
33573369
3358− /*
3359− * It's ok if the gva is remapped by other cpus on shadow guest,
3360− * it's a BUG if the gfn is not a mmio page.
3361− */
3362− if (direct && !check_direct_spte_mmio_pf(spte))
3363− return RET_MMIO_PF_BUG;
3364−
33653370 /*
33663371 * If the page table is zapped by other cpus, let CPU fault again on
33673372 * the address.
@@ -3604,19 +3609,21 @@ static inline bool is_last_gpte(struct kvm_mmu *mmu, unsigned level, unsigned gp · 236 unmodified lines
36043609 #include "paging_tmpl.h"
36053610 #undef PTTYPE
36063611
3607−static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu,
3608− struct kvm_mmu *context)
3612+static void
3613+__reset_rsvds_bits_mask(struct kvm_vcpu *vcpu,
3614+ struct rsvd_bits_validate *rsvd_check,
3615+ int maxphyaddr, int level, bool nx, bool gbpages,
3616+ bool pse)
36093617 {
3610− int maxphyaddr = cpuid_maxphyaddr(vcpu);
36113618 u64 exb_bit_rsvd = 0;
36123619 u64 gbpages_bit_rsvd = 0;
36133620 u64 nonleaf_bit8_rsvd = 0;
36143621
3615− context->bad_mt_xwr = 0;
3622+ rsvd_check->bad_mt_xwr = 0;
36163623
3617− if (!context->nx)
3624+ if (!nx)
36183625 exb_bit_rsvd = rsvd_bits(63, 63);
3619− if (!guest_cpuid_has_gbpages(vcpu))
3626+ if (!gbpages)
36203627 gbpages_bit_rsvd = rsvd_bits(7, 7);
36213628
36223629 /*
@@ -3626,80 +3633,95 @@ static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu, · 3 unmodified lines
36263633 if (guest_cpuid_is_amd(vcpu))
36273634 nonleaf_bit8_rsvd = rsvd_bits(8, 8);
36283635
3629− switch (context->root_level) {
3636+ switch (level) {
36303637 case PT32_ROOT_LEVEL:
36313638 /* no rsvd bits for 2 level 4K page table entries */
3632− context->rsvd_bits_mask[0][1] = 0;
3633− context->rsvd_bits_mask[0][0] = 0;
3634− context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[0][0];
3639+ rsvd_check->rsvd_bits_mask[0][1] = 0;
3640+ rsvd_check->rsvd_bits_mask[0][0] = 0;
3641+ rsvd_check->rsvd_bits_mask[1][0] =
3642+ rsvd_check->rsvd_bits_mask[0][0];
36353643
3636− if (!is_pse(vcpu)) {
3637− context->rsvd_bits_mask[1][1] = 0;
3644+ if (!pse) {
3645+ rsvd_check->rsvd_bits_mask[1][1] = 0;
36383646 break;
36393647 }
36403648
36413649 if (is_cpuid_PSE36())
36423650 /* 36bits PSE 4MB page */
3643− context->rsvd_bits_mask[1][1] = rsvd_bits(17, 21);
3651+ rsvd_check->rsvd_bits_mask[1][1] = rsvd_bits(17, 21);
36443652 else
36453653 /* 32 bits PSE 4MB page */
3646− context->rsvd_bits_mask[1][1] = rsvd_bits(13, 21);
3654+ rsvd_check->rsvd_bits_mask[1][1] = rsvd_bits(13, 21);
36473655 break;
36483656 case PT32E_ROOT_LEVEL:
3649− context->rsvd_bits_mask[0][2] =
3657+ rsvd_check->rsvd_bits_mask[0][2] =
36503658 rsvd_bits(maxphyaddr, 63) |
36513659 rsvd_bits(5, 8) | rsvd_bits(1, 2); /* PDPTE */
3652− context->rsvd_bits_mask[0][1] = exb_bit_rsvd |
3660+ rsvd_check->rsvd_bits_mask[0][1] = exb_bit_rsvd |
36533661 rsvd_bits(maxphyaddr, 62); /* PDE */
3654− context->rsvd_bits_mask[0][0] = exb_bit_rsvd |
3662+ rsvd_check->rsvd_bits_mask[0][0] = exb_bit_rsvd |
36553663 rsvd_bits(maxphyaddr, 62); /* PTE */
3656− context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
3664+ rsvd_check->rsvd_bits_mask[1][1] = exb_bit_rsvd |
36573665 rsvd_bits(maxphyaddr, 62) |
36583666 rsvd_bits(13, 20); /* large page */
3659− context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[0][0];
3667+ rsvd_check->rsvd_bits_mask[1][0] =
3668+ rsvd_check->rsvd_bits_mask[0][0];
36603669 break;
36613670 case PT64_ROOT_LEVEL:
3662− context->rsvd_bits_mask[0][3] = exb_bit_rsvd |
3663− nonleaf_bit8_rsvd | rsvd_bits(7, 7) | rsvd_bits(maxphyaddr, 51);
3664− context->rsvd_bits_mask[0][2] = exb_bit_rsvd |
3665− nonleaf_bit8_rsvd | gbpages_bit_rsvd | rsvd_bits(maxphyaddr, 51);
3666− context->rsvd_bits_mask[0][1] = exb_bit_rsvd |
3671+ rsvd_check->rsvd_bits_mask[0][3] = exb_bit_rsvd |
3672+ nonleaf_bit8_rsvd | rsvd_bits(7, 7) |
3673+ rsvd_bits(maxphyaddr, 51);
3674+ rsvd_check->rsvd_bits_mask[0][2] = exb_bit_rsvd |
3675+ nonleaf_bit8_rsvd | gbpages_bit_rsvd |
36673676 rsvd_bits(maxphyaddr, 51);
3668− context->rsvd_bits_mask[0][0] = exb_bit_rsvd |
3677+ rsvd_check->rsvd_bits_mask[0][1] = exb_bit_rsvd |
36693678 rsvd_bits(maxphyaddr, 51);
3670− context->rsvd_bits_mask[1][3] = context->rsvd_bits_mask[0][3];
3671− context->rsvd_bits_mask[1][2] = exb_bit_rsvd |
3679+ rsvd_check->rsvd_bits_mask[0][0] = exb_bit_rsvd |
3680+ rsvd_bits(maxphyaddr, 51);
3681+ rsvd_check->rsvd_bits_mask[1][3] =
3682+ rsvd_check->rsvd_bits_mask[0][3];
3683+ rsvd_check->rsvd_bits_mask[1][2] = exb_bit_rsvd |
36723684 gbpages_bit_rsvd | rsvd_bits(maxphyaddr, 51) |
36733685 rsvd_bits(13, 29);
3674− context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
3686+ rsvd_check->rsvd_bits_mask[1][1] = exb_bit_rsvd |
36753687 rsvd_bits(maxphyaddr, 51) |
36763688 rsvd_bits(13, 20); /* large page */
3677− context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[0][0];
3689+ rsvd_check->rsvd_bits_mask[1][0] =
3690+ rsvd_check->rsvd_bits_mask[0][0];
36783691 break;
36793692 }
36803693 }
36813694
3682−static void reset_rsvds_bits_mask_ept(struct kvm_vcpu *vcpu,
3683− struct kvm_mmu *context, bool execonly)
3695+static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu,
3696+ struct kvm_mmu *context)
3697+{
3698+ __reset_rsvds_bits_mask(vcpu, &context->guest_rsvd_check,
3699+ cpuid_maxphyaddr(vcpu), context->root_level,
3700+ context->nx, guest_cpuid_has_gbpages(vcpu),
3701+ is_pse(vcpu));
3702+}
3703+
3704+static void
3705+__reset_rsvds_bits_mask_ept(struct rsvd_bits_validate *rsvd_check,
3706+ int maxphyaddr, bool execonly)
36843707 {
3685− int maxphyaddr = cpuid_maxphyaddr(vcpu);
36863708 int pte;
36873709
3688− context->rsvd_bits_mask[0][3] =
3710+ rsvd_check->rsvd_bits_mask[0][3] =
36893711 rsvd_bits(maxphyaddr, 51) | rsvd_bits(3, 7);
3690− context->rsvd_bits_mask[0][2] =
3712+ rsvd_check->rsvd_bits_mask[0][2] =
36913713 rsvd_bits(maxphyaddr, 51) | rsvd_bits(3, 6);
3692− context->rsvd_bits_mask[0][1] =
3714+ rsvd_check->rsvd_bits_mask[0][1] =
36933715 rsvd_bits(maxphyaddr, 51) | rsvd_bits(3, 6);
3694− context->rsvd_bits_mask[0][0] = rsvd_bits(maxphyaddr, 51);
3716+ rsvd_check->rsvd_bits_mask[0][0] = rsvd_bits(maxphyaddr, 51);
36953717
36963718 /* large page */
3697− context->rsvd_bits_mask[1][3] = context->rsvd_bits_mask[0][3];
3698− context->rsvd_bits_mask[1][2] =
3719+ rsvd_check->rsvd_bits_mask[1][3] = rsvd_check->rsvd_bits_mask[0][3];
3720+ rsvd_check->rsvd_bits_mask[1][2] =
36993721 rsvd_bits(maxphyaddr, 51) | rsvd_bits(12, 29);
3700− context->rsvd_bits_mask[1][1] =
3722+ rsvd_check->rsvd_bits_mask[1][1] =
37013723 rsvd_bits(maxphyaddr, 51) | rsvd_bits(12, 20);
3702− context->rsvd_bits_mask[1][0] = context->rsvd_bits_mask[0][0];
3724+ rsvd_check->rsvd_bits_mask[1][0] = rsvd_check->rsvd_bits_mask[0][0];
37033725
37043726 for (pte = 0; pte < 64; pte++) {
37053727 int rwx_bits = pte & 7;
@@ -3707,10 +3729,64 @@ static void reset_rsvds_bits_mask_ept(struct kvm_vcpu *vcpu, · 1 unmodified line
37073729 if (mt == 0x2 || mt == 0x3 || mt == 0x7 ||
37083730 rwx_bits == 0x2 || rwx_bits == 0x6 ||
37093731 (rwx_bits == 0x4 && !execonly))
3710− context->bad_mt_xwr |= (1ull << pte);
3732+ rsvd_check->bad_mt_xwr |= (1ull << pte);
37113733 }
37123734 }
37133735
3736+static void reset_rsvds_bits_mask_ept(struct kvm_vcpu *vcpu,
3737+ struct kvm_mmu *context, bool execonly)
3738+{
3739+ __reset_rsvds_bits_mask_ept(&context->guest_rsvd_check,
3740+ cpuid_maxphyaddr(vcpu), execonly);
3741+}
3742+
3743+/*
3744+ * the page table on host is the shadow page table for the page
3745+ * table in guest or amd nested guest, its mmu features completely
3746+ * follow the features in guest.
3747+ */
3748+void
3749+reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu, struct kvm_mmu *context)
3750+{
3751+ __reset_rsvds_bits_mask(vcpu, &context->shadow_zero_check,
3752+ boot_cpu_data.x86_phys_bits,
3753+ context->shadow_root_level, context->nx,
3754+ guest_cpuid_has_gbpages(vcpu), is_pse(vcpu));
3755+}
3756+EXPORT_SYMBOL_GPL(reset_shadow_zero_bits_mask);
3757+
3758+/*
3759+ * the direct page table on host, use as much mmu features as
3760+ * possible, however, kvm currently does not do execution-protection.
3761+ */
3762+static void
3763+reset_tdp_shadow_zero_bits_mask(struct kvm_vcpu *vcpu,
3764+ struct kvm_mmu *context)
3765+{
3766+ if (guest_cpuid_is_amd(vcpu))
3767+ __reset_rsvds_bits_mask(vcpu, &context->shadow_zero_check,
3768+ boot_cpu_data.x86_phys_bits,
3769+ context->shadow_root_level, false,
3770+ cpu_has_gbpages, true);
3771+ else
3772+ __reset_rsvds_bits_mask_ept(&context->shadow_zero_check,
3773+ boot_cpu_data.x86_phys_bits,
3774+ false);
3775+
3776+}
3777+
3778+/*
3779+ * as the comments in reset_shadow_zero_bits_mask() except it
3780+ * is the shadow page table for intel nested guest.
3781+ */
3782+static void
3783+reset_ept_shadow_zero_bits_mask(struct kvm_vcpu *vcpu,
3784+ struct kvm_mmu *context, bool execonly)
3785+{
3786+ __reset_rsvds_bits_mask_ept(&context->shadow_zero_check,
3787+ boot_cpu_data.x86_phys_bits, execonly);
3788+}
3789+
37143790 static void update_permission_bitmask(struct kvm_vcpu *vcpu,
37153791 struct kvm_mmu *mmu, bool ept)
37163792 {
@@ -3889,6 +3965,7 @@ static void init_kvm_tdp_mmu(struct kvm_vcpu *vcpu) · 172 unmodified lines
38893965
38903966 update_permission_bitmask(vcpu, context, false);
38913967 update_last_pte_bitmap(vcpu, context);
3968+ reset_tdp_shadow_zero_bits_mask(vcpu, context);
38923969 }
38933970
38943971 void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu)
@@ -3916,6 +3993,7 @@ void kvm_init_shadow_mmu(struct kvm_vcpu *vcpu) · 21 unmodified lines
39163993 context->base_role.smap_andnot_wp
39173994 = smap && !is_write_protection(vcpu);
39183995 context->base_role.smm = is_smm(vcpu);
3996+ reset_shadow_zero_bits_mask(vcpu, context);
39193997 }
39203998 EXPORT_SYMBOL_GPL(kvm_init_shadow_mmu);
39213999
@@ -3939,6 +4017,7 @@ void kvm_init_shadow_ept_mmu(struct kvm_vcpu *vcpu, bool execonly) · 17 unmodified lines
39394017
39404018 update_permission_bitmask(vcpu, context, true);
39414019 reset_rsvds_bits_mask_ept(vcpu, context, execonly);
4020+ reset_ept_shadow_zero_bits_mask(vcpu, context, execonly);
39424021 }
39434022 EXPORT_SYMBOL_GPL(kvm_init_shadow_ept_mmu);
39444023
@@ -4860,28 +4939,6 @@ unsigned int kvm_mmu_calculate_mmu_pages(struct kvm *kvm) · 915 unmodified lines
48604939 return nr_mmu_pages;
48614940 }
48624941
4863−int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4])
4864−{
4865− struct kvm_shadow_walk_iterator iterator;
4866− u64 spte;
4867− int nr_sptes = 0;
4868−
4869− if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
4870− return nr_sptes;
4871−
4872− walk_shadow_page_lockless_begin(vcpu);
4873− for_each_shadow_entry_lockless(vcpu, addr, iterator, spte) {
4874− sptes[iterator.level-1] = spte;
4875− nr_sptes++;
4876− if (!is_shadow_present_pte(spte))
4877− break;
4878− }
4879− walk_shadow_page_lockless_end(vcpu);
4880−
4881− return nr_sptes;
4882−}
4883−EXPORT_SYMBOL_GPL(kvm_mmu_get_spte_hierarchy);
4884−
48854942 void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
48864943 {
48874944 kvm_mmu_unload(vcpu);
arch/x86/kvm/mmu.h+3−1
@@ -50,9 +50,11 @@ static inline u64 rsvd_bits(int s, int e) · 49 unmodified lines
5050 return ((1ULL << (e - s + 1)) - 1) << s;
5151 }
5252
53−int kvm_mmu_get_spte_hierarchy(struct kvm_vcpu *vcpu, u64 addr, u64 sptes[4]);
5453 void kvm_mmu_set_mmio_spte_mask(u64 mmio_mask);
5554
55+void
56+reset_shadow_zero_bits_mask(struct kvm_vcpu *vcpu, struct kvm_mmu *context);
57+
5658 /*
5759 * Return values of handle_mmio_page_fault_common:
5860 * RET_MMIO_PF_EMULATE: it is a real mmio page fault, emulate the instruction
arch/x86/kvm/paging_tmpl.h+2−11
@@ -128,14 +128,6 @@ static inline void FNAME(protect_clean_gpte)(unsigned *access, unsigned gpte) · 127 unmodified lines
128128 *access &= mask;
129129 }
130130
131−static bool FNAME(is_rsvd_bits_set)(struct kvm_mmu *mmu, u64 gpte, int level)
132−{
133− int bit7 = (gpte >> 7) & 1, low6 = gpte & 0x3f;
134−
135− return (gpte & mmu->rsvd_bits_mask[bit7][level-1]) |
136− ((mmu->bad_mt_xwr & (1ull << low6)) != 0);
137−}
138−
139131 static inline int FNAME(is_present_gpte)(unsigned long pte)
140132 {
141133 #if PTTYPE != PTTYPE_EPT
@@ -172,7 +164,7 @@ static bool FNAME(prefetch_invalid_gpte)(struct kvm_vcpu *vcpu, · 30 unmodified lines
172164 struct kvm_mmu_page *sp, u64 *spte,
173165 u64 gpte)
174166 {
175− if (FNAME(is_rsvd_bits_set)(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL))
167+ if (is_rsvd_bits_set(&vcpu->arch.mmu, gpte, PT_PAGE_TABLE_LEVEL))
176168 goto no_present;
177169
178170 if (!FNAME(is_present_gpte)(gpte))
@@ -353,8 +345,7 @@ retry_walk: · 174 unmodified lines
353345 if (unlikely(!FNAME(is_present_gpte)(pte)))
354346 goto error;
355347
356− if (unlikely(FNAME(is_rsvd_bits_set)(mmu, pte,
357− walker->level))) {
348+ if (unlikely(is_rsvd_bits_set(mmu, pte, walker->level))) {
358349 errcode |= PFERR_RSVD_MASK | PFERR_PRESENT_MASK;
359350 goto error;
360351 }
arch/x86/kvm/pmu_amd.c+0−2
@@ -133,8 +133,6 @@ static int amd_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · 132 unmodified lines
133133 /* MSR_K7_PERFCTRn */
134134 pmc = get_gp_pmc(pmu, msr, MSR_K7_PERFCTR0);
135135 if (pmc) {
136− if (!msr_info->host_initiated)
137− data = (s64)data;
138136 pmc->counter += data - pmc_read_counter(pmc);
139137 return 0;
140138 }
arch/x86/kvm/svm.c+9−7
@@ -1173,6 +1173,10 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) · 1172 unmodified lines
11731173 if (!is_mmio && !kvm_arch_has_assigned_device(vcpu->kvm))
11741174 return 0;
11751175
1176+ if (!kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED) &&
1177+ kvm_read_cr0(vcpu) & X86_CR0_CD)
1178+ return _PAGE_NOCACHE;
1179+
11761180 mtrr = kvm_mtrr_get_guest_memory_type(vcpu, gfn);
11771181 return mtrr2protval[mtrr];
11781182 }
@@ -1667,13 +1671,10 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) · 488 unmodified lines
16671671
16681672 if (!vcpu->fpu_active)
16691673 cr0 |= X86_CR0_TS;
1670− /*
1671− * re-enable caching here because the QEMU bios
1672− * does not do it - this results in some delay at
1673− * reboot
1674− */
1675− if (kvm_check_has_quirk(vcpu->kvm, KVM_X86_QUIRK_CD_NW_CLEARED))
1676− cr0 &= ~(X86_CR0_CD | X86_CR0_NW);
1674+
1675+ /* These are emulated via page tables. */
1676+ cr0 &= ~(X86_CR0_CD | X86_CR0_NW);
1677+
16771678 svm->vmcb->save.cr0 = cr0;
16781679 mark_dirty(svm->vmcb, VMCB_CR);
16791680 update_cr0_intercept(svm);
@@ -2106,6 +2107,7 @@ static void nested_svm_init_mmu_context(struct kvm_vcpu *vcpu) · 426 unmodified lines
21062107 vcpu->arch.mmu.get_pdptr = nested_svm_get_tdp_pdptr;
21072108 vcpu->arch.mmu.inject_page_fault = nested_svm_inject_npf_exit;
21082109 vcpu->arch.mmu.shadow_root_level = get_npt_level();
2110+ reset_shadow_zero_bits_mask(vcpu, &vcpu->arch.mmu);
21092111 vcpu->arch.walk_mmu = &vcpu->arch.nested_mmu;
21102112 }
21112113
arch/x86/kvm/vmx.c+82−99
@@ -2443,10 +2443,10 @@ static void nested_vmx_setup_ctls_msrs(struct vcpu_vmx *vmx) · 2442 unmodified lines
24432443 CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING |
24442444 #endif
24452445 CPU_BASED_MOV_DR_EXITING | CPU_BASED_UNCOND_IO_EXITING |
2446− CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_EXITING |
2447− CPU_BASED_RDPMC_EXITING | CPU_BASED_RDTSC_EXITING |
2448− CPU_BASED_PAUSE_EXITING | CPU_BASED_TPR_SHADOW |
2449− CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
2446+ CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MONITOR_TRAP_FLAG |
2447+ CPU_BASED_MONITOR_EXITING | CPU_BASED_RDPMC_EXITING |
2448+ CPU_BASED_RDTSC_EXITING | CPU_BASED_PAUSE_EXITING |
2449+ CPU_BASED_TPR_SHADOW | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
24502450 /*
24512451 * We can allow some features even when not supported by the
24522452 * hardware. For example, L1 can specify an MSR bitmap - and we
@@ -3423,12 +3423,12 @@ static void enter_lmode(struct kvm_vcpu *vcpu) · 970 unmodified lines
34233423 vmx_segment_cache_clear(to_vmx(vcpu));
34243424
34253425 guest_tr_ar = vmcs_read32(GUEST_TR_AR_BYTES);
3426− if ((guest_tr_ar & AR_TYPE_MASK) != AR_TYPE_BUSY_64_TSS) {
3426+ if ((guest_tr_ar & VMX_AR_TYPE_MASK) != VMX_AR_TYPE_BUSY_64_TSS) {
34273427 pr_debug_ratelimited("%s: tss fixup for long mode. \n",
34283428 __func__);
34293429 vmcs_write32(GUEST_TR_AR_BYTES,
3430− (guest_tr_ar & ~AR_TYPE_MASK)
3431− | AR_TYPE_BUSY_64_TSS);
3430+ (guest_tr_ar & ~VMX_AR_TYPE_MASK)
3431+ | VMX_AR_TYPE_BUSY_64_TSS);
34323432 }
34333433 vmx_set_efer(vcpu, vcpu->arch.efer | EFER_LMA);
34343434 }
@@ -3719,7 +3719,7 @@ static int vmx_get_cpl(struct kvm_vcpu *vcpu) · 284 unmodified lines
37193719 return 0;
37203720 else {
37213721 int ar = vmx_read_guest_seg_ar(vmx, VCPU_SREG_SS);
3722− return AR_DPL(ar);
3722+ return VMX_AR_DPL(ar);
37233723 }
37243724 }
37253725
@@ -3847,11 +3847,11 @@ static bool code_segment_valid(struct kvm_vcpu *vcpu) · 121 unmodified lines
38473847
38483848 if (cs.unusable)
38493849 return false;
3850− if (~cs.type & (AR_TYPE_CODE_MASK|AR_TYPE_ACCESSES_MASK))
3850+ if (~cs.type & (VMX_AR_TYPE_CODE_MASK|VMX_AR_TYPE_ACCESSES_MASK))
38513851 return false;
38523852 if (!cs.s)
38533853 return false;
3854− if (cs.type & AR_TYPE_WRITEABLE_MASK) {
3854+ if (cs.type & VMX_AR_TYPE_WRITEABLE_MASK) {
38553855 if (cs.dpl > cs_rpl)
38563856 return false;
38573857 } else {
@@ -3901,7 +3901,7 @@ static bool data_segment_valid(struct kvm_vcpu *vcpu, int seg) · 43 unmodified lines
39013901 return false;
39023902 if (!var.present)
39033903 return false;
3904− if (~var.type & (AR_TYPE_CODE_MASK|AR_TYPE_WRITEABLE_MASK)) {
3904+ if (~var.type & (VMX_AR_TYPE_CODE_MASK|VMX_AR_TYPE_WRITEABLE_MASK)) {
39053905 if (var.dpl < rpl) /* DPL < RPL */
39063906 return false;
39073907 }
@@ -5759,73 +5759,9 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu) · 1851 unmodified lines
57595759 return kvm_mmu_page_fault(vcpu, gpa, error_code, NULL, 0);
57605760 }
57615761
5762−static u64 ept_rsvd_mask(u64 spte, int level)
5763−{
5764− int i;
5765− u64 mask = 0;
5766−
5767− for (i = 51; i > boot_cpu_data.x86_phys_bits; i--)
5768− mask |= (1ULL << i);
5769−
5770− if (level == 4)
5771− /* bits 7:3 reserved */
5772− mask |= 0xf8;
5773− else if (spte & (1ULL << 7))
5774− /*
5775− * 1GB/2MB page, bits 29:12 or 20:12 reserved respectively,
5776− * level == 1 if the hypervisor is using the ignored bit 7.
5777− */
5778− mask |= (PAGE_SIZE << ((level - 1) * 9)) - PAGE_SIZE;
5779− else if (level > 1)
5780− /* bits 6:3 reserved */
5781− mask |= 0x78;
5782−
5783− return mask;
5784−}
5785−
5786−static void ept_misconfig_inspect_spte(struct kvm_vcpu *vcpu, u64 spte,
5787− int level)
5788−{
5789− printk(KERN_ERR "%s: spte 0x%llx level %d\n", __func__, spte, level);
5790−
5791− /* 010b (write-only) */
5792− WARN_ON((spte & 0x7) == 0x2);
5793−
5794− /* 110b (write/execute) */
5795− WARN_ON((spte & 0x7) == 0x6);
5796−
5797− /* 100b (execute-only) and value not supported by logical processor */
5798− if (!cpu_has_vmx_ept_execute_only())
5799− WARN_ON((spte & 0x7) == 0x4);
5800−
5801− /* not 000b */
5802− if ((spte & 0x7)) {
5803− u64 rsvd_bits = spte & ept_rsvd_mask(spte, level);
5804−
5805− if (rsvd_bits != 0) {
5806− printk(KERN_ERR "%s: rsvd_bits = 0x%llx\n",
5807− __func__, rsvd_bits);
5808− WARN_ON(1);
5809− }
5810−
5811− /* bits 5:3 are _not_ reserved for large page or leaf page */
5812− if ((rsvd_bits & 0x38) == 0) {
5813− u64 ept_mem_type = (spte & 0x38) >> 3;
5814−
5815− if (ept_mem_type == 2 || ept_mem_type == 3 ||
5816− ept_mem_type == 7) {
5817− printk(KERN_ERR "%s: ept_mem_type=0x%llx\n",
5818− __func__, ept_mem_type);
5819− WARN_ON(1);
5820− }
5821− }
5822− }
5823−}
5824−
58255762 static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
58265763 {
5827− u64 sptes[4];
5828− int nr_sptes, i, ret;
5764+ int ret;
58295765 gpa_t gpa;
58305766
58315767 gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
@@ -5846,13 +5782,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu) · 14 unmodified lines
58465782 return 1;
58475783
58485784 /* It is the real ept misconfig */
5849− printk(KERN_ERR "EPT: Misconfiguration.\n");
5850− printk(KERN_ERR "EPT: GPA: 0x%llx\n", gpa);
5851−
5852− nr_sptes = kvm_mmu_get_spte_hierarchy(vcpu, gpa, sptes);
5853−
5854− for (i = PT64_ROOT_LEVEL; i > PT64_ROOT_LEVEL - nr_sptes; --i)
5855− ept_misconfig_inspect_spte(vcpu, sptes[i-1], i);
5785+ WARN_ON(1);
58565786
58575787 vcpu->run->exit_reason = KVM_EXIT_UNKNOWN;
58585788 vcpu->run->hw.hardware_exit_reason = EXIT_REASON_EPT_MISCONFIG;
@@ -6246,6 +6176,11 @@ static int handle_mwait(struct kvm_vcpu *vcpu) · 387 unmodified lines
62466176 return handle_nop(vcpu);
62476177 }
62486178
6179+static int handle_monitor_trap(struct kvm_vcpu *vcpu)
6180+{
6181+ return 1;
6182+}
6183+
62496184 static int handle_monitor(struct kvm_vcpu *vcpu)
62506185 {
62516186 printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n");
@@ -6408,8 +6343,12 @@ static enum hrtimer_restart vmx_preemption_timer_fn(struct hrtimer *timer) · 156 unmodified lines
64086343 */
64096344 static int get_vmx_mem_address(struct kvm_vcpu *vcpu,
64106345 unsigned long exit_qualification,
6411− u32 vmx_instruction_info, gva_t *ret)
6346+ u32 vmx_instruction_info, bool wr, gva_t *ret)
64126347 {
6348+ gva_t off;
6349+ bool exn;
6350+ struct kvm_segment s;
6351+
64136352 /*
64146353 * According to Vol. 3B, "Information for VM Exits Due to Instruction
64156354 * Execution", on an exit, vmx_instruction_info holds most of the
@@ -6434,22 +6373,63 @@ static int get_vmx_mem_address(struct kvm_vcpu *vcpu, · 18 unmodified lines
64346373
64356374 /* Addr = segment_base + offset */
64366375 /* offset = base + [index * scale] + displacement */
6437− *ret = vmx_get_segment_base(vcpu, seg_reg);
6376+ off = exit_qualification; /* holds the displacement */
64386377 if (base_is_valid)
6439− *ret += kvm_register_read(vcpu, base_reg);
6378+ off += kvm_register_read(vcpu, base_reg);
64406379 if (index_is_valid)
6441− *ret += kvm_register_read(vcpu, index_reg)<<scaling;
6442− *ret += exit_qualification; /* holds the displacement */
6380+ off += kvm_register_read(vcpu, index_reg)<<scaling;
6381+ vmx_get_segment(vcpu, &s, seg_reg);
6382+ *ret = s.base + off;
64436383
64446384 if (addr_size == 1) /* 32 bit */
64456385 *ret &= 0xffffffff;
64466386
6447− /*
6448− * TODO: throw #GP (and return 1) in various cases that the VM*
6449− * instructions require it - e.g., offset beyond segment limit,
6450− * unusable or unreadable/unwritable segment, non-canonical 64-bit
6451− * address, and so on. Currently these are not checked.
6452− */
6387+ /* Checks for #GP/#SS exceptions. */
6388+ exn = false;
6389+ if (is_protmode(vcpu)) {
6390+ /* Protected mode: apply checks for segment validity in the
6391+ * following order:
6392+ * - segment type check (#GP(0) may be thrown)
6393+ * - usability check (#GP(0)/#SS(0))
6394+ * - limit check (#GP(0)/#SS(0))
6395+ */
6396+ if (wr)
6397+ /* #GP(0) if the destination operand is located in a
6398+ * read-only data segment or any code segment.
6399+ */
6400+ exn = ((s.type & 0xa) == 0 || (s.type & 8));
6401+ else
6402+ /* #GP(0) if the source operand is located in an
6403+ * execute-only code segment
6404+ */
6405+ exn = ((s.type & 0xa) == 8);
6406+ }
6407+ if (exn) {
6408+ kvm_queue_exception_e(vcpu, GP_VECTOR, 0);
6409+ return 1;
6410+ }
6411+ if (is_long_mode(vcpu)) {
6412+ /* Long mode: #GP(0)/#SS(0) if the memory address is in a
6413+ * non-canonical form. This is an only check for long mode.
6414+ */
6415+ exn = is_noncanonical_address(*ret);
6416+ } else if (is_protmode(vcpu)) {
6417+ /* Protected mode: #GP(0)/#SS(0) if the segment is unusable.
6418+ */
6419+ exn = (s.unusable != 0);
6420+ /* Protected mode: #GP(0)/#SS(0) if the memory
6421+ * operand is outside the segment limit.
6422+ */
6423+ exn = exn || (off + sizeof(u64) > s.limit);
6424+ }
6425+ if (exn) {
6426+ kvm_queue_exception_e(vcpu,
6427+ seg_reg == VCPU_SREG_SS ?
6428+ SS_VECTOR : GP_VECTOR,
6429+ 0);
6430+ return 1;
6431+ }
6432+
64536433 return 0;
64546434 }
64556435
@@ -6471,7 +6451,7 @@ static int nested_vmx_check_vmptr(struct kvm_vcpu *vcpu, int exit_reason, · 15 unmodified lines
64716451 int maxphyaddr = cpuid_maxphyaddr(vcpu);
64726452
64736453 if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
6474− vmcs_read32(VMX_INSTRUCTION_INFO), &gva))
6454+ vmcs_read32(VMX_INSTRUCTION_INFO), false, &gva))
64756455 return 1;
64766456
64776457 if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &vmptr,
@@ -6999,7 +6979,7 @@ static int handle_vmread(struct kvm_vcpu *vcpu) · 521 unmodified lines
69996979 field_value);
70006980 } else {
70016981 if (get_vmx_mem_address(vcpu, exit_qualification,
7002− vmx_instruction_info, &gva))
6982+ vmx_instruction_info, true, &gva))
70036983 return 1;
70046984 /* _system ok, as nested_vmx_check_permission verified cpl=0 */
70056985 kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, gva,
@@ -7036,7 +7016,7 @@ static int handle_vmwrite(struct kvm_vcpu *vcpu) · 30 unmodified lines
70367016 (((vmx_instruction_info) >> 3) & 0xf));
70377017 else {
70387018 if (get_vmx_mem_address(vcpu, exit_qualification,
7039− vmx_instruction_info, &gva))
7019+ vmx_instruction_info, false, &gva))
70407020 return 1;
70417021 if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva,
70427022 &field_value, (is_64_bit_mode(vcpu) ? 8 : 4), &e)) {
@@ -7128,7 +7108,7 @@ static int handle_vmptrst(struct kvm_vcpu *vcpu) · 85 unmodified lines
71287108 return 1;
71297109
71307110 if (get_vmx_mem_address(vcpu, exit_qualification,
7131− vmx_instruction_info, &vmcs_gva))
7111+ vmx_instruction_info, true, &vmcs_gva))
71327112 return 1;
71337113 /* ok to use *_system, as nested_vmx_check_permission verified cpl=0 */
71347114 if (kvm_write_guest_virt_system(&vcpu->arch.emulate_ctxt, vmcs_gva,
@@ -7184,7 +7164,7 @@ static int handle_invept(struct kvm_vcpu *vcpu) · 49 unmodified lines
71847164 * operand is read even if it isn't needed (e.g., for type==global)
71857165 */
71867166 if (get_vmx_mem_address(vcpu, vmcs_readl(EXIT_QUALIFICATION),
7187− vmx_instruction_info, &gva))
7167+ vmx_instruction_info, false, &gva))
71887168 return 1;
71897169 if (kvm_read_guest_virt(&vcpu->arch.emulate_ctxt, gva, &operand,
71907170 sizeof(operand), &e)) {
@@ -7282,6 +7262,7 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { · 91 unmodified lines
72827262 [EXIT_REASON_EPT_MISCONFIG] = handle_ept_misconfig,
72837263 [EXIT_REASON_PAUSE_INSTRUCTION] = handle_pause,
72847264 [EXIT_REASON_MWAIT_INSTRUCTION] = handle_mwait,
7265+ [EXIT_REASON_MONITOR_TRAP_FLAG] = handle_monitor_trap,
72857266 [EXIT_REASON_MONITOR_INSTRUCTION] = handle_monitor,
72867267 [EXIT_REASON_INVEPT] = handle_invept,
72877268 [EXIT_REASON_INVVPID] = handle_invvpid,
@@ -7542,6 +7523,8 @@ static bool nested_vmx_exit_handled(struct kvm_vcpu *vcpu) · 254 unmodified lines
75427523 return true;
75437524 case EXIT_REASON_MWAIT_INSTRUCTION:
75447525 return nested_cpu_has(vmcs12, CPU_BASED_MWAIT_EXITING);
7526+ case EXIT_REASON_MONITOR_TRAP_FLAG:
7527+ return nested_cpu_has(vmcs12, CPU_BASED_MONITOR_TRAP_FLAG);
75457528 case EXIT_REASON_MONITOR_INSTRUCTION:
75467529 return nested_cpu_has(vmcs12, CPU_BASED_MONITOR_EXITING);
75477530 case EXIT_REASON_PAUSE_INSTRUCTION:
arch/x86/kvm/x86.c+47−276
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include "cpuid.h"
3030 #include "assigned-dev.h"
3131 #include "pmu.h"
32+#include "hyperv.h"
3233
3334 #include <linux/clocksource.h>
3435 #include <linux/interrupt.h>
@@ -221,11 +222,9 @@ static void shared_msr_update(unsigned slot, u32 msr) · 186 unmodified lines
221222 void kvm_define_shared_msr(unsigned slot, u32 msr)
222223 {
223224 BUG_ON(slot >= KVM_NR_SHARED_MSRS);
225+ shared_msrs_global.msrs[slot] = msr;
224226 if (slot >= shared_msrs_global.nr)
225227 shared_msrs_global.nr = slot + 1;
226− shared_msrs_global.msrs[slot] = msr;
227− /* we need ensured the shared_msr_global have been updated */
228− smp_wmb();
229228 }
230229 EXPORT_SYMBOL_GPL(kvm_define_shared_msr);
231230
@@ -526,7 +525,8 @@ int load_pdptrs(struct kvm_vcpu *vcpu, struct kvm_mmu *mmu, unsigned long cr3) · 294 unmodified lines
526525 }
527526 for (i = 0; i < ARRAY_SIZE(pdpte); ++i) {
528527 if (is_present_gpte(pdpte[i]) &&
529− (pdpte[i] & vcpu->arch.mmu.rsvd_bits_mask[0][2])) {
528+ (pdpte[i] &
529+ vcpu->arch.mmu.guest_rsvd_check.rsvd_bits_mask[0][2])) {
530530 ret = 0;
531531 goto out;
532532 }
@@ -949,6 +949,8 @@ static u32 emulated_msrs[] = { · 416 unmodified lines
949949 MSR_KVM_SYSTEM_TIME_NEW, MSR_KVM_WALL_CLOCK_NEW,
950950 HV_X64_MSR_GUEST_OS_ID, HV_X64_MSR_HYPERCALL,
951951 HV_X64_MSR_TIME_REF_COUNT, HV_X64_MSR_REFERENCE_TSC,
952+ HV_X64_MSR_CRASH_P0, HV_X64_MSR_CRASH_P1, HV_X64_MSR_CRASH_P2,
953+ HV_X64_MSR_CRASH_P3, HV_X64_MSR_CRASH_P4, HV_X64_MSR_CRASH_CTL,
952954 HV_X64_MSR_APIC_ASSIST_PAGE, MSR_KVM_ASYNC_PF_EN, MSR_KVM_STEAL_TIME,
953955 MSR_KVM_PV_EOI_EN,
954956
@@ -1217,11 +1219,6 @@ static void kvm_get_time_scale(uint32_t scaled_khz, uint32_t base_khz, · 262 unmodified lines
12171219 __func__, base_khz, scaled_khz, shift, *pmultiplier);
12181220 }
12191221
1220−static inline u64 get_kernel_ns(void)
1221−{
1222− return ktime_get_boot_ns();
1223−}
1224−
12251222 #ifdef CONFIG_X86_64
12261223 static atomic_t kvm_guest_has_master_clock = ATOMIC_INIT(0);
12271224 #endif
@@ -1869,123 +1866,6 @@ out: · 641 unmodified lines
18691866 return r;
18701867 }
18711868
1872−static bool kvm_hv_hypercall_enabled(struct kvm *kvm)
1873−{
1874− return kvm->arch.hv_hypercall & HV_X64_MSR_HYPERCALL_ENABLE;
1875−}
1876−
1877−static bool kvm_hv_msr_partition_wide(u32 msr)
1878−{
1879− bool r = false;
1880− switch (msr) {
1881− case HV_X64_MSR_GUEST_OS_ID:
1882− case HV_X64_MSR_HYPERCALL:
1883− case HV_X64_MSR_REFERENCE_TSC:
1884− case HV_X64_MSR_TIME_REF_COUNT:
1885− r = true;
1886− break;
1887− }
1888−
1889− return r;
1890−}
1891−
1892−static int set_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1893−{
1894− struct kvm *kvm = vcpu->kvm;
1895−
1896− switch (msr) {
1897− case HV_X64_MSR_GUEST_OS_ID:
1898− kvm->arch.hv_guest_os_id = data;
1899− /* setting guest os id to zero disables hypercall page */
1900− if (!kvm->arch.hv_guest_os_id)
1901− kvm->arch.hv_hypercall &= ~HV_X64_MSR_HYPERCALL_ENABLE;
1902− break;
1903− case HV_X64_MSR_HYPERCALL: {
1904− u64 gfn;
1905− unsigned long addr;
1906− u8 instructions[4];
1907−
1908− /* if guest os id is not set hypercall should remain disabled */
1909− if (!kvm->arch.hv_guest_os_id)
1910− break;
1911− if (!(data & HV_X64_MSR_HYPERCALL_ENABLE)) {
1912− kvm->arch.hv_hypercall = data;
1913− break;
1914− }
1915− gfn = data >> HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT;
1916− addr = gfn_to_hva(kvm, gfn);
1917− if (kvm_is_error_hva(addr))
1918− return 1;
1919− kvm_x86_ops->patch_hypercall(vcpu, instructions);
1920− ((unsigned char *)instructions)[3] = 0xc3; /* ret */
1921− if (__copy_to_user((void __user *)addr, instructions, 4))
1922− return 1;
1923− kvm->arch.hv_hypercall = data;
1924− mark_page_dirty(kvm, gfn);
1925− break;
1926− }
1927− case HV_X64_MSR_REFERENCE_TSC: {
1928− u64 gfn;
1929− HV_REFERENCE_TSC_PAGE tsc_ref;
1930− memset(&tsc_ref, 0, sizeof(tsc_ref));
1931− kvm->arch.hv_tsc_page = data;
1932− if (!(data & HV_X64_MSR_TSC_REFERENCE_ENABLE))
1933− break;
1934− gfn = data >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT;
1935− if (kvm_write_guest(kvm, gfn << HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT,
1936− &tsc_ref, sizeof(tsc_ref)))
1937− return 1;
1938− mark_page_dirty(kvm, gfn);
1939− break;
1940− }
1941− default:
1942− vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
1943− "data 0x%llx\n", msr, data);
1944− return 1;
1945− }
1946− return 0;
1947−}
1948−
1949−static int set_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 data)
1950−{
1951− switch (msr) {
1952− case HV_X64_MSR_APIC_ASSIST_PAGE: {
1953− u64 gfn;
1954− unsigned long addr;
1955−
1956− if (!(data & HV_X64_MSR_APIC_ASSIST_PAGE_ENABLE)) {
1957− vcpu->arch.hv_vapic = data;
1958− if (kvm_lapic_enable_pv_eoi(vcpu, 0))
1959− return 1;
1960− break;
1961− }
1962− gfn = data >> HV_X64_MSR_APIC_ASSIST_PAGE_ADDRESS_SHIFT;
1963− addr = kvm_vcpu_gfn_to_hva(vcpu, gfn);
1964− if (kvm_is_error_hva(addr))
1965− return 1;
1966− if (__clear_user((void __user *)addr, PAGE_SIZE))
1967− return 1;
1968− vcpu->arch.hv_vapic = data;
1969− kvm_vcpu_mark_page_dirty(vcpu, gfn);
1970− if (kvm_lapic_enable_pv_eoi(vcpu, gfn_to_gpa(gfn) | KVM_MSR_ENABLED))
1971− return 1;
1972− break;
1973− }
1974− case HV_X64_MSR_EOI:
1975− return kvm_hv_vapic_msr_write(vcpu, APIC_EOI, data);
1976− case HV_X64_MSR_ICR:
1977− return kvm_hv_vapic_msr_write(vcpu, APIC_ICR, data);
1978− case HV_X64_MSR_TPR:
1979− return kvm_hv_vapic_msr_write(vcpu, APIC_TASKPRI, data);
1980− default:
1981− vcpu_unimpl(vcpu, "HYPER-V unimplemented wrmsr: 0x%x "
1982− "data 0x%llx\n", msr, data);
1983− return 1;
1984− }
1985−
1986− return 0;
1987−}
1988−
19891869 static int kvm_pv_enable_async_pf(struct kvm_vcpu *vcpu, u64 data)
19901870 {
19911871 gpa_t gpa = data & ~0x3f;
@@ -2224,15 +2104,10 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · 232 unmodified lines
22242104 */
22252105 break;
22262106 case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15:
2227− if (kvm_hv_msr_partition_wide(msr)) {
2228− int r;
2229− mutex_lock(&vcpu->kvm->lock);
2230− r = set_msr_hyperv_pw(vcpu, msr, data);
2231− mutex_unlock(&vcpu->kvm->lock);
2232− return r;
2233− } else
2234− return set_msr_hyperv(vcpu, msr, data);
2235− break;
2107+ case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
2108+ case HV_X64_MSR_CRASH_CTL:
2109+ return kvm_hv_set_msr_common(vcpu, msr, data,
2110+ msr_info->host_initiated);
22362111 case MSR_IA32_BBL_CR_CTL3:
22372112 /* Drop writes to this legacy MSR -- see rdmsr
22382113 * counterpart for further detail.
@@ -2315,68 +2190,6 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata) · 76 unmodified lines
23152190 return 0;
23162191 }
23172192
2318−static int get_msr_hyperv_pw(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
2319−{
2320− u64 data = 0;
2321− struct kvm *kvm = vcpu->kvm;
2322−
2323− switch (msr) {
2324− case HV_X64_MSR_GUEST_OS_ID:
2325− data = kvm->arch.hv_guest_os_id;
2326− break;
2327− case HV_X64_MSR_HYPERCALL:
2328− data = kvm->arch.hv_hypercall;
2329− break;
2330− case HV_X64_MSR_TIME_REF_COUNT: {
2331− data =
2332− div_u64(get_kernel_ns() + kvm->arch.kvmclock_offset, 100);
2333− break;
2334− }
2335− case HV_X64_MSR_REFERENCE_TSC:
2336− data = kvm->arch.hv_tsc_page;
2337− break;
2338− default:
2339− vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
2340− return 1;
2341− }
2342−
2343− *pdata = data;
2344− return 0;
2345−}
2346−
2347−static int get_msr_hyperv(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
2348−{
2349− u64 data = 0;
2350−
2351− switch (msr) {
2352− case HV_X64_MSR_VP_INDEX: {
2353− int r;
2354− struct kvm_vcpu *v;
2355− kvm_for_each_vcpu(r, v, vcpu->kvm) {
2356− if (v == vcpu) {
2357− data = r;
2358− break;
2359− }
2360− }
2361− break;
2362− }
2363− case HV_X64_MSR_EOI:
2364− return kvm_hv_vapic_msr_read(vcpu, APIC_EOI, pdata);
2365− case HV_X64_MSR_ICR:
2366− return kvm_hv_vapic_msr_read(vcpu, APIC_ICR, pdata);
2367− case HV_X64_MSR_TPR:
2368− return kvm_hv_vapic_msr_read(vcpu, APIC_TASKPRI, pdata);
2369− case HV_X64_MSR_APIC_ASSIST_PAGE:
2370− data = vcpu->arch.hv_vapic;
2371− break;
2372− default:
2373− vcpu_unimpl(vcpu, "Hyper-V unhandled rdmsr: 0x%x\n", msr);
2374− return 1;
2375− }
2376− *pdata = data;
2377− return 0;
2378−}
2379−
23802193 int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
23812194 {
23822195 switch (msr_info->index) {
@@ -2493,14 +2306,10 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · 110 unmodified lines
24932306 msr_info->data = 0x20000000;
24942307 break;
24952308 case HV_X64_MSR_GUEST_OS_ID ... HV_X64_MSR_SINT15:
2496− if (kvm_hv_msr_partition_wide(msr_info->index)) {
2497− int r;
2498− mutex_lock(&vcpu->kvm->lock);
2499− r = get_msr_hyperv_pw(vcpu, msr_info->index, &msr_info->data);
2500− mutex_unlock(&vcpu->kvm->lock);
2501− return r;
2502− } else
2503− return get_msr_hyperv(vcpu, msr_info->index, &msr_info->data);
2309+ case HV_X64_MSR_CRASH_P0 ... HV_X64_MSR_CRASH_P4:
2310+ case HV_X64_MSR_CRASH_CTL:
2311+ return kvm_hv_get_msr_common(vcpu,
2312+ msr_info->index, &msr_info->data);
25042313 break;
25052314 case MSR_IA32_BBL_CR_CTL3:
25062315 /* This legacy MSR exists but isn't fully documented in current
@@ -2651,6 +2460,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · 144 unmodified lines
26512460 case KVM_CAP_TSC_DEADLINE_TIMER:
26522461 case KVM_CAP_ENABLE_CAP_VM:
26532462 case KVM_CAP_DISABLE_QUIRKS:
2463+ case KVM_CAP_SET_BOOT_CPU_ID:
26542464 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
26552465 case KVM_CAP_ASSIGN_DEV_IRQ:
26562466 case KVM_CAP_PCI_2_3:
@@ -3817,30 +3627,25 @@ long kvm_arch_vm_ioctl(struct file *filp, · 1160 unmodified lines
38173627 r = kvm_ioapic_init(kvm);
38183628 if (r) {
38193629 mutex_lock(&kvm->slots_lock);
3820− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
3821− &vpic->dev_master);
3822− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
3823− &vpic->dev_slave);
3824− kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS,
3825− &vpic->dev_eclr);
3630+ kvm_destroy_pic(vpic);
38263631 mutex_unlock(&kvm->slots_lock);
3827− kfree(vpic);
38283632 goto create_irqchip_unlock;
38293633 }
38303634 } else
38313635 goto create_irqchip_unlock;
3832− smp_wmb();
3833− kvm->arch.vpic = vpic;
3834− smp_wmb();
38353636 r = kvm_setup_default_irq_routing(kvm);
38363637 if (r) {
38373638 mutex_lock(&kvm->slots_lock);
38383639 mutex_lock(&kvm->irq_lock);
38393640 kvm_ioapic_destroy(kvm);
3840− kvm_destroy_pic(kvm);
3641+ kvm_destroy_pic(vpic);
38413642 mutex_unlock(&kvm->irq_lock);
38423643 mutex_unlock(&kvm->slots_lock);
3644+ goto create_irqchip_unlock;
38433645 }
3646+ /* Write kvm->irq_routing before kvm->arch.vpic. */
3647+ smp_wmb();
3648+ kvm->arch.vpic = vpic;
38443649 create_irqchip_unlock:
38453650 mutex_unlock(&kvm->lock);
38463651 break;
@@ -3967,6 +3772,15 @@ long kvm_arch_vm_ioctl(struct file *filp, · 120 unmodified lines
39673772 r = kvm_vm_ioctl_reinject(kvm, &control);
39683773 break;
39693774 }
3775+ case KVM_SET_BOOT_CPU_ID:
3776+ r = 0;
3777+ mutex_lock(&kvm->lock);
3778+ if (atomic_read(&kvm->online_vcpus) != 0)
3779+ r = -EBUSY;
3780+ else
3781+ kvm->arch.bsp_vcpu_id = arg;
3782+ mutex_unlock(&kvm->lock);
3783+ break;
39703784 case KVM_XEN_HVM_CONFIG: {
39713785 r = -EFAULT;
39723786 if (copy_from_user(&kvm->arch.xen_hvm_config, argp,
@@ -5882,66 +5696,6 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu) · 1909 unmodified lines
58825696 }
58835697 EXPORT_SYMBOL_GPL(kvm_emulate_halt);
58845698
5885−int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
5886−{
5887− u64 param, ingpa, outgpa, ret;
5888− uint16_t code, rep_idx, rep_cnt, res = HV_STATUS_SUCCESS, rep_done = 0;
5889− bool fast, longmode;
5890−
5891− /*
5892− * hypercall generates UD from non zero cpl and real mode
5893− * per HYPER-V spec
5894− */
5895− if (kvm_x86_ops->get_cpl(vcpu) != 0 || !is_protmode(vcpu)) {
5896− kvm_queue_exception(vcpu, UD_VECTOR);
5897− return 0;
5898− }
5899−
5900− longmode = is_64_bit_mode(vcpu);
5901−
5902− if (!longmode) {
5903− param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
5904− (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
5905− ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
5906− (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
5907− outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
5908− (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
5909− }
5910−#ifdef CONFIG_X86_64
5911− else {
5912− param = kvm_register_read(vcpu, VCPU_REGS_RCX);
5913− ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
5914− outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
5915− }
5916−#endif
5917−
5918− code = param & 0xffff;
5919− fast = (param >> 16) & 0x1;
5920− rep_cnt = (param >> 32) & 0xfff;
5921− rep_idx = (param >> 48) & 0xfff;
5922−
5923− trace_kvm_hv_hypercall(code, fast, rep_cnt, rep_idx, ingpa, outgpa);
5924−
5925− switch (code) {
5926− case HV_X64_HV_NOTIFY_LONG_SPIN_WAIT:
5927− kvm_vcpu_on_spin(vcpu);
5928− break;
5929− default:
5930− res = HV_STATUS_INVALID_HYPERCALL_CODE;
5931− break;
5932− }
5933−
5934− ret = res | (((u64)rep_done & 0xfff) << 32);
5935− if (longmode) {
5936− kvm_register_write(vcpu, VCPU_REGS_RAX, ret);
5937− } else {
5938− kvm_register_write(vcpu, VCPU_REGS_RDX, ret >> 32);
5939− kvm_register_write(vcpu, VCPU_REGS_RAX, ret & 0xffffffff);
5940− }
5941−
5942− return 1;
5943−}
5944−
59455699 /*
59465700 * kvm_pv_kick_cpu_op: Kick a vcpu.
59475701 *
@@ -6518,6 +6272,12 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) · 570 unmodified lines
65186272 vcpu_scan_ioapic(vcpu);
65196273 if (kvm_check_request(KVM_REQ_APIC_PAGE_RELOAD, vcpu))
65206274 kvm_vcpu_reload_apic_access_page(vcpu);
6275+ if (kvm_check_request(KVM_REQ_HV_CRASH, vcpu)) {
6276+ vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT;
6277+ vcpu->run->system_event.type = KVM_SYSTEM_EVENT_CRASH;
6278+ r = 0;
6279+ goto out;
6280+ }
65216281 }
65226282
65236283 if (kvm_check_request(KVM_REQ_EVENT, vcpu) || req_int_win) {
@@ -7540,6 +7300,17 @@ void kvm_arch_check_processor_compat(void *rtn) · 1016 unmodified lines
75407300 kvm_x86_ops->check_processor_compatibility(rtn);
75417301 }
75427302
7303+bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu)
7304+{
7305+ return vcpu->kvm->arch.bsp_vcpu_id == vcpu->vcpu_id;
7306+}
7307+EXPORT_SYMBOL_GPL(kvm_vcpu_is_reset_bsp);
7308+
7309+bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
7310+{
7311+ return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
7312+}
7313+
75437314 bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu)
75447315 {
75457316 return irqchip_in_kernel(vcpu->kvm) == (vcpu->arch.apic != NULL);
arch/x86/kvm/x86.h+5−0
@@ -147,6 +147,11 @@ static inline void kvm_register_writel(struct kvm_vcpu *vcpu, · 146 unmodified lines
147147 return kvm_register_write(vcpu, reg, val);
148148 }
149149
150+static inline u64 get_kernel_ns(void)
151+{
152+ return ktime_get_boot_ns();
153+}
154+
150155 static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk)
151156 {
152157 return !(kvm->arch.disabled_quirks & quirk);
include/linux/kvm_host.h+8−16
@@ -139,6 +139,7 @@ static inline bool is_error_page(struct page *page) · 138 unmodified lines
139139 #define KVM_REQ_DISABLE_IBS 24
140140 #define KVM_REQ_APIC_PAGE_RELOAD 25
141141 #define KVM_REQ_SMI 26
142+#define KVM_REQ_HV_CRASH 27
142143
143144 #define KVM_USERSPACE_IRQ_SOURCE_ID 0
144145 #define KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID 1
@@ -363,9 +364,6 @@ struct kvm { · 218 unmodified lines
363364 struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM];
364365 struct srcu_struct srcu;
365366 struct srcu_struct irq_srcu;
366−#ifdef CONFIG_KVM_APIC_ARCHITECTURE
367− u32 bsp_vcpu_id;
368−#endif
369367 struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
370368 atomic_t online_vcpus;
371369 int last_boosted_vcpu;
@@ -424,8 +422,15 @@ struct kvm { · 52 unmodified lines
424422 #define vcpu_unimpl(vcpu, fmt, ...) \
425423 kvm_pr_unimpl("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
426424
425+#define vcpu_debug(vcpu, fmt, ...) \
426+ kvm_debug("vcpu%i " fmt, (vcpu)->vcpu_id, ## __VA_ARGS__)
427+
427428 static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
428429 {
430+ /* Pairs with smp_wmb() in kvm_vm_ioctl_create_vcpu, in case
431+ * the caller has read kvm->online_vcpus before (as is the case
432+ * for kvm_for_each_vcpu, for example).
433+ */
429434 smp_rmb();
430435 return kvm->vcpus[i];
431436 }
@@ -1055,22 +1060,9 @@ static inline int kvm_ioeventfd(struct kvm *kvm, struct kvm_ioeventfd *args) · 623 unmodified lines
10551060 #endif /* CONFIG_HAVE_KVM_EVENTFD */
10561061
10571062 #ifdef CONFIG_KVM_APIC_ARCHITECTURE
1058−static inline bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu)
1059−{
1060− return vcpu->kvm->bsp_vcpu_id == vcpu->vcpu_id;
1061−}
1062−
1063−static inline bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu)
1064−{
1065− return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0;
1066−}
1067−
10681063 bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu);
1069−
10701064 #else
1071−
10721065 static inline bool kvm_vcpu_compatible(struct kvm_vcpu *vcpu) { return true; }
1073−
10741066 #endif
10751067
10761068 static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)
include/uapi/linux/kvm.h+2−0
@@ -317,6 +317,7 @@ struct kvm_run { · 316 unmodified lines
317317 struct {
318318 #define KVM_SYSTEM_EVENT_SHUTDOWN 1
319319 #define KVM_SYSTEM_EVENT_RESET 2
320+#define KVM_SYSTEM_EVENT_CRASH 3
320321 __u32 type;
321322 __u64 flags;
322323 } system_event;
@@ -481,6 +482,7 @@ struct kvm_s390_psw { · 158 unmodified lines
481482 ((ai) << 26))
482483 #define KVM_S390_INT_IO_MIN 0x00000000u
483484 #define KVM_S390_INT_IO_MAX 0xfffdffffu
485+#define KVM_S390_INT_IO_AI_MASK 0x04000000u
484486
485487
486488 struct kvm_s390_interrupt {
virt/kvm/kvm_main.c+5−14
@@ -2206,6 +2206,11 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) · 2205 unmodified lines
22062206 }
22072207
22082208 kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu;
2209+
2210+ /*
2211+ * Pairs with smp_rmb() in kvm_get_vcpu. Write kvm->vcpus
2212+ * before kvm->online_vcpu's incremented value.
2213+ */
22092214 smp_wmb();
22102215 atomic_inc(&kvm->online_vcpus);
22112216
@@ -2618,9 +2623,6 @@ static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) · 406 unmodified lines
26182623 case KVM_CAP_USER_MEMORY:
26192624 case KVM_CAP_DESTROY_MEMORY_REGION_WORKS:
26202625 case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS:
2621−#ifdef CONFIG_KVM_APIC_ARCHITECTURE
2622− case KVM_CAP_SET_BOOT_CPU_ID:
2623−#endif
26242626 case KVM_CAP_INTERNAL_ERROR_DATA:
26252627 #ifdef CONFIG_HAVE_KVM_MSI
26262628 case KVM_CAP_SIGNAL_MSI:
@@ -2716,17 +2718,6 @@ static long kvm_vm_ioctl(struct file *filp, · 89 unmodified lines
27162718 r = kvm_ioeventfd(kvm, &data);
27172719 break;
27182720 }
2719−#ifdef CONFIG_KVM_APIC_ARCHITECTURE
2720− case KVM_SET_BOOT_CPU_ID:
2721− r = 0;
2722− mutex_lock(&kvm->lock);
2723− if (atomic_read(&kvm->online_vcpus) != 0)
2724− r = -EBUSY;
2725− else
2726− kvm->bsp_vcpu_id = arg;
2727− mutex_unlock(&kvm->lock);
2728− break;
2729−#endif
27302721 #ifdef CONFIG_HAVE_KVM_MSI
27312722 case KVM_SIGNAL_MSI: {
27322723 struct kvm_msi msi;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t