x86/hvm: {svm,vmx}.{c,h} cleanup
cover x86/hvm: {svm,vmx}.{c,h} cleanup
This patch series attempts a cleanup of files {svm,vmx}.{c,h} by removing redundant headers and sorting the rest, removing forward declarations for static functions, reducing the scope of declarations and definitions, removing redundant new lines and trailing spaces etc
Xenia Ragiadakou (4):
x86/svm: cleanup svm.c
x86/svm: cleanup svm.h
x86/vmx: cleanup vmx.c
x86/vmx: cleanup vmx.h
xen/arch/x86/hvm/svm/svm.c | 163 +- xen/arch/x86/hvm/svm/vmcb.c | 3 + xen/arch/x86/hvm/vmx/vmcs.c | 43 + xen/arch/x86/hvm/vmx/vmx.c | 6053 ++++++++++++------------ xen/arch/x86/include/asm/hvm/svm/svm.h | 13 +- xen/arch/x86/include/asm/hvm/vmx/vmx.h | 194 +- 6 files changed, 3210 insertions(+), 3259 deletions(-)
Signature · 1 line
2.37.2
PATCH 1/4 x86/svm: cleanup svm.c
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.h
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Remove the forward declaration of svm_function_table and place start_svm() after the svm_function_table's definition.
Replace double new lines with one.
No functional change intended.
--- xen/arch/x86/hvm/svm/svm.c | 159 +++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 87 deletions(-)
xen/arch/x86/hvm/svm/svm.c +72 -87
@@ -16,60 +16,47 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ +#include <xen/domain_page.h> #include <xen/guest_access.h> +#include <xen/hypercall.h> #include <xen/init.h> #include <xen/lib.h> -#include <xen/trace.h> #include <xen/sched.h> -#include <xen/irq.h> -#include <xen/softirq.h> -#include <xen/hypercall.h> -#include <xen/domain_page.h> +#include <xen/trace.h> #include <xen/xenoprof.h> -#include <asm/current.h> -#include <asm/io.h> -#include <asm/paging.h> -#include <asm/p2m.h> -#include <asm/mem_sharing.h> -#include <asm/regs.h> -#include <asm/cpufeature.h> -#include <asm/processor.h> #include <asm/amd.h> +#include <asm/apic.h> +#include <asm/cpufeature.h> +#include <asm/current.h> #include <asm/debugreg.h> -#include <asm/msr.h> -#include <asm/i387.h> -#include <asm/iocap.h> +#include <asm/gdbsx.h> #include <asm/hvm/emulate.h> #include <asm/hvm/hvm.h> -#include <asm/hvm/support.h> #include <asm/hvm/io.h> -#include <asm/hvm/emulate.h> +#include <asm/hvm/monitor.h> +#include <asm/hvm/nestedhvm.h> +#include <asm/hvm/support.h> #include <asm/hvm/svm/asid.h> -#include <asm/hvm/svm/svm.h> -#include <asm/hvm/svm/vmcb.h> #include <asm/hvm/svm/emulate.h> -#include <asm/hvm/svm/intr.h> -#include <asm/hvm/svm/svmdebug.h> #include <asm/hvm/svm/nestedsvm.h> -#include <asm/hvm/nestedhvm.h> -#include <asm/spec_ctrl.h> -#include <asm/x86_emulate.h> -#include <public/sched.h> -#include <asm/hvm/vpt.h> +#include <asm/hvm/svm/svm.h> +#include <asm/hvm/svm/svmdebug.h> +#include <asm/hvm/svm/vmcb.h> #include <asm/hvm/trace.h> -#include <asm/hap.h> -#include <asm/apic.h> -#include <asm/gdbsx.h> -#include <asm/hvm/monitor.h> +#include <asm/iocap.h> +#include <asm/i387.h> #include <asm/monitor.h> -#include <asm/xstate.h> +#include <asm/msr.h> +#include <asm/paging.h> +#include <asm/processor.h> +#include <asm/p2m.h> +#include <asm/x86_emulate.h> +#include <public/sched.h> void noreturnsvm_asm_do_resume (void );u32 svm_feature_flags; -static struct hvm_function_table svm_function_table; -/* * Physical addresses of the Host State Area (for hardware) and vmcb (for Xen) * which contains Xen's fs/gs/tr/ldtr and GSBASE/STAR/SYSENTER state when in
@@ -505,7 +492,6 @@ static int svm_vmcb_restore(struct vcpu *v, struct hvm_hw_cpu *c)return 0 ; } -static void svm_save_cpu_state (struct vcpu *v,struct hvm_hw_cpu *data) {struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
@@ -517,7 +503,6 @@ static void svm_save_cpu_state(struct vcpu *v, struct hvm_hw_cpu *data) data->msr_syscall_mask = vmcb->sfmask; } -static void svm_load_cpu_state (struct vcpu *v,struct hvm_hw_cpu *data) {struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
@@ -1649,57 +1634,6 @@ static int cf_check svm_cpu_up(void)return _svm_cpu_up (false); } -const struct hvm_function_table *__init start_svm (void ) -{ -bool_t printed =0 ; - -svm_host_osvw_reset (); - -if (_svm_cpu_up (true) ) - { -printk ("SVM: failed to initialise.\n" ); -return NULL ; - } - -setup_vmcb_dump (); - -if ( boot_cpu_data.extended_cpuid_level >=0x8000000a ) - svm_feature_flags =cpuid_edx (0x8000000a ); - -printk ("SVM: Supported advanced features:\n" ); - -/* DecodeAssists fast paths assume nextrip is valid for fast rIP update. */ -if ( !cpu_has_svm_nrips ) -__clear_bit (SVM_FEATURE_DECODEASSISTS , &svm_feature_flags); - -if ( cpu_has_tsc_ratio ) - svm_function_table.tsc_scaling.ratio_frac_bits =32 ; - -#define P (p,s) if ( p ) { printk(" - %s\n", s); printed = 1; } -P (cpu_has_svm_npt,"Nested Page Tables (NPT)" ); -P (cpu_has_svm_lbrv,"Last Branch Record (LBR) Virtualisation" ); -P (cpu_has_svm_nrips,"Next-RIP Saved on #VMEXIT" ); -P (cpu_has_svm_cleanbits,"VMCB Clean Bits" ); -P (cpu_has_svm_decode,"DecodeAssists" ); -P (cpu_has_svm_vloadsave,"Virtual VMLOAD/VMSAVE" ); -P (cpu_has_svm_vgif,"Virtual GIF" ); -P (cpu_has_pause_filter,"Pause-Intercept Filter" ); -P (cpu_has_pause_thresh,"Pause-Intercept Filter Threshold" ); -P (cpu_has_tsc_ratio,"TSC Rate MSR" ); -P (cpu_has_svm_sss,"NPT Supervisor Shadow Stack" ); -P (cpu_has_svm_spec_ctrl,"MSR_SPEC_CTRL virtualisation" ); -#undef P - -if ( !printed ) -printk (" - none\n" ); - - svm_function_table.hap_supported = !!cpu_has_svm_npt; - svm_function_table.hap_capabilities =HVM_HAP_SUPERPAGE_2MB | - (cpu_has_page1gb ?HVM_HAP_SUPERPAGE_1GB :0 ); - -return &svm_function_table; -} -static void svm_do_nested_pgfault (struct vcpu *v,struct cpu_user_regs *regs,uint64_t pfec,paddr_t gpa) {
@@ -2598,6 +2532,57 @@ static struct hvm_function_table __initdata_cf_clobber svm_function_table = { }, }; +const struct hvm_function_table *__init start_svm (void ) +{ +bool_t printed =0 ; + +svm_host_osvw_reset (); + +if (_svm_cpu_up (true) ) + { +printk ("SVM: failed to initialise.\n" ); +return NULL ; + } + +setup_vmcb_dump (); + +if ( boot_cpu_data.extended_cpuid_level >=0x8000000a ) + svm_feature_flags =cpuid_edx (0x8000000a ); + +printk ("SVM: Supported advanced features:\n" ); + +/* DecodeAssists fast paths assume nextrip is valid for fast rIP update. */ +if ( !cpu_has_svm_nrips ) +__clear_bit (SVM_FEATURE_DECODEASSISTS , &svm_feature_flags); + +if ( cpu_has_tsc_ratio ) + svm_function_table.tsc_scaling.ratio_frac_bits =32 ; + +#define P (p,s) if ( p ) { printk(" - %s\n", s); printed = 1; } +P (cpu_has_svm_npt,"Nested Page Tables (NPT)" ); +P (cpu_has_svm_lbrv,"Last Branch Record (LBR) Virtualisation" ); +P (cpu_has_svm_nrips,"Next-RIP Saved on #VMEXIT" ); +P (cpu_has_svm_cleanbits,"VMCB Clean Bits" ); +P (cpu_has_svm_decode,"DecodeAssists" ); +P (cpu_has_svm_vloadsave,"Virtual VMLOAD/VMSAVE" ); +P (cpu_has_svm_vgif,"Virtual GIF" ); +P (cpu_has_pause_filter,"Pause-Intercept Filter" ); +P (cpu_has_pause_thresh,"Pause-Intercept Filter Threshold" ); +P (cpu_has_tsc_ratio,"TSC Rate MSR" ); +P (cpu_has_svm_sss,"NPT Supervisor Shadow Stack" ); +P (cpu_has_svm_spec_ctrl,"MSR_SPEC_CTRL virtualisation" ); +#undef P + +if ( !printed ) +printk (" - none\n" ); + + svm_function_table.hap_supported = !!cpu_has_svm_npt; + svm_function_table.hap_capabilities =HVM_HAP_SUPERPAGE_2MB | + (cpu_has_page1gb ?HVM_HAP_SUPERPAGE_1GB :0 ); + +return &svm_function_table; +} +void svm_vmexit_handler (struct cpu_user_regs *regs) {uint64_t exit_reason;
Signature · 1 line
2.37.2
Re: [PATCH 1/4] x86/svm: cleanup svm.c
Quoted 6 lines · Xenia Ragiadakou
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.h
Out of interest, how are you calculating these? They're accurate as far as I can tell.
Looking at asm/hvm/svm/*, intr.h itself can be straight deleted, svmdebug.h can be merged into vmcb.h, and all the others can move into xen/arch/x86/hvm/svm/ as local headers. None of them have any business being included elsewhere in Xen.
Quoted 2 lines
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Minor grammar point. "Sort the rest of the headers alphabetically" would be a more normal way of phrasing this.
Quoted 9 lines
Remove the forward declaration of
svm_function_tableand placestart_svm()after the svm_function_table's definition.Replace double new lines with one.
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>
Re: [PATCH 1/4] x86/svm: cleanup svm.c
Hi Andrew,
Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Xenia Ragiadakou
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.hOut of interest, how are you calculating these? They're accurate as far as I can tell.
I do not use a script (at least not a decent one), if that 's the question :) . I verify that none of the symbols defined or declared in the header is used in the file including the header.
Quoted 5 lines
Looking at asm/hvm/svm/*,
intr.hitself can be straight deleted,svmdebug.hcan be merged intovmcb.h, and all the others can move into xen/arch/x86/hvm/svm/ as local headers. None of them have any business being included elsewhere in Xen.
I can send another patch for that.
Quoted 6 lines
Quoted 3 lines
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Minor grammar point. "Sort the rest of the headers alphabetically" would be a more normal way of phrasing this.
I will fix it in v2.
Quoted 12 lines
Quoted 10 lines
Remove the forward declaration of
svm_function_tableand placestart_svm()after the svm_function_table's definition.Replace double new lines with one.
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>Acked-by Andrew Cooper <[email protected]>
Signature · 1 line
Xenia
Re: [PATCH 1/4] x86/svm: cleanup svm.c
Quoted 27 lines · Xenia Ragiadakou
Hi Andrew,
Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Xenia Ragiadakou
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.hOut of interest, how are you calculating these? They're accurate as far as I can tell.
I do not use a script (at least not a decent one), if that 's the question :) . I verify that none of the symbols defined or declared in the header is used in the file including the header.
Quoted 5 lines
Looking at asm/hvm/svm/*,
intr.hitself can be straight deleted,svmdebug.hcan be merged intovmcb.h, and all the others can move into xen/arch/x86/hvm/svm/ as local headers. None of them have any business being included elsewhere in Xen.I can send another patch for that.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Minor grammar point. "Sort the rest of the headers alphabetically" would be a more normal way of phrasing this.
I will fix it in v2.
I guess this can be adjusted while committing, seeing that ...
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Remove the forward declaration of
svm_function_tableand placestart_svm()after the svm_function_table's definition.Replace double new lines with one.
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>Acked-by Andrew Cooper <[email protected]>
... it's otherwise ready to be committed.
Jan
Re: [PATCH 1/4] x86/svm: cleanup svm.c
Quoted 43 lines · Jan Beulich
Quoted 27 lines · Xenia Ragiadakou
Hi Andrew,
Quoted 10 lines · Andrew Cooper
Quoted 6 lines · Xenia Ragiadakou
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.hOut of interest, how are you calculating these? They're accurate as far as I can tell.
I do not use a script (at least not a decent one), if that 's the question :) . I verify that none of the symbols defined or declared in the header is used in the file including the header.
Quoted 5 lines
Looking at asm/hvm/svm/*,
intr.hitself can be straight deleted,svmdebug.hcan be merged intovmcb.h, and all the others can move into xen/arch/x86/hvm/svm/ as local headers. None of them have any business being included elsewhere in Xen.I can send another patch for that.
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Minor grammar point. "Sort the rest of the headers alphabetically" would be a more normal way of phrasing this.
I will fix it in v2.
I guess this can be adjusted while committing, seeing that ...
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Remove the forward declaration of
svm_function_tableand placestart_svm()after the svm_function_table's definition.Replace double new lines with one.
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>Acked-by Andrew Cooper <[email protected]>... it's otherwise ready to be committed.
Great, thx.
Quoted 2 lines
Jan
Signature · 1 line
Xenia
Re: [PATCH 1/4] x86/svm: cleanup svm.c
Quoted 52 lines · Xenia Ragiadakou
Quoted 50 lines · Jan Beulich
Quoted 33 lines · Xenia Ragiadakou
Hi Andrew,
Quoted 11 lines · Andrew Cooper
Quoted 6 lines · Xenia Ragiadakou
Do not include the headers:
xen/irq.h
asm/hvm/svm/intr.h
asm/io.h
asm/mem_sharing.h
asm/regs.hOut of interest, how are you calculating these? They're accurate as far
as I can tell.I do not use a script (at least not a decent one), if that 's the question :) . I verify that none of the symbols defined or declared in the header is used in the file including the header.
Quoted 6 lines
Looking at asm/hvm/svm/*,
intr.hitself can be straight deleted,svmdebug.hcan be merged intovmcb.h, and all the others can move into xen/arch/x86/hvm/svm/ as local headers. None of them have any business
being included elsewhere in Xen.I can send another patch for that.
Quoted 5 lines
Quoted 4 lines
because none of the declarations and macro definitions in them is used.
Sort alphabetically the rest of the headers.Quoted 5 lines
Quoted 3 lines
Minor grammar point. "Sort the rest of the headers alphabetically" would
be a more normal way of phrasing this.I will fix it in v2.
I guess this can be adjusted while committing, seeing that ...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Remove the forward declaration of
svm_function_tableand placestart_svm()
after the svm_function_table's definition.Replace double new lines with one.
No functional change intended.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Xenia Ragiadakou <[email protected]>Acked-by Andrew Cooper <[email protected]>... it's otherwise ready to be committed.
Great, thx.
I already committed this patch, with it fixed up, and one other tweak that we commonly do which is to leave a blank line between different groups of headers.
It greatly helps people trying to figure out where to put a new header.
~Andrew
PATCH 2/4 x86/svm: cleanup svm.h
In reply to Xenia RagiadakouRemove the forward declaration of struct vcpu because it is not used.
Move the forward declaration of struct cpu_user_regs just above the function that needs it (to remind that it will need to be removed along with the function).
Move the definitions of NPT_PFEC_with_gla and NPT_PFEC_in_gpt in svm.c because they are used only in this file.
Move the definitions of SVM_PAUSE{FILTER,THRESH}_INIT in vmcb.c because they are used only in this file.
No functional change intended.
--- xen/arch/x86/hvm/svm/svm.c | 6 ++++++ xen/arch/x86/hvm/svm/vmcb.c | 3 +++ xen/arch/x86/include/asm/hvm/svm/svm.h | 13 +------------ 3 files changed, 10 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/svm/svm.c +6 -0
@@ -1634,6 +1634,12 @@ static int cf_check svm_cpu_up(void)return _svm_cpu_up (false); } +/* EXITINFO1 fields on NPT faults */ +#define _NPT_PFEC_with_gla 32 +#define NPT_PFEC_with_gla (1UL<<_NPT_PFEC_with_gla) +#define _NPT_PFEC_in_gpt 33 +#define NPT_PFEC_in_gpt (1UL<<_NPT_PFEC_in_gpt) +static void svm_do_nested_pgfault (struct vcpu *v,struct cpu_user_regs *regs,uint64_t pfec,paddr_t gpa) {
xen/arch/x86/hvm/svm/vmcb.c +3 -0
@@ -30,6 +30,9 @@#include <asm/hvm/svm/svmdebug.h> #include <asm/spec_ctrl.h> +#define SVM_PAUSEFILTER_INIT 4000 +#define SVM_PAUSETHRESH_INIT 1000 +struct vmcb_struct *alloc_vmcb (void ) {struct vmcb_struct *vmcb;
xen/arch/x86/include/asm/hvm/svm/svm.h +1 -12
@@ -45,10 +45,8 @@ static inline void svm_invlpga(unsigned long linear, uint32_t asid) "a" (linear), "c" (asid)); } -struct cpu_user_regs ; -struct vcpu ; -unsigned long *svm_msrbit (unsigned long *msr_bitmap,uint32_t msr); +struct cpu_user_regs ;void __update_guest_eip (struct cpu_user_regs *regs,unsigned int inst_len);/*
@@ -96,17 +94,8 @@ extern u32 svm_feature_flags;#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 SVM_PAUSEFILTER_INIT 4000 -#define SVM_PAUSETHRESH_INIT 1000 -/* TSC rate */ #define DEFAULT_TSC_RATIO 0x0000000100000000ULL#define TSC_RATIO_RSVD_BITS 0xffffff0000000000ULL -/* EXITINFO1 fields on NPT faults */ -#define _NPT_PFEC_with_gla 32 -#define NPT_PFEC_with_gla (1UL<<_NPT_PFEC_with_gla) -#define _NPT_PFEC_in_gpt 33 -#define NPT_PFEC_in_gpt (1UL<<_NPT_PFEC_in_gpt) -#endif /* __ASM_X86_HVM_SVM_H__ */
Signature · 1 line
2.37.2
Re: [PATCH 2/4] x86/svm: cleanup svm.h
Quoted 1 line · Xenia Ragiadakou
Remove the forward declaration of struct vcpu because it is not used.
Huh, turns out that was my fault in c/s b158e72abe, shortly after I introduced them in the first place.
Also, looking into that, there's one legitimate use of svm.h from outside, which is svm_load_segs*() which means we can't make all the headers be local.
But still, most of svm.h shouldn't be includable in the rest of Xen. Perhaps we can make a separate dedicated header for just this.
[edit] And svm_{doman,vcpu}. Perhaps we want a brand new include/asm/hvm/svm.h with only the things needed elsewhere.
Quoted 3 lines
Move the forward declaration of struct
cpu_user_regsjust above the function that needs it (to remind that it will need to be removed along with the function).
I'm not sure. This feels like churn.
Quoted 2 lines
Move the definitions of
NPT_PFEC_with_glaandNPT_PFEC_in_gptinsvm.cbecause they are used only in this file.
IMO, these would better live in vmcb.h because that's where all the other decode information lives, not that there is much. I previously started trying to convert all the exit_into fields into a typed union, but I didn't get as far the NPT info.
Quoted 2 lines
Move the definitions of SVM_PAUSE{FILTER,THRESH}_INIT in
vmcb.cbecause they are used only in this file.
Honestly, at this point you might as well just delete the defines, and opencode at their single usage site. They're pure obfuscation like this, given no statement of units / behaviour, etc.
That said, we do need to stea^W borrow adaptive PLE, and make the settings hvm-common because right now we've got two different ways of configuring the same thing for VT-x and SVM. (This is definitely not cleanup work. Just an observation for anyone feeling at a loose end.)
~Andrew
Re: [PATCH 2/4] x86/svm: cleanup svm.h
Quoted 10 lines · Andrew Cooper
Quoted 1 line · Xenia Ragiadakou
Remove the forward declaration of struct vcpu because it is not used.
Huh, turns out that was my fault in c/s
b158e72abe, shortly after I introduced them in the first place.Also, looking into that, there's one legitimate use of
svm.hfrom outside, which is svm_load_segs*() which means we can't make all the headers be local.
Quoted 5 lines
But still, most of
svm.hshouldn't be includable in the rest of Xen. Perhaps we can make a separate dedicated header for just this.[edit] And svm_{doman,vcpu}. Perhaps we want a brand new
include/asm/hvm/svm.hwith only the things needed elsewhere.
This can be done as part of the series aiming to make svm/vmx support configurable.
Quoted 6 lines
Quoted 4 lines
Move the forward declaration of struct
cpu_user_regsjust above the function that needs it (to remind that it will need to be removed along with the function).I'm not sure. This feels like churn.
Ok I will leave it where it is in v2.
Quoted 8 lines
Quoted 3 lines
Move the definitions of
NPT_PFEC_with_glaandNPT_PFEC_in_gptinsvm.cbecause they are used only in this file.IMO, these would better live in
vmcb.hbecause that's where all the other decode information lives, not that there is much. I previously started trying to convert all theexit_intofields into a typed union, but I didn't get as far the NPT info.
Ok I will fix it in v2.
Quoted 7 lines
Quoted 3 lines
Move the definitions of SVM_PAUSE{FILTER,THRESH}_INIT in
vmcb.cbecause they are used only in this file.Honestly, at this point you might as well just delete the defines, and opencode at their single usage site. They're pure obfuscation like this, given no statement of units / behaviour, etc.
Ok I will do in v2.
Quoted 2 lines
That said, we do need to stea^W borrow adaptive PLE, and make the
I cannot understand what do you mean by "stea^W borrow adaptive PLE".
Quoted 3 lines
settings hvm-common because right now we've got two different ways of configuring the same thing for VT-x and SVM. (This is definitely not cleanup work. Just an observation for anyone feeling at a loose end.)
I will create hvm_function_table stubs for the functions that are used in common code, do the same thing but are implemented differently by svm and vtx, as part of the series aiming to make svm/vmx support configurable.
Quoted 2 lines
~Andrew
Signature · 1 line
Xenia
Re: [PATCH 2/4] x86/svm: cleanup svm.h
Quoted 12 lines · Xenia Ragiadakou
Quoted 10 lines · Andrew Cooper
Quoted 1 line · Xenia Ragiadakou
Remove the forward declaration of struct vcpu because it is not used.
Huh, turns out that was my fault in c/s
b158e72abe, shortly after I introduced them in the first place.Also, looking into that, there's one legitimate use of
svm.hfrom outside, which is svm_load_segs*() which means we can't make all the headers be local.
Quoted 8 lines
Quoted 5 lines
But still, most of
svm.hshouldn't be includable in the rest of Xen. Perhaps we can make a separate dedicated header for just this.[edit] And svm_{doman,vcpu}. Perhaps we want a brand new
include/asm/hvm/svm.hwith only the things needed elsewhere.This can be done as part of the series aiming to make svm/vmx support configurable.
Ok, that's fine.
Honestly, there's a lot of cleanup which can be done. We probably want to end up making a number of $foo-types.h headers so we can construct struct vcpu/domain without xen/sched.h including the majority of Xen in one fell swoop.
Quoted 5 lines
Quoted 3 lines
That said, we do need to stea^W borrow adaptive PLE, and make the
I cannot understand what do you mean by "stea^W borrow adaptive PLE".
Pause Loop Exiting is tricky to get right.
The common expectation is that PLE hits in a spinlock or other mutual exclusion primitive.
It is generally good to let the vCPU spin for a bit, in the expectation that the other vCPU holding lock will release it in a timely fashion. Spinning for a few iterations (even a few hundred) is far lower overhead than taking a vmexit.
But if the other vCPU isn't executing, it can never release the lock, and letting the current vCPU spin does double damage because it consumes the domain's scheduler credit, which in turn pushes out the reschedule of the vCPU that's actually holding the lock. (This is why paravirt spinlocks are so useful in virt. If you get them right, you end up with only the vcpus that can usefully do work to release a lock executing.)
For overall system performance, there is a tradeoff between how long you let a vCPU spin, and when it's better to force such a vCPU to yield. This point depends on the typical spinlock contention inside the guest, and the overall system busyness, both of which vary over time.
Picking fixed numbers for PLE is better than not having PLE in the first place, but only just. There is an algorithm called adaptive-PLE which tries to balance the PLE settings over time to optimise overall system performance.
~Andrew
PATCH 3/4 x86/vmx: cleanup vmx.c
In reply to Xenia RagiadakouDo not include the headers:
asm/hvm/vpic.h
asm/hvm/vpt.h
asm/io.h
asm/mce.h
asm/mem_sharing.h
asm/regs.h
public/arch-x86/cpuid.h
public/hvm/save.h
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Rearrange the code to replace all forward declarations with the function definitions.
Replace double new lines with one.
Reduce scope of nvmx_enqueue_n2_exceptions() to static because it is used only in this file.
Move vmx_update_debug_state() in vmcs.c because it is used only in this file and limit its scope to this file by declaring it static and removing its declaration from vmx.h.
Take the opportunity to remove all trailing spaces in vmx.c.
No functional change intended.
--- xen/arch/x86/hvm/vmx/vmcs.c | 12 + xen/arch/x86/hvm/vmx/vmx.c | 5844 ++++++++++++------------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 1 - 3 files changed, 2913 insertions(+), 2944 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +12 -0
@@ -1864,6 +1864,18 @@ void vmx_vmentry_failure(void)domain_crash (curr->domain); } +static void vmx_update_debug_state (struct vcpu *v) +{ +if ( v->arch.hvm.debug_state_latch ) + v->arch.hvm.vmx.exception_bitmap |=1U << TRAP_int3; +else + v->arch.hvm.vmx.exception_bitmap &= ~(1U << TRAP_int3); + +vmx_vmcs_enter (v); +vmx_update_exception_bitmap (v); +vmx_vmcs_exit (v); +} +void noreturnvmx_asm_do_vmentry (void ); void cf_check vmx_do_resume(void)
xen/arch/x86/hvm/vmx/vmx.c +2901 -2943
2,982 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.37.2
Part of the diff is not shown here. View the raw message.
Re: [PATCH 3/4] x86/vmx: cleanup vmx.c
Quoted 26 lines · Xenia Ragiadakou
Do not include the headers:
asm/hvm/vpic.h
asm/hvm/vpt.h
asm/io.h
asm/mce.h
asm/mem_sharing.h
asm/regs.h
public/arch-x86/cpuid.h
public/hvm/save.h
because none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.Rearrange the code to replace all forward declarations with the function definitions.
Replace double new lines with one.
Reduce scope of
nvmx_enqueue_n2_exceptions()to static because it is used only in this file.Move
vmx_update_debug_state()invmcs.cbecause it is used only in this file and limit its scope to this file by declaring it static and removing its declaration fromvmx.h.Take the opportunity to remove all trailing spaces in
vmx.c.
Quoted 8 lines
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>--- xen/arch/x86/hvm/vmx/vmcs.c | 12 + xen/arch/x86/hvm/vmx/vmx.c | 5844 ++++++++++++------------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 1 - 3 files changed, 2913 insertions(+), 2944 deletions(-)
I'm afraid this is close to unreviewable and hence absolutely needs splitting. With this massive amount of re-arrangement (it's half of vmx.c, after all) I'm also concerned of losing "git blame"-ability for fair parts of the code there.
Jan
Re: [PATCH 3/4] x86/vmx: cleanup vmx.c
Hi Jan,
Quoted 36 lines · Jan Beulich
Quoted 26 lines · Xenia Ragiadakou
Do not include the headers:
asm/hvm/vpic.h asm/hvm/vpt.h asm/io.h asm/mce.h asm/mem_sharing.h asm/regs.h public/arch-x86/cpuid.h public/hvm/save.hbecause none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Rearrange the code to replace all forward declarations with the function definitions.
Replace double new lines with one.
Reduce scope of
nvmx_enqueue_n2_exceptions()to static because it is used only in this file.Move
vmx_update_debug_state()invmcs.cbecause it is used only in this file and limit its scope to this file by declaring it static and removing its declaration fromvmx.h.Take the opportunity to remove all trailing spaces in
vmx.c.Quoted 8 lines
No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>--- xen/arch/x86/hvm/vmx/vmcs.c | 12 + xen/arch/x86/hvm/vmx/vmx.c | 5844 ++++++++++++------------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 1 - 3 files changed, 2913 insertions(+), 2944 deletions(-)
Quoted 3 lines
I'm afraid this is close to unreviewable and hence absolutely needs splitting. With this massive amount of re-arrangement (it's half of
vmx.c, after all) I'm also concerned of losing "git blame"-ability for fair parts of the code there.
I understand. Let me split the changes apart from the one that rearranges the code. Do you agree in principle? or do you want me to except and sth else?
Quoted 2 lines
Jan
Signature · 1 line
Xenia
Re: [PATCH 3/4] x86/vmx: cleanup vmx.c
Quoted 37 lines · Xenia Ragiadakou
Quoted 36 lines · Jan Beulich
Quoted 34 lines · Xenia Ragiadakou
Do not include the headers:
asm/hvm/vpic.h asm/hvm/vpt.h asm/io.h asm/mce.h asm/mem_sharing.h asm/regs.h public/arch-x86/cpuid.h public/hvm/save.hbecause none of the declarations and macro definitions in them is used. Sort alphabetically the rest of the headers.
Rearrange the code to replace all forward declarations with the function definitions.
Replace double new lines with one.
Reduce scope of
nvmx_enqueue_n2_exceptions()to static because it is used only in this file.Move
vmx_update_debug_state()invmcs.cbecause it is used only in this file and limit its scope to this file by declaring it static and removing its declaration fromvmx.h.Take the opportunity to remove all trailing spaces in
vmx.c.No functional change intended.
Signed-off-by Xenia Ragiadakou <[email protected]>--- xen/arch/x86/hvm/vmx/vmcs.c | 12 + xen/arch/x86/hvm/vmx/vmx.c | 5844 ++++++++++++------------ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 1 - 3 files changed, 2913 insertions(+), 2944 deletions(-)
Quoted 7 lines
Quoted 3 lines
I'm afraid this is close to unreviewable and hence absolutely needs splitting. With this massive amount of re-arrangement (it's half of
vmx.c, after all) I'm also concerned of losing "git blame"-ability for fair parts of the code there.I understand. Let me split the changes apart from the one that rearranges the code. Do you agree in principle? or do you want me to except and sth else?
Well, the large amount of code movement wants at least one other party (e.g. Kevin, Andrew, or Roger) agreeing with your approach. As said, I for one don't like this interruption in half-way easy history determination (which can be particularly helpful e.g. when you want to find a commit to put in a Fixes: tag).
Jan
PATCH 4/4 x86/vmx: cleanup vmx.h
In reply to Xenia RagiadakouDo not include the headers:
asm/i387.h
asm/hvm/trace.h
asm/processor.h
asm/regs.h
because none of the declarations and macro definitions in them is used in this file. Sort alphabetically the rest of the headers.
Fix build by including asm/i387.h in vmx.c, needed for vcpu_restore_fpu_lazy().
Move the definition of GAS_VMX_OP just above the functions that use it and undefine it after its usage.
Move in vmcs.c the definitions of:
ept_sync_all()
__vmxoff()
__vmxon()
because they are used only in this file. Take the opportunity to remove a trailing white space.
Move in vmx.c the definitions of:
pi_test_and_set_pir()
pi_test_pir()
pi_test_and_set_on()
pi_set_on()
pi_test_and_clear_on()
pi_test_on()
pi_get_pir()
pi_test_sn()
pi_set_sn()
pi_clear_sn()
vpid_sync_vcpu_gva()
because they are used only in this file.
Move in vmx.c the declarations of:
ve_info_t
ept_qual_t
idt_or_gdt_instr_info_t
ldt_or_tr_instr_info_t
because they are used only in this file.
No functional change intended.
--- xen/arch/x86/hvm/vmx/vmcs.c | 31 ++++ xen/arch/x86/hvm/vmx/vmx.c | 141 ++++++++++++++++++ xen/arch/x86/include/asm/hvm/vmx/vmx.h | 193 ++----------------------- 3 files changed, 182 insertions(+), 183 deletions(-)
xen/arch/x86/hvm/vmx/vmcs.c +31 -0
@@ -691,6 +691,37 @@ void cf_check vmx_cpu_dead(unsigned int cpu)vmx_pi_desc_fixup (cpu); } +static inline void __vmxoff (void ) +{ + asmvolatile ( +VMXOFF_OPCODE + : : : "memory" ); +} + +static inline int __vmxon (u64 addr) +{ +int rc; + + asmvolatile ( +"1: " VMXON_OPCODE MODRM_EAX_06 "\n" +" setna %b0 ; neg %0\n" /* CF==1 or ZF==1 --> rc = -1 */ +"2:\n" +".section .fixup,\"ax\"\n" +"3: sub $2,%0 ; jmp 2b\n" /* #UD or #GP --> rc = -2 */ +".previous\n" + _ASM_EXTABLE(1b, 3b) + : "=q" (rc) + : "0" (0), "a" (&addr) + : "memory"); + +return rc; +} + +static inline void ept_sync_all (void ) +{ +__invept (INVEPT_ALL_CONTEXT ,0 ); +} +static int _vmx_cpu_up (bool bsp) {u32 eax, edx;
xen/arch/x86/hvm/vmx/vmx.c +141 -0
177 lines not on this page · raw message
xen/arch/x86/include/asm/hvm/vmx/vmx.h +10 -183
245 lines not on this page · raw message
Signature · 1 line
2.37.2
Re: [PATCH 4/4] x86/vmx: cleanup vmx.h
Quoted 12 lines · Xenia Ragiadakou
Do not include the headers:
asm/i387.h
asm/hvm/trace.h
asm/processor.h
asm/regs.h
because none of the declarations and macro definitions in them is used in this file. Sort alphabetically the rest of the headers.
Fix build by includingasm/i387.hinvmx.c, needed forvcpu_restore_fpu_lazy().Move the definition of
GAS_VMX_OPjust above the functions that use it and undefine it after its usage.
Quoted 6 lines
Move in
vmcs.cthe definitions of:
ept_sync_all()
__vmxoff()
__vmxon()
because they are used only in this file. Take the opportunity to remove a trailing white space.
While the latter two are probably fine to be moved, I think the first one wants to remain where it is, as new uses might appear.
Quoted 5 lines
Move in
vmx.cthe definitions of:
pi_test_and_set_pir()
pi_test_pir()
pi_test_and_set_on()
pi_set_on()
Quoted 8 lines
pi_test_and_clear_on()
pi_test_on()
pi_get_pir()
pi_test_sn()
pi_set_sn()
pi_clear_sn()
vpid_sync_vcpu_gva()
because they are used only in this file.
I'm not fully convinced of such movement. As a general remark: We typically avoid "inline" for functions in .c files. Yet most if not all of the above are pretty good candidates for being explicitly marked "inline".
Quoted 6 lines
Move in
vmx.cthe declarations of:
ve_info_t
ept_qual_t
idt_or_gdt_instr_info_t
ldt_or_tr_instr_info_t
because they are used only in this file.
I disagree with the movement of such types. Sooner or later they may want using by vvmx.c as well. If you want to move them, then to a private header under xen/arch/x86/hvm/vmx/.
Finally I think at least the individual groups of what is being moved or adjusted want splitting into separate patches.
Jan
Re: [PATCH 4/4] x86/vmx: cleanup vmx.h
Quoted 20 lines · Jan Beulich
Quoted 12 lines · Xenia Ragiadakou
Do not include the headers:
asm/i387.h asm/hvm/trace.h asm/processor.h asm/regs.hbecause none of the declarations and macro definitions in them is used in this file. Sort alphabetically the rest of the headers.
Fix build by includingasm/i387.hinvmx.c, needed forvcpu_restore_fpu_lazy().Move the definition of
GAS_VMX_OPjust above the functions that use it and undefine it after its usage.Quoted 6 lines
Move in
vmcs.cthe definitions of:ept_sync_all() __vmxoff() __vmxon()because they are used only in this file. Take the opportunity to remove a trailing white space.
Quoted 2 lines
While the latter two are probably fine to be moved, I think the first one wants to remain where it is, as new uses might appear.
Ok I will leave it where it is.
Quoted 15 lines
Quoted 13 lines
Move in
vmx.cthe definitions of:pi_test_and_set_pir() pi_test_pir() pi_test_and_set_on() pi_set_on() pi_test_and_clear_on() pi_test_on() pi_get_pir() pi_test_sn() pi_set_sn() pi_clear_sn() vpid_sync_vcpu_gva()Quoted 1 line
because they are used only in this file.
Quoted 3 lines
I'm not fully convinced of such movement. As a general remark: We typically avoid "inline" for functions in .c files. Yet most if not all of the above are pretty good candidates for being explicitly marked "inline".
I could create a private header.
Quoted 11 lines
Quoted 7 lines
Move in
vmx.cthe declarations of:
ve_info_t
ept_qual_t
idt_or_gdt_instr_info_t
ldt_or_tr_instr_info_t
because they are used only in this file.I disagree with the movement of such types. Sooner or later they may want using by
vvmx.cas well. If you want to move them, then to a private header under xen/arch/x86/hvm/vmx/.
Ok will do.
Quoted 3 lines
Finally I think at least the individual groups of what is being moved or adjusted want splitting into separate patches.
Ok.
Quoted 2 lines
Jan
Signature · 1 line
Xenia