linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
To: Yoshinori Sato <ysato@users.sourceforge.jp>,
	Rich Felker <dalias@libc.org>,
	linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [PATCH] arch/sh: fix SH4 flush_dcache_all() for SMP
Date: Fri, 15 Jun 2018 15:50:10 +0000	[thread overview]
Message-ID: <20180615155010.8019-1-thomas.petazzoni@bootlin.com> (raw)

The SH4 flush_dcache_all() function uses current_cpu_data, which
internally uses smp_processor_id(). However, it is incorrect to use
smp_processor_id() in a context where migration is enabled, because
the processor on which the code is running can change at any point in
time.

To avoid this, we enclose the code flushing the dcache in a get_cpu()
/ put_cpu() section so that migration is disabled.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
Note: I am not sure at all this is the best fix. Careful review and
suggestions are welcome.

 arch/sh/mm/cache-sh4.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c
index eee911422cf9..cde8d7f8acbb 100644
--- a/arch/sh/mm/cache-sh4.c
+++ b/arch/sh/mm/cache-sh4.c
@@ -149,13 +149,17 @@ static void flush_icache_all(void)
 static void flush_dcache_all(void)
 {
 	unsigned long addr, end_addr, entry_offset;
+	struct sh_cpuinfo *cpud;
+	int cpu;
+
+	cpu = get_cpu();
+	cpud = &cpu_data[cpu];
 
 	end_addr = CACHE_OC_ADDRESS_ARRAY +
-		(current_cpu_data.dcache.sets <<
-		 current_cpu_data.dcache.entry_shift) *
-			current_cpu_data.dcache.ways;
+		(cpud->dcache.sets << cpud->dcache.entry_shift) *
+		cpud->dcache.ways;
 
-	entry_offset = 1 << current_cpu_data.dcache.entry_shift;
+	entry_offset = 1 << cpud->dcache.entry_shift;
 
 	for (addr = CACHE_OC_ADDRESS_ARRAY; addr < end_addr; ) {
 		__raw_writel(0, addr); addr += entry_offset;
@@ -167,6 +171,8 @@ static void flush_dcache_all(void)
 		__raw_writel(0, addr); addr += entry_offset;
 		__raw_writel(0, addr); addr += entry_offset;
 	}
+
+	put_cpu();
 }
 
 static void sh4_flush_cache_all(void *unused)
-- 
2.14.4


                 reply	other threads:[~2018-06-15 15:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180615155010.8019-1-thomas.petazzoni@bootlin.com \
    --to=thomas.petazzoni@bootlin.com \
    --cc=dalias@libc.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=ysato@users.sourceforge.jp \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).