linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
Cc: x86@kernel.org, linux-edac@vger.kernel.org,
	linux-kernel@vger.kernel.org, Tony Luck <tony.luck@intel.com>,
	"H . Peter Anvin" <hpa@zytor.com>,
	yazen.ghannam@amd.com
Subject: Re: [PATCH v2 1/5] x86/mce/inject: Check if a bank is unpopulated before error injection
Date: Mon, 25 Oct 2021 15:56:43 +0200	[thread overview]
Message-ID: <YXa3m7SWAhRcFi35@zn.tnic> (raw)
In-Reply-To: <20211019233641.140275-2-Smita.KoralahalliChannabasappa@amd.com>

On Tue, Oct 19, 2021 at 06:36:37PM -0500, Smita Koralahalli wrote:
> The MCA_IPID register uniquely identifies a bank's type on Scalable MCA
> (SMCA) systems. When an MCA bank is not populated, the MCA_IPID register
> will read as zero and writes to it will be ignored.
> 
> On a "hw" error injection check the value of this register before trying
> to inject the error.
> 
> Do not impose any limitation on a "sw" injection and allow the user to
> test out all the decoding paths without relying on the available hardware,
> as its purpose is to just test the code.
> 
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
> ---
> v2:
> 	simulate -> inject.
> 	Corrected according to kernel commenting style.
> 	boot_cpu_has() -> cpu_feature_enabled().
> 	Error simulation not possible: Bank %llu unpopulated ->
> 	Cannot set IPID - bank %llu unpopulated.
> 	Used user provided IPID value on sw injection without checking
> 	underlying hardware and defined it under inj_ipid_set().
> ---
>  arch/x86/kernel/cpu/mce/inject.c | 39 +++++++++++++++++++++++++++++---
>  1 file changed, 36 insertions(+), 3 deletions(-)

So I gave it a critical look and did some modifications, see below.
Looking at those IPID MSRs - they're all read-only, which means for !sw
injection, all the module can do is check whether they're 0 - and fail
injection in that case - and do the injection otherwise.

Ok?

---
From: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
Date: Tue, 19 Oct 2021 18:36:37 -0500
Subject: [PATCH] x86/mce/inject: Check if a bank is populated before error
 injection

The MCA_IPID register uniquely identifies a bank's type on Scalable MCA
(SMCA) systems. When an MCA bank is not populated, the MCA_IPID register
will read as zero and writes to it will be ignored.

On a hw-type error injection (injection which writes the actual MCA
registers in an attempt to cause a real MCE) check the value of this
register before trying to inject the error.

Do not impose any limitation on a sw-type injection (software-only
injection) and allow the user to test out all the decoding paths without
relying on the available hardware, as its purpose is to just test the
code.

 [ bp: Heavily massage. ]

Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20211019233641.140275-2-Smita.KoralahalliChannabasappa@amd.com
---
 arch/x86/kernel/cpu/mce/inject.c | 42 +++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c
index 0bfc14041bbb..3333ae7886bd 100644
--- a/arch/x86/kernel/cpu/mce/inject.c
+++ b/arch/x86/kernel/cpu/mce/inject.c
@@ -74,7 +74,6 @@ MCE_INJECT_SET(status);
 MCE_INJECT_SET(misc);
 MCE_INJECT_SET(addr);
 MCE_INJECT_SET(synd);
-MCE_INJECT_SET(ipid);
 
 #define MCE_INJECT_GET(reg)						\
 static int inj_##reg##_get(void *data, u64 *val)			\
@@ -95,6 +94,20 @@ DEFINE_SIMPLE_ATTRIBUTE(status_fops, inj_status_get, inj_status_set, "%llx\n");
 DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n");
 DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n");
 DEFINE_SIMPLE_ATTRIBUTE(synd_fops, inj_synd_get, inj_synd_set, "%llx\n");
+
+/* Use the user provided IPID value on a sw injection. */
+static int inj_ipid_set(void *data, u64 val)
+{
+	struct mce *m = (struct mce *)data;
+
+	if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
+		if (inj_type == SW_INJ)
+			m->ipid = val;
+	}
+
+	return 0;
+}
+
 DEFINE_SIMPLE_ATTRIBUTE(ipid_fops, inj_ipid_get, inj_ipid_set, "%llx\n");
 
 static void setup_inj_struct(struct mce *m)
@@ -577,6 +590,33 @@ static int inj_bank_set(void *data, u64 val)
 	}
 
 	m->bank = val;
+
+	/*
+	 * sw-only injection allows to write arbitrary values into the MCA registers
+	 * because it tests only the decoding paths.
+	 */
+	if (inj_type == SW_INJ)
+		goto inject;
+
+	/*
+	 * Read IPID value to determine if a bank is populated on the target
+	 * CPU.
+	 */
+	if (cpu_feature_enabled(X86_FEATURE_SMCA)) {
+		u64 ipid;
+
+		if (rdmsrl_on_cpu(m->extcpu, MSR_AMD64_SMCA_MCx_IPID(val), &ipid)) {
+			pr_err("Error reading IPID on CPU%d\n", m->extcpu);
+			return -EINVAL;
+		}
+
+		if (!ipid) {
+			pr_err("Cannot inject into bank %llu - it is unpopulated\n", val);
+			return -ENODEV;
+		}
+	}
+
+inject:
 	do_inject();
 
 	/* Reset injection struct */
-- 
2.29.2

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2021-10-25 13:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 23:36 [PATCH v2 0/5] x86/mce: Handle error injection failures in mce-inject module Smita Koralahalli
2021-10-19 23:36 ` [PATCH v2 1/5] x86/mce/inject: Check if a bank is unpopulated before error injection Smita Koralahalli
2021-10-25 13:56   ` Borislav Petkov [this message]
2021-10-25 17:09     ` Koralahalli Channabasappa, Smita
2021-10-19 23:36 ` [PATCH v2 2/5] x86/mce/inject: Warn the user on a not set valid bit in MCA_STATUS Smita Koralahalli
2021-10-20 15:06   ` Luck, Tony
2021-10-26 10:02   ` Borislav Petkov
2021-10-26 16:58     ` Koralahalli Channabasappa, Smita
2021-10-26 17:15       ` Borislav Petkov
2021-10-26 18:53         ` Koralahalli Channabasappa, Smita
2021-10-26 20:25           ` Borislav Petkov
2021-10-19 23:36 ` [PATCH v2 3/5] x86/mce: Use mca_msr_reg() in prepare_msrs() Smita Koralahalli
2021-10-27 11:41   ` Borislav Petkov
2021-10-27 20:19     ` Koralahalli Channabasappa, Smita
2021-10-28  8:53       ` Borislav Petkov
2021-11-01 18:51         ` Koralahalli Channabasappa, Smita
2021-10-19 23:36 ` [PATCH v2 4/5] x86/mce/inject: Check for writes ignored in status registers Smita Koralahalli
2021-10-19 23:36 ` [PATCH v2 5/5] x86/mce/mce-inject: Return error code to userspace from mce-inject module Smita Koralahalli
2021-10-20 15:18   ` Luck, Tony

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YXa3m7SWAhRcFi35@zn.tnic \
    --to=bp@alien8.de \
    --cc=Smita.KoralahalliChannabasappa@amd.com \
    --cc=hpa@zytor.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.org \
    --cc=yazen.ghannam@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).