x86/HVM: Improve EFER validation error messages
PATCH 1/1 x86/HVM: Improve EFER validation error messages
The previous error message was very little use in identifying the actual problem after the fact. Now, hvm_efer_valid() will indicate the issue which it objects to, which is far more useful for diagnosing issues from logs.
--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/hvm.c +22 -16
@@ -1683,8 +1683,9 @@ static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)return 0 ; } -static bool_t hvm_efer_valid (const struct vcpu *v,uint64_t value, -signed int cr0_pg) +/* Return a string indiciating the error, or NULL for valid. */ +static const char *hvm_efer_valid (const struct vcpu *v,uint64_t value, +signed int cr0_pg) {unsigned int ext1_ecx =0 , ext1_edx =0 ;
@@ -1716,31 +1717,31 @@ static bool_t hvm_efer_valid(const struct vcpu *v, uint64_t value,if ( (value &EFER_SCE ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_SYSCALL )) && (cr0_pg >=0 || !(value &EFER_LME )) ) -return 0 ; +return "SCE without feature" ;if ( (value & (EFER_LME |EFER_LMA )) && !(ext1_edx &cpufeat_mask (X86_FEATURE_LM )) ) -return 0 ; +return "LME/LMA without feature" ;if ( (value &EFER_LMA ) && (!(value &EFER_LME ) || !cr0_pg) ) -return 0 ; +return "LMA/LME/CR0.PG inconsistency" ;if ( (value &EFER_NX ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_NX )) ) -return 0 ; +return "NX without feature" ;if ( (value &EFER_SVME ) && (!(ext1_ecx &cpufeat_mask (X86_FEATURE_SVM )) || !nestedhvm_enabled (v->domain)) ) -return 0 ; +return "SVME without nested virt" ;if ( (value &EFER_LMSLE ) && !cpu_has_lmsl ) -return 0 ; +return "LMSLE without support" ;if ( (value &EFER_FFXSE ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_FFXSR )) ) -return 0 ; +return "FFXSE without feature" ; -return 1 ; +return NULL ; }/* These reserved bits in lower 32 remain 0 after any load of CR0 */
@@ -1818,6 +1819,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)struct vcpu *v;struct hvm_hw_cpu ctxt;struct segment_register seg; +const char *errstr;/* Which vcpu is this? */ vcpuid =hvm_load_instance (h);
@@ -1848,10 +1850,11 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)return -EINVAL ; } -if ( !hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )) ) + errstr =hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )); +if ( errstr ) { -printk (XENLOG_G_ERR "HVM%d restore: bad EFER %#" PRIx64"\n" , - d->domain_id, ctxt.msr_efer); +printk (XENLOG_G_ERR "HVM%d restore: bad EFER %#" PRIx64" - %s\n" , + d->domain_id, ctxt.msr_efer, errstr);return -EINVAL ; }
@@ -2988,13 +2991,16 @@ err:int hvm_set_efer (uint64_t value) {struct vcpu *v = current; +const char *errstr; value &= ~EFER_LMA ; -if ( !hvm_efer_valid (v, value,-1 ) ) + errstr =hvm_efer_valid (v, value,-1 ); +if ( errstr ) { -gdprintk (XENLOG_WARNING ,"Trying to set reserved bit in " -"EFER: %#" PRIx64"\n" , value); +printk (XENLOG_G_WARNING +"%pv Invalid EFER update: %#" PRIx64" -> %#" PRIx64" - %s\n" , + v, v->arch.hvm_vcpu.guest_efer, value, errstr);hvm_inject_hw_exception (TRAP_gp_fault,0 );return X86EMUL_EXCEPTION ; }
Signature · 1 line
1.7.10.4
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 23.01.15 at 16:53, <[email protected]> wrote:
The previous error message was very little use in identifying the actual problem after the fact. Now,
hvm_efer_valid()will indicate the issue which it objects to, which is far more useful for diagnosing issues from logs.
Nice, but ...
xen/arch/x86/hvm/hvm.c static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) · line 1857
Quoted 12 lines
xen/arch/x86/hvm/hvm.c +4
-3@@ -1848,10 +1850,11 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)return -EINVAL ; } -if ( !hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )) ) + errstr =hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )); +if ( errstr ) { -printk (XENLOG_G_ERR "HVM%d restore: bad EFER %#" PRIx64"\n" , - d->domain_id, ctxt.msr_efer); +printk (XENLOG_G_ERR "HVM%d restore: bad EFER %#" PRIx64" - %s\n" , + d->domain_id, ctxt.msr_efer, errstr);
... as you fiddle with it to make it more useful, could you make this print domain and vcpu ID?
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1
-0@@ -2988,13 +2991,16 @@ err:int hvm_set_efer (uint64_t value) {struct vcpu *v = current; +const char *errstr;
xen/arch/x86/hvm/hvm.c err: · line 3002
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +4
-3value &= ~EFER_LMA ; -if ( !hvm_efer_valid (v, value,-1 ) ) + errstr =hvm_efer_valid (v, value,-1 ); +if ( errstr ) { -gdprintk (XENLOG_WARNING ,"Trying to set reserved bit in " -"EFER: %#" PRIx64"\n" , value); + printk(XENLOG_G_WARNING + "%pv Invalid EFER update: %#"PRIx64" -> %#"PRIx64" - %s\n",
Perhaps another colon after the %pv?
Jan
PATCH v2 1/1 x86/HVM: Improve EFER validation error messages
The previous error message was very little use in identifying the actual problem after the fact. Now, hvm_efer_valid() will indicate the issue which it objects to, which is far more useful for diagnosing issues from logs.
---
v2: Text formatting tweaks suggested by Jan
--- xen/arch/x86/hvm/hvm.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-)
xen/arch/x86/hvm/hvm.c +22 -16
@@ -1683,8 +1683,9 @@ static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)return 0 ; } -static bool_t hvm_efer_valid (const struct vcpu *v,uint64_t value, -signed int cr0_pg) +/* Return a string indicating the error, or NULL for valid. */ +static const char *hvm_efer_valid (const struct vcpu *v,uint64_t value, +signed int cr0_pg) {unsigned int ext1_ecx =0 , ext1_edx =0 ;
@@ -1716,31 +1717,31 @@ static bool_t hvm_efer_valid(const struct vcpu *v, uint64_t value,if ( (value &EFER_SCE ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_SYSCALL )) && (cr0_pg >=0 || !(value &EFER_LME )) ) -return 0 ; +return "SCE without feature" ;if ( (value & (EFER_LME |EFER_LMA )) && !(ext1_edx &cpufeat_mask (X86_FEATURE_LM )) ) -return 0 ; +return "LME/LMA without feature" ;if ( (value &EFER_LMA ) && (!(value &EFER_LME ) || !cr0_pg) ) -return 0 ; +return "LMA/LME/CR0.PG inconsistency" ;if ( (value &EFER_NX ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_NX )) ) -return 0 ; +return "NX without feature" ;if ( (value &EFER_SVME ) && (!(ext1_ecx &cpufeat_mask (X86_FEATURE_SVM )) || !nestedhvm_enabled (v->domain)) ) -return 0 ; +return "SVME without nested virt" ;if ( (value &EFER_LMSLE ) && !cpu_has_lmsl ) -return 0 ; +return "LMSLE without support" ;if ( (value &EFER_FFXSE ) && !(ext1_edx &cpufeat_mask (X86_FEATURE_FFXSR )) ) -return 0 ; +return "FFXSE without feature" ; -return 1 ; +return NULL ; }/* These reserved bits in lower 32 remain 0 after any load of CR0 */
@@ -1818,6 +1819,7 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)struct vcpu *v;struct hvm_hw_cpu ctxt;struct segment_register seg; +const char *errstr;/* Which vcpu is this? */ vcpuid =hvm_load_instance (h);
@@ -1848,10 +1850,11 @@ static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)return -EINVAL ; } -if ( !hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )) ) + errstr =hvm_efer_valid (v, ctxt.msr_efer,MASK_EXTR (ctxt.cr0,X86_CR0_PG )); +if ( errstr ) { -printk (XENLOG_G_ERR "HVM%d restore: bad EFER %#" PRIx64"\n" , - d->domain_id, ctxt.msr_efer); +printk (XENLOG_G_ERR "%pv: HVM restore: bad EFER %#" PRIx64" - %s\n" , + v, ctxt.msr_efer, errstr);return -EINVAL ; }
@@ -2988,13 +2991,16 @@ err:int hvm_set_efer (uint64_t value) {struct vcpu *v = current; +const char *errstr; value &= ~EFER_LMA ; -if ( !hvm_efer_valid (v, value,-1 ) ) + errstr =hvm_efer_valid (v, value,-1 ); +if ( errstr ) { -gdprintk (XENLOG_WARNING ,"Trying to set reserved bit in " -"EFER: %#" PRIx64"\n" , value); +printk (XENLOG_G_WARNING +"%pv: Invalid EFER update: %#" PRIx64" -> %#" PRIx64" - %s\n" , + v, v->arch.hvm_vcpu.guest_efer, value, errstr);hvm_inject_hw_exception (TRAP_gp_fault,0 );return X86EMUL_EXCEPTION ; }
Signature · 1 line
1.7.10.4