LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Finn Thain <fthain@telegraphics.com.au>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Stephen N Chivers <schivers@csc.com.au>,
	Thomas Gleixner <tglx@linutronix.de>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	John Stultz <john.stultz@linaro.org>,
	linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org,
	Philip Blundell <philb@gnu.org>,
	Michael Schmitz <schmitzmic@gmail.com>,
	Joshua Thompson <funaho@jurai.org>
Subject: [RFC PATCH 02/13] m68k: Fix mutual exclusion in arch_gettimeoffset
Date: Mon, 12 Nov 2018 15:12:39 +1100
Message-ID: <6ba103c7e24d316e4bee7f713d5a8485a548c4e7.1541995959.git.fthain@telegraphics.com.au> (raw)
In-Reply-To: <cover.1541995959.git.fthain@telegraphics.com.au>

Implementations of arch_gettimeoffset are generally not re-entrant
and assume that interrupts have been disabled. Unfortunately this
pre-condition got broken in v2.6.32.

Cc: Philip Blundell <philb@gnu.org>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Joshua Thompson <funaho@jurai.org>
Fixes: 4ad4c76b7afb ("m68k: convert to use arch_gettimeoffset()")
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 arch/m68k/amiga/config.c    |  6 +++++-
 arch/m68k/atari/time.c      |  6 +++++-
 arch/m68k/bvme6000/config.c | 10 +++++++---
 arch/m68k/hp300/time.c      |  8 +++++++-
 arch/m68k/mac/via.c         |  5 +++++
 arch/m68k/mvme147/config.c  |  6 +++++-
 arch/m68k/mvme16x/config.c  |  1 -
 7 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/arch/m68k/amiga/config.c b/arch/m68k/amiga/config.c
index 65f63a457130..5ec3687984a9 100644
--- a/arch/m68k/amiga/config.c
+++ b/arch/m68k/amiga/config.c
@@ -492,12 +492,14 @@ static void __init amiga_sched_init(irq_handler_t timer_routine)
 
 #define TICK_SIZE 10000
 
-/* This is always executed with interrupts disabled.  */
 static u32 amiga_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned short hi, lo, hi2;
 	u32 ticks, offset = 0;
 
+	local_irq_save(flags);
+
 	/* read CIA B timer A current value */
 	hi  = ciab.tahi;
 	lo  = ciab.talo;
@@ -515,6 +517,8 @@ static u32 amiga_gettimeoffset(void)
 		if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
 			offset = 10000;
 
+	local_irq_restore(flags);
+
 	ticks = jiffy_ticks - ticks;
 	ticks = (10000 * ticks) / jiffy_ticks;
 
diff --git a/arch/m68k/atari/time.c b/arch/m68k/atari/time.c
index 9cca64286464..4765e9a58293 100644
--- a/arch/m68k/atari/time.c
+++ b/arch/m68k/atari/time.c
@@ -40,11 +40,13 @@ atari_sched_init(irq_handler_t timer_routine)
 
 #define TICK_SIZE 10000
 
-/* This is always executed with interrupts disabled.  */
 u32 atari_gettimeoffset(void)
 {
+  unsigned long flags;
   u32 ticks, offset = 0;
 
+  local_irq_save(flags);
+
   /* read MFP timer C current value */
   ticks = st_mfp.tim_dt_c;
   /* The probability of underflow is less than 2% */
@@ -53,6 +55,8 @@ u32 atari_gettimeoffset(void)
     if (st_mfp.int_pn_b & (1 << 5))
       offset = TICK_SIZE;
 
+  local_irq_restore(flags);
+
   ticks = INT_TICKS - ticks;
   ticks = ticks * 10000L / INT_TICKS;
 
diff --git a/arch/m68k/bvme6000/config.c b/arch/m68k/bvme6000/config.c
index 143ee9fa3893..0afdef10a5a4 100644
--- a/arch/m68k/bvme6000/config.c
+++ b/arch/m68k/bvme6000/config.c
@@ -206,8 +206,6 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 }
 
 
-/* This is always executed with interrupts disabled.  */
-
 /*
  * NOTE:  Don't accept any readings within 5us of rollover, as
  * the T1INT bit may be a little slow getting set.  There is also
@@ -217,12 +215,16 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 
 u32 bvme6000_gettimeoffset(void)
 {
+    unsigned long flags;
     volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
     volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
-    unsigned char msr = rtc->msr & 0xc0;
+    unsigned char msr;
     unsigned char t1int, t1op;
     u32 v = 800000, ov;
 
+    local_irq_save(flags);
+
+    msr = rtc->msr & 0xc0;
     rtc->msr = 0;	/* Ensure timer registers accessible */
 
     do {
@@ -245,6 +247,8 @@ u32 bvme6000_gettimeoffset(void)
 	v += 10000;			/* Int pending, + 10ms */
     rtc->msr = msr;
 
+    local_irq_restore(flags);
+
     return v * 1000;
 }
 
