[PATCH] powerpc: Fix accumulate_stolen_time() vs. CONFIG_PREEMPT

Benjamin Herrenschmidt benh at kernel.crashing.org
Thu Jan 13 16:57:05 EST 2011


The function accumulate_stolen_time() is called on pSeries to scan
the hypervisor event log every now and then. This happens very early
during the exception entry process, while the PACA soft/hard_enabled
fields don't properly reflect the state of the system, which is
basically hard irq disabled.

This causes various debug checks to trigger when CONFIG_PREEMPT is
enabled which can themselves cause the machine to crash due to the
unexpected context they are called from.

We fix that by temporarily setting the PACA fields to reflect the
hard disabled state in accumulate_stolen_time(). This keeps the
overhead to that function, hopefully called rarely and only on
those pSeries machines.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 0104069..714685c 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -265,11 +265,26 @@ void accumulate_stolen_time(void)
 {
 	u64 sst, ust;
 
-	sst = scan_dispatch_log(get_paca()->starttime_user);
-	ust = scan_dispatch_log(get_paca()->starttime);
-	get_paca()->system_time -= sst;
-	get_paca()->user_time -= ust;
-	get_paca()->stolen_time += ust + sst;
+	u8 save_soft_enabled = local_paca->soft_enabled;
+	u8 save_hard_enabled = local_paca->hard_enabled;
+
+	/* We are called early in the exception entry, before
+	 * soft/hard_enabled are sync'ed to the expected state
+	 * for the exception. We are hard disabled but the PACA
+	 * needs to reflect that so various debug stuff doesn't
+	 * complain
+	 */
+	local_paca->soft_enabled = 0;
+	local_paca->hard_enabled = 0;
+
+	sst = scan_dispatch_log(local_paca->starttime_user);
+	ust = scan_dispatch_log(local_paca->starttime);
+	local_paca->system_time -= sst;
+	local_paca->user_time -= ust;
+	local_paca->stolen_time += ust + sst;
+
+	local_paca->soft_enabled = save_soft_enabled;
+	local_paca->hard_enabled = save_hard_enabled;
 }
 
 static inline u64 calculate_stolen_time(u64 stop_tb)




More information about the Linuxppc-dev mailing list