Skip to contentSkip to conversation

RFC: [sparc32] Mask PIL in local_irq_xxx

PATCH Keith M Wesolowski 2 participants 2 messages Feb 8, 2004 – Feb 9, 2004 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

Here's a patch to mask out CWP when doing local_irq_restore. Since Pete's notes indicate that Dave advised outlining local_irq_restore after making this change, it seems only sensible to outline the other two as well, since they are of similar size and tend to be called in the same places (local_irq_save especially).

This removes the need to restore the flags (release locks, etc) in the same frame as they are saved (locks taken, etc). So it's not "Fucked Up" any more, though it's probably slightly slower.

Comments?

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.1554 -> 1.1555
# arch/sparc/kernel/irq.c 1.26 -> 1.27
# arch/sparc/kernel/sparc_ksyms.c 1.23 -> 1.24
# arch/sparc/kernel/process.c 1.33 -> 1.34
# include/asm-sparc/system.h 1.18 -> 1.19
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 04/02/07 [email protected] 1.1555
# Mask PIL in local_irq operations.
#
# Outline large local_irq functions.
# --------------------------------------------
#

arch/sparc/kernel/irq.c +60 -0
diff -Nru a/arch/sparc/kernel/irq.c b/arch/sparc/kernel/irq.c
@@ -52,6 +52,66 @@
 /* Used to protect the IRQ action lists */
 spinlock_t irq_action_lock = SPIN_LOCK_UNLOCKED;
 
+#ifdef CONFIG_SMP
+#define SMP_NOP2 "nop; nop;\n\t"
+#define SMP_NOP3 "nop; nop; nop;\n\t"
+#else
+#define SMP_NOP2
+#define SMP_NOP3
+#endif /* SMP */
+unsigned long __local_irq_save(void)
+{
+	unsigned long retval;
+	unsigned long tmp;
+
+	__asm__ __volatile__(
+		"rd	%%psr, %0\n\t"
+		SMP_NOP3	/* Sun4m + Cypress + SMP bug */
+		"or	%0, %2, %1\n\t"
+		"wr	%1, 0, %%psr\n\t"
+		"nop; nop; nop\n"
+		: "=&r" (retval), "=r" (tmp)
+		: "i" (PSR_PIL)
+		: "memory");
+
+	return retval;
+}
+
+void local_irq_enable(void)
+{
+	unsigned long tmp;
+
+	__asm__ __volatile__(
+		"rd	%%psr, %0\n\t"
+		SMP_NOP3	/* Sun4m + Cypress + SMP bug */
+		"andn	%0, %1, %0\n\t"
+		"wr	%0, 0, %%psr\n\t"
+		"nop; nop; nop\n"
+		: "=&r" (tmp)
+		: "i" (PSR_PIL)
+		: "memory");
+}
+
+void local_irq_restore(unsigned long old_psr)
+{
+	unsigned long tmp;
+
+	__asm__ __volatile__(
+		"rd	%%psr, %0\n\t"
+		"and	%2, %1, %2\n\t"
+		SMP_NOP2	/* Sun4m + Cypress + SMP bug */
+		"andn	%0, %1, %0\n\t"
+		"wr	%0, %2, %%psr\n\t"
+		"nop; nop; nop\n"
+		: "=&r" (tmp)
+		: "i" (PSR_PIL), "r" (old_psr)
+		: "memory");
+}
+
+EXPORT_SYMBOL(__local_irq_save);
+EXPORT_SYMBOL(local_irq_enable);
+EXPORT_SYMBOL(local_irq_restore);
+
 /*
  * Dave Redman ([email protected])
  *
arch/sparc/kernel/process.c +5 -4
diff -Nru a/arch/sparc/kernel/process.c b/arch/sparc/kernel/process.c
@@ -148,11 +148,12 @@
 
 extern void (*prom_palette)(int);
 
+/* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
 void machine_halt(void)
 {
-	sti();
+	local_irq_enable();
 	mdelay(8);
-	cli();
+	local_irq_disable();
 	if (!serial_console && prom_palette)
 		prom_palette (1);
 	prom_halt();
@@ -165,9 +166,9 @@
 {
 	char *p;
 	
-	sti();
+	local_irq_enable();
 	mdelay(8);
-	cli();
+	local_irq_disable();
 
 	p = strchr (reboot_command, '\n');
 	if (p) *p = 0;
arch/sparc/kernel/sparc_ksyms.c +0 -4
diff -Nru a/arch/sparc/kernel/sparc_ksyms.c b/arch/sparc/kernel/sparc_ksyms.c
@@ -159,10 +159,6 @@
 /* IRQ implementation. */
 EXPORT_SYMBOL(global_irq_holder);
 EXPORT_SYMBOL(synchronize_irq);
-EXPORT_SYMBOL(__global_cli);
-EXPORT_SYMBOL(__global_sti);
-EXPORT_SYMBOL(__global_save_flags);
-EXPORT_SYMBOL(__global_restore_flags);
 
 /* Misc SMP information */
 EXPORT_SYMBOL(__cpu_number_map);
include/asm-sparc/system.h +6 -92

113 lines not on this page · raw message

Signature · 1 line
Keith M Wesolowski
#1 lore raw

arch/sparc/kernel/irq.c line 61

Quoted 7 lines · On Sat, 7 Feb 2004 18:02:39 -0800 Keith M Wesolowski <[email protected]>…
arch/sparc/kernel/irq.c +7 -0
+#ifdef CONFIG_SMP
+#define SMP_NOP2 "nop; nop;\n\t"
+#define SMP_NOP3 "nop; nop; nop;\n\t"
+#else
+#define SMP_NOP2
+#define SMP_NOP3
+#endif /* SMP */

Nice touch.

arch/sparc/kernel/process.c line 155

Quoted 6 lines
arch/sparc/kernel/process.c +2 -1
+/* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
 void machine_halt(void)
 {
-	sti();
+	local_irq_enable();
 	mdelay(8);

You might want to consider if jailing would be appropriate. I seem to remember that it cannot break through masked CPUs by design, but in actuality our SMP IPI shouldn't either (which is what cli() is).

-- Pete