mce: fix coding style
cover mce: fix coding style
Some files in xen/arch/x86/cpu/mcheck use mixed coding styles. Unify them to Xen hypervisor coding style. For mctelem.c which is entirely in one coding style, only remove extra blanks.
No functional change is introduced.
Haozhong Zhang (6):
x86/mce: adapt mce.{c,h} to Xen hypervisor coding style x86/vmce: adapt vmce.c to Xen hypervisor coding style x86/mce: adapt mcation.c to Xen hypervisor coding style x86/mce: adapt mce_intel.c to Xen hypervisor coding style x86/mce: add emacs block to mctelem.c
x86/mce: remove trailing spaces in mctelem.c
xen/arch/x86/cpu/mcheck/mcaction.c | 74 ++--- xen/arch/x86/cpu/mcheck/mce.c | 536 ++++++++++++++++++++---------------- xen/arch/x86/cpu/mcheck/mce.h | 21 +- xen/arch/x86/cpu/mcheck/mce_intel.c | 262 ++++++++++-------- xen/arch/x86/cpu/mcheck/mctelem.c | 14 +- xen/arch/x86/cpu/mcheck/vmce.c | 5 +- 6 files changed, 509 insertions(+), 403 deletions(-)
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 1/6 x86/mce: adapt mce.{c, h} to Xen hypervisor coding style
--- xen/arch/x86/cpu/mcheck/mce.c | 536 +++++++++++++++++++++++------------------- xen/arch/x86/cpu/mcheck/mce.h | 21 +- 2 files changed, 311 insertions(+), 246 deletions(-)
xen/arch/x86/cpu/mcheck/mce.c +297 -239
@@ -64,7 +64,7 @@ struct mca_banks *mca_allbanks;int mce_verbosity;static int __init mce_set_verbosity (const char *str) { -if (strcmp ("verbose" , str) ==0 ) +if (strcmp ("verbose" , str) ==0 ) mce_verbosity =MCE_VERBOSE ;else return -EINVAL ;
@@ -81,7 +81,6 @@ static void unexpected_machine_check(const struct cpu_user_regs *regs)fatal_trap (regs,1 ); } -static x86_mce_vector_t _machine_check_vector = unexpected_machine_check;void x86_mce_vector_register (x86_mce_vector_t hdlr)
@@ -97,11 +96,13 @@ void do_machine_check(const struct cpu_user_regs *regs)_machine_check_vector (regs); } -/* Init machine check callback handler +/* +* Init machine check callback handler * It is used to collect additional information provided by newer * CPU families/models without the need to duplicate the whole handler. * This avoids having many handlers doing almost nearly the same and each -* with its own tweaks ands bugs. */ +* with its own tweaks ands bugs. +*/ static x86_mce_callback_t mc_callback_bank_extended =NULL ;void x86_mce_callback_register (x86_mce_callback_t cbfunc)
@@ -109,7 +110,8 @@ void x86_mce_callback_register(x86_mce_callback_t cbfunc) mc_callback_bank_extended = cbfunc; } -/* Machine check recoverable judgement callback handler +/* +* Machine check recoverable judgement callback handler * It is used to judge whether an UC error is recoverable by software */ static mce_recoverable_t mc_recoverable_scan =NULL ;
@@ -124,12 +126,12 @@ struct mca_banks *mcabanks_alloc(void)struct mca_banks *mb; mb = xmalloc(struct mca_banks); -if (!mb) +if ( !mb )return NULL ; mb->bank_map = xzalloc_array(unsigned long,BITS_TO_LONGS (nr_mce_banks)); -if (!mb->bank_map) +if ( !mb->bank_map ) {xfree (mb);return NULL ;
@@ -142,9 +144,9 @@ struct mca_banks *mcabanks_alloc(void)void mcabanks_free (struct mca_banks *banks) { -if (banks ==NULL ) +if ( banks ==NULL )return ; -if (banks->bank_map) +if ( banks->bank_map )xfree (banks->bank_map);xfree (banks); }
@@ -155,15 +157,16 @@ static void mcabank_clear(int banknum) status =mca_rdmsr (MSR_IA32_MCx_STATUS (banknum)); -if (status & MCi_STATUS_ADDRV) +if ( status & MCi_STATUS_ADDRV )mca_wrmsr (MSR_IA32_MCx_ADDR (banknum),0x0ULL ); -if (status & MCi_STATUS_MISCV) +if ( status & MCi_STATUS_MISCV )mca_wrmsr (MSR_IA32_MCx_MISC (banknum),0x0ULL );mca_wrmsr (MSR_IA32_MCx_STATUS (banknum),0x0ULL ); } -/* Judging whether to Clear Machine Check error bank callback handler +/* +* Judging whether to Clear Machine Check error bank callback handler * According to Intel latest MCA OS Recovery Writer's Guide, * whether the error MCA bank needs to be cleared is decided by the mca_source * and MCi_status bit value.
@@ -188,17 +191,15 @@ const struct mca_error_handler *__read_mostly mce_uhandlers;unsigned int __read_mostly mce_dhandler_num;unsigned int __read_mostly mce_uhandler_num; - -static void mca_init_bank (enum mca_source who, -struct mc_info *mi,int bank) +static void mca_init_bank (enum mca_source who,struct mc_info *mi,int bank) {struct mcinfo_bank *mib; -if (!mi) +if ( !mi )return ; mib =x86_mcinfo_reserve (mi,sizeof (*mib),MC_TYPE_BANK ); -if (!mib) +if ( !mib ) { mi->flags |=MCINFO_FLAGS_UNCOMPLETE ;return ;
@@ -209,26 +210,27 @@ static void mca_init_bank(enum mca_source who, mib->mc_bank = bank; mib->mc_domid =DOMID_INVALID ; -if (mib->mc_status & MCi_STATUS_MISCV) +if ( mib->mc_status & MCi_STATUS_MISCV ) mib->mc_misc =mca_rdmsr (MSR_IA32_MCx_MISC (bank)); -if (mib->mc_status & MCi_STATUS_ADDRV) +if ( mib->mc_status & MCi_STATUS_ADDRV ) mib->mc_addr =mca_rdmsr (MSR_IA32_MCx_ADDR (bank)); -if ((mib->mc_status & MCi_STATUS_MISCV) && - (mib->mc_status & MCi_STATUS_ADDRV) && - (mc_check_addr (mib->mc_status, mib->mc_misc,MC_ADDR_PHYSICAL )) && - (who ==MCA_POLLER || who ==MCA_CMCI_HANDLER ) && - (mfn_valid (_mfn (paddr_to_pfn (mib->mc_addr))))) +if ( (mib->mc_status & MCi_STATUS_MISCV) && + (mib->mc_status & MCi_STATUS_ADDRV) && + (mc_check_addr (mib->mc_status, mib->mc_misc,MC_ADDR_PHYSICAL )) && + (who ==MCA_POLLER || who ==MCA_CMCI_HANDLER ) && + (mfn_valid (_mfn (paddr_to_pfn (mib->mc_addr)))) ) {struct domain *d; d =maddr_get_owner (mib->mc_addr); -if (d) +if ( d ) mib->mc_domid = d->domain_id; } -if (who ==MCA_CMCI_HANDLER ) { +if ( who ==MCA_CMCI_HANDLER ) + { mib->mc_ctrl2 =mca_rdmsr (MSR_IA32_MC0_CTL2 + bank); mib->mc_tsc =rdtsc (); }
@@ -252,7 +254,8 @@ static int mca_init_global(uint32_t flags, struct mcinfo_global *mig) &mig->mc_coreid, &mig->mc_core_threadid, &mig->mc_apicid, NULL, NULL, NULL); -if (curr !=INVALID_VCPU ) { +if ( curr !=INVALID_VCPU ) + { mig->mc_domid = curr->domain->domain_id; mig->mc_vcpuid = curr->vcpu_id; }
@@ -260,14 +263,17 @@ static int mca_init_global(uint32_t flags, struct mcinfo_global *mig)return 0 ; } -/* Utility function to perform MCA bank telemetry readout and to push that +/* +* Utility function to perform MCA bank telemetry readout and to push that * telemetry towards an interested dom0 for logging and diagnosis. * The caller - #MC handler or MCA poll function - must arrange that we -* do not migrate cpus. */ +* do not migrate cpus. +*/ /* XXFM Could add overflow counting? */ -/* Add out_param clear_bank for Machine Check Handler Caller. +/* +* Add out_param clear_bank for Machine Check Handler Caller. * For Intel latest CPU, whether to clear the error bank status needs to * be judged by the callback function defined above. */
@@ -286,7 +292,8 @@ mcheck_mca_logout(enum mca_source who, struct mca_banks *bankmask,int i; gstatus =mca_rdmsr (MSR_IA32_MCG_STATUS ); -switch (who) { +switch ( who ) + {case MCA_MCE_SCAN : mc_flags =MC_FLAG_MCE ; which =MC_URGENT ;
@@ -307,34 +314,42 @@ mcheck_mca_logout(enum mca_source who, struct mca_banks *bankmask,BUG (); } -/* If no mc_recovery_scan callback handler registered, +/* +* If no mc_recovery_scan callback handler registered, * this error is not recoverable */ - recover = (mc_recoverable_scan) ?1 :0 ; + recover = mc_recoverable_scan ?1 :0 ; -for (i =0 ; i < nr_mce_banks; i++) { +for ( i =0 ; i < nr_mce_banks; i++ ) + {/* Skip bank if corresponding bit in bankmask is clear */ -if (!mcabanks_test (i, bankmask)) +if ( !mcabanks_test (i, bankmask) )continue ; status =mca_rdmsr (MSR_IA32_MCx_STATUS (i)); -if (!(status & MCi_STATUS_VAL)) +if ( !(status & MCi_STATUS_VAL) )continue ;/* this bank has no valid telemetry */ -/* For Intel Latest CPU CMCI/MCE Handler caller, we need to +/* +* For Intel Latest CPU CMCI/MCE Handler caller, we need to * decide whether to clear bank by MCi_STATUS bit value such as * OVER/UC/EN/PCC/S/AR */ if ( mc_need_clearbank_scan ) need_clear =mc_need_clearbank_scan (who, status); -/* If this is the first bank with valid MCA DATA, then +/* +* If this is the first bank with valid MCA DATA, then * try to reserve an entry from the urgent/nonurgent queue * depending on whether we are called from an exception or * a poller; this can fail (for example dom0 may not -* yet have consumed past telemetry). */ -if (errcnt++ ==0 ) { -if ( (mctc =mctelem_reserve (which)) !=NULL ) { +* yet have consumed past telemetry). +*/ +if ( errcnt++ ==0 ) + { + mctc =mctelem_reserve (which); +if ( mctc ) + { mci =mctelem_dataptr (mctc);mcinfo_clear (mci); mig =x86_mcinfo_reserve (mci,sizeof (*mig),MC_TYPE_GLOBAL );
@@ -342,49 +357,50 @@ mcheck_mca_logout(enum mca_source who, struct mca_banks *bankmask,ASSERT (mig);mca_init_global (mc_flags, mig);/* A hook here to get global extended msrs */ -if (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL ) +if ( boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL )intel_get_extended_msrs (mig, mci); } }/* flag for uncorrected errors */ -if (!uc && ((status & MCi_STATUS_UC) !=0 )) +if ( !uc && ((status & MCi_STATUS_UC) !=0 ) ) uc = true;/* flag processor context corrupt */ -if (!pcc && ((status & MCi_STATUS_PCC) !=0 )) +if ( !pcc && ((status & MCi_STATUS_PCC) !=0 ) ) pcc = true; -if (recover && uc) +if ( recover && uc )/* uc = true, recover = true, we need not panic. */ recover =mc_recoverable_scan (status);mca_init_bank (who, mci, i); -if (mc_callback_bank_extended) +if ( mc_callback_bank_extended )mc_callback_bank_extended (mci, i, status);/* By default, need_clear = true */ -if (who !=MCA_MCE_SCAN && need_clear) +if ( who !=MCA_MCE_SCAN && need_clear )/* Clear bank */ mcabank_clear (i); -else if ( who ==MCA_MCE_SCAN && need_clear) +else if ( who ==MCA_MCE_SCAN && need_clear )mcabanks_set (i, clear_bank);wmb (); } -if (mig && errcnt >0 ) { -if (pcc) +if ( mig && errcnt >0 ) + { +if ( pcc ) mig->mc_flags |=MC_FLAG_UNCORRECTABLE ; -else if (uc) +else if ( uc ) mig->mc_flags |=MC_FLAG_RECOVERABLE ;else mig->mc_flags |=MC_FLAG_CORRECTABLE ; } - -if (sp) { +if ( sp ) + { sp->errcnt = errcnt; sp->ripv = (gstatus &MCG_STATUS_RIPV ) !=0 ; sp->eipv = (gstatus &MCG_STATUS_EIPV ) !=0 ;
@@ -399,19 +415,20 @@ mcheck_mca_logout(enum mca_source who, struct mca_banks *bankmask,static void mce_spin_lock (spinlock_t *lk) { -while (!spin_trylock (lk)) { -cpu_relax (); -mce_panic_check (); - } +while ( !spin_trylock (lk) ) + { +cpu_relax (); +mce_panic_check (); + } }static void mce_spin_unlock (spinlock_t *lk) { -spin_unlock (lk); +spin_unlock (lk); }static enum mce_result mce_action (const struct cpu_user_regs *regs, -mctelem_cookie_t mctc); +mctelem_cookie_t mctc);/* * Return:
@@ -419,11 +436,11 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,* 0: Continue to next step */ static int mce_urgent_action (const struct cpu_user_regs *regs, -mctelem_cookie_t mctc) +mctelem_cookie_t mctc) {uint64_t gstatus; -if ( mctc ==NULL ) +if ( mctc ==NULL )return 0 ; gstatus =mca_rdmsr (MSR_IA32_MCG_STATUS );
@@ -460,50 +477,49 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)mce_spin_lock (&mce_logout_lock); -if (clear_bank !=NULL ) { -memset ( clear_bank->bank_map,0x0 , -sizeof (long ) *BITS_TO_LONGS (clear_bank->num)); - } +if ( clear_bank !=NULL ) +memset (clear_bank->bank_map,0x0 , +sizeof (long ) *BITS_TO_LONGS (clear_bank->num)); mctc =mcheck_mca_logout (MCA_MCE_SCAN , bankmask, &bs, clear_bank); lmce = bs.lmce; bcast = mce_broadcast && !lmce; -if (bs.errcnt) { +if ( bs.errcnt ) + {/* * Uncorrected errors must be dealt with in softirq context. */ -if (bs.uc || bs.pcc) { +if ( bs.uc || bs.pcc ) + {add_taint (TAINT_MACHINE_CHECK ); -if (mctc !=NULL ) +if ( mctc )mctelem_defer (mctc, lmce);/* * For PCC=1 and can't be recovered, context is lost, so * reboot now without clearing the banks, and deal with * the telemetry after reboot (the MSRs are sticky) */ -if (bs.pcc || !bs.recoverable) +if ( bs.pcc || !bs.recoverable )cpumask_set_cpu (smp_processor_id (), &mce_fatal_cpus); - }else { -if (mctc !=NULL ) -mctelem_commit (mctc); } +else if ( mctc !=NULL ) +mctelem_commit (mctc);atomic_set (&found_error,1 );/* The last CPU will be take check/clean-up etc */ atomic_set (&severity_cpu,smp_processor_id ());mce_printk (MCE_CRITICAL ,"MCE: clear_bank map %lx on CPU%d\n" , - *((unsigned long *)clear_bank),smp_processor_id ()); -if (clear_bank !=NULL ) + *((unsigned long *)clear_bank),smp_processor_id ()); +if ( clear_bank !=NULL )mcheck_mca_clearbanks (clear_bank); - }else { -if (mctc !=NULL ) -mctelem_dismiss (mctc); } +else if ( mctc !=NULL ) +mctelem_dismiss (mctc);mce_spin_unlock (&mce_logout_lock);mce_barrier_enter (&mce_trap_bar, bcast); -if ( mctc !=NULL &&mce_urgent_action (regs, mctc)) +if ( mctc !=NULL &&mce_urgent_action (regs, mctc) )cpumask_set_cpu (smp_processor_id (), &mce_fatal_cpus);mce_barrier_exit (&mce_trap_bar, bcast);
@@ -511,14 +527,16 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)* Wait until everybody has processed the trap. */ mce_barrier_enter (&mce_trap_bar, bcast); -if (lmce ||atomic_read (&severity_cpu) ==smp_processor_id ()) { -/* According to SDM, if no error bank found on any cpus, +if ( lmce ||atomic_read (&severity_cpu) ==smp_processor_id () ) + { +/* +* According to SDM, if no error bank found on any cpus, * something unexpected happening, we can't do any * recovery job but to reset the system. */ -if (atomic_read (&found_error) ==0 ) +if (atomic_read (&found_error) ==0 )mc_panic ("MCE: No CPU found valid MCE, need reset" ); -if (!cpumask_empty (&mce_fatal_cpus)) +if ( !cpumask_empty (&mce_fatal_cpus) ) {char *ebufp, ebuf[96 ] ="MCE: Fatal error happened on CPUs " ; ebufp = ebuf +strlen (ebuf);
@@ -533,7 +551,8 @@ void mcheck_cmn_handler(const struct cpu_user_regs *regs)/* Clear flags after above fatal check */ mce_barrier_enter (&mce_trap_bar, bcast); gstatus =mca_rdmsr (MSR_IA32_MCG_STATUS ); -if ((gstatus &MCG_STATUS_MCIP ) !=0 ) { +if ( (gstatus &MCG_STATUS_MCIP ) !=0 ) + {mce_printk (MCE_CRITICAL ,"MCE: Clear MCIP@ last step" );mca_wrmsr (MSR_IA32_MCG_STATUS ,0 ); }
@@ -546,8 +565,9 @@ void mcheck_mca_clearbanks(struct mca_banks *bankmask) {int i; -for (i =0 ; i < nr_mce_banks; i++) { -if (!mcabanks_test (i, bankmask)) +for ( i =0 ; i < nr_mce_banks; i++ ) + { +if ( !mcabanks_test (i, bankmask) )continue ;mcabank_clear (i); }
@@ -565,19 +585,16 @@ bool mce_available(const struct cpuinfo_x86 *c)*/ unsigned int mce_firstbank (struct cpuinfo_x86 *c) { -if (c->x86 ==6 ) { -if (c->x86_vendor ==X86_VENDOR_INTEL && c->x86_model <0x1a ) -return 1 ; - } - -return 0 ; +return c->x86 ==6 && + c->x86_vendor ==X86_VENDOR_INTEL && c->x86_model <0x1a ; }int show_mca_info (int inited,struct cpuinfo_x86 *c) {static enum mcheck_type g_type = mcheck_unset; -if (inited != g_type) { +if ( inited != g_type ) + {char prefix[20 ];static const char *const type_str[] = { [mcheck_amd_famXX] = "AMD",
@@ -589,7 +606,8 @@ int show_mca_info(int inited, struct cpuinfo_x86 *c) g_type != mcheck_unset ?XENLOG_WARNING :XENLOG_INFO , smp_processor_id());BUG_ON (inited >=ARRAY_SIZE (type_str)); -switch (inited) { +switch ( inited ) + {default :printk ("%s%s machine check reporting enabled\n" , prefix, type_str[inited]);
@@ -618,14 +636,16 @@ static void set_poll_bankmask(struct cpuinfo_x86 *c) mb =per_cpu (poll_bankmask, cpu);BUG_ON (!mb); -if (cmci_support && opt_mce) { +if ( cmci_support && opt_mce ) + { mb->num =per_cpu (no_cmci_banks, cpu)->num;bitmap_copy (mb->bank_map,per_cpu (no_cmci_banks, cpu)->bank_map, nr_mce_banks); } -else { +else + {bitmap_copy (mb->bank_map, mca_allbanks->bank_map, nr_mce_banks); -if (mce_firstbank (c)) +if (mce_firstbank (c) )mcabanks_clear (0 , mb); } }
@@ -637,10 +657,10 @@ int mca_cap_init(void)rdmsrl (MSR_IA32_MCG_CAP , msr_content); -if (msr_content &MCG_CTL_P )/* Control register present ? */ +if ( msr_content &MCG_CTL_P )/* Control register present ? */ wrmsrl (MSR_IA32_MCG_CTL ,0xffffffffffffffffULL ); -if (nr_mce_banks && (msr_content &MCG_CAP_COUNT ) != nr_mce_banks) +if ( nr_mce_banks && (msr_content &MCG_CAP_COUNT ) != nr_mce_banks ) {dprintk (XENLOG_WARNING ,"Different bank number on cpu %x\n" ,smp_processor_id ());
@@ -648,7 +668,7 @@ int mca_cap_init(void) } nr_mce_banks = msr_content &MCG_CAP_COUNT ; -if (!nr_mce_banks) +if ( !nr_mce_banks ) {printk (XENLOG_INFO "CPU%u: No MCE banks present. " "Machine check support disabled\n" ,smp_processor_id ());
@@ -656,16 +676,16 @@ int mca_cap_init(void) }/* mcabanks_alloc depends on nr_mce_banks */ -if (!mca_allbanks) +if ( !mca_allbanks ) {int i; mca_allbanks =mcabanks_alloc (); -for ( i =0 ; i < nr_mce_banks; i++) +for ( i =0 ; i < nr_mce_banks; i++ )mcabanks_set (i, mca_allbanks); } -return mca_allbanks ?0 :-ENOMEM ; +return mca_allbanks ?0 : -ENOMEM ; }static void cpu_bank_free (unsigned int cpu)
@@ -731,7 +751,7 @@ void mcheck_init(struct cpuinfo_x86 *c, bool bsp)return ; } -if (!mce_available (c)) +if ( !mce_available (c) ) {printk (XENLOG_INFO "CPU%i: No machine check support available\n" ,smp_processor_id ());
@@ -739,20 +759,22 @@ void mcheck_init(struct cpuinfo_x86 *c, bool bsp) }/*Hardware Enable */ -if (mca_cap_init ()) +if (mca_cap_init () )return ;/* Early MCE initialisation for BSP. */ if ( bsp &&cpu_bank_alloc (smp_processor_id ()) )BUG (); -switch (c->x86_vendor) { +switch ( c->x86_vendor ) + {case X86_VENDOR_AMD : inited =amd_mcheck_init (c);break ;case X86_VENDOR_INTEL : -switch (c->x86) { +switch ( c->x86 ) + {case 6 :case 15 : inited =intel_mcheck_init (c, bsp);
@@ -765,7 +787,7 @@ void mcheck_init(struct cpuinfo_x86 *c, bool bsp) }show_mca_info (inited, c); -if (inited == mcheck_none || inited == mcheck_unset) +if ( inited == mcheck_none || inited == mcheck_unset ) goto out;intpose_init ();
@@ -807,15 +829,14 @@ void *x86_mcinfo_reserve(struct mc_info *mi, mic_index = mic_base =x86_mcinfo_first (mi);/* go to first free entry */ -for (i =0 ; i <x86_mcinfo_nentries (mi); i++) { +for ( i =0 ; i <x86_mcinfo_nentries (mi); i++ ) mic_index =x86_mcinfo_next (mic_index); - }/* check if there is enough size */ end1 = (unsigned long )((uint8_t *)mic_base +sizeof (struct mc_info )); end2 = (unsigned long )((uint8_t *)mic_index + size); -if (end1 < end2) +if ( end1 < end2 ) {mce_printk (MCE_CRITICAL ,"mcinfo_add: No space left in mc_info\n" );
@@ -854,9 +875,11 @@ static void x86_mcinfo_apei_save(apei_write_mce (&m); } -/* Dump machine check information in a format, +/* +* Dump machine check information in a format, * mcelog can parse. This is used only when -* Dom0 does not take the notification. */ +* Dom0 does not take the notification. +*/ void x86_mcinfo_dump (struct mc_info *mi) {struct mcinfo_common *mic =NULL ;
@@ -865,27 +888,26 @@ void x86_mcinfo_dump(struct mc_info *mi)/* first print the global info */ x86_mcinfo_lookup (mic, mi,MC_TYPE_GLOBAL ); -if (mic ==NULL ) +if ( mic ==NULL )return ; mc_global = (struct mcinfo_global *)mic; -if (mc_global->mc_flags &MC_FLAG_MCE ) { +if ( mc_global->mc_flags &MC_FLAG_MCE )printk (XENLOG_WARNING "CPU%d: Machine Check Exception: %16" PRIx64"\n" , mc_global->mc_coreid, mc_global->mc_gstatus); - }else if (mc_global->mc_flags &MC_FLAG_CMCI ) { +else if ( mc_global->mc_flags &MC_FLAG_CMCI )printk (XENLOG_WARNING "CMCI occurred on CPU %d.\n" , mc_global->mc_coreid); - }else if (mc_global->mc_flags &MC_FLAG_POLLED ) { +else if ( mc_global->mc_flags &MC_FLAG_POLLED )printk (XENLOG_WARNING "POLLED occurred on CPU %d.\n" , mc_global->mc_coreid); - }/* then the bank information */ x86_mcinfo_lookup (mic, mi,MC_TYPE_BANK );/* finds the first entry */ do { - if (mic == NULL) + if ( mic == NULL ) return; - if (mic->type != MC_TYPE_BANK) + if ( mic->type != MC_TYPE_BANK ) goto next; mc_bank = (struct mcinfo_bank *)mic;
@@ -893,20 +915,20 @@ void x86_mcinfo_dump(struct mc_info *mi)printk (XENLOG_WARNING "Bank %d: %16" PRIx64, mc_bank->mc_bank, mc_bank->mc_status); -if (mc_bank->mc_status & MCi_STATUS_MISCV) +if ( mc_bank->mc_status & MCi_STATUS_MISCV )printk ("[%16" PRIx64"]" , mc_bank->mc_misc); -if (mc_bank->mc_status & MCi_STATUS_ADDRV) +if ( mc_bank->mc_status & MCi_STATUS_ADDRV )printk (" at %16" PRIx64, mc_bank->mc_addr);printk ("\n" ); -if (is_mc_panic) +if ( is_mc_panic )x86_mcinfo_apei_save (mc_global, mc_bank); - next: + next: mic =x86_mcinfo_next (mic);/* next entry */ -if ((mic ==NULL ) || (mic->size ==0 )) +if ( (mic ==NULL ) || (mic->size ==0 ) )break ; - }while (1 ); + }while (1 ); }static void do_mc_get_cpu_info (void *v)
@@ -925,8 +947,9 @@ static void do_mc_get_cpu_info(void *v)/* * Deal with sparse masks, condensed into a contig array. */ -while (cpn >=0 ) { -if (cpu_online (cpn)) +while ( cpn >=0 ) + { +if (cpu_online (cpn) ) cindex++; cpn--; }
@@ -956,14 +979,15 @@ static void do_mc_get_cpu_info(void *v) xcp->mc_msrvalues[0 ].reg =MSR_IA32_MCG_CAP ;rdmsrl (MSR_IA32_MCG_CAP , xcp->mc_msrvalues[0 ].value); -if (c->cpuid_level >=1 ) { +if ( c->cpuid_level >=1 ) + {cpuid (1 , &junk, &ebx, &junk, &junk); xcp->mc_clusterid = (ebx >>24 ) &0xff ; - }else + } +else xcp->mc_clusterid =get_apic_id (); } - void x86_mc_get_cpu_info(unsigned cpu, uint32_t *chipid, uint16_t *coreid, uint16_t *threadid, uint32_t *apicid, unsigned *ncores, unsigned *ncores_active,
@@ -973,28 +997,31 @@ void x86_mc_get_cpu_info(unsigned cpu, uint32_t *chipid, uint16_t *coreid, *apicid =cpu_physical_id (cpu); c = &cpu_data[cpu]; -if (c->apicid ==BAD_APICID ) { +if ( c->apicid ==BAD_APICID ) + { *chipid = cpu; *coreid =0 ; *threadid =0 ; -if (ncores !=NULL ) +if ( ncores !=NULL ) *ncores =1 ; -if (ncores_active !=NULL ) +if ( ncores_active !=NULL ) *ncores_active =1 ; -if (nthreads !=NULL ) +if ( nthreads !=NULL ) *nthreads =1 ; - }else { + } +else + { *chipid = c->phys_proc_id; -if (c->x86_max_cores >1 ) +if ( c->x86_max_cores >1 ) *coreid = c->cpu_core_id;else *coreid =0 ; *threadid = c->apicid & ((1 << (c->x86_num_siblings -1 )) -1 ); -if (ncores !=NULL ) +if ( ncores !=NULL ) *ncores = c->x86_max_cores; -if (ncores_active !=NULL ) +if ( ncores_active !=NULL ) *ncores_active = c->booted_cores; -if (nthreads !=NULL ) +if ( nthreads !=NULL ) *nthreads = c->x86_num_siblings; } }
@@ -1002,7 +1029,7 @@ void x86_mc_get_cpu_info(unsigned cpu, uint32_t *chipid, uint16_t *coreid,#define INTPOSE_NENT 50static struct intpose_ent { -unsigned int cpu_nr; +unsigned int cpu_nr;uint64_t msr;uint64_t val; } intpose_arr[INTPOSE_NENT ];
@@ -1012,12 +1039,11 @@ static void intpose_init(void)static int done;int i; -if (done++ >0 ) +if ( done++ >0 )return ; -for (i =0 ; i <INTPOSE_NENT ; i++) { +for ( i =0 ; i <INTPOSE_NENT ; i++ ) intpose_arr[i].cpu_nr =-1 ; - } }
@@ -1026,10 +1052,11 @@ struct intpose_ent *intpose_lookup(unsigned int cpu_nr, uint64_t msr, {int i; -for (i =0 ; i <INTPOSE_NENT ; i++) { -if (intpose_arr[i].cpu_nr == cpu_nr && - intpose_arr[i].msr == msr) { -if (valp !=NULL ) +for ( i =0 ; i <INTPOSE_NENT ; i++ ) + { +if ( intpose_arr[i].cpu_nr == cpu_nr && intpose_arr[i].msr == msr ) + { +if ( valp !=NULL ) *valp = intpose_arr[i].val;return &intpose_arr[i]; }
@@ -1040,16 +1067,19 @@ struct intpose_ent *intpose_lookup(unsigned int cpu_nr, uint64_t msr,static void intpose_add (unsigned int cpu_nr,uint64_t msr,uint64_t val) { -struct intpose_ent *ent; +struct intpose_ent *ent =intpose_lookup (cpu_nr, msr,NULL );int i; -if ((ent =intpose_lookup (cpu_nr, msr,NULL )) !=NULL ) { +if ( ent ) + { ent->val = val;return ; } -for (i =0 , ent = &intpose_arr[0 ]; i <INTPOSE_NENT ; i++, ent++) { -if (ent->cpu_nr ==-1 ) { +for ( i =0 , ent = &intpose_arr[0 ]; i <INTPOSE_NENT ; i++, ent++ ) + { +if ( ent->cpu_nr ==-1 ) + { ent->cpu_nr = cpu_nr; ent->msr = msr; ent->val = val;
@@ -1083,50 +1113,60 @@ static bool x86_mc_msrinject_verify(struct xen_mc_msrinject *mci) c = &cpu_data[smp_processor_id ()]; -for (i =0 ; i < mci->mcinj_count; i++) { +for ( i =0 ; i < mci->mcinj_count; i++ ) + {uint64_t reg = mci->mcinj_msr[i].reg;const char *reason =NULL ; -if (IS_MCA_BANKREG (reg)) { -if (c->x86_vendor ==X86_VENDOR_AMD ) { -/* On AMD we can set MCi_STATUS_WREN in the +if (IS_MCA_BANKREG (reg) ) + { +if ( c->x86_vendor ==X86_VENDOR_AMD ) + { +/* +* On AMD we can set MCi_STATUS_WREN in the * HWCR MSR to allow non-zero writes to banks * MSRs not to #GP. The injector in dom0 * should set that bit, but we detect when it * is necessary and set it as a courtesy to -* avoid #GP in the hypervisor. */ +* avoid #GP in the hypervisor. +*/ mci->mcinj_flags |= _MC_MSRINJ_F_REQ_HWCR_WREN;continue ; - }else { -/* No alternative but to interpose, so require -* that the injector specified as such. */ -if (!(mci->mcinj_flags & -MC_MSRINJ_F_INTERPOSE )) { + } +else + { +/* +* No alternative but to interpose, so require +* that the injector specified as such. +*/ +if ( !(mci->mcinj_flags &MC_MSRINJ_F_INTERPOSE ) ) reason ="must specify interposition" ; - } } - }else { -switch (reg) { -/* MSRs acceptable on all x86 cpus */ + } +else + { +switch ( reg ) + { +/* MSRs acceptable on all x86 cpus */ case MSR_IA32_MCG_STATUS :break ;case MSR_F10_MC4_MISC1 :case MSR_F10_MC4_MISC2 :case MSR_F10_MC4_MISC3 : -if (c->x86_vendor !=X86_VENDOR_AMD ) +if ( c->x86_vendor !=X86_VENDOR_AMD ) reason ="only supported on AMD" ; -else if (c->x86 <0x10 ) +else if ( c->x86 <0x10 ) reason ="only supported on AMD Fam10h+" ;break ; -/* MSRs that the HV will take care of */ +/* MSRs that the HV will take care of */ case MSR_K8_HWCR : -if (c->x86_vendor ==X86_VENDOR_AMD ) +if ( c->x86_vendor ==X86_VENDOR_AMD ) reason ="HV will operate HWCR" ;else - reason ="only supported on AMD" ; + reason ="only supported on AMD" ;break ;default :
@@ -1135,7 +1175,8 @@ static bool x86_mc_msrinject_verify(struct xen_mc_msrinject *mci) } } -if (reason !=NULL ) { +if ( reason !=NULL ) + {printk ("HV MSR INJECT ERROR: MSR %#Lx %s\n" , (unsigned long long )mci->mcinj_msr[i].reg, reason); errs++;
@@ -1151,7 +1192,8 @@ static uint64_t x86_mc_hwcr_wren(void)rdmsrl (MSR_K8_HWCR , old); -if (!(old & K8_HWCR_MCi_STATUS_WREN)) { +if ( !(old & K8_HWCR_MCi_STATUS_WREN) ) + {uint64_t new = old | K8_HWCR_MCi_STATUS_WREN;wrmsrl (MSR_K8_HWCR , new); }
@@ -1161,7 +1203,7 @@ static uint64_t x86_mc_hwcr_wren(void)static void x86_mc_hwcr_wren_restore (uint64_t hwcr) { -if (!(hwcr & K8_HWCR_MCi_STATUS_WREN)) +if ( !(hwcr & K8_HWCR_MCi_STATUS_WREN) )wrmsrl (MSR_K8_HWCR , hwcr); }
@@ -1173,26 +1215,26 @@ static void x86_mc_msrinject(void *data)int intpose;int i; -if (mci->mcinj_flags & _MC_MSRINJ_F_REQ_HWCR_WREN) +if ( mci->mcinj_flags & _MC_MSRINJ_F_REQ_HWCR_WREN ) hwcr =x86_mc_hwcr_wren (); intpose = (mci->mcinj_flags &MC_MSRINJ_F_INTERPOSE ) !=0 ; -for (i =0 , msr = &mci->mcinj_msr[0 ]; - i < mci->mcinj_count; i++, msr++) { +for ( i =0 , msr = &mci->mcinj_msr[0 ]; i < mci->mcinj_count; i++, msr++ ) + {printk ("HV MSR INJECT (%s) target %u actual %u MSR %#Lx <-- %#Lx\n" , - intpose ?"interpose" :"hardware" , + intpose ?"interpose" :"hardware" , mci->mcinj_cpunr,smp_processor_id (), (unsigned long long )msr->reg, (unsigned long long )msr->value); -if (intpose) +if ( intpose )intpose_add (mci->mcinj_cpunr, msr->reg, msr->value);else wrmsrl (msr->reg, msr->value); } -if (mci->mcinj_flags & _MC_MSRINJ_F_REQ_HWCR_WREN) +if ( mci->mcinj_flags & _MC_MSRINJ_F_REQ_HWCR_WREN )x86_mc_hwcr_wren_restore (hwcr); }
@@ -1297,12 +1339,14 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)if ( op->interface_version !=XEN_MCA_INTERFACE_VERSION )return x86_mcerr ("do_mca: interface version mismatch" , -EACCES ); -switch (op->cmd) { +switch ( op->cmd ) + {case XEN_MC_fetch: mc_fetch.nat = &op->u.mc_fetch; cmdflags = mc_fetch.nat->flags; -switch (cmdflags & (XEN_MC_NONURGENT |XEN_MC_URGENT )) { +switch ( cmdflags & (XEN_MC_NONURGENT |XEN_MC_URGENT ) ) + {case XEN_MC_NONURGENT : which =MC_NONURGENT ;break ;
@@ -1317,30 +1361,37 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) flags =XEN_MC_OK ; -if (cmdflags &XEN_MC_ACK ) { +if ( cmdflags &XEN_MC_ACK ) + {mctelem_cookie_t cookie =ID2COOKIE (mc_fetch.nat->fetch_id);mctelem_ack (which, cookie); - }else { -if (!is_pv_32bit_vcpu (v) - ?guest_handle_is_null (mc_fetch.nat->data) - :compat_handle_is_null (mc_fetch.cmp->data)) + } +else + { +if ( !is_pv_32bit_vcpu (v) + ?guest_handle_is_null (mc_fetch.nat->data) + :compat_handle_is_null (mc_fetch.cmp->data) )return x86_mcerr ("do_mca fetch: guest buffer " "invalid" , -EINVAL ); -if ((mctc =mctelem_consume_oldest_begin (which))) { + mctc =mctelem_consume_oldest_begin (which); +if ( mctc ) + {struct mc_info *mcip =mctelem_dataptr (mctc); -if (!is_pv_32bit_vcpu (v) - ?copy_to_guest (mc_fetch.nat->data, mcip,1 ) - :copy_to_compat (mc_fetch.cmp->data, - mcip,1 )) { +if ( !is_pv_32bit_vcpu (v) + ?copy_to_guest (mc_fetch.nat->data, mcip,1 ) + :copy_to_compat (mc_fetch.cmp->data, mcip,1 ) ) + { ret = -EFAULT ; flags |=XEN_MC_FETCHFAILED ; mc_fetch.nat->fetch_id =0 ; - }else { - mc_fetch.nat->fetch_id =COOKIE2ID (mctc); } +else + mc_fetch.nat->fetch_id =COOKIE2ID (mctc);mctelem_consume_oldest_end (mctc); - }else { + } +else + {/* There is no data */ flags |=XEN_MC_NODATA ; mc_fetch.nat->fetch_id =0 ;
@@ -1360,48 +1411,47 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) mc_physcpuinfo.nat = &op->u.mc_physcpuinfo; nlcpu =num_online_cpus (); -if (!is_pv_32bit_vcpu (v) - ? !guest_handle_is_null (mc_physcpuinfo.nat->info) - : !compat_handle_is_null (mc_physcpuinfo.cmp->info)) { -if (mc_physcpuinfo.nat->ncpus <=0 ) +if ( !is_pv_32bit_vcpu (v) + ? !guest_handle_is_null (mc_physcpuinfo.nat->info) + : !compat_handle_is_null (mc_physcpuinfo.cmp->info) ) + { +if ( mc_physcpuinfo.nat->ncpus <=0 )return x86_mcerr ("do_mca cpuinfo: ncpus <= 0" , -EINVAL ); nlcpu =min (nlcpu, (int )mc_physcpuinfo.nat->ncpus); log_cpus =xmalloc_array (xen_mc_logical_cpu_t, nlcpu); -if (log_cpus ==NULL ) +if ( log_cpus ==NULL )return x86_mcerr ("do_mca cpuinfo" , -ENOMEM );on_each_cpu (do_mc_get_cpu_info, log_cpus,1 ); -if (!is_pv_32bit_vcpu (v) - ?copy_to_guest (mc_physcpuinfo.nat->info, - log_cpus, nlcpu) - :copy_to_compat (mc_physcpuinfo.cmp->info, - log_cpus, nlcpu)) +if ( !is_pv_32bit_vcpu (v) + ?copy_to_guest (mc_physcpuinfo.nat->info, log_cpus, nlcpu) + :copy_to_compat (mc_physcpuinfo.cmp->info, log_cpus, nlcpu) ) ret = -EFAULT ;xfree (log_cpus); } mc_physcpuinfo.nat->ncpus = nlcpu; -if (copy_to_guest (u_xen_mc, op,1 )) +if (copy_to_guest (u_xen_mc, op,1 ) )return x86_mcerr ("do_mca cpuinfo" , -EFAULT );break ;case XEN_MC_msrinject: -if (nr_mce_banks ==0 ) +if ( nr_mce_banks ==0 )return x86_mcerr ("do_mca inject" , -ENODEV ); mc_msrinject = &op->u.mc_msrinject; target = mc_msrinject->mcinj_cpunr; -if (target >= nr_cpu_ids) +if ( target >= nr_cpu_ids )return x86_mcerr ("do_mca inject: bad target" , -EINVAL ); -if (!cpu_online (target)) +if ( !cpu_online (target) )return x86_mcerr ("do_mca inject: target offline" , -EINVAL ); -if (mc_msrinject->mcinj_count ==0 ) +if ( mc_msrinject->mcinj_count ==0 )return 0 ;if ( mc_msrinject->mcinj_flags &MC_MSRINJ_F_GPADDR )
@@ -1450,7 +1500,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)put_domain (d); } -if (!x86_mc_msrinject_verify (mc_msrinject)) +if ( !x86_mc_msrinject_verify (mc_msrinject) )return x86_mcerr ("do_mca inject: illegal MSR" , -EINVAL );add_taint (TAINT_ERROR_INJECT );
@@ -1461,16 +1511,16 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)break ;case XEN_MC_mceinject: -if (nr_mce_banks ==0 ) +if ( nr_mce_banks ==0 )return x86_mcerr ("do_mca #MC" , -ENODEV ); mc_mceinject = &op->u.mc_mceinject; target = mc_mceinject->mceinj_cpunr; -if (target >= nr_cpu_ids) +if ( target >= nr_cpu_ids )return x86_mcerr ("do_mca #MC: bad target" , -EINVAL ); -if (!cpu_online (target)) +if ( !cpu_online (target) )return x86_mcerr ("do_mca #MC: target offline" , -EINVAL );add_taint (TAINT_ERROR_INJECT );
@@ -1488,7 +1538,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)cpumask_var_t cmv;bool broadcast = op->u.mc_inject_v2.flags &XEN_MC_INJECT_CPU_BROADCAST ; -if (nr_mce_banks ==0 ) +if ( nr_mce_banks ==0 )return x86_mcerr ("do_mca #MC" , -ENODEV );if ( broadcast )
@@ -1510,7 +1560,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc) "Not all required CPUs are online\n"); } -switch (op->u.mc_inject_v2.flags &XEN_MC_INJECT_TYPE_MASK ) +switch ( op->u.mc_inject_v2.flags &XEN_MC_INJECT_TYPE_MASK ) {case XEN_MC_INJECT_TYPE_MCE : if ( mce_broadcast &&
@@ -1521,8 +1571,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)case XEN_MC_INJECT_TYPE_CMCI :if ( !cmci_apic_vector ) - ret =x86_mcerr ( -"No CMCI supported in platform\n" , -EINVAL ); + ret =x86_mcerr ("No CMCI supported in platform\n" , -EINVAL );else {if (cpumask_test_cpu (smp_processor_id (), cpumap) )
@@ -1557,7 +1606,7 @@ long do_mca(XEN_GUEST_HANDLE_PARAM(xen_mc_t) u_xen_mc)break ; } -if (cpumap != &cpu_online_map) +if ( cpumap != &cpu_online_map )free_cpumask_var (cmv);break ;
@@ -1608,7 +1657,8 @@ void mc_panic(char *s)panic ("HARDWARE ERROR" ); } -/* Machine Check owner judge algorithm: +/* +* Machine Check owner judge algorithm: * When error happens, all cpus serially read its msr banks. * The first CPU who fetches the error bank's info will clear * this bank. Later readers can't get any information again.
@@ -1625,7 +1675,7 @@ void mc_panic(char *s)/* Maybe called in MCE context, no lock, no printk */ static enum mce_result mce_action (const struct cpu_user_regs *regs, -mctelem_cookie_t mctc) +mctelem_cookie_t mctc) {struct mc_info *local_mi;enum mce_result bank_result =MCER_NOERROR ;
@@ -1636,15 +1686,16 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,unsigned int i, handler_num = mce_dhandler_num;/* When in mce context, regs is valid */ -if (regs) +if ( regs ) { handler_num = mce_uhandler_num; handlers = mce_uhandlers; } - local_mi = (struct mc_info *)mctelem_dataptr (mctc); + local_mi = (struct mc_info *)mctelem_dataptr (mctc);x86_mcinfo_lookup (mic, local_mi,MC_TYPE_GLOBAL ); -if (mic ==NULL ) { +if ( mic ==NULL ) + {printk (KERN_ERR "MCE: get local buffer entry failed\n " );return MCER_CONTINUE ; }
@@ -1659,17 +1710,19 @@ static enum mce_result mce_action(const struct cpu_user_regs *regs,for ( ; bank_result !=MCER_RESET && mic && mic->size; mic =x86_mcinfo_next (mic) ) { -if (mic->type !=MC_TYPE_BANK ) { +if ( mic->type !=MC_TYPE_BANK ) + {continue ; } - binfo.mib = (struct mcinfo_bank *)mic; + binfo.mib = (struct mcinfo_bank *)mic; binfo.bank = binfo.mib->mc_bank; bank_result =MCER_NOERROR ; -for ( i =0 ; i < handler_num; i++ ) { -if (handlers[i].owned_error (binfo.mib->mc_status)) +for ( i =0 ; i < handler_num; i++ ) + { +if ( handlers[i].owned_error (binfo.mib->mc_status) ) { handlers[i].recovery_handler (&binfo, &bank_result, regs); -if (worst_result < bank_result) +if ( worst_result < bank_result ) worst_result = bank_result;break ; }
@@ -1691,7 +1744,7 @@ static int mce_delayed_action(mctelem_cookie_t mctc) result =mce_action (NULL , mctc); -switch (result) +switch ( result ) {case MCER_RESET :dprintk (XENLOG_ERR ,"MCE delayed action failed\n" );
@@ -1702,12 +1755,12 @@ static int mce_delayed_action(mctelem_cookie_t mctc)case MCER_RECOVERED :dprintk (XENLOG_INFO ,"MCE: Error is successfully recovered\n" ); - ret =1 ; + ret =1 ;break ;case MCER_CONTINUE :dprintk (XENLOG_INFO ,"MCE: Error can't be recovered, " -"system is tainted\n" ); +"system is tainted\n" );x86_mcinfo_dump (mctelem_dataptr (mctc)); ret =1 ;break ;
@@ -1734,7 +1787,8 @@ static void mce_softirq(void)mce_barrier_enter (&mce_inside_bar, bcast); -if (!lmce) { +if ( !lmce ) + {/* * Everybody is here. Now let's see who gets to do the * recovery work. Right now we just see if there's a CPU
@@ -1747,28 +1801,31 @@ static void mce_softirq(void)atomic_set (&severity_cpu, cpu);mce_barrier_enter (&mce_severity_bar, bcast); -if (!mctelem_has_deferred (cpu)) +if ( !mctelem_has_deferred (cpu) )atomic_set (&severity_cpu, cpu);mce_barrier_exit (&mce_severity_bar, bcast); }/* We choose severity_cpu for further processing */ -if (lmce ||atomic_read (&severity_cpu) == cpu) { +if ( lmce ||atomic_read (&severity_cpu) == cpu ) + {mce_printk (MCE_VERBOSE ,"CPU%d handling errors\n" , cpu); -/* Step1: Fill DOM0 LOG buffer, vMCE injection buffer and +/* +* Step1: Fill DOM0 LOG buffer, vMCE injection buffer and * vMCE MSRs virtualization buffer */ -if (lmce) +if ( lmce )mctelem_process_deferred (cpu, mce_delayed_action, true);else for_each_online_cpu (workcpu)mctelem_process_deferred (workcpu, mce_delayed_action, false);/* Step2: Send Log to DOM0 through vIRQ */ -if (dom0_vmce_enabled ()) { +if (dom0_vmce_enabled () ) + {mce_printk (MCE_VERBOSE ,"MCE: send MCE# to DOM0 through virq\n" );send_global_virq (VIRQ_MCA ); }
@@ -1777,7 +1834,8 @@ static void mce_softirq(void)mce_barrier_exit (&mce_inside_bar, bcast); } -/* Machine Check owner judge algorithm: +/* +* Machine Check owner judge algorithm: * When error happens, all cpus serially read its msr banks. * The first CPU who fetches the error bank's info will clear * this bank. Later readers can't get any infor again.
@@ -1793,7 +1851,7 @@ static void mce_softirq(void)*/ void mce_handler_init (void ) { -if (smp_processor_id () !=0 ) +if (smp_processor_id () !=0 )return ;/* callback register, do we really need so many callback? */
xen/arch/x86/cpu/mcheck/mce.h +14 -7
@@ -19,7 +19,8 @@#define MCE_CRITICAL 2extern int mce_verbosity; -/* Define the default level of machine check related print. +/* +* Define the default level of machine check related print. * When set mce_verbosity=verbose, all mce debug information * will be printed, otherwise, those information will not be * printed.
@@ -62,8 +63,10 @@ void x86_mc_get_cpu_info(unsigned, uint32_t *, uint16_t *, uint16_t *,typedef void (*x86_mce_vector_t )(const struct cpu_user_regs *regs);extern void x86_mce_vector_register (x86_mce_vector_t ); -/* Common generic MCE handler that implementations may nominate -* via x86_mce_vector_register. */ +/* +* Common generic MCE handler that implementations may nominate +* via x86_mce_vector_register. +*/ extern void mcheck_cmn_handler (const struct cpu_user_regs *regs);/* Register a handler for judging whether mce is recoverable. */
@@ -90,12 +93,14 @@ static inline uint64_t mca_rdmsr(unsigned int msr) }while (0 ) -/* Utility function to "logout" all architectural MCA telemetry from the MCA +/* +* Utility function to "logout" all architectural MCA telemetry from the MCA * banks of the current processor. A cookie is returned which may be * uses to reference the data so logged (the cookie can be NULL if * no logout structures were available). The caller can also pass a pointer * to a structure which will be completed with some summary information -* of the MCA data observed in the logout operation. */ +* of the MCA data observed in the logout operation. +*/ enum mca_source { MCA_POLLER,
@@ -126,7 +131,8 @@ extern void mcheck_mca_clearbanks(struct mca_banks *);extern mctelem_cookie_t mcheck_mca_logout (enum mca_source ,struct mca_banks *,struct mca_summary *,struct mca_banks *); -/* Register callbacks to be made during bank telemetry logout. +/* +* Register callbacks to be made during bank telemetry logout. * Those callbacks are only available to those machine check handlers * that call to the common mcheck_cmn_handler or who use the common * telemetry logout function mcheck_mca_logout in error polling.
@@ -136,7 +142,8 @@ extern mctelem_cookie_t mcheck_mca_logout(enum mca_source, struct mca_banks *,typedef bool (*mce_need_clearbank_t )(enum mca_source who,u64 status);extern void mce_need_clearbank_register (mce_need_clearbank_t ); -/* Register a callback to collect additional information (typically non- +/* +* Register a callback to collect additional information (typically non- * architectural) provided by newer CPU families/models without the need * to duplicate the whole handler resulting in various handlers each with * its own tweaks and bugs. The callback receives an struct mc_info pointer
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 2/6 x86/vmce: adapt vmce.c to Xen hypervisor coding style
In reply to Haozhong Zhang--- xen/arch/x86/cpu/mcheck/vmce.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/x86/cpu/mcheck/vmce.c +3 -2
@@ -185,7 +185,7 @@ int vmce_rdmsr(uint32_t msr, uint64_t *val) {case MSR_IA32_MCG_STATUS : *val = cur->arch.vmce.mcg_status; -if (*val) +if ( *val )mce_printk (MCE_VERBOSE ,"MCE: %pv: rd MCG_STATUS %#" PRIx64"\n" , cur, *val);break ;
@@ -354,7 +354,8 @@ static int vmce_save_vcpu_ctxt(struct domain *d, hvm_domain_context_t *h)struct vcpu *v;int err =0 ; -for_each_vcpu ( d, v ) { + for_each_vcpu ( d, v ) + {struct hvm_vmce_vcpu ctxt = { .caps = v->arch.vmce.mcg_cap, .mci_ctl2_bank0 = v->arch.vmce.bank[0 ].mci_ctl2,
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 3/6 x86/mce: adapt mcation.c to Xen hypervisor coding style
In reply to Haozhong Zhang--- xen/arch/x86/cpu/mcheck/mcaction.c | 74 +++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 33 deletions(-)
xen/arch/x86/cpu/mcheck/mcaction.c +41 -33
@@ -6,15 +6,16 @@static struct mcinfo_recovery *mci_action_add_pageoffline (int bank,struct mc_info *mi, -uint64_t mfn,uint32_t status) +uint64_t mfn,uint32_t status) {struct mcinfo_recovery *rec; -if (!mi) +if ( !mi )return NULL ; rec =x86_mcinfo_reserve (mi,sizeof (*rec),MC_TYPE_RECOVERY ); -if (!rec) { +if ( !rec ) + { mi->flags |=MCINFO_FLAGS_UNCOMPLETE ;return NULL ; }
@@ -46,14 +47,15 @@ mc_memerr_dhandler(struct mca_binfo *binfo,int vmce_vcpuid;unsigned int mc_vcpuid; -if (!mc_check_addr (bank->mc_status, bank->mc_misc,MC_ADDR_PHYSICAL )) { +if ( !mc_check_addr (bank->mc_status, bank->mc_misc,MC_ADDR_PHYSICAL ) ) + {dprintk (XENLOG_WARNING , -"No physical address provided for memory error\n" ); +"No physical address provided for memory error\n" );return ; } mfn = bank->mc_addr >>PAGE_SHIFT ; -if (offline_page (mfn,1 , &status)) +if (offline_page (mfn,1 , &status) ) {dprintk (XENLOG_WARNING ,"Failed to offline page %lx for MCE error\n" , mfn);
@@ -63,21 +65,26 @@ mc_memerr_dhandler(struct mca_binfo *binfo,mci_action_add_pageoffline (binfo->bank, binfo->mi, mfn, status);/* This is free page */ -if (status &PG_OFFLINE_OFFLINED ) +if ( status &PG_OFFLINE_OFFLINED ) *result =MCER_RECOVERED ; -else if (status &PG_OFFLINE_AGAIN ) +else if ( status &PG_OFFLINE_AGAIN ) *result =MCER_CONTINUE ; -else if (status &PG_OFFLINE_PENDING ) { +else if ( status &PG_OFFLINE_PENDING ) + {/* This page has owner */ -if (status &PG_OFFLINE_OWNED ) { +if ( status &PG_OFFLINE_OWNED ) + { bank->mc_domid = status >>PG_OFFLINE_OWNER_SHIFT ;mce_printk (MCE_QUIET ,"MCE: This error page is ownded" -" by DOM %d\n" , bank->mc_domid); -/* XXX: Cannot handle shared pages yet +" by DOM %d\n" , bank->mc_domid); +/* +* XXX: Cannot handle shared pages yet * (this should identify all domains and gfn mapping to -* the mfn in question) */ +* the mfn in question) +*/ BUG_ON ( bank->mc_domid ==DOMID_COW ); -if ( bank->mc_domid !=DOMID_XEN ) { +if ( bank->mc_domid !=DOMID_XEN ) + { d =get_domain_by_id (bank->mc_domid);ASSERT (d); gfn =get_gpfn_from_mfn ((bank->mc_addr) >>PAGE_SHIFT );
@@ -85,45 +92,46 @@ mc_memerr_dhandler(struct mca_binfo *binfo,if (unmmap_broken_page (d,_mfn (mfn), gfn) ) {printk ("Unmap broken memory %lx for DOM%d failed\n" , - mfn, d->domain_id); + mfn, d->domain_id); goto vmce_failed; } mc_vcpuid = global->mc_vcpuid; -if (mc_vcpuid ==XEN_MC_VCPUID_INVALID || -/* -* Because MC# may happen asynchronously with the actual -* operation that triggers the error, the domain ID as -* well as the vCPU ID collected in 'global' at MC# are -* not always precise. In that case, fallback to broadcast. -*/ - global->mc_domid != bank->mc_domid || - (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL && - (!(global->mc_gstatus &MCG_STATUS_LMCE ) || - !(d->vcpu[mc_vcpuid]->arch.vmce.mcg_ext_ctl & -MCG_EXT_CTL_LMCE_EN )))) +if ( mc_vcpuid ==XEN_MC_VCPUID_INVALID || +/* +* Because MC# may happen asynchronously with the actual +* operation that triggers the error, the domain ID as +* well as the vCPU ID collected in 'global' at MC# are +* not always precise. In that case, fallback to broadcast. +*/ + global->mc_domid != bank->mc_domid || + (boot_cpu_data.x86_vendor ==X86_VENDOR_INTEL && + (!(global->mc_gstatus &MCG_STATUS_LMCE ) || + !(d->vcpu[mc_vcpuid]->arch.vmce.mcg_ext_ctl & +MCG_EXT_CTL_LMCE_EN ))) ) vmce_vcpuid =VMCE_INJECT_BROADCAST ;else vmce_vcpuid = mc_vcpuid; bank->mc_addr = gfn <<PAGE_SHIFT | - (bank->mc_addr & (PAGE_SIZE -1 )); -if (fill_vmsr_data (bank, d, global->mc_gstatus, vmce_vcpuid)) + (bank->mc_addr & (PAGE_SIZE -1 )); +if (fill_vmsr_data (bank, d, global->mc_gstatus, vmce_vcpuid) ) {mce_printk (MCE_QUIET ,"Fill vMCE# data for DOM%d " -"failed\n" , bank->mc_domid); +"failed\n" , bank->mc_domid); goto vmce_failed; } -/* We will inject vMCE to DOMU*/ +/* We will inject vMCE to DOMU */ if (inject_vmce (d, vmce_vcpuid) <0 ) {mce_printk (MCE_QUIET ,"inject vMCE to DOM%d" -" failed\n" , d->domain_id); +" failed\n" , d->domain_id); goto vmce_failed; } -/* Impacted domain go on with domain's recovery job +/* +* Impacted domain go on with domain's recovery job * if the domain has its own MCA handler. * For xen, it has contained the error and finished * its own recovery job.
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 4/6 x86/mce: adapt mce_intel.c to Xen hypervisor coding style
In reply to Haozhong Zhang--- xen/arch/x86/cpu/mcheck/mce_intel.c | 262 +++++++++++++++++++----------------- 1 file changed, 142 insertions(+), 120 deletions(-)
xen/arch/x86/cpu/mcheck/mce_intel.c +142 -120
@@ -7,7 +7,7 @@#include <xen/smp.h> #include <xen/mm.h> #include <xen/cpu.h> -#include <asm/processor.h> +#include <asm/processor.h> #include <public/sysctl.h> #include <asm/system.h> #include <asm/msr.h>
@@ -64,7 +64,7 @@ static void intel_thermal_interrupt(struct cpu_user_regs *regs)ack_APIC_irq (); -if (NOW () <per_cpu (next, cpu)) +if (NOW () <per_cpu (next, cpu) )return ;per_cpu (next, cpu) =NOW () +MILLISECS (5000 );
@@ -78,17 +78,16 @@ static void intel_thermal_interrupt(struct cpu_user_regs *regs)printk (KERN_EMERG "CPU%u: Temperature above threshold\n" , cpu);printk (KERN_EMERG "CPU%u: Running in modulated clock mode\n" , cpu);add_taint (TAINT_MACHINE_CHECK ); - }else { + }else printk (KERN_INFO "CPU%u: Temperature/speed normal\n" , cpu); - } }/* Thermal monitoring depends on APIC, ACPI and clock modulation */ static bool intel_thermal_supported (struct cpuinfo_x86 *c) { -if (!cpu_has_apic) +if ( !cpu_has_apic )return false; -if (!cpu_has (c,X86_FEATURE_ACPI ) || !cpu_has (c,X86_FEATURE_TM1 )) +if ( !cpu_has (c,X86_FEATURE_ACPI ) || !cpu_has (c,X86_FEATURE_TM1 ) )return false;return true; }
@@ -102,7 +101,7 @@ static void __init mcheck_intel_therm_init(void)* LVT value on BSP and use that value to restore APs' thermal LVT * entry BIOS programmed later */ -if (intel_thermal_supported (&boot_cpu_data)) +if (intel_thermal_supported (&boot_cpu_data) ) lvtthmr_init =apic_read (APIC_LVTTHMR ); }
@@ -115,7 +114,7 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)unsigned int cpu =smp_processor_id ();static uint8_t thermal_apic_vector; -if (!intel_thermal_supported (c)) +if ( !intel_thermal_supported (c) )return ;/* -ENODEV */ /* first check if its enabled already, in which case there might
@@ -134,23 +133,25 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)* BIOS has programmed on AP based on BSP's info we saved (since BIOS * is required to set the same value for all threads/cores). */ -if ((val &APIC_MODE_MASK ) !=APIC_DM_FIXED - || (val &APIC_VECTOR_MASK ) >0xf ) +if ( (val &APIC_MODE_MASK ) !=APIC_DM_FIXED + || (val &APIC_VECTOR_MASK ) >0xf )apic_write (APIC_LVTTHMR , val); -if ((msr_content & (1ULL <<3 )) - && (val &APIC_MODE_MASK ) ==APIC_DM_SMI ) { -if (c == &boot_cpu_data) +if ( (msr_content & (1ULL <<3 )) + && (val &APIC_MODE_MASK ) ==APIC_DM_SMI ) + { +if ( c == &boot_cpu_data )printk (KERN_DEBUG "Thermal monitoring handled by SMI\n" );return ;/* -EBUSY */ } -if (cpu_has (c,X86_FEATURE_TM2 ) && (msr_content & (1ULL <<13 ))) +if (cpu_has (c,X86_FEATURE_TM2 ) && (msr_content & (1ULL <<13 )) ) tm2 =1 ;/* check whether a vector already exists, temporarily masked? */ -if (val &APIC_VECTOR_MASK ) { -if (c == &boot_cpu_data) +if ( val &APIC_VECTOR_MASK ) + { +if ( c == &boot_cpu_data )printk (KERN_DEBUG "Thermal LVT vector (%#x) already installed\n" , val &APIC_VECTOR_MASK );return ;/* -EBUSY */
@@ -170,9 +171,9 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)wrmsrl (MSR_IA32_MISC_ENABLE , msr_content | (1ULL <<3 ));apic_write (APIC_LVTTHMR , val & ~APIC_LVT_MASKED ); -if (opt_cpu_info) +if ( opt_cpu_info )printk (KERN_INFO "CPU%u: Thermal monitoring enabled (%s)\n" , - cpu, tm2 ?"TM2" :"TM1" ); + cpu, tm2 ?"TM2" :"TM1" ); return; }#endif /* CONFIG_X86_MCE_THERMAL */
@@ -181,7 +182,8 @@ static void intel_init_thermal(struct cpuinfo_x86 *c)static inline void intel_get_extended_msr (struct mcinfo_extended *ext,u32 msr) {if ( ext->mc_msrs <ARRAY_SIZE (ext->mc_msr) - && msr <MSR_IA32_MCG_EAX + nr_intel_ext_msrs ) { + && msr <MSR_IA32_MCG_EAX + nr_intel_ext_msrs ) + { ext->mc_msr[ext->mc_msrs].reg = msr;rdmsrl (msr, ext->mc_msr[ext->mc_msrs].value); ++ext->mc_msrs;
@@ -199,21 +201,21 @@ intel_get_extended_msrs(struct mcinfo_global *mig, struct mc_info *mi)* According to spec, processor _support_ 64 bit will always * have MSR beyond IA32_MCG_MISC */ -if (!mi|| !mig || nr_intel_ext_msrs ==0 || - !(mig->mc_gstatus &MCG_STATUS_EIPV )) +if ( !mi|| !mig || nr_intel_ext_msrs ==0 || + !(mig->mc_gstatus &MCG_STATUS_EIPV ) )return NULL ; mc_ext =x86_mcinfo_reserve (mi,sizeof (*mc_ext),MC_TYPE_EXTENDED ); -if (!mc_ext) +if ( !mc_ext ) { mi->flags |=MCINFO_FLAGS_UNCOMPLETE ;return NULL ; } -for (i =MSR_IA32_MCG_EAX ; i <=MSR_IA32_MCG_MISC ; i++) +for ( i =MSR_IA32_MCG_EAX ; i <=MSR_IA32_MCG_MISC ; i++ )intel_get_extended_msr (mc_ext, i); -for (i =MSR_IA32_MCG_R8 ; i <=MSR_IA32_MCG_R15 ; i++) +for ( i =MSR_IA32_MCG_R8 ; i <=MSR_IA32_MCG_R15 ; i++ )intel_get_extended_msr (mc_ext, i);return mc_ext;
@@ -231,24 +233,24 @@ enum intel_mce_typestatic enum intel_mce_type intel_check_mce_type (uint64_t status) { -if (!(status & MCi_STATUS_VAL)) +if ( !(status & MCi_STATUS_VAL) )return intel_mce_invalid; -if (status & MCi_STATUS_PCC) +if ( status & MCi_STATUS_PCC )return intel_mce_fatal;/* Corrected error? */ -if (!(status & MCi_STATUS_UC)) +if ( !(status & MCi_STATUS_UC) )return intel_mce_corrected; -if (!ser_support) +if ( !ser_support )return intel_mce_fatal; -if (status & MCi_STATUS_S) +if ( status & MCi_STATUS_S ) { -if (status & MCi_STATUS_AR) +if ( status & MCi_STATUS_AR ) { -if (status & MCi_STATUS_OVER) +if ( status & MCi_STATUS_OVER )return intel_mce_fatal;else return intel_mce_ucr_srar;
@@ -273,18 +275,16 @@ static void intel_memerr_dhandler(static bool intel_srar_check (uint64_t status) { -return (intel_check_mce_type (status) == intel_mce_ucr_srar ); +return (intel_check_mce_type (status) == intel_mce_ucr_srar); }static bool intel_checkaddr (uint64_t status,uint64_t misc,int addrtype) { -if (!(status & MCi_STATUS_ADDRV) || - !(status & MCi_STATUS_MISCV) || - ((misc & MCi_MISC_ADDRMOD_MASK) != MCi_MISC_PHYSMOD) ) - { +if ( !(status & MCi_STATUS_ADDRV) || + !(status & MCi_STATUS_MISCV) || + ((misc & MCi_MISC_ADDRMOD_MASK) != MCi_MISC_PHYSMOD) )/* addr is virtual */ return (addrtype ==MC_ADDR_VIRTUAL ); - }return (addrtype ==MC_ADDR_PHYSICAL ); }
@@ -310,7 +310,7 @@ static void intel_srar_dhandler(static bool intel_srao_check (uint64_t status) { -return (intel_check_mce_type (status) == intel_mce_ucr_srao ); +return (intel_check_mce_type (status) == intel_mce_ucr_srao); } static void intel_srao_dhandler(
@@ -337,7 +337,7 @@ static void intel_srao_dhandler(static bool intel_default_check (uint64_t status) { -return 1 ; +return true; } static void intel_default_mce_dhandler(
@@ -350,7 +350,7 @@ static void intel_default_mce_dhandler( type =intel_check_mce_type (status); -if (type == intel_mce_fatal) +if ( type == intel_mce_fatal ) *result =MCER_RESET ;else *result =MCER_CONTINUE ;
@@ -372,7 +372,7 @@ static void intel_default_mce_uhandler( type =intel_check_mce_type (status); -switch (type) +switch ( type ) {case intel_mce_fatal: *result =MCER_RESET ;
@@ -396,30 +396,32 @@ static const struct mca_error_handler intel_mce_uhandlers[] = {* 1) ser_support = 1, Superious error, OVER = 0, EN = 0, UC = 1 * 2) ser_support = 1, SRAR, UC = 1, OVER = 0, S = 1, AR = 1, [EN = 1] * 3) ser_support = 1, SRAO, UC = 1, S = 1, AR = 0, [EN = 1] -*/ +*/ static bool intel_need_clearbank_scan (enum mca_source who,u64 status) { -if ( who ==MCA_CMCI_HANDLER ) { +if ( who ==MCA_CMCI_HANDLER ) + {/* CMCI need clear bank */ if ( !(status & MCi_STATUS_UC) )return true;/* Spurious need clear bank */ else if ( ser_support && !(status & MCi_STATUS_OVER) - && !(status & MCi_STATUS_EN) ) + && !(status & MCi_STATUS_EN) )return true;/* UCNA OVER = 0 need clear bank */ -else if ( ser_support && !(status & MCi_STATUS_OVER) - && !(status & MCi_STATUS_PCC) && !(status & MCi_STATUS_S) - && !(status & MCi_STATUS_AR)) +else if ( ser_support && !(status & MCi_STATUS_OVER) + && !(status & MCi_STATUS_PCC) && !(status & MCi_STATUS_S) + && !(status & MCi_STATUS_AR) )return true;/* Only Log, no clear */ else return false; } -else if ( who ==MCA_MCE_SCAN ) { +else if ( who ==MCA_MCE_SCAN ) + {if ( !ser_support )return false; -/* +/* * For fatal error, it shouldn't be cleared so that sticky bank * have chance to be handled after reboot by polling */
@@ -427,16 +429,16 @@ static bool intel_need_clearbank_scan(enum mca_source who, u64 status)return false;/* Spurious need clear bank */ else if ( !(status & MCi_STATUS_OVER) - && (status & MCi_STATUS_UC) && !(status & MCi_STATUS_EN)) + && (status & MCi_STATUS_UC) && !(status & MCi_STATUS_EN) )return true;/* SRAR OVER=0 clear bank. OVER = 1 have caused reset */ else if ( (status & MCi_STATUS_UC) - && (status & MCi_STATUS_S) && (status & MCi_STATUS_AR ) - && !(status & MCi_STATUS_OVER) ) + && (status & MCi_STATUS_S) && (status & MCi_STATUS_AR) + && !(status & MCi_STATUS_OVER) )return true;/* SRAO need clear bank */ - else if ( !(status & MCi_STATUS_AR) - && (status & MCi_STATUS_S) && (status & MCi_STATUS_UC)) + else if ( !(status & MCi_STATUS_AR) + && (status & MCi_STATUS_S) && (status & MCi_STATUS_UC) )return true; else return false;
@@ -445,7 +447,8 @@ static bool intel_need_clearbank_scan(enum mca_source who, u64 status)return true; } -/* MCE continues/is recoverable when +/* +* MCE continues/is recoverable when * 1) CE UC = 0 * 2) Supious ser_support = 1, OVER = 0, En = 0 [UC = 1] * 3) SRAR ser_support = 1, OVER = 0, PCC = 0, S = 1, AR = 1 [UC =1, EN = 1]
@@ -457,23 +460,23 @@ static bool intel_recoverable_scan(uint64_t status)if ( !(status & MCi_STATUS_UC ) )return true; -else if ( ser_support && !(status & MCi_STATUS_EN) - && !(status & MCi_STATUS_OVER) ) +else if ( ser_support && !(status & MCi_STATUS_EN) + && !(status & MCi_STATUS_OVER) )return true;/* SRAR error */ -else if ( ser_support && !(status & MCi_STATUS_OVER) - && !(status & MCi_STATUS_PCC) && (status & MCi_STATUS_S) - && (status & MCi_STATUS_AR) && (status & MCi_STATUS_EN) ) +else if ( ser_support && !(status & MCi_STATUS_OVER) + && !(status & MCi_STATUS_PCC) && (status & MCi_STATUS_S) + && (status & MCi_STATUS_AR) && (status & MCi_STATUS_EN) )return true;/* SRAO error */ -else if (ser_support && !(status & MCi_STATUS_PCC) - && (status & MCi_STATUS_S) && !(status & MCi_STATUS_AR) - && (status & MCi_STATUS_EN)) +else if ( ser_support && !(status & MCi_STATUS_PCC) + && (status & MCi_STATUS_S) && !(status & MCi_STATUS_AR) + && (status & MCi_STATUS_EN) )return true;/* UCNA error */ -else if (ser_support && !(status & MCi_STATUS_OVER) - && (status & MCi_STATUS_EN) && !(status & MCi_STATUS_PCC) - && !(status & MCi_STATUS_S) && !(status & MCi_STATUS_AR)) +else if ( ser_support && !(status & MCi_STATUS_OVER) + && (status & MCi_STATUS_EN) && !(status & MCi_STATUS_PCC) + && !(status & MCi_STATUS_S) && !(status & MCi_STATUS_AR) )return true;return false; }
@@ -494,7 +497,8 @@ static int do_cmci_discover(int i)rdmsrl (msr, val);/* Some other CPU already owns this bank. */ -if (val &CMCI_EN ) { +if ( val &CMCI_EN ) + {mcabanks_clear (i,__get_cpu_var (mce_banks_owned)); goto out; }
@@ -505,7 +509,8 @@ static int do_cmci_discover(int i)rdmsrl (msr, val); } -if (!(val &CMCI_EN )) { +if ( !(val &CMCI_EN ) ) + {/* This bank does not support CMCI. Polling timer has to handle it. */ mcabanks_set (i,__get_cpu_var (no_cmci_banks));wrmsrl (msr, val & ~CMCI_THRESHOLD_MASK );
@@ -515,10 +520,10 @@ static int do_cmci_discover(int i) threshold = cmci_threshold;if ( threshold > max_threshold ) { -mce_printk (MCE_QUIET , -"CMCI: threshold %#x too large for CPU%u bank %u, using %#x\n" , - threshold,smp_processor_id (), i, max_threshold); - threshold = max_threshold; +mce_printk (MCE_QUIET , +"CMCI: threshold %#x too large for CPU%u bank %u, using %#x\n" , + threshold,smp_processor_id (), i, max_threshold); + threshold = max_threshold; }wrmsrl (msr, (val & ~CMCI_THRESHOLD_MASK ) |CMCI_EN | threshold);mcabanks_set (i,__get_cpu_var (mce_banks_owned));
@@ -538,13 +543,14 @@ static void cmci_discover(void)spin_lock_irqsave (&cmci_discover_lock, flags); -for (i =0 ; i < nr_mce_banks; i++) -if (!mcabanks_test (i,__get_cpu_var (mce_banks_owned))) +for ( i =0 ; i < nr_mce_banks; i++ ) +if ( !mcabanks_test (i,__get_cpu_var (mce_banks_owned)) )do_cmci_discover (i);spin_unlock_irqrestore (&cmci_discover_lock, flags); -/* In case CMCI happended when do owner change. +/* +* In case CMCI happended when do owner change. * If CMCI happened yet not processed immediately, * MCi_status (error_count bit 38~52) is not cleared, * the CMCI interrupt will never be triggered again.
@@ -553,27 +559,32 @@ static void cmci_discover(void) mctc =mcheck_mca_logout (MCA_CMCI_HANDLER ,__get_cpu_var (mce_banks_owned), &bs,NULL ); -if (bs.errcnt && mctc !=NULL ) { -if (dom0_vmce_enabled ()) { +if ( bs.errcnt && mctc !=NULL ) + { +if (dom0_vmce_enabled () ) + {mctelem_commit (mctc);send_global_virq (VIRQ_MCA ); - }else { + } +else + {x86_mcinfo_dump (mctelem_dataptr (mctc));mctelem_dismiss (mctc); } - }else if (mctc !=NULL ) + } +else if ( mctc !=NULL )mctelem_dismiss (mctc);mce_printk (MCE_VERBOSE ,"CMCI: CPU%d owner_map[%lx], no_cmci_map[%lx]\n" , -smp_processor_id (), - *((unsigned long *)__get_cpu_var (mce_banks_owned)->bank_map), - *((unsigned long *)__get_cpu_var (no_cmci_banks)->bank_map)); +smp_processor_id (), + *((unsigned long *)__get_cpu_var (mce_banks_owned)->bank_map), + *((unsigned long *)__get_cpu_var (no_cmci_banks)->bank_map)); }/* * Define an owner for each bank. Banks can be shared between CPUs * and to avoid reporting events multiple times always set up one -* CPU as owner. +* CPU as owner. * * The assignment has to be redone when CPUs go offline and * any of the owners goes away. Also pollers run in parallel so we
@@ -583,7 +594,7 @@ static void cmci_discover(void)static void mce_set_owner (void ) { -if (!cmci_support || !opt_mce) +if ( !cmci_support || !opt_mce )return ;cmci_discover ();
@@ -596,7 +607,7 @@ static void __cpu_mcheck_distribute_cmci(void *unused)static void cpu_mcheck_distribute_cmci (void ) { -if (cmci_support && opt_mce) +if ( cmci_support && opt_mce )on_each_cpu (__cpu_mcheck_distribute_cmci,NULL ,0 ); }
@@ -604,19 +615,20 @@ static void clear_cmci(void) {int i; -if (!cmci_support || !opt_mce) +if ( !cmci_support || !opt_mce )return ;mce_printk (MCE_VERBOSE ,"CMCI: clear_cmci support on CPU%d\n" , -smp_processor_id ()); +smp_processor_id ()); -for (i =0 ; i < nr_mce_banks; i++) { +for ( i =0 ; i < nr_mce_banks; i++ ) + {unsigned msr =MSR_IA32_MCx_CTL2 (i);u64 val; -if (!mcabanks_test (i,__get_cpu_var (mce_banks_owned))) +if ( !mcabanks_test (i,__get_cpu_var (mce_banks_owned)) )continue ;rdmsrl (msr, val); -if (val & (CMCI_EN |CMCI_THRESHOLD_MASK )) +if ( val & (CMCI_EN |CMCI_THRESHOLD_MASK ) )wrmsrl (msr, val & ~(CMCI_EN |CMCI_THRESHOLD_MASK ));mcabanks_clear (i,__get_cpu_var (mce_banks_owned)); }
@@ -626,7 +638,7 @@ static void cpu_mcheck_disable(void) {clear_in_cr4 (X86_CR4_MCE ); -if (cmci_support && opt_mce) +if ( cmci_support && opt_mce )clear_cmci (); }
@@ -640,16 +652,21 @@ static void cmci_interrupt(struct cpu_user_regs *regs) mctc =mcheck_mca_logout (MCA_CMCI_HANDLER ,__get_cpu_var (mce_banks_owned), &bs,NULL ); -if (bs.errcnt && mctc !=NULL ) { -if (dom0_vmce_enabled ()) { +if ( bs.errcnt && mctc !=NULL ) + { +if (dom0_vmce_enabled () ) + {mctelem_commit (mctc);mce_printk (MCE_VERBOSE ,"CMCI: send CMCI to DOM0 through virq\n" );send_global_virq (VIRQ_MCA ); - }else { + } +else + {x86_mcinfo_dump (mctelem_dataptr (mctc));mctelem_dismiss (mctc); - } - }else if (mctc !=NULL ) + } + } +else if ( mctc !=NULL )mctelem_dismiss (mctc); }
@@ -658,8 +675,9 @@ static void intel_init_cmci(struct cpuinfo_x86 *c)u32 l, apic;int cpu =smp_processor_id (); -if (!mce_available (c) || !cmci_support) { -if (opt_cpu_info) +if ( !mce_available (c) || !cmci_support ) + { +if ( opt_cpu_info )mce_printk (MCE_QUIET ,"CMCI: CPU%d has no CMCI support\n" , cpu);return ; }
@@ -668,7 +686,7 @@ static void intel_init_cmci(struct cpuinfo_x86 *c)if ( apic &APIC_VECTOR_MASK ) {mce_printk (MCE_QUIET ,"CPU%d CMCI LVT vector (%#x) already installed\n" , - cpu, ( apic &APIC_VECTOR_MASK )); + cpu, ( apic &APIC_VECTOR_MASK ));return ; }
@@ -688,15 +706,16 @@ static void intel_init_cmci(struct cpuinfo_x86 *c)static bool mce_is_broadcast (struct cpuinfo_x86 *c) { -if (mce_force_broadcast) +if ( mce_force_broadcast )return true; -/* According to Intel SDM Dec, 2009, 15.10.4.1, For processors with +/* +* According to Intel SDM Dec, 2009, 15.10.4.1, For processors with * DisplayFamily_DisplayModel encoding of 06H_EH and above, * a MCA signal is broadcast to all logical processors in the system */ -if (c->x86_vendor ==X86_VENDOR_INTEL && c->x86 ==6 && - c->x86_model >=0xe ) +if ( c->x86_vendor ==X86_VENDOR_INTEL && c->x86 ==6 && + c->x86_model >=0xe )return true;return false; }
@@ -736,23 +755,23 @@ static void intel_init_mca(struct cpuinfo_x86 *c)rdmsrl (MSR_IA32_MCG_CAP , msr_content); -if ((msr_content &MCG_CMCI_P ) && cpu_has_apic) +if ( (msr_content &MCG_CMCI_P ) && cpu_has_apic ) cmci = true;/* Support Software Error Recovery */ -if (msr_content &MCG_SER_P ) +if ( msr_content &MCG_SER_P ) ser = true; -if (msr_content &MCG_EXT_P ) +if ( msr_content &MCG_EXT_P ) ext_num = (msr_content >>MCG_EXT_CNT ) &0xff ; first =mce_firstbank (c); -if (!mce_force_broadcast && (msr_content &MCG_LMCE_P )) +if ( !mce_force_broadcast && (msr_content &MCG_LMCE_P ) ) lmce =intel_enable_lmce ();#define CAP (enabled, name) ((enabled) ? ", " name : "") -if (smp_processor_id () ==0 ) +if (smp_processor_id () ==0 ) { dprintk(XENLOG_INFO, "MCA Capability: firstbank %d, extended MCE MSR %d%s%s%s%s\n",
@@ -769,10 +788,10 @@ static void intel_init_mca(struct cpuinfo_x86 *c) nr_intel_ext_msrs = ext_num; firstbank = first; } -else if (cmci != cmci_support || ser != ser_support || - broadcast != mce_broadcast || - first != firstbank || ext_num != nr_intel_ext_msrs || - lmce != lmce_support) +else if ( cmci != cmci_support || ser != ser_support || + broadcast != mce_broadcast || + first != firstbank || ext_num != nr_intel_ext_msrs || + lmce != lmce_support )dprintk (XENLOG_WARNING ,"CPU%u has different MCA capability " "(firstbank %d, extended MCE MSR %d%s%s%s%s)"
@@ -793,7 +812,8 @@ static void intel_mce_post_reset(void) mctc =mcheck_mca_logout (MCA_RESET , mca_allbanks, &bs,NULL );/* in the boot up stage, print out and also log in DOM0 boot process */ -if (bs.errcnt && mctc !=NULL ) { +if ( bs.errcnt && mctc !=NULL ) + {x86_mcinfo_dump (mctelem_dataptr (mctc));mctelem_commit (mctc); }
@@ -808,12 +828,14 @@ static void intel_init_mce(void)intel_mce_post_reset ();/* clear all banks */ -for (i = firstbank; i < nr_mce_banks; i++) +for ( i = firstbank; i < nr_mce_banks; i++ ) { -/* Some banks are shared across cores, use MCi_CTRL to judge whether -* this bank has been initialized by other cores already. */ +/* +* Some banks are shared across cores, use MCi_CTRL to judge whether +* this bank has been initialized by other cores already. +*/ rdmsrl (MSR_IA32_MCx_CTL (i), msr_content); -if (!msr_content) +if ( !msr_content ) {/* if ctl is 0, this bank is never initialized */ mce_printk (MCE_VERBOSE ,"mce_init: init bank%d\n" , i);
@@ -821,7 +843,7 @@ static void intel_init_mce(void)wrmsrl (MSR_IA32_MCx_STATUS (i),0x0ULL ); } } -if (firstbank)/* if cmci enabled, firstbank = 0 */ +if ( firstbank )/* if cmci enabled, firstbank = 0 */ wrmsrl (MSR_IA32_MC0_STATUS ,0x0ULL );x86_mce_vector_register (mcheck_cmn_handler);
@@ -849,7 +871,7 @@ static int cpu_mcabank_alloc(unsigned int cpu)struct mca_banks *cmci =mcabanks_alloc ();struct mca_banks *owned =mcabanks_alloc (); -if (!cmci || !owned) +if ( !cmci || !owned ) goto out;per_cpu (no_cmci_banks, cpu) = cmci;
@@ -857,7 +879,7 @@ static int cpu_mcabank_alloc(unsigned int cpu)per_cpu (last_state, cpu) =-1 ;return 0 ; -out: + out:mcabanks_free (cmci);mcabanks_free (owned);return -ENOMEM ;
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 5/6 x86/mce: add emacs block to mctelem.c
In reply to Haozhong Zhangmctelem.c uses the tab indention. Add an emacs block to avoid mixed indention styles in certain editors.
--- xen/arch/x86/cpu/mcheck/mctelem.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
xen/arch/x86/cpu/mcheck/mctelem.c +10 -0
@@ -550,3 +550,13 @@ void mctelem_ack(mctelem_class_t which, mctelem_cookie_t cookie)wmb ();spin_unlock (&processing_lock); } + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: t +* tab-width: 8 +* End: +*/
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH 6/6 x86/mce: remove extra blanks in mctelem.c
In reply to Haozhong ZhangThe entire file of mctelem.c is in Linux coding style, so do not change the coding style and only remove trailing spaces and extra blank lines.
--- xen/arch/x86/cpu/mcheck/mctelem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/cpu/mcheck/mctelem.c +2 -2
@@ -220,7 +220,7 @@ void mctelem_process_deferred(unsigned int cpu,int ret;/* -* First, unhook the list of telemetry structures, and +* First, unhook the list of telemetry structures, and * hook it up to the processing list head for this CPU. * * If @lmce is true and a non-local MC# occurs before the
@@ -339,7 +339,7 @@ void __init mctelem_init(unsigned int datasz) {char *datarr;unsigned int i; - +BUILD_BUG_ON (MC_URGENT !=0 ||MC_NONURGENT !=1 ||MC_NCLASSES !=2 ); datasz = (datasz & ~0xf ) +0x10 ;/* 16 byte roundup */
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 6 lines · Haozhong Zhang
Some files in xen/arch/x86/cpu/mcheck use mixed coding styles. Unify them to Xen hypervisor coding style. For
mctelem.cwhich is entirely in one coding style, only remove extra blanks.No functional change is introduced.
Quoted 7 lines
Haozhong Zhang (6):
x86/mce: adapt mce.{c,h} to Xen hypervisor coding style x86/vmce: adaptvmce.cto Xen hypervisor coding style x86/mce: adaptmcation.cto Xen hypervisor coding style x86/mce: adaptmce_intel.cto Xen hypervisor coding style x86/mce: add emacs block tomctelem.c
x86/mce: remove trailing spaces inmctelem.c
mce*.[ch] seem to have been imported from 2.6.x Linux more than 10 years ago. I'm not sure if we care enough to stay close to Linux at this stage.
Code-wise:
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Andrew Cooper
Acked-byQuoted 14 lines · Wei Liu
Quoted 6 lines · Haozhong Zhang
Some files in xen/arch/x86/cpu/mcheck use mixed coding styles. Unify them to Xen hypervisor coding style. For
mctelem.cwhich is entirely in one coding style, only remove extra blanks.No functional change is introduced.
Quoted 7 lines
Haozhong Zhang (6):
x86/mce: adapt mce.{c,h} to Xen hypervisor coding style x86/vmce: adaptvmce.cto Xen hypervisor coding style x86/mce: adaptmcation.cto Xen hypervisor coding style x86/mce: adaptmce_intel.cto Xen hypervisor coding style x86/mce: add emacs block tomctelem.c
x86/mce: remove trailing spaces inmctelem.c
Quoted 7 lines
mce*.[ch] seem to have been imported from 2.6.x Linux more than 10 years ago. I'm not sure if we care enough to stay close to Linux at this stage.
Code-wise:
Reviewed-by Wei Liu <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel