Lines Matching refs:vcpu

59 static void enable_all_hw_bp(struct kvm_vcpu *vcpu)  in enable_all_hw_bp()  argument
62 u64 *cr9 = &vcpu->arch.sie_block->gcr[9]; in enable_all_hw_bp()
63 u64 *cr10 = &vcpu->arch.sie_block->gcr[10]; in enable_all_hw_bp()
64 u64 *cr11 = &vcpu->arch.sie_block->gcr[11]; in enable_all_hw_bp()
67 if (vcpu->arch.guestdbg.nr_hw_bp <= 0 || in enable_all_hw_bp()
68 vcpu->arch.guestdbg.hw_bp_info == NULL) in enable_all_hw_bp()
79 for (i = 0; i < vcpu->arch.guestdbg.nr_hw_bp; i++) { in enable_all_hw_bp()
80 start = vcpu->arch.guestdbg.hw_bp_info[i].addr; in enable_all_hw_bp()
81 len = vcpu->arch.guestdbg.hw_bp_info[i].len; in enable_all_hw_bp()
99 static void enable_all_hw_wp(struct kvm_vcpu *vcpu) in enable_all_hw_wp() argument
102 u64 *cr9 = &vcpu->arch.sie_block->gcr[9]; in enable_all_hw_wp()
103 u64 *cr10 = &vcpu->arch.sie_block->gcr[10]; in enable_all_hw_wp()
104 u64 *cr11 = &vcpu->arch.sie_block->gcr[11]; in enable_all_hw_wp()
107 if (vcpu->arch.guestdbg.nr_hw_wp <= 0 || in enable_all_hw_wp()
108 vcpu->arch.guestdbg.hw_wp_info == NULL) in enable_all_hw_wp()
121 for (i = 0; i < vcpu->arch.guestdbg.nr_hw_wp; i++) { in enable_all_hw_wp()
122 start = vcpu->arch.guestdbg.hw_wp_info[i].addr; in enable_all_hw_wp()
123 len = vcpu->arch.guestdbg.hw_wp_info[i].len; in enable_all_hw_wp()
130 void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu) in kvm_s390_backup_guest_per_regs() argument
132 vcpu->arch.guestdbg.cr0 = vcpu->arch.sie_block->gcr[0]; in kvm_s390_backup_guest_per_regs()
133 vcpu->arch.guestdbg.cr9 = vcpu->arch.sie_block->gcr[9]; in kvm_s390_backup_guest_per_regs()
134 vcpu->arch.guestdbg.cr10 = vcpu->arch.sie_block->gcr[10]; in kvm_s390_backup_guest_per_regs()
135 vcpu->arch.guestdbg.cr11 = vcpu->arch.sie_block->gcr[11]; in kvm_s390_backup_guest_per_regs()
138 void kvm_s390_restore_guest_per_regs(struct kvm_vcpu *vcpu) in kvm_s390_restore_guest_per_regs() argument
140 vcpu->arch.sie_block->gcr[0] = vcpu->arch.guestdbg.cr0; in kvm_s390_restore_guest_per_regs()
141 vcpu->arch.sie_block->gcr[9] = vcpu->arch.guestdbg.cr9; in kvm_s390_restore_guest_per_regs()
142 vcpu->arch.sie_block->gcr[10] = vcpu->arch.guestdbg.cr10; in kvm_s390_restore_guest_per_regs()
143 vcpu->arch.sie_block->gcr[11] = vcpu->arch.guestdbg.cr11; in kvm_s390_restore_guest_per_regs()
146 void kvm_s390_patch_guest_per_regs(struct kvm_vcpu *vcpu) in kvm_s390_patch_guest_per_regs() argument
154 if (guestdbg_sstep_enabled(vcpu)) { in kvm_s390_patch_guest_per_regs()
156 vcpu->arch.sie_block->gcr[0] &= ~CR0_CLOCK_COMPARATOR_SUBMASK; in kvm_s390_patch_guest_per_regs()
157 vcpu->arch.sie_block->gcr[9] |= PER_EVENT_IFETCH; in kvm_s390_patch_guest_per_regs()
158 vcpu->arch.sie_block->gcr[10] = 0; in kvm_s390_patch_guest_per_regs()
159 vcpu->arch.sie_block->gcr[11] = -1UL; in kvm_s390_patch_guest_per_regs()
162 if (guestdbg_hw_bp_enabled(vcpu)) { in kvm_s390_patch_guest_per_regs()
163 enable_all_hw_bp(vcpu); in kvm_s390_patch_guest_per_regs()
164 enable_all_hw_wp(vcpu); in kvm_s390_patch_guest_per_regs()
168 if (vcpu->arch.sie_block->gcr[9] & PER_EVENT_NULLIFICATION) in kvm_s390_patch_guest_per_regs()
169 vcpu->arch.sie_block->gcr[9] &= ~PER_EVENT_NULLIFICATION; in kvm_s390_patch_guest_per_regs()
174 static int __import_wp_info(struct kvm_vcpu *vcpu, in __import_wp_info() argument
191 ret = read_guest_abs(vcpu, wp_info->phys_addr, wp_info->old_data, in __import_wp_info()
203 int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, in kvm_s390_import_bp_data() argument
256 ret = __import_wp_info(vcpu, &bp_data[i], in kvm_s390_import_bp_data()
270 vcpu->arch.guestdbg.nr_hw_bp = nr_bp; in kvm_s390_import_bp_data()
271 vcpu->arch.guestdbg.hw_bp_info = bp_info; in kvm_s390_import_bp_data()
272 vcpu->arch.guestdbg.nr_hw_wp = nr_wp; in kvm_s390_import_bp_data()
273 vcpu->arch.guestdbg.hw_wp_info = wp_info; in kvm_s390_import_bp_data()
282 void kvm_s390_clear_bp_data(struct kvm_vcpu *vcpu) in kvm_s390_clear_bp_data() argument
287 for (i = 0; i < vcpu->arch.guestdbg.nr_hw_wp; i++) { in kvm_s390_clear_bp_data()
288 hw_wp_info = &vcpu->arch.guestdbg.hw_wp_info[i]; in kvm_s390_clear_bp_data()
292 kfree(vcpu->arch.guestdbg.hw_wp_info); in kvm_s390_clear_bp_data()
293 vcpu->arch.guestdbg.hw_wp_info = NULL; in kvm_s390_clear_bp_data()
295 kfree(vcpu->arch.guestdbg.hw_bp_info); in kvm_s390_clear_bp_data()
296 vcpu->arch.guestdbg.hw_bp_info = NULL; in kvm_s390_clear_bp_data()
298 vcpu->arch.guestdbg.nr_hw_wp = 0; in kvm_s390_clear_bp_data()
299 vcpu->arch.guestdbg.nr_hw_bp = 0; in kvm_s390_clear_bp_data()
313 static struct kvm_hw_bp_info_arch *find_hw_bp(struct kvm_vcpu *vcpu, in find_hw_bp() argument
316 struct kvm_hw_bp_info_arch *bp_info = vcpu->arch.guestdbg.hw_bp_info; in find_hw_bp()
319 if (vcpu->arch.guestdbg.nr_hw_bp == 0) in find_hw_bp()
322 for (i = 0; i < vcpu->arch.guestdbg.nr_hw_bp; i++) { in find_hw_bp()
338 static struct kvm_hw_wp_info_arch *any_wp_changed(struct kvm_vcpu *vcpu) in any_wp_changed() argument
344 if (vcpu->arch.guestdbg.nr_hw_wp == 0) in any_wp_changed()
347 for (i = 0; i < vcpu->arch.guestdbg.nr_hw_wp; i++) { in any_wp_changed()
348 wp_info = &vcpu->arch.guestdbg.hw_wp_info[i]; in any_wp_changed()
357 if (!read_guest_abs(vcpu, wp_info->phys_addr, temp, in any_wp_changed()
371 void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu) in kvm_s390_prepare_debug_exit() argument
373 vcpu->run->exit_reason = KVM_EXIT_DEBUG; in kvm_s390_prepare_debug_exit()
374 vcpu->guest_debug &= ~KVM_GUESTDBG_EXIT_PENDING; in kvm_s390_prepare_debug_exit()
388 static int debug_exit_required(struct kvm_vcpu *vcpu, u8 perc, in debug_exit_required() argument
391 struct kvm_debug_exit_arch *debug_exit = &vcpu->run->debug.arch; in debug_exit_required()
394 unsigned long addr = vcpu->arch.sie_block->gpsw.addr; in debug_exit_required()
396 if (guestdbg_hw_bp_enabled(vcpu)) { in debug_exit_required()
398 vcpu->arch.guestdbg.nr_hw_wp > 0) { in debug_exit_required()
399 wp_info = any_wp_changed(vcpu); in debug_exit_required()
407 vcpu->arch.guestdbg.nr_hw_bp > 0) { in debug_exit_required()
408 bp_info = find_hw_bp(vcpu, addr); in debug_exit_required()
413 vcpu->arch.guestdbg.last_bp = addr; in debug_exit_required()
417 bp_info = find_hw_bp(vcpu, peraddr); in debug_exit_required()
418 if (bp_info && vcpu->arch.guestdbg.last_bp != peraddr) { in debug_exit_required()
425 if (guestdbg_sstep_enabled(vcpu) && per_bp_event(perc)) { in debug_exit_required()
436 static int per_fetched_addr(struct kvm_vcpu *vcpu, unsigned long *addr) in per_fetched_addr() argument
442 if (vcpu->arch.sie_block->icptcode == ICPT_PROGI) { in per_fetched_addr()
444 *addr = vcpu->arch.sie_block->peraddr; in per_fetched_addr()
450 rc = read_guest_instr(vcpu, *addr, &opcode, 2); in per_fetched_addr()
459 *addr = __rewind_psw(vcpu->arch.sie_block->gpsw, in per_fetched_addr()
460 kvm_s390_get_ilen(vcpu)); in per_fetched_addr()
461 if (vcpu->arch.sie_block->icptstatus & 0x01) { in per_fetched_addr()
462 exec_ilen = (vcpu->arch.sie_block->icptstatus & 0x60) >> 4; in per_fetched_addr()
470 rc = read_guest_instr(vcpu, *addr, &opcode, exec_ilen); in per_fetched_addr()
485 *addr = base ? vcpu->run->s.regs.gprs[base] : 0; in per_fetched_addr()
486 *addr += index ? vcpu->run->s.regs.gprs[index] : 0; in per_fetched_addr()
489 *addr = kvm_s390_logical_to_effective(vcpu, *addr); in per_fetched_addr()
494 #define guest_per_enabled(vcpu) \ argument
495 (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER)
497 int kvm_s390_handle_per_ifetch_icpt(struct kvm_vcpu *vcpu) in kvm_s390_handle_per_ifetch_icpt() argument
499 const u64 cr10 = vcpu->arch.sie_block->gcr[10]; in kvm_s390_handle_per_ifetch_icpt()
500 const u64 cr11 = vcpu->arch.sie_block->gcr[11]; in kvm_s390_handle_per_ifetch_icpt()
501 const u8 ilen = kvm_s390_get_ilen(vcpu); in kvm_s390_handle_per_ifetch_icpt()
505 .per_address = __rewind_psw(vcpu->arch.sie_block->gpsw, ilen), in kvm_s390_handle_per_ifetch_icpt()
515 if (!guestdbg_enabled(vcpu)) in kvm_s390_handle_per_ifetch_icpt()
516 return kvm_s390_inject_prog_irq(vcpu, &pgm_info); in kvm_s390_handle_per_ifetch_icpt()
518 if (debug_exit_required(vcpu, pgm_info.per_code, pgm_info.per_address)) in kvm_s390_handle_per_ifetch_icpt()
519 vcpu->guest_debug |= KVM_GUESTDBG_EXIT_PENDING; in kvm_s390_handle_per_ifetch_icpt()
521 if (!guest_per_enabled(vcpu) || in kvm_s390_handle_per_ifetch_icpt()
522 !(vcpu->arch.sie_block->gcr[9] & PER_EVENT_IFETCH)) in kvm_s390_handle_per_ifetch_icpt()
525 rc = per_fetched_addr(vcpu, &fetched_addr); in kvm_s390_handle_per_ifetch_icpt()
530 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); in kvm_s390_handle_per_ifetch_icpt()
533 return kvm_s390_inject_prog_irq(vcpu, &pgm_info); in kvm_s390_handle_per_ifetch_icpt()
537 static int filter_guest_per_event(struct kvm_vcpu *vcpu) in filter_guest_per_event() argument
539 const u8 perc = vcpu->arch.sie_block->perc; in filter_guest_per_event()
540 u64 addr = vcpu->arch.sie_block->gpsw.addr; in filter_guest_per_event()
541 u64 cr9 = vcpu->arch.sie_block->gcr[9]; in filter_guest_per_event()
542 u64 cr10 = vcpu->arch.sie_block->gcr[10]; in filter_guest_per_event()
543 u64 cr11 = vcpu->arch.sie_block->gcr[11]; in filter_guest_per_event()
549 if (!guest_per_enabled(vcpu)) in filter_guest_per_event()
560 rc = per_fetched_addr(vcpu, &fetched_addr); in filter_guest_per_event()
574 vcpu->arch.sie_block->perc = guest_perc; in filter_guest_per_event()
577 vcpu->arch.sie_block->iprcc &= ~PGM_PER; in filter_guest_per_event()
581 #define pssec(vcpu) (vcpu->arch.sie_block->gcr[1] & _ASCE_SPACE_SWITCH) argument
582 #define hssec(vcpu) (vcpu->arch.sie_block->gcr[13] & _ASCE_SPACE_SWITCH) argument
583 #define old_ssec(vcpu) ((vcpu->arch.sie_block->tecmc >> 31) & 0x1) argument
584 #define old_as_is_home(vcpu) !(vcpu->arch.sie_block->tecmc & 0xffff) argument
586 int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu) in kvm_s390_handle_per_event() argument
590 if (debug_exit_required(vcpu, vcpu->arch.sie_block->perc, in kvm_s390_handle_per_event()
591 vcpu->arch.sie_block->peraddr)) in kvm_s390_handle_per_event()
592 vcpu->guest_debug |= KVM_GUESTDBG_EXIT_PENDING; in kvm_s390_handle_per_event()
594 rc = filter_guest_per_event(vcpu); in kvm_s390_handle_per_event()
604 if (vcpu->arch.sie_block->iprcc == PGM_SPACE_SWITCH) { in kvm_s390_handle_per_event()
605 vcpu->arch.sie_block->iprcc = 0; in kvm_s390_handle_per_event()
606 new_as = psw_bits(vcpu->arch.sie_block->gpsw).as; in kvm_s390_handle_per_event()
613 if (((new_as == PSW_BITS_AS_HOME) ^ old_as_is_home(vcpu)) && in kvm_s390_handle_per_event()
614 (pssec(vcpu) || hssec(vcpu))) in kvm_s390_handle_per_event()
615 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH; in kvm_s390_handle_per_event()
621 if (new_as == PSW_BITS_AS_PRIMARY && !old_as_is_home(vcpu) && in kvm_s390_handle_per_event()
622 (pssec(vcpu) || old_ssec(vcpu))) in kvm_s390_handle_per_event()
623 vcpu->arch.sie_block->iprcc = PGM_SPACE_SWITCH; in kvm_s390_handle_per_event()