diff --git a/arch/m68k/hp300/time.c b/arch/m68k/hp300/time.c
index 289d928a46cb..5cf711fd0858 100644
--- a/arch/m68k/hp300/time.c
+++ b/arch/m68k/hp300/time.c
@@ -49,16 +49,22 @@ static irqreturn_t hp300_tick(int irq, void *dev_id)
 
 u32 hp300_gettimeoffset(void)
 {
-  /* Read current timer 1 value */
+  unsigned long flags;
   unsigned char lsb, msb1, msb2;
   unsigned short ticks;
 
+  local_irq_save(flags);
+
+  /* Read current timer 1 value */
   msb1 = in_8(CLOCKBASE + 5);
   lsb = in_8(CLOCKBASE + 7);
   msb2 = in_8(CLOCKBASE + 5);
   if (msb1 != msb2)
     /* A carry happened while we were reading.  Read it again */
     lsb = in_8(CLOCKBASE + 7);
+
+  local_irq_restore(flags);
+
   ticks = INTVAL - ((msb2 << 8) | lsb);
   return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000;
 }
diff --git a/arch/m68k/mac/via.c b/arch/m68k/mac/via.c
index e4facff0c1f3..e5dff74f59b3 100644
--- a/arch/m68k/mac/via.c
+++ b/arch/m68k/mac/via.c
@@ -318,8 +318,11 @@ void via_debug_dump(void)
 
 u32 mac_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned long ticks, offset = 0;
 
+	local_irq_save(flags);
+
 	/* read VIA1 timer 2 current value */
 	ticks = via1[vT1CL] | (via1[vT1CH] << 8);
 	/* The probability of underflow is less than 2% */
@@ -327,6 +330,8 @@ u32 mac_gettimeoffset(void)
 		/* Check for pending timer interrupt in VIA1 IFR */
 		if (via1[vIFR] & 0x40) offset = TICK_SIZE;
 
+	local_irq_restore(flags);
+
 	ticks = MAC_CLOCK_TICK - ticks;
 	ticks = ticks * 10000L / MAC_CLOCK_TICK;
 
diff --git a/arch/m68k/mvme147/config.c b/arch/m68k/mvme147/config.c
index adea549d240e..8074940b0aa1 100644
--- a/arch/m68k/mvme147/config.c
+++ b/arch/m68k/mvme147/config.c
@@ -125,17 +125,21 @@ void mvme147_sched_init (irq_handler_t timer_routine)
 	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
 }
 
-/* This is always executed with interrupts disabled.  */
 /* XXX There are race hazards in this code XXX */
 u32 mvme147_gettimeoffset(void)
 {
+	unsigned long flags;
 	volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
 	unsigned short n;
 
+	local_irq_save(flags);
+
 	n = *cp;
 	while (n != *cp)
 		n = *cp;
 
+	local_irq_restore(flags);
+
 	n -= PCC_TIMER_PRELOAD;
 	return ((unsigned long)n * 25 / 4) * 1000;
 }
diff --git a/arch/m68k/mvme16x/config.c b/arch/m68k/mvme16x/config.c
index 6ee36a5b528d..d4aec717e688 100644
--- a/arch/m68k/mvme16x/config.c
+++ b/arch/m68k/mvme16x/config.c
@@ -381,7 +381,6 @@ void mvme16x_sched_init (irq_handler_t timer_routine)
 }
 
 
