[v2,1/2] x86/mce/AMD: Define function to get SMCA bank type
diff mbox series

Message ID 20171207203955.118171-1-Yazen.Ghannam@amd.com
State New, archived
Headers show
Series
  • [v2,1/2] x86/mce/AMD: Define function to get SMCA bank type
Related show

Commit Message

Ghannam, Yazen Dec. 7, 2017, 8:39 p.m. UTC
From: Yazen Ghannam <yazen.ghannam@amd.com>

Scalable MCA systems have various types of banks. The bank's type can
determine how we handle errors from it. For example, if a bank represents
a UMC then we will need to convert its address from a normalized address
to a system physical address before handling the error.

Define a static function to return a bank's SMCA type.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
---
Link:
https://lkml.kernel.org/r/20171201155034.39206-1-Yazen.Ghannam@amd.com

v1->v2:
* Make function static to mcheck/mce_amd.c.

 arch/x86/kernel/cpu/mcheck/mce_amd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Borislav Petkov Dec. 10, 2017, 2:47 p.m. UTC | #1
On Thu, Dec 07, 2017 at 02:39:54PM -0600, Yazen Ghannam wrote:
> diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> index a38ab1fa53a2..219d5115f4d4 100644
> --- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
> +++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
> @@ -110,6 +110,16 @@ const char *smca_get_long_name(enum smca_bank_types t)
>  }
>  EXPORT_SYMBOL_GPL(smca_get_long_name);
>  
> +static enum smca_bank_types smca_get_bank_type(struct mce *m)
> +{
> +	struct smca_bank bank = smca_banks[m->bank];
					   ^^^^^^^^

That's a NULL ptr deref waiting to happen.

Also, struct smca_bank bank should be a pointer.

I ended up committing this:

---
From: Yazen Ghannam <yazen.ghannam@amd.com>
Date: Thu, 7 Dec 2017 14:39:54 -0600
Subject: [PATCH] x86/MCE/AMD: Define a function to get SMCA bank type

Scalable MCA systems have various types of banks. The bank's type
can determine how we handle errors from it. For example, if a bank
represents a UMC (Unified Memory Controller) then we will need to
convert its address from a normalized address to a system physical
address before handling the error.

Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: linux-edac <linux-edac@vger.kernel.org>
Cc: x86-ml <x86@kernel.org>
Link: http://lkml.kernel.org/r/20171207203955.118171-1-Yazen.Ghannam@amd.com
[ Verify m->bank is within range and use bank pointer. ]
Signed-off-by:
---
 arch/x86/kernel/cpu/mcheck/mce_amd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index a38ab1fa53a2..661c4738be27 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -110,6 +110,20 @@ const char *smca_get_long_name(enum smca_bank_types t)
 }
 EXPORT_SYMBOL_GPL(smca_get_long_name);
 
+static enum smca_bank_types smca_get_bank_type(struct mce *m)
+{
+	struct smca_bank *b;
+
+	if (m->bank >= N_SMCA_BANK_TYPES)
+		return N_SMCA_BANK_TYPES;
+
+	b = &smca_banks[m->bank];
+	if (!b->hwid)
+		return N_SMCA_BANK_TYPES;
+
+	return b->hwid->bank_type;
+}
+
 static struct smca_hwid smca_hwid_mcatypes[] = {
 	/* { bank_type, hwid_mcatype, xec_bitmap } */

Patch
diff mbox series

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd.c b/arch/x86/kernel/cpu/mcheck/mce_amd.c
index a38ab1fa53a2..219d5115f4d4 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd.c
@@ -110,6 +110,16 @@  const char *smca_get_long_name(enum smca_bank_types t)
 }
 EXPORT_SYMBOL_GPL(smca_get_long_name);
 
+static enum smca_bank_types smca_get_bank_type(struct mce *m)
+{
+	struct smca_bank bank = smca_banks[m->bank];
+
+	if (!bank.hwid)
+		return N_SMCA_BANK_TYPES;
+
+	return bank.hwid->bank_type;
+}
+
 static struct smca_hwid smca_hwid_mcatypes[] = {
 	/* { bank_type, hwid_mcatype, xec_bitmap } */