From 9eb3394bf2037120881a8846bc67064f49325366 Mon Sep 17 00:00:00 2001 From: Richard Mortimer Date: Tue, 17 Jan 2006 15:21:01 -0800 Subject: [PATCH 1/4] [SPARC64]: Eliminate race condition reading Hummingbird STICK register Ensure a consistent value is read from the STICK register by ensuring that both high and low are read without high changing due to a roll over of the low register. Various Debian/SPARC users (myself include) have noticed problems with Hummingbird based systems. The symptoms are that the system time is seen to jump forward 3 days, 6 hours, 11 minutes give or take a few seconds. In many cases the system then hangs some time afterwards. I've spotted a race condition in the code to read the STICK register. I could not work out why 3d, 6h, 11m is important but guess that it is due to the 2^32 jump of STICK (forwards on one read and then the next read will seem to be backwards) during a timer interrupt. I'm guessing that a change of -2^32 will get converted to a large unsigned increment after the arithmetic manipulation between STICK, nanoseconds, jiffies etc. I did a test where I modified __hbird_read_stick to artificially inject rollover faults forcefully every few seconds. With this I saw the clock jump over 6 times in 12 hours compared to once every month or so. Signed-off-by: Richard Mortimer Signed-off-by: David S. Miller --- arch/sparc64/kernel/time.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c index 459c8fbe02b4..a22930d62adf 100644 --- a/arch/sparc64/kernel/time.c +++ b/arch/sparc64/kernel/time.c @@ -280,9 +280,9 @@ static struct sparc64_tick_ops stick_operations __read_mostly = { * Since STICK is constantly updating, we have to access it carefully. * * The sequence we use to read is: - * 1) read low - * 2) read high - * 3) read low again, if it rolled over increment high by 1 + * 1) read high + * 2) read low + * 3) read high again, if it rolled re-read both low and high again. * * Writing STICK safely is also tricky: * 1) write low to zero @@ -295,18 +295,18 @@ static struct sparc64_tick_ops stick_operations __read_mostly = { static unsigned long __hbird_read_stick(void) { unsigned long ret, tmp1, tmp2, tmp3; - unsigned long addr = HBIRD_STICK_ADDR; + unsigned long addr = HBIRD_STICK_ADDR+8; - __asm__ __volatile__("ldxa [%1] %5, %2\n\t" - "add %1, 0x8, %1\n\t" - "ldxa [%1] %5, %3\n\t" + __asm__ __volatile__("ldxa [%1] %5, %2\n" + "1:\n\t" "sub %1, 0x8, %1\n\t" + "ldxa [%1] %5, %3\n\t" + "add %1, 0x8, %1\n\t" "ldxa [%1] %5, %4\n\t" "cmp %4, %2\n\t" - "blu,a,pn %%xcc, 1f\n\t" - " add %3, 1, %3\n" - "1:\n\t" - "sllx %3, 32, %3\n\t" + "bne,a,pn %%xcc, 1b\n\t" + " mov %4, %2\n\t" + "sllx %4, 32, %4\n\t" "or %3, %4, %0\n\t" : "=&r" (ret), "=&r" (addr), "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3) From 1ae613883468eab2fb8a077aad9fdedfbfa73d1b Mon Sep 17 00:00:00 2001 From: Eric Sesterhenn Date: Tue, 17 Jan 2006 15:36:05 -0800 Subject: [PATCH 2/4] [SPARC]: change if() BUG(); to BUG_ON in iommu.c this patch changes if() BUG(); constructs in iommu.c to BUG_ON(); so it gets save to define BUG() and BUG_ON() to nullstatements. Signed-off-by: Eric Sesterhenn Signed-off-by: David S. Miller --- arch/sparc/mm/iommu.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/sparc/mm/iommu.c b/arch/sparc/mm/iommu.c index 489bf68d5f05..77840c804786 100644 --- a/arch/sparc/mm/iommu.c +++ b/arch/sparc/mm/iommu.c @@ -295,8 +295,7 @@ static void iommu_release_one(u32 busa, int npages, struct sbus_bus *sbus) int ioptex; int i; - if (busa < iommu->start) - BUG(); + BUG_ON(busa < iommu->start); ioptex = (busa - iommu->start) >> PAGE_SHIFT; for (i = 0; i < npages; i++) { iopte_val(iommu->page_table[ioptex + i]) = 0; @@ -340,9 +339,9 @@ static int iommu_map_dma_area(dma_addr_t *pba, unsigned long va, iopte_t *first; int ioptex; - if ((va & ~PAGE_MASK) != 0) BUG(); - if ((addr & ~PAGE_MASK) != 0) BUG(); - if ((len & ~PAGE_MASK) != 0) BUG(); + BUG_ON((va & ~PAGE_MASK) != 0); + BUG_ON((addr & ~PAGE_MASK) != 0); + BUG_ON((len & ~PAGE_MASK) != 0); /* page color = physical address */ ioptex = bit_map_string_get(&iommu->usemap, len >> PAGE_SHIFT, @@ -405,8 +404,8 @@ static void iommu_unmap_dma_area(unsigned long busa, int len) unsigned long end; int ioptex = (busa - iommu->start) >> PAGE_SHIFT; - if ((busa & ~PAGE_MASK) != 0) BUG(); - if ((len & ~PAGE_MASK) != 0) BUG(); + BUG_ON((busa & ~PAGE_MASK) != 0); + BUG_ON((len & ~PAGE_MASK) != 0); iopte += ioptex; end = busa + len; From c7006638a50cbf16bb420fa91e5af2dd22d28621 Mon Sep 17 00:00:00 2001 From: "David S. Miller" Date: Tue, 17 Jan 2006 15:53:11 -0800 Subject: [PATCH 3/4] [SPARC]: Fix sbusfb build. sbusfb_compat_ioctl() needs to return int, not long, as that is what the fb_ops->fb_compat_ioctl method prototype wants. Need to git rid of the "struct file *file" first argument to fbiogetputcmap() and fbiogscursor() to match calls done in sbusfb_compat_ioctl(). Signed-off-by: David S. Miller --- drivers/video/sbuslib.c | 9 +++------ drivers/video/sbuslib.h | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/video/sbuslib.c b/drivers/video/sbuslib.c index 55e6e2d60d3a..a4d7cc51ce0b 100644 --- a/drivers/video/sbuslib.c +++ b/drivers/video/sbuslib.c @@ -199,8 +199,7 @@ struct fbcmap32 { #define FBIOPUTCMAP32 _IOW('F', 3, struct fbcmap32) #define FBIOGETCMAP32 _IOW('F', 4, struct fbcmap32) -static int fbiogetputcmap(struct file *file, struct fb_info *info, - unsigned int cmd, unsigned long arg) +static int fbiogetputcmap(struct fb_info *info, unsigned int cmd, unsigned long arg) { struct fbcmap32 __user *argp = (void __user *)arg; struct fbcmap __user *p = compat_alloc_user_space(sizeof(*p)); @@ -236,8 +235,7 @@ struct fbcursor32 { #define FBIOSCURSOR32 _IOW('F', 24, struct fbcursor32) #define FBIOGCURSOR32 _IOW('F', 25, struct fbcursor32) -static int fbiogscursor(struct file *file, struct fb_info *info, - unsigned long arg) +static int fbiogscursor(struct fb_info *info, unsigned long arg) { struct fbcursor __user *p = compat_alloc_user_space(sizeof(*p)); struct fbcursor32 __user *argp = (void __user *)arg; @@ -263,8 +261,7 @@ static int fbiogscursor(struct file *file, struct fb_info *info, return info->fbops->fb_ioctl(info, FBIOSCURSOR, (unsigned long)p); } -long sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, - unsigned long arg) +int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { switch (cmd) { case FBIOGTYPE: diff --git a/drivers/video/sbuslib.h b/drivers/video/sbuslib.h index f753939013ed..492828c3fe8f 100644 --- a/drivers/video/sbuslib.h +++ b/drivers/video/sbuslib.h @@ -20,7 +20,7 @@ extern int sbusfb_mmap_helper(struct sbus_mmap_map *map, int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg, struct fb_info *info, int type, int fb_depth, unsigned long fb_size); -long sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, +int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg); #endif /* _SBUSLIB_H */ From 4f3f2f6f3e7ce68c533e7786114f05181772ff6f Mon Sep 17 00:00:00 2001 From: "David S. Miller" Date: Tue, 17 Jan 2006 15:55:58 -0800 Subject: [PATCH 4/4] [SOUND]: sparc/cs4231: Fix some typos which wrecked the build. Signed-off-by: David S. Miller --- sound/sparc/cs4231.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c index e9086e95a31f..fd6543998788 100644 --- a/sound/sparc/cs4231.c +++ b/sound/sparc/cs4231.c @@ -69,13 +69,14 @@ struct sbus_dma_info { }; #endif +struct snd_cs4231; struct cs4231_dma_control { void (*prepare)(struct cs4231_dma_control *dma_cont, int dir); void (*enable)(struct cs4231_dma_control *dma_cont, int on); int (*request)(struct cs4231_dma_control *dma_cont, dma_addr_t bus_addr, size_t len); unsigned int (*address)(struct cs4231_dma_control *dma_cont); void (*reset)(struct snd_cs4231 *chip); - void (*preallocate)(struct snd_cs4231 *chip, struct snd_snd_pcm *pcm); + void (*preallocate)(struct snd_cs4231 *chip, struct snd_pcm *pcm); #ifdef EBUS_SUPPORT struct ebus_dma_info ebus_info; #endif