m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()
Subsystems (4)
Geert Uytterhoeven
maintainerPATCH 1/5 m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()
hwreg_present() and hwreg_write() temporarily change the VBR register to another vector table. This table contains a valid bus error handler only, all other entries point to arbitrary addresses.
If an interrupt comes in while the temporary table is active, the processor will start executing at such an arbitrary address, and the kernel will crash.
While most callers run early, before interrupt are disabled, or explicitly disable interrupts, Finn Thain pointed out that macsonic has one callsite that doesn't, causing intermittent boot crashes. There's another unsafe callsite in hilkbd.
Fix this for good by disabling and restoring interrupts inside hwreg_present() and hwreg_write().
Explicitly disabling interrupts can be removed from the callsites later.
--- arch/m68k/mm/hwtest.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/m68k/mm/hwtest.c +6 -0
@@ -28,9 +28,11 @@int hwreg_present (volatile void *regp ) {int ret =0 ; +unsigned long flags;long save_sp, save_vbr;long tmp_vectors[3 ]; +local_irq_save (flags); __asm__ __volatile__ ("movec %/vbr,%2\n\t" "movel #Lberr1,%4@(8)\n\t"
@@ -46,6 +48,7 @@ int hwreg_present( volatile void *regp ) : "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr) : "a" (regp), "a" (tmp_vectors) ); +local_irq_restore (flags);return ( ret ); }
@@ -58,9 +61,11 @@ EXPORT_SYMBOL(hwreg_present);int hwreg_write (volatile void *regp,unsigned short val ) {int ret; +unsigned long flags;long save_sp, save_vbr;long tmp_vectors[3 ]; +local_irq_save (flags); __asm__ __volatile__ ("movec %/vbr,%2\n\t" "movel #Lberr2,%4@(8)\n\t"
@@ -78,6 +83,7 @@ int hwreg_write( volatile void *regp, unsigned short val ) : "=&d" (ret), "=&r" (save_sp), "=&r" (save_vbr) : "a" (regp), "a" (tmp_vectors), "g" (val) ); +local_irq_restore (flags);return ( ret ); }
Signature · 1 line
1.9.1
Geert Uytterhoeven
maintainerPATCH 2/5 m68k: Reformat arch/m68k/mm/hwtest.c
No functional changes
--- arch/m68k/mm/hwtest.c | 78 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 38 deletions(-)
arch/m68k/mm/hwtest.c +40 -38
@@ -25,32 +25,32 @@#include <linux/module.h> -int hwreg_present (volatile void *regp ) +int hwreg_present (volatile void *regp) { -int ret =0 ; -unsigned long flags; -long save_sp, save_vbr; -long tmp_vectors[3 ]; +int ret =0 ; +unsigned long flags; +long save_sp, save_vbr; +long tmp_vectors[3 ]; -local_irq_save (flags); - __asm__ __volatile__ - ("movec %/vbr,%2\n\t" -"movel #Lberr1,%4@(8)\n\t" -"movec %4,%/vbr\n\t" -"movel %/sp,%1\n\t" -"moveq #0,%0\n\t" -"tstb %3@\n\t" +local_irq_save (flags); + __asm__ __volatile__ ( +"movec %/vbr,%2\n\t" +"movel #Lberr1,%4@(8)\n\t" +"movec %4,%/vbr\n\t" +"movel %/sp,%1\n\t" +"moveq #0,%0\n\t" +"tstb %3@\n\t" "nop\n\t" -"moveq #1,%0\n" -"Lberr1:\n\t" -"movel %1,%/sp\n\t" -"movec %2,%/vbr" +"moveq #1,%0\n" +"Lberr1:\n\t" +"movel %1,%/sp\n\t" +"movec %2,%/vbr" :"=&d" (ret),"=&r" (save_sp),"=&r" (save_vbr) :"a" (regp),"a" (tmp_vectors) - ); -local_irq_restore (flags); + ); +local_irq_restore (flags); -return ( ret ); +return ret; }EXPORT_SYMBOL (hwreg_present);
@@ -58,34 +58,36 @@ EXPORT_SYMBOL(hwreg_present);* by a bus error handler. Returns 1 if successful, 0 otherwise. */ -int hwreg_write (volatile void *regp,unsigned short val ) +int hwreg_write (volatile void *regp,unsigned short val) { -int ret; +int ret;unsigned long flags; -long save_sp, save_vbr; -long tmp_vectors[3 ]; +long save_sp, save_vbr; +long tmp_vectors[3 ];local_irq_save (flags); - __asm__ __volatile__ - ("movec %/vbr,%2\n\t" -"movel #Lberr2,%4@(8)\n\t" -"movec %4,%/vbr\n\t" -"movel %/sp,%1\n\t" -"moveq #0,%0\n\t" -"movew %5,%3@\n\t" -"nop \n\t" /* If this nop isn't present, 'ret' may already be -* loaded with 1 at the time the bus error -* happens! */ -"moveq #1,%0\n" + __asm__ __volatile__ ( +"movec %/vbr,%2\n\t" +"movel #Lberr2,%4@(8)\n\t" +"movec %4,%/vbr\n\t" +"movel %/sp,%1\n\t" +"moveq #0,%0\n\t" +"movew %5,%3@\n\t" +"nop\n\t" +/* +* If this nop isn't present, 'ret' may already be loaded +* with 1 at the time the bus error happens! +*/ +"moveq #1,%0\n" "Lberr2:\n\t" -"movel %1,%/sp\n\t" -"movec %2,%/vbr" +"movel %1,%/sp\n\t" +"movec %2,%/vbr" :"=&d" (ret),"=&r" (save_sp),"=&r" (save_vbr) :"a" (regp),"a" (tmp_vectors),"g" (val) );local_irq_restore (flags); -return ( ret ); +return ret; }EXPORT_SYMBOL (hwreg_write);
Signature · 1 line
1.9.1
Geert Uytterhoeven
maintainerPATCH 3/5 cirrus/mac89x0: Remove superfluous interrupt disable/restore
In reply to Geert UytterhoevenAs of commit XXX ("m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()"), this is no longer needed.
---
Do not apply before commit XXX has been applied.
--- drivers/net/ethernet/cirrus/mac89x0.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/cirrus/mac89x0.c +2 -6
@@ -216,14 +216,10 @@ struct net_device * __init mac89x0_probe(int unit) ioaddr = (unsigned long )nubus_slot_addr (slot) | (((slot&0xf ) <<20 ) +DEFAULTIOBASE ); { -unsigned long flags;int card_present; -local_irq_save (flags); - card_present = (hwreg_present ((void *) ioaddr+4 ) && -hwreg_present ((void *) ioaddr +DATA_PORT )); -local_irq_restore (flags); - + card_present = (hwreg_present ((void *)ioaddr +4 ) && +hwreg_present ((void *)ioaddr +DATA_PORT ));if (!card_present) goto out; }
Signature · 1 line
1.9.1
Geert Uytterhoeven
maintainerPATCH 4/5 natsemi/macsonic: Remove superfluous interrupt disable/restore
In reply to Geert UytterhoevenAs of commit XXX ("m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()"), this is no longer needed.
---
Do not apply before commit XXX has been applied.
--- drivers/net/ethernet/natsemi/macsonic.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/ethernet/natsemi/macsonic.c +0 -4
@@ -326,13 +326,9 @@ static int mac_onboard_sonic_probe(struct net_device *dev) macintosh_config->ident == MAC_MODEL_P588 || macintosh_config->ident == MAC_MODEL_P575 || macintosh_config->ident == MAC_MODEL_C610) { -unsigned long flags;int card_present; -local_irq_save (flags); card_present =hwreg_present ((void *)ONBOARD_SONIC_REGISTERS ); -local_irq_restore (flags); -if (!card_present) {printk ("none.\n" );return -ENODEV ;
Signature · 1 line
1.9.1
Geert Uytterhoeven
maintainerPATCH 4/5 natsemi/macsonic: Remove superfluous interrupt disable/restore
In reply to Geert UytterhoevenAs of commit XXX ("m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()"), this is no longer needed.
---
Do not apply before commit XXX has been applied.
--- drivers/net/ethernet/natsemi/macsonic.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/ethernet/natsemi/macsonic.c +0 -4
@@ -326,13 +326,9 @@ static int mac_onboard_sonic_probe(struct net_device *dev) macintosh_config->ident == MAC_MODEL_P588 || macintosh_config->ident == MAC_MODEL_P575 || macintosh_config->ident == MAC_MODEL_C610) { -unsigned long flags;int card_present; -local_irq_save (flags); card_present =hwreg_present ((void *)ONBOARD_SONIC_REGISTERS ); -local_irq_restore (flags); -if (!card_present) {printk ("none.\n" );return -ENODEV ;
Signature · 1 line
1.9.1
Geert Uytterhoeven
maintainerPATCH 5/5 nubus: Remove superfluous interrupt disable/restore
In reply to Geert UytterhoevenAs of commit XXX ("m68k: Disable/restore interrupts in hwreg_present()/hwreg_write()"), this is no longer needed.
---
Do not apply before commit XXX has been applied.
--- drivers/nubus/nubus.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/nubus/nubus.c +0 -4
@@ -920,14 +920,10 @@ void __init nubus_probe_slot(int slot) rp =nubus_rom_addr (slot);for (i =4 ; i; i--) { -unsigned long flags;int card_present; rp--; -local_irq_save (flags); card_present =hwreg_present (rp); -local_irq_restore (flags); -if (!card_present)continue ;
Signature · 1 line
1.9.1
Quoted 1 line · Geert Uytterhoeven
While most callers run early, before interrupt are disabled, or
interrupts are enabled
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different."
Geert Uytterhoeven
maintainerQuoted 3 lines · Andreas Schwab
Quoted 1 line
While most callers run early, before interrupt are disabled, or
interrupts are enabled
Thanks, will fix.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Geert Uytterhoeven
maintainerQuoted 6 lines · Geert Uytterhoeven
Quoted 3 lines · Andreas Schwab
Quoted 1 line
While most callers run early, before interrupt are disabled, or
interrupts are enabled
Thanks, will fix.
Fixed and queued for 3.18, together with the reformat in PATCH 2/5.
I'll resend the remaining 3 after v3.18-rc1.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Geert Uytterhoeven
maintainerQuoted 6 lines · Geert Uytterhoeven
Quoted 3 lines · Andreas Schwab
Quoted 1 line
While most callers run early, before interrupt are disabled, or
interrupts are enabled
Thanks, will fix.
Fixed and queued for 3.18, together with the reformat in PATCH 2/5.
I'll resend the remaining 3 after v3.18-rc1.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Geert Uytterhoeven
maintainerQuoted 3 lines · Andreas Schwab
Quoted 1 line
While most callers run early, before interrupt are disabled, or
interrupts are enabled
Thanks, will fix.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds