mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hugh Dickins <hugh@veritas.com>
To: Andi Kleen <ak@suse.de>
Cc: Dave Jones <davej@redhat.com>,
	"Sergey S. Kostyliov" <rathamahata@ehouse.ru>,
	Clem Taylor <clem.taylor@gmail.com>,
	Chris Wright <chrisw@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: x86-64 bad pmds in 2.6.11.6
Date: Thu, 14 Apr 2005 14:54:01 +0100 (BST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0504141419250.25074@goblin.wat.veritas.com> (raw)
In-Reply-To: <20050407062928.GH24469@wotan.suse.de>

On Thu, 7 Apr 2005, Andi Kleen wrote:
> Dave Jones wrote:
> > I realised today that this happens every time X starts up for
> > the first time.   I did some experiments, and found that with 2.6.12rc1
> > it's gone. Either it got fixed accidentally, or its hidden now
> > by one of the many changes in 4-level patches.
> > 
> > I'll try and narrow this down a little more tomorrow, to see if I
> > can pinpoint the exact -bk snapshot (may be tricky given they were
> > broken for a while), as it'd be good to get this fixed in 2.6.11.x
> > if .12 isn't going to show up any time soon.
> 
> Can you supply a strace of the /dev/mem, /dev/kmem accesses of 
> your X server? (including the mmaps or read/writes if available)
> 
> My X server doesn't seem to cause that.

I can't explain why it should appear fixed in 2.6.12-rc1 (probably
other complicating factors at work), but I do believe you've fixed
this in 2.6.12-rc2, and the patch which should go into -stable is
your load_cr3 patch below, which Linus took from Andrew on 28 March.

