x86/svm: Untangle the remaining global svm/ headers
cover x86/svm: Untangle the remaining global svm/ headers
This turned out to be a little easier than I was expecting.
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2212088192
Andrew Cooper (5):
x86/svm: Move asm/hvm/svm/svm.h up one directory x86/svm: Move svm_intercept_msr() into svm.h x86/svm: Introduce svm-types.h
x86/svm: Merge nestedsvm.h into svm-types.h x86/svm: Merge vmcb.h into svm-types.h
xen/arch/x86/cpu-policy.c | 2 +-
xen/arch/x86/cpu/vpmu_amd.c | 5 +-
xen/arch/x86/domain.c | 2 +-
xen/arch/x86/hvm/svm/asid.c | 2 +-
xen/arch/x86/hvm/svm/emulate.c | 3 +-
xen/arch/x86/hvm/svm/intr.c | 1 -
xen/arch/x86/hvm/svm/nestedsvm.c | 3 +-
xen/arch/x86/hvm/svm/svm.c | 3 +-
xen/arch/x86/hvm/svm/vmcb.c | 3 +-
xen/arch/x86/include/asm/hvm/domain.h | 2 +-
.../asm/hvm/{svm/nestedsvm.h => svm-types.h} | 76 +++++++++++++------
xen/arch/x86/include/asm/hvm/{svm => }/svm.h | 8 ++
xen/arch/x86/include/asm/hvm/svm/vmcb.h | 63 ---------------
xen/arch/x86/include/asm/hvm/vcpu.h | 3 +-
xen/arch/x86/spec_ctrl.c | 2 +-
15 files changed, 73 insertions(+), 105 deletions(-)
rename xen/arch/x86/include/asm/hvm/{svm/nestedsvm.h => svm-types.h} (52%)
rename xen/arch/x86/include/asm/hvm/{svm => }/svm.h (86%)
delete mode 100644 xen/arch/x86/include/asm/hvm/svm/vmcb.hbase-commit: e6836f213f0f9d3aeaf7c89ce1e20716795b37bd
Signature · 1 line
2.39.5
PATCH 1/5 x86/svm: Move asm/hvm/svm/svm.h up one directory
... in preparation to remove the svm/ directory entirely.
intr.c doesn't need to include svm.h at all.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
---
xen/arch/x86/cpu-policy.c | 2 +-
xen/arch/x86/domain.c | 2 +-
xen/arch/x86/hvm/svm/asid.c | 2 +-
xen/arch/x86/hvm/svm/emulate.c | 2 +-
xen/arch/x86/hvm/svm/intr.c | 1 -
xen/arch/x86/hvm/svm/nestedsvm.c | 2 +-
xen/arch/x86/hvm/svm/svm.c | 2 +-
xen/arch/x86/hvm/svm/vmcb.c | 2 +-
xen/arch/x86/include/asm/hvm/{svm => }/svm.h | 0
xen/arch/x86/spec_ctrl.c | 2 +-
10 files changed, 8 insertions(+), 9 deletions(-)
rename xen/arch/x86/include/asm/hvm/{svm => }/svm.h (100%)xen/arch/x86/cpu-policy.c +1 -1
@@ -9,7 +9,7 @@#include <asm/amd.h> #include <asm/cpu-policy.h> #include <asm/hvm/nestedhvm.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/intel-family.h> #include <asm/msr-index.h> #include <asm/paging.h>
xen/arch/x86/domain.c +1 -1
@@ -48,7 +48,7 @@#include <asm/guest-msr.h> #include <asm/hvm/hvm.h> #include <asm/hvm/nestedhvm.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/hvm/viridian.h> #include <asm/i387.h> #include <asm/idt.h>
xen/arch/x86/hvm/svm/asid.c +1 -1
@@ -6,7 +6,7 @@#include <asm/amd.h> #include <asm/hvm/nestedhvm.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include "svm.h" #include "vmcb.h"
xen/arch/x86/hvm/svm/emulate.c +1 -1
@@ -11,7 +11,7 @@#include <asm/msr.h> #include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/hvm/svm/vmcb.h> #include "svm.h"
xen/arch/x86/hvm/svm/intr.c +0 -1
@@ -17,7 +17,6 @@#include <asm/hvm/hvm.h> #include <asm/hvm/io.h> #include <asm/hvm/vlapic.h> -#include <asm/hvm/svm/svm.h> #include <asm/hvm/nestedhvm.h> /* for nestedhvm_vcpu_in_guestmode */ #include <asm/vm_event.h> #include <xen/event.h>
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
@@ -6,7 +6,7 @@*/ #include <asm/hvm/support.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/hvm/nestedhvm.h> #include <asm/paging.h> /* paging_mode_hap */
xen/arch/x86/hvm/svm/svm.c +1 -1
@@ -26,7 +26,7 @@#include <asm/hvm/monitor.h> #include <asm/hvm/nestedhvm.h> #include <asm/hvm/support.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/i387.h> #include <asm/idt.h>
xen/arch/x86/hvm/svm/vmcb.c +1 -1
@@ -15,7 +15,7 @@#include <xen/softirq.h> #include <asm/guest-msr.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/hvm/svm/vmcb.h> #include <asm/msr-index.h> #include <asm/p2m.h>
xen/arch/x86/include/asm/hvm/svm.h renamed from xen/arch/x86/include/asm/hvm/svm/svm.h +0 -0
xen/arch/x86/spec_ctrl.c +1 -1
@@ -11,7 +11,7 @@#include <xen/warning.h> #include <asm/amd.h> -#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm.h> #include <asm/intel-family.h> #include <asm/microcode.h> #include <asm/msr.h>
Signature · 1 line
2.39.5
PATCH 2/5 x86/svm: Move svm_intercept_msr() into svm.h
In reply to Andrew CooperThe single user of svm_intercept_msr() outside of the main svm logic is in vpmu_amd.c. Currently the declaration is picked up transitively through xen/sched.h, so include asm/hvm/svm.h explicitly.
Sort the headers while doing so.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/cpu/vpmu_amd.c | 5 ++++- xen/arch/x86/include/asm/hvm/svm.h | 8 ++++++++ xen/arch/x86/include/asm/hvm/svm/vmcb.h | 8 -------- 3 files changed, 12 insertions(+), 9 deletions(-)
xen/arch/x86/cpu/vpmu_amd.c +4 -1
@@ -13,10 +13,13 @@#include <xen/err.h> #include <xen/sched.h> #include <xen/xenoprof.h> +#include <asm/apic.h> -#include <asm/vpmu.h> #include <asm/hvm/save.h> +#include <asm/hvm/svm.h> #include <asm/hvm/vlapic.h> +#include <asm/vpmu.h> +#include <public/pmu.h> #define MSR_F10H_EVNTSEL_GO_SHIFT 40
xen/arch/x86/include/asm/hvm/svm.h +8 -0
@@ -57,4 +57,12 @@ static inline bool cpu_has_svm_feature(unsigned int feat)#define cpu_has_svm_sss cpu_has_svm_feature(SVM_FEATURE_SSS)#define cpu_has_svm_spec_ctrl cpu_has_svm_feature(SVM_FEATURE_SPEC_CTRL) +#define MSR_INTERCEPT_NONE 0 +#define MSR_INTERCEPT_READ 1 +#define MSR_INTERCEPT_WRITE 2 +#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) +void svm_intercept_msr (struct vcpu *v,uint32_t msr,int flags); +#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) +#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) +#endif /* __ASM_X86_HVM_SVM_H__ */
xen/arch/x86/include/asm/hvm/svm/vmcb.h +0 -8
@@ -42,14 +42,6 @@ struct svm_vcpu { uint64_t guest_sysenter_eip; }; -#define MSR_INTERCEPT_NONE 0 -#define MSR_INTERCEPT_READ 1 -#define MSR_INTERCEPT_WRITE 2 -#define MSR_INTERCEPT_RW (MSR_INTERCEPT_WRITE | MSR_INTERCEPT_READ) -void svm_intercept_msr (struct vcpu *v,uint32_t msr,int flags); -#define svm_disable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_NONE) -#define svm_enable_intercept_for_msr (v, msr) svm_intercept_msr((v), (msr), MSR_INTERCEPT_RW) -#endif /* ASM_X86_HVM_SVM_VMCS_H__ */ /*
Signature · 1 line
2.39.5
PATCH 3/5 x86/svm: Introduce svm-types.h
In reply to Andrew CooperIn order to reduce the header tangle around xen/sched.h, we need to split types away from other declarations.
Introduce a new svm/svm-types.h to do this, including it from hvm/domain.h and hvm/vcpu.h, and dropping all other inclusions of svm/vmcb.h and svm/nestedhvm.h
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/hvm/svm/emulate.c | 1 - xen/arch/x86/hvm/svm/nestedsvm.c | 1 - xen/arch/x86/hvm/svm/svm.c | 1 - xen/arch/x86/hvm/svm/vmcb.c | 1 - xen/arch/x86/include/asm/hvm/domain.h | 2 +- xen/arch/x86/include/asm/hvm/svm-types.h | 11 +++++++++++ xen/arch/x86/include/asm/hvm/vcpu.h | 3 +-- 7 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 xen/arch/x86/include/asm/hvm/svm-types.h
xen/arch/x86/hvm/svm/emulate.c +0 -1
@@ -12,7 +12,6 @@#include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h> #include <asm/hvm/svm.h> -#include <asm/hvm/svm/vmcb.h> #include "svm.h" #include "vmcb.h"
xen/arch/x86/hvm/svm/nestedsvm.c +0 -1
@@ -7,7 +7,6 @@#include <asm/hvm/support.h> #include <asm/hvm/svm.h> -#include <asm/hvm/svm/vmcb.h> #include <asm/hvm/nestedhvm.h> #include <asm/paging.h> /* paging_mode_hap */ #include <asm/event.h> /* for local_event_delivery_(en|dis)able */
xen/arch/x86/hvm/svm/svm.c +0 -1
@@ -27,7 +27,6 @@#include <asm/hvm/nestedhvm.h> #include <asm/hvm/support.h> #include <asm/hvm/svm.h> -#include <asm/hvm/svm/vmcb.h> #include <asm/i387.h> #include <asm/idt.h> #include <asm/iocap.h>
xen/arch/x86/hvm/svm/vmcb.c +0 -1
@@ -16,7 +16,6 @@#include <asm/guest-msr.h> #include <asm/hvm/svm.h> -#include <asm/hvm/svm/vmcb.h> #include <asm/msr-index.h> #include <asm/p2m.h> #include <asm/spec_ctrl.h>
xen/arch/x86/include/asm/hvm/domain.h +1 -1
@@ -15,7 +15,7 @@#include <asm/hvm/io.h> #include <asm/hvm/vmx/vmcs.h> -#include <asm/hvm/svm/vmcb.h> +#include <asm/hvm/svm-types.h> #ifdef CONFIG_MEM_SHARING struct mem_sharing_domain
xen/arch/x86/include/asm/hvm/svm-types.h new file +11 -0
@@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* SVM types needed to form struct domain/vcpu. +*/ +#ifndef X86_SVM_TYPES_H +#define X86_SVM_TYPES_H + +#include <asm/hvm/svm/vmcb.h> +#include <asm/hvm/svm/nestedsvm.h> + +#endif /* X86_SVM_TYPES_H */
xen/arch/x86/include/asm/hvm/vcpu.h +1 -2
@@ -12,8 +12,7 @@#include <asm/hvm/vlapic.h> #include <asm/hvm/vmx/vmcs.h> #include <asm/hvm/vmx/vvmx.h> -#include <asm/hvm/svm/vmcb.h> -#include <asm/hvm/svm/nestedsvm.h> +#include <asm/hvm/svm-types.h> #include <asm/mtrr.h> #include <public/hvm/ioreq.h>
Signature · 1 line
2.39.5
PATCH 4/5 x86/svm: Merge nestedsvm.h into svm-types.h
In reply to Andrew CooperWhile doing so, move the ns_gif field to beside ns_hap_enabled to remove 7 padding bytes, and make some style fixes to comments/etc.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/include/asm/hvm/svm-types.h | 66 +++++++++++++++- xen/arch/x86/include/asm/hvm/svm/nestedsvm.h | 79 -------------------- 2 files changed, 65 insertions(+), 80 deletions(-) delete mode 100644 xen/arch/x86/include/asm/hvm/svm/nestedsvm.h
xen/arch/x86/include/asm/hvm/svm-types.h +65 -1
@@ -5,7 +5,71 @@#ifndef X86_SVM_TYPES_H #define X86_SVM_TYPES_H +#include <xen/types.h> +#include <asm/hvm/svm/vmcb.h> -#include <asm/hvm/svm/nestedsvm.h> + +struct nestedsvm { +uint64_t ns_msr_hsavepa;/* MSR HSAVE_PA value */ + +/* +* l1 guest physical address of virtual vmcb used by prior VMRUN. Needed +* for VMCB Cleanbit emulation. +*/ +uint64_t ns_ovvmcb_pa; + +/* Cached real intercepts of the l2 guest */ +uint32_t ns_cr_intercepts; +uint32_t ns_dr_intercepts; +uint32_t ns_exception_intercepts; +uint32_t ns_general1_intercepts; +uint32_t ns_general2_intercepts; + +/* Cached real MSR permission bitmaps of the l2 guest */ +unsigned long *ns_cached_msrpm; +/* Merged MSR permission bitmap */ +unsigned long *ns_merged_msrpm; + +/* guest physical address of virtual io permission map */ +paddr_t ns_iomap_pa, ns_oiomap_pa; +/* Shadow io permission map */ +unsigned long *ns_iomap; + +/* +* Cached guest_cr[0] of l1 guest while l2 guest runs. Needed to handle +* FPU context switching. +*/ +uint64_t ns_cr0; + +/* +* Cache guest cr3/host cr3 the guest sets up for the l2 guest. +* Used by Shadow-on-Shadow and Nested-on-Nested. +* ns_vmcb_guestcr3: in l2 guest physical address space and points to +* the l2 guest page table +* ns_vmcb_hostcr3: in l1 guest physical address space and points to +* the l1 guest nested page table +*/ +uint64_t ns_vmcb_guestcr3, ns_vmcb_hostcr3; +uint32_t ns_asid; + +bool ns_gif; +bool ns_hap_enabled; + +/* Only meaningful when vmexit_pending flag is set */ +struct { +uint64_t exitcode;/* native exitcode to inject into l1 guest */ +uint64_t exitinfo1;/* additional information to the exitcode */ +uint64_t exitinfo2;/* additional information to the exitcode */ + } ns_vmexit; + +union { +uint32_t bytes; +struct { +uint32_t rflagsif:1 ; +uint32_t vintrmask:1 ; +uint32_t reserved:30 ; + } fields; + } ns_hostflags; +};#endif /* X86_SVM_TYPES_H */
xen/arch/x86/include/asm/hvm/svm/nestedsvm.h deleted +0 -79
79 lines not on this page · raw message
Signature · 1 line
2.39.5
PATCH 5/5 x86/svm: Merge vmcb.h into svm-types.h
In reply to Andrew CooperWhile doing so, make some style fixes to comments/etc.
This removes the include/asm/hvm/svm/ subdirectory.
No functional change.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- xen/arch/x86/include/asm/hvm/svm-types.h | 32 +++++++++++++- xen/arch/x86/include/asm/hvm/svm/vmcb.h | 55 ------------------------ 2 files changed, 31 insertions(+), 56 deletions(-) delete mode 100644 xen/arch/x86/include/asm/hvm/svm/vmcb.h
xen/arch/x86/include/asm/hvm/svm-types.h +31 -1
@@ -7,7 +7,37 @@#include <xen/types.h> -#include <asm/hvm/svm/vmcb.h> +struct svm_domain { +union { +uint64_t raw[2 ]; +struct { +uint64_t length; +uint64_t status; + }; + } osvw; +}; + +struct svm_vcpu { +struct vmcb_struct *vmcb; +unsigned long *msrpm; +uint64_t vmcb_pa; +int launch_core; + +uint8_t vmcb_sync_state;/* enum vmcb_sync_state */ + +/* VMCB has a cached instruction from #PF/#NPF Decode Assist? */ +uint8_t cached_insn_len;/* Zero if no cached instruction. */ + +/* +* Upper four bytes are undefined in the VMCB, therefore we can't use the +* fields in the VMCB. Write a 64bit value and then read a 64bit value is +* fine unless there's a VMRUN/VMEXIT in between which clears the upper +* four bytes. +*/ +uint64_t guest_sysenter_cs; +uint64_t guest_sysenter_esp; +uint64_t guest_sysenter_eip; +};struct nestedsvm {uint64_t ns_msr_hsavepa;/* MSR HSAVE_PA value */
xen/arch/x86/include/asm/hvm/svm/vmcb.h deleted +0 -55
55 lines not on this page · raw message
Signature · 1 line
2.39.5
Quoted 10 lines · Andrew Cooper
This turned out to be a little easier than I was expecting.
https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2212088192
Andrew Cooper (5):
x86/svm: Moveasm/hvm/svm/svm.hup one directory x86/svm: Movesvm_intercept_msr()intosvm.hx86/svm: Introducesvm-types.h
x86/svm: Mergenestedsvm.hintosvm-types.hx86/svm: Mergevmcb.hintosvm-types.h
ideally with svm/svm-types.h in patch 3's description corrected to hvm/svm-types.h.
Jan