kvm/svm: implement new DecodeAssist features
cover kvm/svm: implement new DecodeAssist features
Hi,
version 2 of the DecodeAssist patches.
Changes over version 1:
- goes on top of the CR8 handling fix I sent out earlier this week (required for proper handling of CR8 exceptions)
- handles exception cases properly (for mov cr and mov dr)
- uses X86_FEATURE_ names instead of SVM_FEATURE names (for boot_cpu_has) (thanks to Joerg for spotting this)
- use static_cpu_has where appropriate
- some minor code cleanups (for instance cr register calculation)
- move prefetch callback into x86_decode_insn and out of every fetch I refrained from ditching the callback at all, as I dont like extending every emulate_instruction call with "NULL, 0". But if this is desperately needed, I can still change it.
- rename vendor specific prefetch function names
Upcoming AMD CPUs will have a SVM enhancement called DecodeAssist which will provide more information when intercepting certain events. These information allows to skip the instruction fetching and decoding and handle the intercept immediately.
This patch set implements all the features which are documented in the recent AMD manual (APM vol. 2). For details see the patches.
Please review and apply.
Regards,
Andre.
PATCH 1/5 kvm/svm: add new SVM feature bit names
the recent APM Vol.2 and the recent AMD CPUID specification describe new CPUID features bits for SVM. Name them here for later usage.
--- arch/x86/kvm/svm.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/kvm/svm.c +4 -0
@@ -51,6 +51,10 @@ MODULE_LICENSE("GPL");#define SVM_FEATURE_LBRV (1 << 1)#define SVM_FEATURE_SVML (1 << 2)#define SVM_FEATURE_NRIP (1 << 3) +#define SVM_FEATURE_TSC_RATE (1 << 4) +#define SVM_FEATURE_VMCB_CLEAN (1 << 5) +#define SVM_FEATURE_FLUSH_ASID (1 << 6) +#define SVM_FEATURE_DECODE_ASSIST (1 << 7)#define SVM_FEATURE_PAUSE_FILTER (1 << 10)#define NESTED_EXIT_HOST 0/* Exit handled on host level */
Signature · 1 line
1.6.4
PATCH 2/5 kvm/svm: enhance MOV CR intercept handler
In reply to Andre PrzywaraNewer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle CR register access intercepts. Implement the handling in svm.c and use it when the info is provided.
--- arch/x86/include/asm/svm.h | 2 + arch/x86/kvm/svm.c | 91 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 11 deletions(-)
arch/x86/include/asm/svm.h +2 -0
@@ -256,6 +256,8 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 +#define SVM_EXITINFO_REG_MASK 0x0F +#define SVM_EXIT_READ_CR0 0x000#define SVM_EXIT_READ_CR3 0x003#define SVM_EXIT_READ_CR4 0x004
arch/x86/kvm/svm.c +80 -11
126 lines not on this page · raw message
Signature · 1 line
1.6.4
Re: [PATCH 2/5] kvm/svm: enhance MOV CR intercept handler
Quoted 33 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle CR register access intercepts. Implement the handling in
svm.cand use it when the info is provided.Signed-off-by Andre Przywara<[email protected]>--- arch/x86/include/asm/svm.h | 2 + arch/x86/kvm/svm.c | 91 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 11 deletions(-)arch/x86/include/asm/svm.h +2
-0@@ -256,6 +256,8 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 +#define SVM_EXITINFO_REG_MASK 0x0F +#define SVM_EXIT_READ_CR0 0x000#define SVM_EXIT_READ_CR3 0x003#define SVM_EXIT_READ_CR4 0x004arch/x86/kvm/svm.c +1
-0@@ -2594,12 +2594,81 @@ static int emulate_on_interception(struct vcpu_svm *svm)return emulate_instruction (&svm->vcpu,0 ,0 ,0 ) ==EMULATE_DONE ; } +static int cr_interception (struct vcpu_svm *svm)
arch/x86/kvm/svm.c static int emulate_on_interception(struct vcpu_svm *svm) · line 2607
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+{ +int reg, cr; +unsigned long val; +int err; + +if (!static_cpu_has (X86_FEATURE_DECODEASSISTS )) +return emulate_on_interception (svm); + +/* bit 63 is the valid bit, as not all instructions (like lmsw) +provide the information */
Please use kernel style comments:
/*
* text
* text
*/
Even better, use a name for the bit, which will obviate the need for a comment.
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 2/5] kvm/svm: enhance MOV CR intercept handler
In reply to Andre PrzywaraQuoted 60 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle CR register access intercepts. Implement the handling in
svm.cand use it when the info is provided.Signed-off-by Andre Przywara <[email protected]>--- arch/x86/include/asm/svm.h | 2 + arch/x86/kvm/svm.c | 91 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 11 deletions(-)arch/x86/include/asm/svm.h +2
-0@@ -256,6 +256,8 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 +#define SVM_EXITINFO_REG_MASK 0x0F +#define SVM_EXIT_READ_CR0 0x000#define SVM_EXIT_READ_CR3 0x003#define SVM_EXIT_READ_CR4 0x004arch/x86/kvm/svm.c +28
-0@@ -2594,12 +2594,81 @@ static int emulate_on_interception(struct vcpu_svm *svm)return emulate_instruction (&svm->vcpu,0 ,0 ,0 ) ==EMULATE_DONE ; } +static int cr_interception (struct vcpu_svm *svm) +{ +int reg, cr; +unsigned long val; +int err; + +if (!static_cpu_has (X86_FEATURE_DECODEASSISTS )) +return emulate_on_interception (svm); + +/* bit 63 is the valid bit, as not all instructions (like lmsw) +provide the information */ +if (unlikely ((svm->vmcb->control.exit_info_1 & (1ULL <<63 )) ==0 )) +return emulate_on_interception (svm); + + reg = svm->vmcb->control.exit_info_1 &SVM_EXITINFO_REG_MASK ; + cr = svm->vmcb->control.exit_code -SVM_EXIT_READ_CR0 ; + + err =0 ; +if (cr >=16 ) {/* mov to cr */ + cr -=16 ; + val =kvm_register_read (&svm->vcpu, reg); +switch (cr) { +case 0 : + err =kvm_set_cr0 (&svm->vcpu, val); +break ; +case 3 : + err =kvm_set_cr3 (&svm->vcpu, val); +break ;
arch/x86/kvm/svm.c static int emulate_on_interception(struct vcpu_svm *svm) · line 2634
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+case 4 : + err =kvm_set_cr4 (&svm->vcpu, val); +break ; +case 8 : + err =kvm_set_cr8 (&svm->vcpu, val); +break ; +default : +WARN (1 ,"unhandled write to CR%d" , cr); +return EMULATE_FAIL ; + }
Wrong return value? Is WARN() really wanted?
Re: [PATCH 2/5] kvm/svm: enhance MOV CR intercept handler
Quoted 65 lines · Marcelo Tosatti
Quoted 64 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle CR register access intercepts. Implement the handling in
svm.cand use it when the info is provided.Signed-off-by Andre Przywara <[email protected]>--- arch/x86/include/asm/svm.h | 2 + arch/x86/kvm/svm.c | 91 ++++++++++++++++++++++++++++++++++++++----- 2 files changed, 82 insertions(+), 11 deletions(-)arch/x86/include/asm/svm.h +2
-0@@ -256,6 +256,8 @@ struct __attribute__ ((__packed__)) vmcb {#define SVM_EXITINFOSHIFT_TS_REASON_JMP 38#define SVM_EXITINFOSHIFT_TS_HAS_ERROR_CODE 44 +#define SVM_EXITINFO_REG_MASK 0x0F +#define SVM_EXIT_READ_CR0 0x000#define SVM_EXIT_READ_CR3 0x003#define SVM_EXIT_READ_CR4 0x004arch/x86/kvm/svm.c +32
-0@@ -2594,12 +2594,81 @@ static int emulate_on_interception(struct vcpu_svm *svm)return emulate_instruction (&svm->vcpu,0 ,0 ,0 ) ==EMULATE_DONE ; } +static int cr_interception (struct vcpu_svm *svm) +{ +int reg, cr; +unsigned long val; +int err; + +if (!static_cpu_has (X86_FEATURE_DECODEASSISTS )) +return emulate_on_interception (svm); + +/* bit 63 is the valid bit, as not all instructions (like lmsw) +provide the information */ +if (unlikely ((svm->vmcb->control.exit_info_1 & (1ULL <<63 )) ==0 )) +return emulate_on_interception (svm); + + reg = svm->vmcb->control.exit_info_1 &SVM_EXITINFO_REG_MASK ; + cr = svm->vmcb->control.exit_code -SVM_EXIT_READ_CR0 ; + + err =0 ; +if (cr >=16 ) {/* mov to cr */ + cr -=16 ; + val =kvm_register_read (&svm->vcpu, reg); +switch (cr) { +case 0 : + err =kvm_set_cr0 (&svm->vcpu, val); +break ; +case 3 : + err =kvm_set_cr3 (&svm->vcpu, val); +break ; +case 4 : + err =kvm_set_cr4 (&svm->vcpu, val); +break ; +case 8 :
Quoted 8 lines
arch/x86/kvm/svm.c static int emulate_on_interception(struct vcpu_svm *svm) · line 2634
Quoted 6 lines
arch/x86/kvm/svm.c +6
-0+ err =kvm_set_cr8 (&svm->vcpu, val); +break ; +default : +WARN (1 ,"unhandled write to CR%d" , cr); +return EMULATE_FAIL ; + }Wrong return value?
Thats right, thanks for catching this. I copied this from somewhere else ;-(
Quoted 1 line
Is
WARN()really wanted?
Well, this is a rather pathological code path. Illegal CR accesses generate #UD before interception, and additionally we don't set the intercept bits for these, so this should really never occur. But just for the sake of completeness I can inject an #UD here and return 1. So I leave the WARN in to inform the user that something stupid is going on, but it could also be BUG().
Regards,
Andre.
Signature · 3 lines
Andre Przywara AMD-OSRC (Dresden) Tel: x29712
PATCH 3/5 kvm/svm: enhance mov DR intercept handler
In reply to Andre PrzywaraNewer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle debug register access intercepts. Implement the handling in svm.c and use it when the info is provided.
--- arch/x86/kvm/svm.c | 61 ++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 45 insertions(+), 16 deletions(-)
arch/x86/kvm/svm.c +45 -16
@@ -2680,6 +2680,35 @@ static int cr0_write_interception(struct vcpu_svm *svm)return r; } +static int dr_interception (struct vcpu_svm *svm) +{ +int reg, dr; +unsigned long val; +int err; + +if (!boot_cpu_has (X86_FEATURE_DECODEASSISTS )) +return emulate_on_interception (svm); + + reg = svm->vmcb->control.exit_info_1 &SVM_EXITINFO_REG_MASK ; + dr = svm->vmcb->control.exit_code -SVM_EXIT_READ_DR0 ; + +if (dr >=16 ) {/* mov to DRn */ + val =kvm_register_read (&svm->vcpu, reg); + err =kvm_set_dr (&svm->vcpu, dr -16 , val); + }else { + err =kvm_get_dr (&svm->vcpu, dr, &val); +if (!err) +kvm_register_write (&svm->vcpu, reg, val); + } + +if (!err) +skip_emulated_instruction (&svm->vcpu); +else +kvm_inject_gp (&svm->vcpu,0 ); + +return 1 ; +} +static int cr8_write_interception (struct vcpu_svm *svm) {struct kvm_run *kvm_run = svm->vcpu.run;
@@ -2943,22 +2972,22 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_WRITE_CR3] = cr_interception, [SVM_EXIT_WRITE_CR4] = cr_interception, [SVM_EXIT_WRITE_CR8] = cr8_write_interception, - [SVM_EXIT_READ_DR0] = emulate_on_interception, - [SVM_EXIT_READ_DR1] = emulate_on_interception, - [SVM_EXIT_READ_DR2] = emulate_on_interception, - [SVM_EXIT_READ_DR3] = emulate_on_interception, - [SVM_EXIT_READ_DR4] = emulate_on_interception, - [SVM_EXIT_READ_DR5] = emulate_on_interception, - [SVM_EXIT_READ_DR6] = emulate_on_interception, - [SVM_EXIT_READ_DR7] = emulate_on_interception, - [SVM_EXIT_WRITE_DR0] = emulate_on_interception, - [SVM_EXIT_WRITE_DR1] = emulate_on_interception, - [SVM_EXIT_WRITE_DR2] = emulate_on_interception, - [SVM_EXIT_WRITE_DR3] = emulate_on_interception, - [SVM_EXIT_WRITE_DR4] = emulate_on_interception, - [SVM_EXIT_WRITE_DR5] = emulate_on_interception, - [SVM_EXIT_WRITE_DR6] = emulate_on_interception, - [SVM_EXIT_WRITE_DR7] = emulate_on_interception, + [SVM_EXIT_READ_DR0] = dr_interception, + [SVM_EXIT_READ_DR1] = dr_interception, + [SVM_EXIT_READ_DR2] = dr_interception, + [SVM_EXIT_READ_DR3] = dr_interception, + [SVM_EXIT_READ_DR4] = dr_interception, + [SVM_EXIT_READ_DR5] = dr_interception, + [SVM_EXIT_READ_DR6] = dr_interception, + [SVM_EXIT_READ_DR7] = dr_interception, + [SVM_EXIT_WRITE_DR0] = dr_interception, + [SVM_EXIT_WRITE_DR1] = dr_interception, + [SVM_EXIT_WRITE_DR2] = dr_interception, + [SVM_EXIT_WRITE_DR3] = dr_interception, + [SVM_EXIT_WRITE_DR4] = dr_interception, + [SVM_EXIT_WRITE_DR5] = dr_interception, + [SVM_EXIT_WRITE_DR6] = dr_interception, + [SVM_EXIT_WRITE_DR7] = dr_interception, [SVM_EXIT_EXCP_BASE + DB_VECTOR] = db_interception, [SVM_EXIT_EXCP_BASE + BP_VECTOR] = bp_interception, [SVM_EXIT_EXCP_BASE + UD_VECTOR] = ud_interception,
Signature · 1 line
1.6.4
Re: [PATCH 3/5] kvm/svm: enhance mov DR intercept handler
arch/x86/kvm/svm.c static int cr0_write_interception(struct vcpu_svm *svm) · line 2708
Quoted 11 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle debug register access intercepts. Implement the handling in
svm.cand use it when the info is provided.arch/x86/kvm/svm.c +6
-0+ +if (!err) +skip_emulated_instruction (&svm->vcpu); +else +kvm_inject_gp (&svm->vcpu,0 ); +
This repeats, how about using complete_insn_gp()?
Signature · 1 line
error compiling committee.c: too many arguments to function
Re: [PATCH 3/5] kvm/svm: enhance mov DR intercept handler
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle debug register access intercepts. Implement the handling in
svm.cand use it when the info is provided.
Quoted 8 lines
arch/x86/kvm/svm.c static int cr0_write_interception(struct vcpu_svm *svm) · line 2708
Quoted 6 lines
arch/x86/kvm/svm.c +6
-0+ +if (!err) +skip_emulated_instruction (&svm->vcpu); +else +kvm_inject_gp (&svm->vcpu,0 ); +This repeats, how about using
complete_insn_gp()?
Do you want this to be in x86.c? We could use kvm_x86_ops->skip_emulated_instruction.
Also shall I look for more similarities in the [CD]R intercept handling code between VMX and SVM? The switch responsible for actually reading and writing the regs is very similar. I could also try to merge this with the functionality in the emulator (if that works, haven't checked)
Regards,
Andre.
Signature · 3 lines
Andre Przywara AMD-Operating System Research Center (OSRC), Dresden, Germany Tel: +49 351 448-3567-12
Re: [PATCH 3/5] kvm/svm: enhance mov DR intercept handler
Quoted 15 lines · Andre Przywara
Quoted 6 lines · Avi Kivity
Quoted 5 lines · Andre Przywara
Newer SVM implementations provide the GPR number in the VMCB, so that the emulation path is no longer necesarry to handle debug register access intercepts. Implement the handling in
svm.cand use it when the info is provided.Quoted 8 lines
arch/x86/kvm/svm.c static int cr0_write_interception(struct vcpu_svm *svm) · line 2708
Quoted 6 lines
arch/x86/kvm/svm.c +6
-0+ +if (!err) +skip_emulated_instruction (&svm->vcpu); +else +kvm_inject_gp (&svm->vcpu,0 ); +This repeats, how about using
complete_insn_gp()?
Quoted 1 line
Do you want this to be in
x86.c?
Yes.
Quoted 3 lines
We could use
kvm_x86_ops->skip_emulated_instruction.
Also shall I look for more similarities in the [CD]R intercept handling code between VMX and SVM? The switch responsible for actually reading and writing the regs is very similar. I could also try to merge this with the functionality in the emulator (if that works, haven't checked)
Let's get DecodeAssist merged first, and do more unification afterwards.
Signature · 1 line
error compiling committee.c: too many arguments to function
PATCH 4/5 kvm/svm: implement enhanced INVLPG intercept
In reply to Andre PrzywaraWhen the DecodeAssist feature is available, the linear address is provided in the VMCB on INVLPG intercepts. Use it directly to avoid any decoding and emulation.
This is only useful for shadow paging, though.
--- arch/x86/kvm/svm.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/kvm/svm.c +6 -1
@@ -2586,7 +2586,12 @@ static int iret_interception(struct vcpu_svm *svm)static int invlpg_interception (struct vcpu_svm *svm) { -return emulate_instruction (&svm->vcpu,0 ,0 ,0 ) ==EMULATE_DONE ; +if (!static_cpu_has (X86_FEATURE_DECODEASSISTS )) +return emulate_instruction (&svm->vcpu,0 ,0 ,0 ) ==EMULATE_DONE ; + +kvm_mmu_invlpg (&svm->vcpu, svm->vmcb->control.exit_info_1); +skip_emulated_instruction (&svm->vcpu); +return 1 ; }static int emulate_on_interception (struct vcpu_svm *svm)
Signature · 1 line
1.6.4
PATCH 5/5 kvm/svm: copy instruction bytes from VMCB
In reply to Andre PrzywaraIn case of a nested page fault or an intercepted #PF newer SVM implementations provide a copy of the faulting instruction bytes in the VMCB.
Use these bytes to feed the instruction emulator and avoid the costly guest instruction fetch in this case.
--- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/include/asm/svm.h | 4 +++- arch/x86/kvm/emulate.c | 1 + arch/x86/kvm/svm.c | 20 ++++++++++++++++++++ arch/x86/kvm/vmx.c | 7 +++++++ 5 files changed, 34 insertions(+), 1 deletions(-)
arch/x86/include/asm/kvm_host.h +3 -0
@@ -586,6 +586,9 @@ struct kvm_x86_ops {void (*write_tsc_offset)(struct kvm_vcpu *vcpu,u64 offset);void (*get_exit_info)(struct kvm_vcpu *vcpu,u64 *info1,u64 *info2); + +int (*prefetch_instruction)(struct kvm_vcpu *vcpu); +const struct trace_print_flags *exit_reasons_str; };
arch/x86/include/asm/svm.h +3 -1
@@ -81,7 +81,9 @@ struct __attribute__ ((__packed__)) vmcb_control_area {u64 lbr_ctl;u64 reserved_5;u64 next_rip; -u8 reserved_6[816 ]; +u8 insn_len; +u8 insn_bytes[15 ]; +u8 reserved_6[800 ]; };
arch/x86/kvm/emulate.c +1 -0
@@ -2623,6 +2623,7 @@ x86_decode_insn(struct x86_emulate_ctxt *ctxt) c->eip = ctxt->eip; c->fetch.start = c->fetch.end = c->eip; ctxt->cs_base =seg_base (ctxt, ops,VCPU_SREG_CS ); + kvm_x86_ops->prefetch_instruction (ctxt->vcpu);switch (mode) {case X86EMUL_MODE_REAL :
arch/x86/kvm/svm.c +20 -0
@@ -464,6 +464,24 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)svm_set_interrupt_shadow (vcpu,0 ); } +static int svm_prefetch_instruction (struct kvm_vcpu *vcpu) +{ +struct vcpu_svm *svm =to_svm (vcpu); +uint8_t len; +struct fetch_cache *fetch; + + len = svm->vmcb->control.insn_len &0x0F ; +if (len ==0 ) +return 1 ; + + fetch = &svm->vcpu.arch.emulate_ctxt.decode.fetch; + fetch->start =kvm_rip_read (&svm->vcpu); + fetch->end = fetch->start + len; +memcpy (fetch->data, svm->vmcb->control.insn_bytes, len); + +return 0 ; +} +static void svm_queue_exception (struct kvm_vcpu *vcpu,unsigned nr,bool has_error_code,u32 error_code,bool reinject)
@@ -3848,6 +3866,8 @@ static struct kvm_x86_ops svm_x86_ops = { .adjust_tsc_offset = svm_adjust_tsc_offset, .set_tdp_cr3 = set_tdp_cr3, + + .prefetch_instruction = svm_prefetch_instruction, };static int __init svm_init (void )
arch/x86/kvm/vmx.c +7 -0
@@ -1009,6 +1009,11 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)vmx_set_interrupt_shadow (vcpu,0 ); } +static int vmx_prefetch_instruction (struct kvm_vcpu *vcpu) +{ +return 1 ; +} +static void vmx_queue_exception (struct kvm_vcpu *vcpu,unsigned nr,bool has_error_code,u32 error_code,bool reinject)
@@ -4362,6 +4367,8 @@ static struct kvm_x86_ops vmx_x86_ops = { .adjust_tsc_offset = vmx_adjust_tsc_offset, .set_tdp_cr3 = vmx_set_cr3, + + .prefetch_instruction = vmx_prefetch_instruction, };static int __init vmx_init (void )
Signature · 1 line
1.6.4
Re: [PATCH 5/5] kvm/svm: copy instruction bytes from VMCB
Quoted 15 lines · Andre Przywara
In case of a nested page fault or an intercepted #PF newer SVM implementations provide a copy of the faulting instruction bytes in the VMCB.
Use these bytes to feed the instruction emulator and avoid the costly guest instruction fetch in this case.arch/x86/kvm/svm.c +7
-0+static int svm_prefetch_instruction (struct kvm_vcpu *vcpu) +{ +struct vcpu_svm *svm =to_svm (vcpu); +uint8_t len; +struct fetch_cache *fetch; + + len = svm->vmcb->control.insn_len&0x0F ;
arch/x86/kvm/svm.c static void skip_emulated_instruction(struct kvm_vcpu *vcpu) · line 483
Quoted 10 lines
arch/x86/kvm/svm.c +10
-0+if (len ==0 ) +return 1 ; + + fetch =&svm->vcpu.arch.emulate_ctxt.decode.fetch; + fetch->start =kvm_rip_read (&svm->vcpu); + fetch->end = fetch->start + len; +memcpy (fetch->data, svm->vmcb->control.insn_bytes, len); + +return 0 ; +}
This reaching in into the emulator internals from svm code is not very good. It also assumes ->prefetch_instruction() is called immediately after an exit; this isn't true in vmx and at least was considered for svm (emulating multiple instructions during the nsvm vmexit sequence).
Alternatives are:
- add the insn data to emulate_instruction() and friends (my first suggestion)
- adding x86_decode_insn_init(), which initializes the decode cache, and x86_decode_insn_prefill_cache(), called only if we have the insn data
Another one: teach kvm_fetch_guest_virt() to check if addr/bytes intersects with csbase+rip/len; if so, use that instead of doing the page table dance.
Signature · 1 line
error compiling committee.c: too many arguments to function