I say this because I was intrigued by the resemblance between Sergey's
and Dave's corruptions, and spent a while trying to work out where they
come from.  The giveaway is the little ASCII string they share at the
end (seen also in Clem's extract)

 mm/memory.c:97: bad pmd ffff81004b017730(5f36387800000000).
 mm/memory.c:97: bad pmd ffff81004b017738(0000000000003436).

That says "x86_64", and a grep for that as a string shows ELF_PLATFORM,
and a grep for that shows create_elf_tables in fs/binfmt_elf.c.  _All_
this pmd corruption (except for the first line, presumably pushing a
user address on stack) originates from create_elf_tables (the neatly
ascending stack addresses being the argv and envp pointers, incrementing
by 1 because only a NUL-string is found for each, the real strings being
off elsewhere in the intended new stack page, not in this pmd page).

It looks very much as if the mm being created has for pmd a page
which was used for user stack in the outgoing mm; but somehow exec's
exit_mmap TLB flushing hasn't taken effect.  I only now noticed this
patch where you fix just such an issue.

Hugh

From: "Andi Kleen" <ak@suse.de>

Always reload CR3 completely when a lazy MM thread drops a MM.  This avoids
keeping stale mappings around in the TLB that could be run into by the CPU by
itself (e.g.  during prefetches).

Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/x86_64/kernel/smp.c         |    3 ++-
 25-akpm/include/asm-x86_64/mmu_context.h |   10 ++++++++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff -puN arch/x86_64/kernel/smp.c~x86_64-always-reload-cr3-completely-when-a-lazy-mm arch/x86_64/kernel/smp.c
--- 25/arch/x86_64/kernel/smp.c~x86_64-always-reload-cr3-completely-when-a-lazy-mm	Wed Mar 23 15:38:58 2005
+++ 25-akpm/arch/x86_64/kernel/smp.c	Wed Mar 23 15:38:58 2005
@@ -25,6 +25,7 @@
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>
 #include <asm/mach_apic.h>
+#include <asm/mmu_context.h>
 #include <asm/proto.h>
 
 /*
@@ -52,7 +53,7 @@ static inline void leave_mm (unsigned lo
 	if (read_pda(mmu_state) == TLBSTATE_OK)
 		BUG();
 	clear_bit(cpu, &read_pda(active_mm)->cpu_vm_mask);
-	__flush_tlb();
+	load_cr3(swapper_pg_dir);
 }
 
 /*
diff -puN include/asm-x86_64/mmu_context.h~x86_64-always-reload-cr3-completely-when-a-lazy-mm include/asm-x86_64/mmu_context.h
--- 25/include/asm-x86_64/mmu_context.h~x86_64-always-reload-cr3-completely-when-a-lazy-mm	Wed Mar 23 15:38:58 2005
+++ 25-akpm/include/asm-x86_64/mmu_context.h	Wed Mar 23 15:38:58 2005
@@ -28,6 +28,11 @@ static inline void enter_lazy_tlb(struct
 }
 #endif
 
+static inline void load_cr3(pgd_t *pgd)
+{
+	asm volatile("movq %0,%%cr3" :: "r" (__pa(pgd)) : "memory");
+}
+
 static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 
 			     struct task_struct *tsk)
 {
@@ -40,7 +45,8 @@ static inline void switch_mm(struct mm_s
 		write_pda(active_mm, next);
 #endif
 		set_bit(cpu, &next->cpu_vm_mask);
-		asm volatile("movq %0,%%cr3" :: "r" (__pa(next->pgd)) : "memory");
+		load_cr3(next->pgd);
+
 		if (unlikely(next->context.ldt != prev->context.ldt)) 
 			load_LDT_nolock(&next->context, cpu);
 	}
@@ -54,7 +60,7 @@ static inline void switch_mm(struct mm_s
 			 * tlb flush IPI delivery. We must reload CR3
 			 * to make sure to use no freed page tables.
 			 */
-			asm volatile("movq %0,%%cr3" :: "r" (__pa(next->pgd)) : "memory");
+			load_cr3(next->pgd);
 			load_LDT_nolock(&next->context, cpu);
 		}
 	}

  reply	other threads:[~2005-04-14 13:53 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-30 21:44 Dave Jones
2005-03-31 10:41 ` Andi Kleen
2005-03-31 21:52   ` Dave Jones
2005-04-01 11:52     ` Sergey S. Kostyliov
2005-04-07  2:49   ` Dave Jones
2005-04-07  6:29     ` Andi Kleen
2005-04-14 13:54       ` Hugh Dickins [this message]
2005-04-14 17:01         ` Andi Kleen
2005-04-14 17:34           ` Hugh Dickins
2005-04-14 18:10             ` Andi Kleen
2005-04-14 18:11               ` x86-64 bad pmds in 2.6.11.6 II Andi Kleen
2005-04-14 18:27                 ` Chris Wright
2005-04-15 17:24                   ` Andi Kleen
2005-04-15 17:28                     ` Chris Wright
2005-04-15 17:58                       ` Hugh Dickins
2005-04-15 18:07                         ` Dave Jones
2005-04-22 17:37                           ` Debugging patch was " Andi Kleen
2005-04-27 14:23                           ` New debugging " Andi Kleen
2005-04-27 17:37                             ` Dave Jones
2005-04-29 11:07                               ` Hans Kristian Rosbach
2005-04-19 13:35                         ` Andi Kleen
2005-04-19 15:52                           ` Hugh Dickins
2005-04-29 11:12                             ` Christopher Warner
2005-04-29 16:13                               ` Chris Wright
2005-04-29 17:32                               ` Dave Jones
2005-05-02 17:00                                 ` Andi Kleen
2005-05-02 15:28                                   ` Christopher Warner
2005-05-02 20:33                                     ` Chris Wright
2005-05-02 21:08                                       ` Dave Jones
2005-05-03 14:28                                         ` Andi Kleen
2005-05-03 15:15                                           ` Dave Jones
2005-05-10  9:36                                     ` Christopher Warner
2005-05-10 16:26                                       ` Chris Wright
2005-05-10 12:03                                         ` Christopher Warner
2005-05-10 16:38                                       ` Dave Jones
2005-05-10 16:46                                         ` Andi Kleen
2005-05-10 16:59                                           ` Dave Jones
2005-05-10 20:32                                             ` Andi Kleen
2005-05-10 20:43                                               ` Chris Wright
2005-05-12 21:23                                             ` Andi Kleen
2005-05-13 21:51                                               ` Peter J. Stieber
2005-05-14 17:29                                                 ` Peter J. Stieber
2005-04-08 16:33 x86-64 bad pmds in 2.6.11.6 Clem Taylor
2005-08-08 16:55 Andy Davidson
2005-09-20 17:12 Charles McCreary
2005-09-20 17:30 ` Linus Torvalds
2005-09-20 19:44   ` Chris Wedgwood
2005-09-20 23:23     ` Dave Jones

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=Pine.LNX.4.61.0504141419250.25074@goblin.wat.veritas.com \
    --to=hugh@veritas.com \
    --cc=ak@suse.de \
    --cc=chrisw@osdl.org \
    --cc=clem.taylor@gmail.com \
    --cc=davej@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rathamahata@ehouse.ru \
    /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

all inboxes | Powered by JetHome®