x86/RAS: Hide SMCA bank names
authorBorislav Petkov <bp@suse.de>
Thu, 3 Nov 2016 20:12:33 +0000 (21:12 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Tue, 8 Nov 2016 16:10:15 +0000 (17:10 +0100)
Add accessor functions and hide the smca_names array. Also, add a
sanity-check to bank HWID assignment in get_smca_bank_info().

Signed-off-by: Borislav Petkov <bp@suse.de>
Link: http://lkml.kernel.org/r/20161104152317.5r276t35df53qk76@pd.tnic
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/include/asm/mce.h
arch/x86/kernel/cpu/mcheck/mce_amd.c
drivers/edac/mce_amd.c

index 8ffd21596dd7af29b4aff8ef8ad68b9ead921bb4..748b8da8e62714c6d6c4bf42ad70aa45349649a9 100644 (file)
@@ -356,13 +356,6 @@ enum smca_bank_types {
        N_SMCA_BANK_TYPES
 };
 
-struct smca_bank_name {
-       const char *name;       /* Short name for sysfs */
-       const char *long_name;  /* Long name for pretty-printing */
-};
-
-extern struct smca_bank_name smca_names[N_SMCA_BANK_TYPES];
-
 #define HWID_MCATYPE(hwid, mcatype) ((hwid << 16) | mcatype)
 
 struct smca_hwid {
@@ -379,6 +372,7 @@ struct smca_bank {
 
 extern struct smca_bank smca_banks[MAX_NR_BANKS];
 
+extern const char *smca_get_long_name(enum smca_bank_types t);
 #endif
 
 #endif /* _ASM_X86_MCE_H */
index afeb02b871279924082068040f99dff42679e1b9..e68a305ff666998db6bece8956b7966b8965d0f0 100644 (file)
@@ -69,7 +69,12 @@ static const char * const smca_umc_block_names[] = {
        "misc_umc"
 };
 
-struct smca_bank_name smca_names[] = {
+struct smca_bank_name {
+       const char *name;       /* Short name for sysfs */
+       const char *long_name;  /* Long name for pretty-printing */
+};
+
+static struct smca_bank_name smca_names[] = {
        [SMCA_LS]       = { "load_store",       "Load Store Unit" },
        [SMCA_IF]       = { "insn_fetch",       "Instruction Fetch Unit" },
        [SMCA_L2_CACHE] = { "l2_cache",         "L2 Cache" },
@@ -84,7 +89,23 @@ struct smca_bank_name smca_names[] = {
        [SMCA_PSP]      = { "psp",              "Platform Security Processor" },
        [SMCA_SMU]      = { "smu",              "System Management Unit" },
 };
-EXPORT_SYMBOL_GPL(smca_names);
+
+const char *smca_get_name(enum smca_bank_types t)
+{
+       if (t >= N_SMCA_BANK_TYPES)
+               return NULL;
+
+       return smca_names[t].name;
+}
+
+const char *smca_get_long_name(enum smca_bank_types t)
+{
+       if (t >= N_SMCA_BANK_TYPES)
+               return NULL;
+
+       return smca_names[t].long_name;
+}
+EXPORT_SYMBOL_GPL(smca_get_long_name);
 
 static struct smca_hwid smca_hwid_mcatypes[] = {
        /* { bank_type, hwid_mcatype, xec_bitmap } */
@@ -163,6 +184,11 @@ static void get_smca_bank_info(unsigned int bank)
        for (i = 0; i < ARRAY_SIZE(smca_hwid_mcatypes); i++) {
                s_hwid = &smca_hwid_mcatypes[i];
                if (hwid_mcatype == s_hwid->hwid_mcatype) {
+
+                       WARN(smca_banks[bank].hwid,
+                            "Bank %s already initialized!\n",
+                            smca_get_name(s_hwid->bank_type));
+
                        smca_banks[bank].hwid = s_hwid;
                        smca_banks[bank].id = instance_id;
                        break;
@@ -832,7 +858,7 @@ static const char *get_name(unsigned int bank, struct threshold_block *b)
        }
 
        snprintf(buf_mcatype, MAX_MCATYPE_NAME_LEN,
-                "%s_%x", smca_names[bank_type].name,
+                "%s_%x", smca_get_name(bank_type),
                          smca_banks[bank].id);
        return buf_mcatype;
 }
index 3dee58583d25ca811fa4ac38f3e8fa46fa5ad952..80762acd8cc8431be01f8a716b29ec2e73089c01 100644 (file)
@@ -867,7 +867,7 @@ static void decode_smca_errors(struct mce *m)
                return;
 
        bank_type = hwid->bank_type;
-       ip_name = smca_names[bank_type].long_name;
+       ip_name = smca_get_long_name(bank_type);
 
        pr_emerg(HW_ERR "%s Extended Error Code: %d\n", ip_name, xec);