linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/mce: Add helper functions to remove duplicate code
@ 2020-04-27  6:13 Ganesh Goudar
  2020-04-27  6:13 ` [PATCH 2/2] powerpc/mce: Do not poison the memory using guest effective addr Ganesh Goudar
  0 siblings, 1 reply; 2+ messages in thread
From: Ganesh Goudar @ 2020-04-27  6:13 UTC (permalink / raw)
  To: mpe, linuxppc-dev; +Cc: mahesh, Ganesh Goudar

mce_handle_ierror() and mce_handle_derror() has some duplicate
code to recover from the recoverable MCE errors and to get the
MCE error sub-type while generating MCE error info, Add helper
functions to remove it.

Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
---
 arch/powerpc/kernel/mce_power.c | 136 +++++++++++++-------------------
 1 file changed, 56 insertions(+), 80 deletions(-)

diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
index 067b094bfeff..143e79450e93 100644
--- a/arch/powerpc/kernel/mce_power.c
+++ b/arch/powerpc/kernel/mce_power.c
@@ -391,6 +391,56 @@ static int mce_find_instr_ea_and_phys(struct pt_regs *regs, uint64_t *addr,
 	return -1;
 }
 
+static int mce_correct_err(unsigned int err_type)
+{
+	int handled = 0;
+
+	/* attempt to correct the error */
+	switch (err_type) {
+	case MCE_ERROR_TYPE_SLB:
+		if (local_paca->in_mce == 1)
+			slb_save_contents(local_paca->mce_faulty_slbs);
+		handled = mce_flush(MCE_FLUSH_SLB);
+		break;
+	case MCE_ERROR_TYPE_ERAT:
+		handled = mce_flush(MCE_FLUSH_ERAT);
+		break;
+	case MCE_ERROR_TYPE_TLB:
+		handled = mce_flush(MCE_FLUSH_TLB);
+		break;
+	}
+	return handled;
+}
+
+static void mce_err_get_sub_type(struct mce_error_info *mce_err,
+				 unsigned int err_type,
+				 unsigned int err_sub_type)
+{
+	switch (err_type) {
+	case MCE_ERROR_TYPE_UE:
+		mce_err->u.ue_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_SLB:
+		mce_err->u.slb_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_ERAT:
+		mce_err->u.erat_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_TLB:
+		mce_err->u.tlb_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_USER:
+		mce_err->u.user_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_RA:
+		mce_err->u.ra_error_type = err_sub_type;
+		break;
+	case MCE_ERROR_TYPE_LINK:
+		mce_err->u.link_error_type = err_sub_type;
+		break;
+	}
+}
+
 static int mce_handle_ierror(struct pt_regs *regs,
 		const struct mce_ierror_table table[],
 		struct mce_error_info *mce_err, uint64_t *addr,
@@ -405,48 +455,13 @@ static int mce_handle_ierror(struct pt_regs *regs,
 	for (i = 0; table[i].srr1_mask; i++) {
 		if ((srr1 & table[i].srr1_mask) != table[i].srr1_value)
 			continue;
-
-		/* attempt to correct the error */
-		switch (table[i].error_type) {
-		case MCE_ERROR_TYPE_SLB:
-			if (local_paca->in_mce == 1)
-				slb_save_contents(local_paca->mce_faulty_slbs);
-			handled = mce_flush(MCE_FLUSH_SLB);
-			break;
-		case MCE_ERROR_TYPE_ERAT:
-			handled = mce_flush(MCE_FLUSH_ERAT);
-			break;
-		case MCE_ERROR_TYPE_TLB:
-			handled = mce_flush(MCE_FLUSH_TLB);
-			break;
-		}
+		handled = mce_correct_err(table[i].error_type);
 
 		/* now fill in mce_error_info */
 		mce_err->error_type = table[i].error_type;
 		mce_err->error_class = table[i].error_class;
-		switch (table[i].error_type) {
-		case MCE_ERROR_TYPE_UE:
-			mce_err->u.ue_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_SLB:
-			mce_err->u.slb_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_ERAT:
-			mce_err->u.erat_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_TLB:
-			mce_err->u.tlb_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_USER:
-			mce_err->u.user_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_RA:
-			mce_err->u.ra_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_LINK:
-			mce_err->u.link_error_type = table[i].error_subtype;
-			break;
-		}
+		mce_err_get_sub_type(mce_err, table[i].error_type,
+				     table[i].error_subtype);
 		mce_err->sync_error = table[i].sync_error;
 		mce_err->severity = table[i].severity;
 		mce_err->initiator = table[i].initiator;
@@ -492,25 +507,7 @@ static int mce_handle_derror(struct pt_regs *regs,
 	for (i = 0; table[i].dsisr_value; i++) {
 		if (!(dsisr & table[i].dsisr_value))
 			continue;
-
-		/* attempt to correct the error */
-		switch (table[i].error_type) {
-		case MCE_ERROR_TYPE_SLB:
-			if (local_paca->in_mce == 1)
-				slb_save_contents(local_paca->mce_faulty_slbs);
-			if (mce_flush(MCE_FLUSH_SLB))
-				handled = 1;
-			break;
-		case MCE_ERROR_TYPE_ERAT:
-			if (mce_flush(MCE_FLUSH_ERAT))
-				handled = 1;
-			break;
-		case MCE_ERROR_TYPE_TLB:
-			if (mce_flush(MCE_FLUSH_TLB))
-				handled = 1;
-			break;
-		}
-
+		handled = mce_correct_err(table[i].error_type);
 		/*
 		 * Attempt to handle multiple conditions, but only return
 		 * one. Ensure uncorrectable errors are first in the table
@@ -522,29 +519,8 @@ static int mce_handle_derror(struct pt_regs *regs,
 		/* now fill in mce_error_info */
 		mce_err->error_type = table[i].error_type;
 		mce_err->error_class = table[i].error_class;
-		switch (table[i].error_type) {
-		case MCE_ERROR_TYPE_UE:
-			mce_err->u.ue_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_SLB:
-			mce_err->u.slb_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_ERAT:
-			mce_err->u.erat_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_TLB:
-			mce_err->u.tlb_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_USER:
-			mce_err->u.user_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_RA:
-			mce_err->u.ra_error_type = table[i].error_subtype;
-			break;
-		case MCE_ERROR_TYPE_LINK:
-			mce_err->u.link_error_type = table[i].error_subtype;
-			break;
-		}
+		mce_err_get_sub_type(mce_err, table[i].error_type,
+				     table[i].error_subtype);
 		mce_err->sync_error = table[i].sync_error;
 		mce_err->severity = table[i].severity;
 		mce_err->initiator = table[i].initiator;
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] powerpc/mce: Do not poison the memory using guest effective addr
  2020-04-27  6:13 [PATCH 1/2] powerpc/mce: Add helper functions to remove duplicate code Ganesh Goudar
@ 2020-04-27  6:13 ` Ganesh Goudar
  0 siblings, 0 replies; 2+ messages in thread
