From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
Zwane Mwaikambo <zwane@arm.linux.org.uk>,
"Theodore Ts'o" <tytso@mit.edu>,
Randy Dunlap <rdunlap@xenotime.net>,
Dave Jones <davej@redhat.com>,
Chuck Wolber <chuckw@quantumlinux.com>,
Chris Wedgwood <reviews@ml.cw.f00f.org>,
Michael Krufky <mkrufky@linuxtv.org>,
Chuck Ebbert <cebbert@redhat.com>,
Domenico Andreoli <cavokz@gmail.com>,
torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Ralf Baechle <ralf@linux-mips.org>
Subject: [patch 03/19] MIPS: MT: Fix bug in multithreaded kernels.
Date: Wed, 14 Nov 2007 22:14:32 -0800 [thread overview]
Message-ID: <20071115061432.GD7980@kroah.com> (raw)
In-Reply-To: <20071115061415.GA7980@kroah.com>
[-- Attachment #1: mips-mt-fix-bug-in-multithreaded-kernels.patch --]
[-- Type: text/plain, Size: 3180 bytes --]
-stable review patch. If anyone has any objections, please let us know.
------------------
From: Ralf Baechle <ralf@linux-mips.org>
patch a76ab5c10d99bdf458067cb495e72c0ee5f09909 in mainline.
When GDB writes a breakpoint into address area of inferior process the
kernel needs to invalidate the modified memory in the inferior which
is done by calling flush_cache_page which in turns calls
r4k_flush_cache_page and local_r4k_flush_cache_page for VSMP or SMTC
kernel via r4k_on_each_cpu().
As the VSMP and SMTC SMP kernels for 34K are running on a single shared
caches it is possible to get away without interprocessor function calls.
This optimization is implemented in r4k_on_each_cpu, so
local_r4k_flush_cache_page is only ever called on the local CPU.
This is where the following code in local_r4k_flush_cache_page() strikes:
/*
* If ownes no valid ASID yet, cannot possibly have gotten
* this page into the cache.
*/
if (cpu_context(smp_processor_id(), mm) == 0)
return;
On VSMP and SMTC had a function of cpu_context() for each CPU(TC).
So in case another CPU than the CPU executing local_r4k_cache_flush_page
has not accessed the mm but one of the other CPUs has there may be data
to be flushed in the cache yet local_r4k_cache_flush_page will falsely
return leaving the I-cache inconsistent for the breakpoint.
While the issue was discovered with GDB it also exists in
local_r4k_flush_cache_range() and local_r4k_flush_cache().
Fixed by introducing a new function has_valid_asid which on MT kernels
returns true if a mm is active on any processor in the system.
This is relativly expensive since for memory acccesses in that loop
cache misses have to be assumed but it seems the most viable solution
for 2.6.23 and older -stable kernels.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
arch/mips/mm/c-r4k.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -360,11 +360,26 @@ static void r4k___flush_cache_all(void)
r4k_on_each_cpu(local_r4k___flush_cache_all, NULL, 1, 1);
}
+static inline int has_valid_asid(const struct mm_struct *mm)
+{
+#if defined(CONFIG_MIPS_MT_SMP) || defined(CONFIG_MIPS_MT_SMTC)
+ int i;
+
+ for_each_online_cpu(i)
+ if (cpu_context(i, mm))
+ return 1;
+
+ return 0;
+#else
+ return cpu_context(smp_processor_id(), mm);
+#endif
+}
+
static inline void local_r4k_flush_cache_range(void * args)
{
struct vm_area_struct *vma = args;
- if (!(cpu_context(smp_processor_id(), vma->vm_mm)))
+ if (!(has_valid_asid(vma->vm_mm)))
return;
r4k_blast_dcache();
@@ -383,7 +398,7 @@ static inline void local_r4k_flush_cache
{
struct mm_struct *mm = args;
- if (!cpu_context(smp_processor_id(), mm))
+ if (!has_valid_asid(mm))
return;
/*
@@ -434,7 +449,7 @@ static inline void local_r4k_flush_cache
* If ownes no valid ASID yet, cannot possibly have gotten
* this page into the cache.
*/
- if (cpu_context(smp_processor_id(), mm) == 0)
+ if (!has_valid_asid(mm))
return;
addr &= PAGE_MASK;
--
next prev parent reply other threads:[~2007-11-15 6:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071115054813.977066477@mini.kroah.org>
2007-11-15 6:14 ` [patch 00/19] 2.6.23-stable review, arch specific stuff Greg KH
2007-11-15 6:14 ` [patch 01/19] Fix sparc64 niagara optimized RAID xor asm Greg KH
2007-11-15 6:14 ` [patch 02/19] Fix sparc64 MAP_FIXED handling of framebuffer mmaps Greg KH
2007-11-15 6:14 ` Greg KH [this message]
2007-11-15 6:14 ` [patch 04/19] MIPS: R1: Fix hazard barriers to make kernels work on R2 also Greg KH
2007-11-15 6:14 ` [patch 05/19] POWERPC: Fix handling of stfiwx math emulation Greg KH
2007-11-15 6:14 ` [patch 06/19] POWERPC: Make sure to of_node_get() the result of pci_device_to_OF_node() Greg KH
2007-11-15 6:14 ` [patch 07/19] UML - Stop using libc asm/page.h Greg KH
2007-11-15 6:14 ` [patch 08/19] UML - Fix kernel vs libc symbols clash Greg KH
2007-11-15 6:14 ` [patch 09/19] UML - stop using libc asm/user.h Greg KH
2007-11-15 6:14 ` [patch 10/19] UML - kill subprocesses on exit Greg KH
2007-11-15 6:14 ` [patch 11/19] xen: add batch completion callbacks Greg KH
2007-11-15 6:15 ` [patch 12/19] xen: deal with stale cr3 values when unpinning pagetables Greg KH
2007-11-15 6:15 ` [patch 13/19] xen: fix incorrect vcpu_register_vcpu_info hypercall argument Greg KH
2007-11-15 6:15 ` [patch 14/19] xfs: eagerly remove vmap mappings to avoid upsetting Xen Greg KH
2007-11-15 6:15 ` [patch 15/19] x86: fix global_flush_tlb() bug Greg KH
2007-11-15 6:15 ` [patch 16/19] x86 setup: handle boot loaders which set up the stack incorrectly Greg KH
2007-11-15 7:27 ` H. Peter Anvin
2007-11-15 16:42 ` Greg KH
2007-11-15 6:15 ` [patch 17/19] x86 setup: sizeof() is unsigned, unbreak comparisons Greg KH
2007-11-15 6:15 ` [patch 18/19] x86: fix TSC clock source calibration error Greg KH
2007-11-15 6:15 ` [patch 19/19] revert "x86_64: allocate sparsemem memmap above 4G" Greg KH
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=20071115061432.GD7980@kroah.com \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=cavokz@gmail.com \
--cc=cebbert@redhat.com \
--cc=chuckw@quantumlinux.com \
--cc=davej@redhat.com \
--cc=jmforbes@linuxtx.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mkrufky@linuxtv.org \
--cc=ralf@linux-mips.org \
--cc=rdunlap@xenotime.net \
--cc=reviews@ml.cw.f00f.org \
--cc=stable@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=zwane@arm.linux.org.uk \
/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