-/* This is always executed with interrupts disabled.  */
 u32 mvme16x_gettimeoffset(void)
 {
     return (*(volatile u32 *)0xfff42008) * 1000;
-- 
2.18.1


  parent reply index

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12  4:12 [RFC PATCH 00/13] m68k: Drop arch_gettimeoffset and adopt clocksource API Finn Thain
2018-11-12  4:12 ` [RFC PATCH 08/13] m68k: atari: Convert to " Finn Thain
2018-11-12  4:12 ` [RFC PATCH 04/13] m68k: mac: Clean up unused timer definitions Finn Thain
2018-11-12  4:12 ` [RFC PATCH 10/13] m68k: hp300: Convert to clocksource API Finn Thain
2018-11-12  4:12 ` [RFC PATCH 11/13] m68k: mac: " Finn Thain
2018-11-12  4:12 ` [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset Finn Thain
2018-11-12  8:34   ` Christoph Hellwig
2018-11-13  3:39     ` Finn Thain
2018-11-13  9:20       ` Russell King - ARM Linux
2018-11-13 21:55         ` Finn Thain
2018-11-13 23:43           ` Russell King - ARM Linux
2018-11-14  1:35             ` Michael Schmitz
2018-11-14  7:58               ` Russell King - ARM Linux
2018-11-15  1:34                 ` Michael Schmitz
2018-11-14  3:17             ` Finn Thain
2018-11-14 14:16               ` Russell King - ARM Linux
2018-11-14 14:58                 ` Geert Uytterhoeven
2018-11-14 18:11                   ` Russell King - ARM Linux
2018-11-15  4:12                 ` Finn Thain
2018-11-16 17:47                   ` Russell King - ARM Linux
2018-11-16 22:49                     ` Finn Thain
2018-11-17  3:00                       ` Michael Schmitz
2018-11-14 12:05   ` Russell King - ARM Linux
2018-11-12  4:12 ` Finn Thain [this message]
2018-11-12  4:12 ` [RFC PATCH 07/13] m68k: amiga: Convert to clocksource API Finn Thain
2018-11-12  9:02   ` Geert Uytterhoeven
2018-11-12  9:21     ` Finn Thain
2018-11-12  4:12 ` [RFC PATCH 09/13] m68k: bvme6000: " Finn Thain
2018-11-12  4:12 ` [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET Finn Thain
2018-11-12  9:00   ` Geert Uytterhoeven
2018-11-12  9:06     ` Finn Thain
2018-11-13  2:29       ` Michael Schmitz
2018-11-13  3:14         ` Finn Thain
2018-11-13  4:50           ` Michael Schmitz
2018-11-13  6:15             ` Finn Thain
2018-11-13  8:24               ` Michael Schmitz
2018-11-13 22:11                 ` Finn Thain
2018-11-14  1:08                   ` Michael Schmitz
2018-11-14  2:58                     ` Michael Schmitz
2018-11-14 23:54                       ` Michael Schmitz
2018-11-15  4:37                         ` Finn Thain
2018-11-15  6:35                         ` Michael Schmitz
2018-11-16  0:04                           ` Finn Thain
2018-11-12  4:12 ` [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource API Finn Thain
2018-11-12 18:37   ` Thomas Gleixner
2018-11-13  0:11     ` Finn Thain
2018-11-13 22:04       ` Finn Thain
2018-11-13 22:10         ` [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource APIy Thomas Gleixner
2018-11-13 22:33           ` Finn Thain
2018-11-18 17:12             ` Thomas Gleixner
2018-11-12  4:12 ` [RFC PATCH 03/13] m68k: mac: Fix VIA timer counter accesses Finn Thain
2018-11-12  4:12 ` [RFC PATCH 12/13] m68k: mvme147: Convert to clocksource API Finn Thain
2018-11-12  4:12 ` [RFC PATCH 05/13] m68k: apollo, q40, sun3, sun3x: Remove arch_gettimeoffset implementations Finn Thain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ba103c7e24d316e4bee7f713d5a8485a548c4e7.1541995959.git.fthain@telegraphics.com.au \
    --to=fthain@telegraphics.com.au \
    --cc=arnd@arndb.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=funaho@jurai.org \
    --cc=geert@linux-m68k.org \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=philb@gnu.org \
    --cc=schivers@csc.com.au \
    --cc=schmitzmic@gmail.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lore.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git