c1f0cc4a9369a8ddcb7a1a60650b3d6dc5e5b3d5
[linux-2.6-microblaze.git] / arch / x86 / kvm / svm / svm.h
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Kernel-based Virtual Machine driver for Linux
4  *
5  * AMD SVM support
6  *
7  * Copyright (C) 2006 Qumranet, Inc.
8  * Copyright 2010 Red Hat, Inc. and/or its affiliates.
9  *
10  * Authors:
11  *   Yaniv Kamay  <yaniv@qumranet.com>
12  *   Avi Kivity   <avi@qumranet.com>
13  */
14
15 #ifndef __SVM_SVM_H
16 #define __SVM_SVM_H
17
18 #include <linux/kvm_types.h>
19 #include <linux/kvm_host.h>
20 #include <linux/bits.h>
21
22 #include <asm/svm.h>
23 #include <asm/sev-common.h>
24
25 #define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT)
26
27 #define IOPM_SIZE PAGE_SIZE * 3
28 #define MSRPM_SIZE PAGE_SIZE * 2
29
30 #define MAX_DIRECT_ACCESS_MSRS  20
31 #define MSRPM_OFFSETS   16
32 extern u32 msrpm_offsets[MSRPM_OFFSETS] __read_mostly;
33 extern bool npt_enabled;
34 extern bool intercept_smi;
35
36 /*
37  * Clean bits in VMCB.
38  * VMCB_ALL_CLEAN_MASK might also need to
39  * be updated if this enum is modified.
40  */
41 enum {
42         VMCB_INTERCEPTS, /* Intercept vectors, TSC offset,
43                             pause filter count */
44         VMCB_PERM_MAP,   /* IOPM Base and MSRPM Base */
45         VMCB_ASID,       /* ASID */
46         VMCB_INTR,       /* int_ctl, int_vector */
47         VMCB_NPT,        /* npt_en, nCR3, gPAT */
48         VMCB_CR,         /* CR0, CR3, CR4, EFER */
49         VMCB_DR,         /* DR6, DR7 */
50         VMCB_DT,         /* GDT, IDT */
51         VMCB_SEG,        /* CS, DS, SS, ES, CPL */
52         VMCB_CR2,        /* CR2 only */
53         VMCB_LBR,        /* DBGCTL, BR_FROM, BR_TO, LAST_EX_FROM, LAST_EX_TO */
54         VMCB_AVIC,       /* AVIC APIC_BAR, AVIC APIC_BACKING_PAGE,
55                           * AVIC PHYSICAL_TABLE pointer,
56                           * AVIC LOGICAL_TABLE pointer
57                           */
58         VMCB_SW = 31,    /* Reserved for hypervisor/software use */
59 };
60
61 #define VMCB_ALL_CLEAN_MASK (                                   \
62         (1U << VMCB_INTERCEPTS) | (1U << VMCB_PERM_MAP) |       \
63         (1U << VMCB_ASID) | (1U << VMCB_INTR) |                 \
64         (1U << VMCB_NPT) | (1U << VMCB_CR) | (1U << VMCB_DR) |  \
65         (1U << VMCB_DT) | (1U << VMCB_SEG) | (1U << VMCB_CR2) | \
66         (1U << VMCB_LBR) | (1U << VMCB_AVIC) |                  \
67         (1U << VMCB_SW))
68
69 /* TPR and CR2 are always written before VMRUN */
70 #define VMCB_ALWAYS_DIRTY_MASK  ((1U << VMCB_INTR) | (1U << VMCB_CR2))
71
72 struct kvm_sev_info {
73         bool active;            /* SEV enabled guest */
74         bool es_active;         /* SEV-ES enabled guest */
75         unsigned int asid;      /* ASID used for this guest */
76         unsigned int handle;    /* SEV firmware handle */
77         int fd;                 /* SEV device fd */
78         unsigned long pages_locked; /* Number of pages locked */
79         struct list_head regions_list;  /* List of registered regions */
80         u64 ap_jump_table;      /* SEV-ES AP Jump Table address */
81         struct kvm *enc_context_owner; /* Owner of copied encryption context */
82         unsigned long num_mirrored_vms; /* Number of VMs sharing this ASID */
83         struct misc_cg *misc_cg; /* For misc cgroup accounting */
84         atomic_t migration_in_progress;
85 };
86
87 struct kvm_svm {
88         struct kvm kvm;
89
90         /* Struct members for AVIC */
91         u32 avic_vm_id;
92         struct page *avic_logical_id_table_page;
93         struct page *avic_physical_id_table_page;
94         struct hlist_node hnode;
95
96         struct kvm_sev_info sev_info;
97 };
98
99 struct kvm_vcpu;
100
101 struct kvm_vmcb_info {
102         struct vmcb *ptr;
103         unsigned long pa;
104         int cpu;
105         uint64_t asid_generation;
106 };
107
108 struct vmcb_save_area_cached {
109         u64 efer;
110         u64 cr4;
111         u64 cr3;
112         u64 cr0;
113         u64 dr7;
114         u64 dr6;
115 };
116
117 struct vmcb_ctrl_area_cached {
118         u32 intercepts[MAX_INTERCEPT];
119         u16 pause_filter_thresh;
120         u16 pause_filter_count;
121         u64 iopm_base_pa;
122         u64 msrpm_base_pa;
123         u64 tsc_offset;
124         u32 asid;
125         u8 tlb_ctl;
126         u32 int_ctl;
127         u32 int_vector;
128         u32 int_state;
129         u32 exit_code;
130         u32 exit_code_hi;
131         u64 exit_info_1;
132         u64 exit_info_2;
133         u32 exit_int_info;
134         u32 exit_int_info_err;
135         u64 nested_ctl;
136         u32 event_inj;
137         u32 event_inj_err;
138         u64 nested_cr3;
139         u64 virt_ext;
140         u32 clean;
141         u8 reserved_sw[32];
142 };
143
144 struct svm_nested_state {
145         struct kvm_vmcb_info vmcb02;
146         u64 hsave_msr;
147         u64 vm_cr_msr;
148         u64 vmcb12_gpa;
149         u64 last_vmcb12_gpa;
150
151         /* These are the merged vectors */
152         u32 *msrpm;
153
154         /* A VMRUN has started but has not yet been performed, so
155          * we cannot inject a nested vmexit yet.  */
156         bool nested_run_pending;
157
158         /* cache for control fields of the guest */
159         struct vmcb_ctrl_area_cached ctl;
160
161         /*
162          * Note: this struct is not kept up-to-date while L2 runs; it is only
163          * valid within nested_svm_vmrun.
164          */
165         struct vmcb_save_area_cached save;
166
167         bool initialized;
168
169         /*
170          * Indicates whether MSR bitmap for L2 needs to be rebuilt due to
171          * changes in MSR bitmap for L1 or switching to a different L2. Note,
172          * this flag can only be used reliably in conjunction with a paravirt L1
173          * which informs L0 whether any changes to MSR bitmap for L2 were done
174          * on its side.
175          */
176         bool force_msr_bitmap_recalc;
177 };
178
179 struct vcpu_sev_es_state {
180         /* SEV-ES support */
181         struct vmcb_save_area *vmsa;
182         struct ghcb *ghcb;
183         struct kvm_host_map ghcb_map;
184         bool received_first_sipi;
185
186         /* SEV-ES scratch area support */
187         void *ghcb_sa;
188         u32 ghcb_sa_len;
189         bool ghcb_sa_sync;
190         bool ghcb_sa_free;
191 };
192
193 struct vcpu_svm {
194         struct kvm_vcpu vcpu;
195         /* vmcb always points at current_vmcb->ptr, it's purely a shorthand. */
196         struct vmcb *vmcb;
197         struct kvm_vmcb_info vmcb01;
198         struct kvm_vmcb_info *current_vmcb;
199         struct svm_cpu_data *svm_data;
200         u32 asid;
201         u32 sysenter_esp_hi;
202         u32 sysenter_eip_hi;
203         uint64_t tsc_aux;
204
205         u64 msr_decfg;
206
207         u64 next_rip;
208
209         u64 spec_ctrl;
210
211         u64 tsc_ratio_msr;
212         /*
213          * Contains guest-controlled bits of VIRT_SPEC_CTRL, which will be
214          * translated into the appropriate L2_CFG bits on the host to
215          * perform speculative control.
216          */
217         u64 virt_spec_ctrl;
218
219         u32 *msrpm;
220
221         ulong nmi_iret_rip;
222
223         struct svm_nested_state nested;
224
225         bool nmi_singlestep;
226         u64 nmi_singlestep_guest_rflags;
227
228         unsigned int3_injected;
229         unsigned long int3_rip;
230
231         /* cached guest cpuid flags for faster access */
232         bool nrips_enabled                : 1;
233         bool tsc_scaling_enabled          : 1;
234
235         u32 ldr_reg;
236         u32 dfr_reg;
237         struct page *avic_backing_page;
238         u64 *avic_physical_id_cache;
239
240         /*
241          * Per-vcpu list of struct amd_svm_iommu_ir:
242          * This is used mainly to store interrupt remapping information used
243          * when update the vcpu affinity. This avoids the need to scan for
244          * IRTE and try to match ga_tag in the IOMMU driver.
245          */
246         struct list_head ir_list;
247         spinlock_t ir_list_lock;
248
249         /* Save desired MSR intercept (read: pass-through) state */
250         struct {
251                 DECLARE_BITMAP(read, MAX_DIRECT_ACCESS_MSRS);
252                 DECLARE_BITMAP(write, MAX_DIRECT_ACCESS_MSRS);
253         } shadow_msr_intercept;
254
255         struct vcpu_sev_es_state sev_es;
256
257         bool guest_state_loaded;
258 };
259
260 struct svm_cpu_data {
261         int cpu;
262
263         u64 asid_generation;
264         u32 max_asid;
265         u32 next_asid;
266         u32 min_asid;
267         struct kvm_ldttss_desc *tss_desc;
268
269         struct page *save_area;
270         struct vmcb *current_vmcb;
271
272         /* index = sev_asid, value = vmcb pointer */
273         struct vmcb **sev_vmcbs;
274 };
275
276 DECLARE_PER_CPU(struct svm_cpu_data *, svm_data);
277
278 void recalc_intercepts(struct vcpu_svm *svm);
279
280 static __always_inline struct kvm_svm *to_kvm_svm(struct kvm *kvm)
281 {
282         return container_of(kvm, struct kvm_svm, kvm);
283 }
284
285 static __always_inline bool sev_guest(struct kvm *kvm)
286 {
287 #ifdef CONFIG_KVM_AMD_SEV
288         struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
289
290         return sev->active;
291 #else
292         return false;
293 #endif
294 }
295
296 static __always_inline bool sev_es_guest(struct kvm *kvm)
297 {
298 #ifdef CONFIG_KVM_AMD_SEV
299         struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
300
301         return sev->es_active && !WARN_ON_ONCE(!sev->active);
302 #else
303         return false;
304 #endif
305 }
306
307 static inline void vmcb_mark_all_dirty(struct vmcb *vmcb)
308 {
309         vmcb->control.clean = 0;
310 }
311
312 static inline void vmcb_mark_all_clean(struct vmcb *vmcb)
313 {
314         vmcb->control.clean = VMCB_ALL_CLEAN_MASK
315                                & ~VMCB_ALWAYS_DIRTY_MASK;
316 }
317
318 static inline void vmcb_mark_dirty(struct vmcb *vmcb, int bit)
319 {
320         vmcb->control.clean &= ~(1 << bit);
321 }
322
323 static inline bool vmcb_is_dirty(struct vmcb *vmcb, int bit)
324 {
325         return !test_bit(bit, (unsigned long *)&vmcb->control.clean);
326 }
327
328 static __always_inline struct vcpu_svm *to_svm(struct kvm_vcpu *vcpu)
329 {
330         return container_of(vcpu, struct vcpu_svm, vcpu);
331 }
332
333 /*
334  * Only the PDPTRs are loaded on demand into the shadow MMU.  All other
335  * fields are synchronized on VM-Exit, because accessing the VMCB is cheap.
336  *
337  * CR3 might be out of date in the VMCB but it is not marked dirty; instead,
338  * KVM_REQ_LOAD_MMU_PGD is always requested when the cached vcpu->arch.cr3
339  * is changed.  svm_load_mmu_pgd() then syncs the new CR3 value into the VMCB.
340  */
341 #define SVM_REGS_LAZY_LOAD_SET  (1 << VCPU_EXREG_PDPTR)
342
343 static inline void vmcb_set_intercept(struct vmcb_control_area *control, u32 bit)
344 {
345         WARN_ON_ONCE(bit >= 32 * MAX_INTERCEPT);
346         __set_bit(bit, (unsigned long *)&control->intercepts);
347 }
348
349 static inline void vmcb_clr_intercept(struct vmcb_control_area *control, u32 bit)
350 {
351         WARN_ON_ONCE(bit >= 32 * MAX_INTERCEPT);
352         __clear_bit(bit, (unsigned long *)&control->intercepts);
353 }
354
355 static inline bool vmcb_is_intercept(struct vmcb_control_area *control, u32 bit)
356 {
357         WARN_ON_ONCE(bit >= 32 * MAX_INTERCEPT);
358         return test_bit(bit, (unsigned long *)&control->intercepts);
359 }
360
361 static inline bool vmcb12_is_intercept(struct vmcb_ctrl_area_cached *control, u32 bit)
362 {
363         WARN_ON_ONCE(bit >= 32 * MAX_INTERCEPT);
364         return test_bit(bit, (unsigned long *)&control->intercepts);
365 }
366
367 static inline void set_dr_intercepts(struct vcpu_svm *svm)
368 {
369         struct vmcb *vmcb = svm->vmcb01.ptr;
370
371         if (!sev_es_guest(svm->vcpu.kvm)) {
372                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_READ);
373                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_READ);
374                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_READ);
375                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_READ);
376                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_READ);
377                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_READ);
378                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_READ);
379                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_WRITE);
380                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_WRITE);
381                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_WRITE);
382                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_WRITE);
383                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_WRITE);
384                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_WRITE);
385                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_WRITE);
386         }
387
388         vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ);
389         vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE);
390
391         recalc_intercepts(svm);
392 }
393
394 static inline void clr_dr_intercepts(struct vcpu_svm *svm)
395 {
396         struct vmcb *vmcb = svm->vmcb01.ptr;
397
398         vmcb->control.intercepts[INTERCEPT_DR] = 0;
399
400         /* DR7 access must remain intercepted for an SEV-ES guest */
401         if (sev_es_guest(svm->vcpu.kvm)) {
402                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ);
403                 vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE);
404         }
405
406         recalc_intercepts(svm);
407 }
408
409 static inline void set_exception_intercept(struct vcpu_svm *svm, u32 bit)
410 {
411         struct vmcb *vmcb = svm->vmcb01.ptr;
412
413         WARN_ON_ONCE(bit >= 32);
414         vmcb_set_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit);
415
416         recalc_intercepts(svm);
417 }
418
419 static inline void clr_exception_intercept(struct vcpu_svm *svm, u32 bit)
420 {
421         struct vmcb *vmcb = svm->vmcb01.ptr;
422
423         WARN_ON_ONCE(bit >= 32);
424         vmcb_clr_intercept(&vmcb->control, INTERCEPT_EXCEPTION_OFFSET + bit);
425
426         recalc_intercepts(svm);
427 }
428
429 static inline void svm_set_intercept(struct vcpu_svm *svm, int bit)
430 {
431         struct vmcb *vmcb = svm->vmcb01.ptr;
432
433         vmcb_set_intercept(&vmcb->control, bit);
434
435         recalc_intercepts(svm);
436 }
437
438 static inline void svm_clr_intercept(struct vcpu_svm *svm, int bit)
439 {
440         struct vmcb *vmcb = svm->vmcb01.ptr;
441
442         vmcb_clr_intercept(&vmcb->control, bit);
443
444         recalc_intercepts(svm);
445 }
446
447 static inline bool svm_is_intercept(struct vcpu_svm *svm, int bit)
448 {
449         return vmcb_is_intercept(&svm->vmcb->control, bit);
450 }
451
452 static inline bool vgif_enabled(struct vcpu_svm *svm)
453 {
454         return !!(svm->vmcb->control.int_ctl & V_GIF_ENABLE_MASK);
455 }
456
457 static inline void enable_gif(struct vcpu_svm *svm)
458 {
459         if (vgif_enabled(svm))
460                 svm->vmcb->control.int_ctl |= V_GIF_MASK;
461         else
462                 svm->vcpu.arch.hflags |= HF_GIF_MASK;
463 }
464
465 static inline void disable_gif(struct vcpu_svm *svm)
466 {
467         if (vgif_enabled(svm))
468                 svm->vmcb->control.int_ctl &= ~V_GIF_MASK;
469         else
470                 svm->vcpu.arch.hflags &= ~HF_GIF_MASK;
471 }
472
473 static inline bool gif_set(struct vcpu_svm *svm)
474 {
475         if (vgif_enabled(svm))
476                 return !!(svm->vmcb->control.int_ctl & V_GIF_MASK);
477         else
478                 return !!(svm->vcpu.arch.hflags & HF_GIF_MASK);
479 }
480
481 /* svm.c */
482 #define MSR_INVALID                             0xffffffffU
483
484 extern bool dump_invalid_vmcb;
485
486 u32 svm_msrpm_offset(u32 msr);
487 u32 *svm_vcpu_alloc_msrpm(void);
488 void svm_vcpu_init_msrpm(struct kvm_vcpu *vcpu, u32 *msrpm);
489 void svm_vcpu_free_msrpm(u32 *msrpm);
490
491 int svm_set_efer(struct kvm_vcpu *vcpu, u64 efer);
492 void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
493 void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
494 void disable_nmi_singlestep(struct vcpu_svm *svm);
495 bool svm_smi_blocked(struct kvm_vcpu *vcpu);
496 bool svm_nmi_blocked(struct kvm_vcpu *vcpu);
497 bool svm_interrupt_blocked(struct kvm_vcpu *vcpu);
498 void svm_set_gif(struct vcpu_svm *svm, bool value);
499 int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code);
500 void set_msr_interception(struct kvm_vcpu *vcpu, u32 *msrpm, u32 msr,
501                           int read, int write);
502 void svm_complete_interrupt_delivery(struct kvm_vcpu *vcpu, int delivery_mode,
503                                      int trig_mode, int vec);
504
505 /* nested.c */
506
507 #define NESTED_EXIT_HOST        0       /* Exit handled on host level */
508 #define NESTED_EXIT_DONE        1       /* Exit caused nested vmexit  */
509 #define NESTED_EXIT_CONTINUE    2       /* Further checks needed      */
510
511 static inline bool nested_svm_virtualize_tpr(struct kvm_vcpu *vcpu)
512 {
513         struct vcpu_svm *svm = to_svm(vcpu);
514
515         return is_guest_mode(vcpu) && (svm->nested.ctl.int_ctl & V_INTR_MASKING_MASK);
516 }
517
518 static inline bool nested_exit_on_smi(struct vcpu_svm *svm)
519 {
520         return vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_SMI);
521 }
522
523 static inline bool nested_exit_on_intr(struct vcpu_svm *svm)
524 {
525         return vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_INTR);
526 }
527
528 static inline bool nested_exit_on_nmi(struct vcpu_svm *svm)
529 {
530         return vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_NMI);
531 }
532
533 int enter_svm_guest_mode(struct kvm_vcpu *vcpu,
534                          u64 vmcb_gpa, struct vmcb *vmcb12, bool from_vmrun);
535 void svm_leave_nested(struct kvm_vcpu *vcpu);
536 void svm_free_nested(struct vcpu_svm *svm);
537 int svm_allocate_nested(struct vcpu_svm *svm);
538 int nested_svm_vmrun(struct kvm_vcpu *vcpu);
539 void svm_copy_vmrun_state(struct vmcb_save_area *to_save,
540                           struct vmcb_save_area *from_save);
541 void svm_copy_vmloadsave_state(struct vmcb *to_vmcb, struct vmcb *from_vmcb);
542 int nested_svm_vmexit(struct vcpu_svm *svm);
543
544 static inline int nested_svm_simple_vmexit(struct vcpu_svm *svm, u32 exit_code)
545 {
546         svm->vmcb->control.exit_code   = exit_code;
547         svm->vmcb->control.exit_info_1 = 0;
548         svm->vmcb->control.exit_info_2 = 0;
549         return nested_svm_vmexit(svm);
550 }
551
552 int nested_svm_exit_handled(struct vcpu_svm *svm);
553 int nested_svm_check_permissions(struct kvm_vcpu *vcpu);
554 int nested_svm_check_exception(struct vcpu_svm *svm, unsigned nr,
555                                bool has_error_code, u32 error_code);
556 int nested_svm_exit_special(struct vcpu_svm *svm);
557 void nested_svm_update_tsc_ratio_msr(struct kvm_vcpu *vcpu);
558 void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier);
559 void nested_copy_vmcb_control_to_cache(struct vcpu_svm *svm,
560                                        struct vmcb_control_area *control);
561 void nested_copy_vmcb_save_to_cache(struct vcpu_svm *svm,
562                                     struct vmcb_save_area *save);
563 void nested_sync_control_from_vmcb02(struct vcpu_svm *svm);
564 void nested_vmcb02_compute_g_pat(struct vcpu_svm *svm);
565 void svm_switch_vmcb(struct vcpu_svm *svm, struct kvm_vmcb_info *target_vmcb);
566
567 extern struct kvm_x86_nested_ops svm_nested_ops;
568
569 /* avic.c */
570
571 int avic_ga_log_notifier(u32 ga_tag);
572 void avic_vm_destroy(struct kvm *kvm);
573 int avic_vm_init(struct kvm *kvm);
574 void avic_init_vmcb(struct vcpu_svm *svm);
575 int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu);
576 int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu);
577 int avic_init_vcpu(struct vcpu_svm *svm);
578 void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
579 void avic_vcpu_put(struct kvm_vcpu *vcpu);
580 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
581 void avic_set_virtual_apic_mode(struct kvm_vcpu *vcpu);
582 void avic_refresh_apicv_exec_ctrl(struct kvm_vcpu *vcpu);
583 bool avic_check_apicv_inhibit_reasons(ulong bit);
584 void avic_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
585 void avic_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr);
586 void avic_hwapic_isr_update(struct kvm_vcpu *vcpu, int max_isr);
587 bool avic_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu);
588 int avic_pi_update_irte(struct kvm *kvm, unsigned int host_irq,
589                         uint32_t guest_irq, bool set);
590 void avic_vcpu_blocking(struct kvm_vcpu *vcpu);
591 void avic_vcpu_unblocking(struct kvm_vcpu *vcpu);
592 void avic_ring_doorbell(struct kvm_vcpu *vcpu);
593
594 /* sev.c */
595
596 #define GHCB_VERSION_MAX        1ULL
597 #define GHCB_VERSION_MIN        1ULL
598
599
600 extern unsigned int max_sev_asid;
601
602 void sev_vm_destroy(struct kvm *kvm);
603 int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp);
604 int sev_mem_enc_register_region(struct kvm *kvm,
605                                 struct kvm_enc_region *range);
606 int sev_mem_enc_unregister_region(struct kvm *kvm,
607                                   struct kvm_enc_region *range);
608 int sev_vm_copy_enc_context_from(struct kvm *kvm, unsigned int source_fd);
609 int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd);
610 void pre_sev_run(struct vcpu_svm *svm, int cpu);
611 void __init sev_set_cpu_caps(void);
612 void __init sev_hardware_setup(void);
613 void sev_hardware_unsetup(void);
614 int sev_cpu_init(struct svm_cpu_data *sd);
615 void sev_free_vcpu(struct kvm_vcpu *vcpu);
616 int sev_handle_vmgexit(struct kvm_vcpu *vcpu);
617 int sev_es_string_io(struct vcpu_svm *svm, int size, unsigned int port, int in);
618 void sev_es_init_vmcb(struct vcpu_svm *svm);
619 void sev_es_vcpu_reset(struct vcpu_svm *svm);
620 void sev_vcpu_deliver_sipi_vector(struct kvm_vcpu *vcpu, u8 vector);
621 void sev_es_prepare_switch_to_guest(struct vmcb_save_area *hostsa);
622 void sev_es_unmap_ghcb(struct vcpu_svm *svm);
623
624 /* vmenter.S */
625
626 void __svm_sev_es_vcpu_run(unsigned long vmcb_pa);
627 void __svm_vcpu_run(unsigned long vmcb_pa, unsigned long *regs);
628
629 #endif