From: Ganesh Goudar @ 2020-04-27  6:13 UTC (permalink / raw)
  To: mpe, linuxppc-dev; +Cc: mahesh, Ganesh Goudar

As of now, if we hit UE due to memory failure in guest, host MCE
handler tries to find the pfn or physical address where the memory
error occurred using guest effective address and uses that pfn to
poison the memory, which is not right.

If we hit UE in guest, do not try to find pfn in host and thereby
avoid poisoning the memory in host.

Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Ganesh Goudar <ganeshgr@linux.ibm.com>
---
 arch/powerpc/kernel/mce_power.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/mce_power.c b/arch/powerpc/kernel/mce_power.c
index 143e79450e93..4e541dd3af0d 100644
--- a/arch/powerpc/kernel/mce_power.c
+++ b/arch/powerpc/kernel/mce_power.c
@@ -471,6 +471,10 @@ static int mce_handle_ierror(struct pt_regs *regs,
 				table[i].error_type == MCE_ERROR_TYPE_UE) {
 				unsigned long pfn;
 
+#ifdef CONFIG_KVM_BOOK3S_HANDLER
+				if (get_paca()->kvm_hstate.in_guest)
+					return handled;
+#endif
 				if (get_paca()->in_mce < MAX_MCE_DEPTH) {
 					pfn = addr_to_pfn(regs, regs->nip);
 					if (pfn != ULONG_MAX) {
@@ -515,6 +519,7 @@ static int mce_handle_derror(struct pt_regs *regs,
 		 */
 		if (found)
 			continue;
+		found = 1;
 
 		/* now fill in mce_error_info */
 		mce_err->error_type = table[i].error_type;
@@ -528,6 +533,10 @@ static int mce_handle_derror(struct pt_regs *regs,
 			*addr = regs->dar;
 		else if (mce_err->sync_error &&
 				table[i].error_type == MCE_ERROR_TYPE_UE) {
+#ifdef CONFIG_KVM_BOOK3S_HANDLER
+			if (get_paca()->kvm_hstate.in_guest)
+				continue;
+#endif
 			/*
 			 * We do a maximum of 4 nested MCE calls, see
 			 * kernel/exception-64s.h
@@ -536,7 +545,6 @@ static int mce_handle_derror(struct pt_regs *regs,
 				mce_find_instr_ea_and_phys(regs, addr,
 							   phys_addr);
 		}
-		found = 1;
 	}
 
 	if (found)
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-04-27  6:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  6:13 [PATCH 1/2] powerpc/mce: Add helper functions to remove duplicate code Ganesh Goudar
2020-04-27  6:13 ` [PATCH 2/2] powerpc/mce: Do not poison the memory using guest effective addr Ganesh Goudar

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).