| 1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 |
/* |
| 3 |
* definition for kvm on s390 |
| 4 |
* |
| 5 |
* Copyright IBM Corp. 2008, 2020 |
| 6 |
* |
| 7 |
* Author(s): Carsten Otte <[email protected]> |
| 8 |
* Christian Borntraeger <[email protected]> |
| 9 |
* Christian Ehrhardt <[email protected]> |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef ARCH_S390_KVM_S390_H |
| 13 |
#define ARCH_S390_KVM_S390_H |
| 14 |
|
| 15 |
#include <linux/hrtimer.h> |
| 16 |
#include <linux/kvm.h> |
| 17 |
#include <linux/kvm_host.h> |
| 18 |
#include <linux/lockdep.h> |
| 19 |
#include <asm/facility.h> |
| 20 |
#include <asm/processor.h> |
| 21 |
#include <asm/sclp.h> |
| 22 |
#include "dat.h" |
| 23 |
#include "gmap.h" |
| 24 |
|
| 25 |
#define KVM_S390_UCONTROL_MEMSLOT (KVM_USER_MEM_SLOTS + 0) |
| 26 |
|
| 27 |
union kvm_s390_quad { |
| 28 |
__uint128_t sixteen; |
| 29 |
unsigned long eight; |
| 30 |
unsigned int four; |
| 31 |
unsigned short two; |
| 32 |
unsigned char one; |
| 33 |
}; |
| 34 |
|
| 35 |
static inline void kvm_s390_fpu_store(struct kvm_run *run) |
| 36 |
{ |
| 37 |
fpu_stfpc(&run->s.regs.fpc); |
| 38 |
if (cpu_has_vx()) |
| 39 |
save_vx_regs((__vector128 *)&run->s.regs.vrs); |
| 40 |
else |
| 41 |
save_fp_regs((freg_t *)&run->s.regs.fprs); |
| 42 |
} |
| 43 |
|
| 44 |
static inline void kvm_s390_fpu_load(struct kvm_run *run) |
| 45 |
{ |
| 46 |
fpu_lfpc_safe(&run->s.regs.fpc); |
| 47 |
if (cpu_has_vx()) |
| 48 |
load_vx_regs((__vector128 *)&run->s.regs.vrs); |
| 49 |
else |
| 50 |
load_fp_regs((freg_t *)&run->s.regs.fprs); |
| 51 |
} |
| 52 |
|
| 53 |
/* Transactional Memory Execution related macros */ |
| 54 |
#define IS_TE_ENABLED(vcpu) ((vcpu->arch.sie_block->ecb & ECB_TE)) |
| 55 |
#define TDB_FORMAT1 1 |
| 56 |
#define IS_ITDB_VALID(vcpu) \ |
| 57 |
((*(char *)phys_to_virt((vcpu)->arch.sie_block->itdba) == TDB_FORMAT1)) |
| 58 |
|
| 59 |
extern debug_info_t *kvm_s390_dbf; |
| 60 |
extern debug_info_t *kvm_s390_dbf_uv; |
| 61 |
|
| 62 |
#define KVM_UV_EVENT(d_kvm, d_loglevel, d_string, d_args...)\ |
| 63 |
do { \ |
| 64 |
debug_sprintf_event((d_kvm)->arch.dbf, d_loglevel, d_string "\n", \ |
| 65 |
d_args); \ |
| 66 |
debug_sprintf_event(kvm_s390_dbf_uv, d_loglevel, \ |
| 67 |
"%d: " d_string "\n", (d_kvm)->userspace_pid, \ |
| 68 |
d_args); \ |
| 69 |
} while (0) |
| 70 |
|
| 71 |
#define KVM_EVENT(d_loglevel, d_string, d_args...)\ |
| 72 |
do { \ |
| 73 |
debug_sprintf_event(kvm_s390_dbf, d_loglevel, d_string "\n", \ |
| 74 |
d_args); \ |
| 75 |
} while (0) |
| 76 |
|
| 77 |
#define VM_EVENT(d_kvm, d_loglevel, d_string, d_args...)\ |
| 78 |
do { \ |
| 79 |
debug_sprintf_event(d_kvm->arch.dbf, d_loglevel, d_string "\n", \ |
| 80 |
d_args); \ |
| 81 |
} while (0) |
| 82 |
|
| 83 |
#define VCPU_EVENT(d_vcpu, d_loglevel, d_string, d_args...)\ |
| 84 |
do { \ |
| 85 |
debug_sprintf_event(d_vcpu->kvm->arch.dbf, d_loglevel, \ |
| 86 |
"%02d[%016lx-%016lx]: " d_string "\n", d_vcpu->vcpu_id, \ |
| 87 |
d_vcpu->arch.sie_block->gpsw.mask, d_vcpu->arch.sie_block->gpsw.addr,\ |
| 88 |
d_args); \ |
| 89 |
} while (0) |
| 90 |
|
| 91 |
static inline void kvm_s390_set_cpuflags(struct kvm_vcpu *vcpu, u32 flags) |
| 92 |
{ |
| 93 |
atomic_or(flags, &vcpu->arch.sie_block->cpuflags); |
| 94 |
} |
| 95 |
|
| 96 |
static inline void kvm_s390_clear_cpuflags(struct kvm_vcpu *vcpu, u32 flags) |
| 97 |
{ |
| 98 |
atomic_andnot(flags, &vcpu->arch.sie_block->cpuflags); |
| 99 |
} |
| 100 |
|
| 101 |
static inline bool kvm_s390_test_cpuflags(struct kvm_vcpu *vcpu, u32 flags) |
| 102 |
{ |
| 103 |
return (atomic_read(&vcpu->arch.sie_block->cpuflags) & flags) == flags; |
| 104 |
} |
| 105 |
|
| 106 |
static inline int is_vcpu_stopped(struct kvm_vcpu *vcpu) |
| 107 |
{ |
| 108 |
return kvm_s390_test_cpuflags(vcpu, CPUSTAT_STOPPED); |
| 109 |
} |
| 110 |
|
| 111 |
static inline int is_vcpu_idle(struct kvm_vcpu *vcpu) |
| 112 |
{ |
| 113 |
return test_bit(vcpu->vcpu_idx, vcpu->kvm->arch.idle_mask); |
| 114 |
} |
| 115 |
|
| 116 |
static inline int kvm_is_ucontrol(struct kvm *kvm) |
| 117 |
{ |
| 118 |
#ifdef CONFIG_KVM_S390_UCONTROL |
| 119 |
return test_bit(GMAP_FLAG_IS_UCONTROL, &kvm->arch.gmap->flags); |
| 120 |
#else |
| 121 |
return 0; |
| 122 |
#endif |
| 123 |
} |
| 124 |
|
| 125 |
#define GUEST_PREFIX_SHIFT 13 |
| 126 |
static inline u32 kvm_s390_get_prefix(struct kvm_vcpu *vcpu) |
| 127 |
{ |
| 128 |
return vcpu->arch.sie_block->prefix << GUEST_PREFIX_SHIFT; |
| 129 |
} |
| 130 |
|
| 131 |
static inline void kvm_s390_set_prefix(struct kvm_vcpu *vcpu, u32 prefix) |
| 132 |
{ |
| 133 |
VCPU_EVENT(vcpu, 3, "set prefix of cpu %03u to 0x%x", vcpu->vcpu_id, |
| 134 |
prefix); |
| 135 |
vcpu->arch.sie_block->prefix = prefix >> GUEST_PREFIX_SHIFT; |
| 136 |
kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu); |
| 137 |
kvm_make_request(KVM_REQ_REFRESH_GUEST_PREFIX, vcpu); |
| 138 |
} |
| 139 |
|
| 140 |
static inline u64 kvm_s390_get_base_disp_s(struct kvm_vcpu *vcpu, u8 *ar) |
| 141 |
{ |
| 142 |
u32 base2 = vcpu->arch.sie_block->ipb >> 28; |
| 143 |
u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16); |
| 144 |
|
| 145 |
if (ar) |
| 146 |
*ar = base2; |
| 147 |
|
| 148 |
return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2; |
| 149 |
} |
| 150 |
|
| 151 |
static inline u64 kvm_s390_get_base_disp_siy(struct kvm_vcpu *vcpu, u8 *ar) |
| 152 |
{ |
| 153 |
u32 base1 = vcpu->arch.sie_block->ipb >> 28; |
| 154 |
s64 disp1; |
| 155 |
|
| 156 |
/* The displacement is a 20bit _SIGNED_ value */ |
| 157 |
disp1 = sign_extend64(((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) + |
| 158 |
((vcpu->arch.sie_block->ipb & 0xff00) << 4), 19); |
| 159 |
|
| 160 |
if (ar) |
| 161 |
*ar = base1; |
| 162 |
|
| 163 |
return (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1; |
| 164 |
} |
| 165 |
|
| 166 |
static inline void kvm_s390_get_base_disp_sse(struct kvm_vcpu *vcpu, |
| 167 |
u64 *address1, u64 *address2, |
| 168 |
u8 *ar_b1, u8 *ar_b2) |
| 169 |
{ |
| 170 |
u32 base1 = (vcpu->arch.sie_block->ipb & 0xf0000000) >> 28; |
| 171 |
u32 disp1 = (vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16; |
| 172 |
u32 base2 = (vcpu->arch.sie_block->ipb & 0xf000) >> 12; |
| 173 |
u32 disp2 = vcpu->arch.sie_block->ipb & 0x0fff; |
| 174 |
|
| 175 |
*address1 = (base1 ? vcpu->run->s.regs.gprs[base1] : 0) + disp1; |
| 176 |
*address2 = (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2; |
| 177 |
|
| 178 |
if (ar_b1) |
| 179 |
*ar_b1 = base1; |
| 180 |
if (ar_b2) |
| 181 |
*ar_b2 = base2; |
| 182 |
} |
| 183 |
|
| 184 |
static inline void kvm_s390_get_regs_rre(struct kvm_vcpu *vcpu, int *r1, int *r2) |
| 185 |
{ |
| 186 |
if (r1) |
| 187 |
*r1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 20; |
| 188 |
if (r2) |
| 189 |
*r2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16; |
| 190 |
} |
| 191 |
|
| 192 |
static inline u64 kvm_s390_get_base_disp_rsy(struct kvm_vcpu *vcpu, u8 *ar) |
| 193 |
{ |
| 194 |
u32 base2 = vcpu->arch.sie_block->ipb >> 28; |
| 195 |
u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) + |
| 196 |
((vcpu->arch.sie_block->ipb & 0xff00) << 4); |
| 197 |
/* The displacement is a 20bit _SIGNED_ value */ |
| 198 |
if (disp2 & 0x80000) |
| 199 |
disp2+=0xfff00000; |
| 200 |
|
| 201 |
if (ar) |
| 202 |
*ar = base2; |
| 203 |
|
| 204 |
return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + (long)(int)disp2; |
| 205 |
} |
| 206 |
|
| 207 |
static inline u64 kvm_s390_get_base_disp_rs(struct kvm_vcpu *vcpu, u8 *ar) |
| 208 |
{ |
| 209 |
u32 base2 = vcpu->arch.sie_block->ipb >> 28; |
| 210 |
u32 disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16); |
| 211 |
|
| 212 |
if (ar) |
| 213 |
*ar = base2; |
| 214 |
|
| 215 |
return (base2 ? vcpu->run->s.regs.gprs[base2] : 0) + disp2; |
| 216 |
} |
| 217 |
|
| 218 |
/* Set the condition code in the guest program status word */ |
| 219 |
static inline void kvm_s390_set_psw_cc(struct kvm_vcpu *vcpu, unsigned long cc) |
| 220 |
{ |
| 221 |
vcpu->arch.sie_block->gpsw.mask &= ~(3UL << 44); |
| 222 |
vcpu->arch.sie_block->gpsw.mask |= cc << 44; |
| 223 |
} |
| 224 |
|
| 225 |
/* test availability of facility in a kvm instance */ |
| 226 |
static inline int test_kvm_facility(struct kvm *kvm, unsigned long nr) |
| 227 |
{ |
| 228 |
return __test_facility(nr, kvm->arch.model.fac_mask) && |
| 229 |
__test_facility(nr, kvm->arch.model.fac_list); |
| 230 |
} |
| 231 |
|
| 232 |
static inline int set_kvm_facility(u64 *fac_list, unsigned long nr) |
| 233 |
{ |
| 234 |
unsigned char *ptr; |
| 235 |
|
| 236 |
if (nr >= MAX_FACILITY_BIT) |
| 237 |
return -EINVAL; |
| 238 |
ptr = (unsigned char *) fac_list + (nr >> 3); |
| 239 |
*ptr |= (0x80UL >> (nr & 7)); |
| 240 |
return 0; |
| 241 |
} |
| 242 |
|
| 243 |
static inline int test_kvm_cpu_feat(struct kvm *kvm, unsigned long nr) |
| 244 |
{ |
| 245 |
WARN_ON_ONCE(nr >= KVM_S390_VM_CPU_FEAT_NR_BITS); |
| 246 |
return test_bit_inv(nr, kvm->arch.cpu_feat); |
| 247 |
} |
| 248 |
|
| 249 |
/* are cpu states controlled by user space */ |
| 250 |
static inline int kvm_s390_user_cpu_state_ctrl(struct kvm *kvm) |
| 251 |
{ |
| 252 |
return kvm->arch.user_cpu_state_ctrl != 0; |
| 253 |
} |
| 254 |
|
| 255 |
static inline void kvm_s390_set_user_cpu_state_ctrl(struct kvm *kvm) |
| 256 |
{ |
| 257 |
if (kvm->arch.user_cpu_state_ctrl) |
| 258 |
return; |
| 259 |
|
| 260 |
VM_EVENT(kvm, 3, "%s", "ENABLE: Userspace CPU state control"); |
| 261 |
kvm->arch.user_cpu_state_ctrl = 1; |
| 262 |
} |
| 263 |
|
| 264 |
/* get the end gfn of the last (highest gfn) memslot */ |
| 265 |
static inline unsigned long kvm_s390_get_gfn_end(struct kvm_memslots *slots) |
| 266 |
{ |
| 267 |
struct rb_node *node; |
| 268 |
struct kvm_memory_slot *ms; |
| 269 |
|
| 270 |
if (WARN_ON(kvm_memslots_empty(slots))) |
| 271 |
return 0; |
| 272 |
|
| 273 |
node = rb_last(&slots->gfn_tree); |
| 274 |
ms = container_of(node, struct kvm_memory_slot, gfn_node[slots->node_idx]); |
| 275 |
return ms->base_gfn + ms->npages; |
| 276 |
} |
| 277 |
|
| 278 |
static inline u32 kvm_s390_get_gisa_desc(struct kvm *kvm) |
| 279 |
{ |
| 280 |
u32 gd; |
| 281 |
|
| 282 |
if (!kvm->arch.gisa_int.origin) |
| 283 |
return 0; |
| 284 |
|
| 285 |
gd = virt_to_phys(kvm->arch.gisa_int.origin); |
| 286 |
|
| 287 |
if (gd && sclp.has_gisaf) |
| 288 |
gd |= GISA_FORMAT1; |
| 289 |
return gd; |
| 290 |
} |
| 291 |
|
| 292 |
static inline hva_t gpa_to_hva(struct kvm *kvm, gpa_t gpa) |
| 293 |
{ |
| 294 |
hva_t hva = gfn_to_hva(kvm, gpa_to_gfn(gpa)); |
| 295 |
|
| 296 |
if (!kvm_is_error_hva(hva)) |
| 297 |
hva |= offset_in_page(gpa); |
| 298 |
return hva; |
| 299 |
} |
| 300 |
|
| 301 |
/* implemented in pv.c */ |
| 302 |
int kvm_s390_pv_destroy_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc); |
| 303 |
int kvm_s390_pv_create_cpu(struct kvm_vcpu *vcpu, u16 *rc, u16 *rrc); |
| 304 |
int kvm_s390_pv_set_aside(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 305 |
int kvm_s390_pv_deinit_aside_vm(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 306 |
int kvm_s390_pv_deinit_cleanup_all(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 307 |
int kvm_s390_pv_deinit_vm(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 308 |
int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 309 |
int kvm_s390_pv_set_sec_parms(struct kvm *kvm, void *hdr, u64 length, u16 *rc, |
| 310 |
u16 *rrc); |
| 311 |
int kvm_s390_pv_unpack(struct kvm *kvm, unsigned long addr, unsigned long size, |
| 312 |
unsigned long tweak, u16 *rc, u16 *rrc); |
| 313 |
int kvm_s390_pv_set_cpu_state(struct kvm_vcpu *vcpu, u8 state); |
| 314 |
int kvm_s390_pv_dump_cpu(struct kvm_vcpu *vcpu, void *buff, u16 *rc, u16 *rrc); |
| 315 |
int kvm_s390_pv_dump_stor_state(struct kvm *kvm, void __user *buff_user, |
| 316 |
u64 *gaddr, u64 buff_user_len, u16 *rc, u16 *rrc); |
| 317 |
int kvm_s390_pv_dump_complete(struct kvm *kvm, void __user *buff_user, |
| 318 |
u16 *rc, u16 *rrc); |
| 319 |
int kvm_s390_pv_destroy_page(struct kvm *kvm, unsigned long gaddr); |
| 320 |
int kvm_s390_pv_convert_to_secure(struct kvm *kvm, unsigned long gaddr); |
| 321 |
int kvm_s390_pv_make_secure(struct kvm *kvm, unsigned long gaddr, void *uvcb); |
| 322 |
|
| 323 |
static inline u64 kvm_s390_pv_get_handle(struct kvm *kvm) |
| 324 |
{ |
| 325 |
return kvm->arch.pv.handle; |
| 326 |
} |
| 327 |
|
| 328 |
static inline u64 kvm_s390_pv_cpu_get_handle(struct kvm_vcpu *vcpu) |
| 329 |
{ |
| 330 |
return vcpu->arch.pv.handle; |
| 331 |
} |
| 332 |
|
| 333 |
/** |
| 334 |
* __kvm_s390_pv_destroy_page() - Destroy a guest page. |
| 335 |
* @page: the page to destroy |
| 336 |
* |
| 337 |
* An attempt will be made to destroy the given guest page. If the attempt |
| 338 |
* fails, an attempt is made to export the page. If both attempts fail, an |
| 339 |
* appropriate error is returned. |
| 340 |
* |
| 341 |
* Context: must be called holding the mm lock for gmap->mm |
| 342 |
*/ |
| 343 |
static inline int __kvm_s390_pv_destroy_page(struct page *page) |
| 344 |
{ |
| 345 |
struct folio *folio = page_folio(page); |
| 346 |
int rc; |
| 347 |
|
| 348 |
/* Large folios cannot be secure. Small folio implies FW_LEVEL_PTE. */ |
| 349 |
if (folio_test_large(folio)) |
| 350 |
return -EFAULT; |
| 351 |
|
| 352 |
rc = uv_destroy_folio(folio); |
| 353 |
/* |
| 354 |
* Fault handlers can race; it is possible that two CPUs will fault |
| 355 |
* on the same secure page. One CPU can destroy the page, reboot, |
| 356 |
* re-enter secure mode and import it, while the second CPU was |
| 357 |
* stuck at the beginning of the handler. At some point the second |
| 358 |
* CPU will be able to progress, and it will not be able to destroy |
| 359 |
* the page. In that case we do not want to terminate the process, |
| 360 |
* we instead try to export the page. |
| 361 |
*/ |
| 362 |
if (rc) |
| 363 |
rc = uv_convert_from_secure_folio(folio); |
| 364 |
|
| 365 |
return rc; |
| 366 |
} |
| 367 |
|
| 368 |
/* implemented in interrupt.c */ |
| 369 |
int kvm_s390_handle_wait(struct kvm_vcpu *vcpu); |
| 370 |
void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu); |
| 371 |
enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer); |
| 372 |
int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu); |
| 373 |
void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu); |
| 374 |
void kvm_s390_clear_float_irqs(struct kvm *kvm); |
| 375 |
int __must_check kvm_s390_inject_vm(struct kvm *kvm, |
| 376 |
struct kvm_s390_interrupt *s390int); |
| 377 |
int __must_check kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, |
| 378 |
struct kvm_s390_irq *irq); |
| 379 |
static inline int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, |
| 380 |
struct kvm_s390_pgm_info *pgm_info) |
| 381 |
{ |
| 382 |
struct kvm_s390_irq irq = { |
| 383 |
.type = KVM_S390_PROGRAM_INT, |
| 384 |
.u.pgm = *pgm_info, |
| 385 |
}; |
| 386 |
|
| 387 |
return kvm_s390_inject_vcpu(vcpu, &irq); |
| 388 |
} |
| 389 |
static inline int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) |
| 390 |
{ |
| 391 |
struct kvm_s390_irq irq = { |
| 392 |
.type = KVM_S390_PROGRAM_INT, |
| 393 |
.u.pgm.code = code, |
| 394 |
}; |
| 395 |
|
| 396 |
return kvm_s390_inject_vcpu(vcpu, &irq); |
| 397 |
} |
| 398 |
struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
| 399 |
u64 isc_mask, u32 schid); |
| 400 |
int kvm_s390_reinject_io_int(struct kvm *kvm, |
| 401 |
struct kvm_s390_interrupt_info *inti); |
| 402 |
int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked); |
| 403 |
|
| 404 |
/* implemented in intercept.c */ |
| 405 |
u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu); |
| 406 |
int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu); |
| 407 |
static inline void kvm_s390_rewind_psw(struct kvm_vcpu *vcpu, int ilen) |
| 408 |
{ |
| 409 |
struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block; |
| 410 |
|
| 411 |
sie_block->gpsw.addr = __rewind_psw(sie_block->gpsw, ilen); |
| 412 |
} |
| 413 |
static inline void kvm_s390_forward_psw(struct kvm_vcpu *vcpu, int ilen) |
| 414 |
{ |
| 415 |
kvm_s390_rewind_psw(vcpu, -ilen); |
| 416 |
} |
| 417 |
static inline void kvm_s390_retry_instr(struct kvm_vcpu *vcpu) |
| 418 |
{ |
| 419 |
/* don't inject PER events if we re-execute the instruction */ |
| 420 |
vcpu->arch.sie_block->icptstatus &= ~0x02; |
| 421 |
kvm_s390_rewind_psw(vcpu, kvm_s390_get_ilen(vcpu)); |
| 422 |
} |
| 423 |
|
| 424 |
int handle_sthyi(struct kvm_vcpu *vcpu); |
| 425 |
|
| 426 |
/* implemented in priv.c */ |
| 427 |
int is_valid_psw(psw_t *psw); |
| 428 |
int kvm_s390_handle_aa(struct kvm_vcpu *vcpu); |
| 429 |
int kvm_s390_handle_b2(struct kvm_vcpu *vcpu); |
| 430 |
int kvm_s390_handle_e3(struct kvm_vcpu *vcpu); |
| 431 |
int kvm_s390_handle_e5(struct kvm_vcpu *vcpu); |
| 432 |
int kvm_s390_handle_01(struct kvm_vcpu *vcpu); |
| 433 |
int kvm_s390_handle_b9(struct kvm_vcpu *vcpu); |
| 434 |
int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu); |
| 435 |
int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu); |
| 436 |
int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu); |
| 437 |
int kvm_s390_handle_eb(struct kvm_vcpu *vcpu); |
| 438 |
int kvm_s390_skey_check_enable(struct kvm_vcpu *vcpu); |
| 439 |
|
| 440 |
/* implemented in vsie.c */ |
| 441 |
int kvm_s390_handle_vsie(struct kvm_vcpu *vcpu); |
| 442 |
void kvm_s390_vsie_kick(struct kvm_vcpu *vcpu); |
| 443 |
void kvm_s390_vsie_gmap_notifier(struct gmap *gmap, gpa_t start, gpa_t end); |
| 444 |
void kvm_s390_vsie_init(struct kvm *kvm); |
| 445 |
void kvm_s390_vsie_destroy(struct kvm *kvm); |
| 446 |
|
| 447 |
/* implemented in sigp.c */ |
| 448 |
int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu); |
| 449 |
int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu); |
| 450 |
|
| 451 |
/* implemented in kvm-s390.c */ |
| 452 |
int kvm_s390_try_set_tod_clock(struct kvm *kvm, const struct kvm_s390_vm_tod_clock *gtod); |
| 453 |
int kvm_s390_store_status_unloaded(struct kvm_vcpu *vcpu, unsigned long addr); |
| 454 |
int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr); |
| 455 |
int kvm_s390_vcpu_start(struct kvm_vcpu *vcpu); |
| 456 |
int kvm_s390_vcpu_stop(struct kvm_vcpu *vcpu); |
| 457 |
void kvm_s390_vcpu_block(struct kvm_vcpu *vcpu); |
| 458 |
void kvm_s390_vcpu_unblock(struct kvm_vcpu *vcpu); |
| 459 |
bool kvm_s390_vcpu_sie_inhibited(struct kvm_vcpu *vcpu); |
| 460 |
void exit_sie(struct kvm_vcpu *vcpu); |
| 461 |
void kvm_s390_sync_request(int req, struct kvm_vcpu *vcpu); |
| 462 |
int kvm_s390_vcpu_setup_cmma(struct kvm_vcpu *vcpu); |
| 463 |
void kvm_s390_vcpu_unsetup_cmma(struct kvm_vcpu *vcpu); |
| 464 |
void kvm_s390_set_cpu_timer(struct kvm_vcpu *vcpu, __u64 cputm); |
| 465 |
__u64 kvm_s390_get_cpu_timer(struct kvm_vcpu *vcpu); |
| 466 |
int kvm_s390_cpus_from_pv(struct kvm *kvm, u16 *rc, u16 *rrc); |
| 467 |
int __kvm_s390_mprotect_many(struct gmap *gmap, gpa_t gpa, u8 npages, unsigned int prot, |
| 468 |
unsigned long bits); |
| 469 |
|
| 470 |
bool kvm_arch_setup_async_pf(struct kvm_vcpu *vcpu); |
| 471 |
|
| 472 |
/* implemented in diag.c */ |
| 473 |
int kvm_s390_handle_diag(struct kvm_vcpu *vcpu); |
| 474 |
|
| 475 |
static inline void kvm_s390_vcpu_block_all(struct kvm *kvm) |
| 476 |
{ |
| 477 |
unsigned long i; |
| 478 |
struct kvm_vcpu *vcpu; |
| 479 |
|
| 480 |
WARN_ON(!mutex_is_locked(&kvm->lock)); |
| 481 |
kvm_for_each_vcpu(i, vcpu, kvm) |
| 482 |
kvm_s390_vcpu_block(vcpu); |
| 483 |
} |
| 484 |
|
| 485 |
static inline void kvm_s390_vcpu_unblock_all(struct kvm *kvm) |
| 486 |
{ |
| 487 |
unsigned long i; |
| 488 |
struct kvm_vcpu *vcpu; |
| 489 |
|
| 490 |
kvm_for_each_vcpu(i, vcpu, kvm) |
| 491 |
kvm_s390_vcpu_unblock(vcpu); |
| 492 |
} |
| 493 |
|
| 494 |
static inline u64 kvm_s390_get_tod_clock_fast(struct kvm *kvm) |
| 495 |
{ |
| 496 |
u64 rc; |
| 497 |
|
| 498 |
preempt_disable(); |
| 499 |
rc = get_tod_clock_fast() + kvm->arch.epoch; |
| 500 |
preempt_enable(); |
| 501 |
return rc; |
| 502 |
} |
| 503 |
|
| 504 |
/** |
| 505 |
* kvm_s390_inject_prog_cond - conditionally inject a program check |
| 506 |
* @vcpu: virtual cpu |
| 507 |
* @rc: original return/error code |
| 508 |
* |
| 509 |
* This function is supposed to be used after regular guest access functions |
| 510 |
* failed, to conditionally inject a program check to a vcpu. The typical |
| 511 |
* pattern would look like |
| 512 |
* |
| 513 |
* rc = write_guest(vcpu, addr, data, len); |
| 514 |
* if (rc) |
| 515 |
* return kvm_s390_inject_prog_cond(vcpu, rc); |
| 516 |
* |
| 517 |
* A negative return code from guest access functions implies an internal error |
| 518 |
* like e.g. out of memory. In these cases no program check should be injected |
| 519 |
* to the guest. |
| 520 |
* A positive value implies that an exception happened while accessing a guest's |
| 521 |
* memory. In this case all data belonging to the corresponding program check |
| 522 |
* has been stored in vcpu->arch.pgm and can be injected with |
| 523 |
* kvm_s390_inject_prog_irq(). |
| 524 |
* |
| 525 |
* Returns: - the original @rc value if @rc was negative (internal error) |
| 526 |
* - zero if @rc was already zero |
| 527 |
* - zero or error code from injecting if @rc was positive |
| 528 |
* (program check injected to @vcpu) |
| 529 |
*/ |
| 530 |
static inline int kvm_s390_inject_prog_cond(struct kvm_vcpu *vcpu, int rc) |
| 531 |
{ |
| 532 |
if (rc <= 0) |
| 533 |
return rc; |
| 534 |
return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm); |
| 535 |
} |
| 536 |
|
| 537 |
int s390int_to_s390irq(struct kvm_s390_interrupt *s390int, |
| 538 |
struct kvm_s390_irq *s390irq); |
| 539 |
|
| 540 |
/* implemented in interrupt.c */ |
| 541 |
int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop); |
| 542 |
int psw_extint_disabled(struct kvm_vcpu *vcpu); |
| 543 |
void kvm_s390_destroy_adapters(struct kvm *kvm); |
| 544 |
int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu); |
| 545 |
extern struct kvm_device_ops kvm_flic_ops; |
| 546 |
int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu); |
| 547 |
int kvm_s390_is_restart_irq_pending(struct kvm_vcpu *vcpu); |
| 548 |
void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu); |
| 549 |
int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, |
| 550 |
void __user *buf, int len); |
| 551 |
int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, |
| 552 |
__u8 __user *buf, int len); |
| 553 |
void kvm_s390_gisa_init(struct kvm *kvm); |
| 554 |
void kvm_s390_gisa_clear(struct kvm *kvm); |
| 555 |
void kvm_s390_gisa_destroy(struct kvm *kvm); |
| 556 |
void kvm_s390_gisa_disable(struct kvm *kvm); |
| 557 |
void kvm_s390_gisa_enable(struct kvm *kvm); |
| 558 |
int __init kvm_s390_gib_init(u8 nisc); |
| 559 |
void kvm_s390_gib_destroy(void); |
| 560 |
|
| 561 |
/* implemented in guestdbg.c */ |
| 562 |
void kvm_s390_backup_guest_per_regs(struct kvm_vcpu *vcpu); |
| 563 |
void kvm_s390_restore_guest_per_regs(struct kvm_vcpu *vcpu); |
| 564 |
void kvm_s390_patch_guest_per_regs(struct kvm_vcpu *vcpu); |
| 565 |
int kvm_s390_import_bp_data(struct kvm_vcpu *vcpu, |
| 566 |
struct kvm_guest_debug *dbg); |
| 567 |
void kvm_s390_clear_bp_data(struct kvm_vcpu *vcpu); |
| 568 |
void kvm_s390_prepare_debug_exit(struct kvm_vcpu *vcpu); |
| 569 |
int kvm_s390_handle_per_ifetch_icpt(struct kvm_vcpu *vcpu); |
| 570 |
int kvm_s390_handle_per_event(struct kvm_vcpu *vcpu); |
| 571 |
|
| 572 |
static inline int kvm_s390_use_sca_entries(void) |
| 573 |
{ |
| 574 |
/* |
| 575 |
* Without SIGP interpretation, only SRS interpretation (if available) |
| 576 |
* might use the entries. By not setting the entries and keeping them |
| 577 |
* invalid, hardware will not access them but intercept. |
| 578 |
*/ |
| 579 |
return sclp.has_sigpif && sclp.has_esca; |
| 580 |
} |
| 581 |
void kvm_s390_reinject_machine_check(struct kvm_vcpu *vcpu, |
| 582 |
struct mcck_volatile_info *mcck_info); |
| 583 |
|
| 584 |
static inline bool kvm_s390_cur_gmap_fault_is_write(void) |
| 585 |
{ |
| 586 |
if (current->thread.gmap_int_code == PGM_PROTECTION) |
| 587 |
return true; |
| 588 |
return test_facility(75) && (current->thread.gmap_teid.fsi == TEID_FSI_STORE); |
| 589 |
} |
| 590 |
|
| 591 |
/** |
| 592 |
* kvm_s390_vcpu_crypto_reset_all |
| 593 |
* |
| 594 |
* Reset the crypto attributes for each vcpu. This can be done while the vcpus |
| 595 |
* are running as each vcpu will be removed from SIE before resetting the crypt |
| 596 |
* attributes and restored to SIE afterward. |
| 597 |
* |
| 598 |
* Note: The kvm->lock must be held while calling this function |
| 599 |
* |
| 600 |
* @kvm: the KVM guest |
| 601 |
*/ |
| 602 |
void kvm_s390_vcpu_crypto_reset_all(struct kvm *kvm); |
| 603 |
|
| 604 |
/** |
| 605 |
* kvm_s390_vcpu_pci_enable_interp |
| 606 |
* |
| 607 |
* Set the associated PCI attributes for each vcpu to allow for zPCI Load/Store |
| 608 |
* interpretation as well as adapter interruption forwarding. |
| 609 |
* |
| 610 |
* @kvm: the KVM guest |
| 611 |
*/ |
| 612 |
void kvm_s390_vcpu_pci_enable_interp(struct kvm *kvm); |
| 613 |
|
| 614 |
/** |
| 615 |
* diag9c_forwarding_hz |
| 616 |
* |
| 617 |
* Set the maximum number of diag9c forwarding per second |
| 618 |
*/ |
| 619 |
extern unsigned int diag9c_forwarding_hz; |
| 620 |
|
| 621 |
#endif |