LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <andi@firstfloor.org>,
tglx@linutronix.de, linux-kernel@vger.kernel.org
Subject: Re: unify pagetable accessors patch causes double fault II
Date: Tue, 15 Jan 2008 14:53:17 +0100 [thread overview]
Message-ID: <20080115135317.GA13493@elte.hu> (raw)
In-Reply-To: <478BE628.7090008@goop.org>
* Jeremy Fitzhardinge <jeremy@goop.org> wrote:
> Can you try this out? It applies after "x86: move all asm/pgtable
> constants into one place".
and here's the patch
Subject: Re: unify pagetable accessors patch causes double fault II
From: Jeremy Fitzhardinge <jeremy@goop.org>
Andi Kleen wrote:
>> OK, I see the problem. The problem is that the _PAGE_X defines are
>> defined with _AC(UL, 1 << _PAGE_BIT_X), which has unsigned long type.
>> This means that ~_PAGE_X also has unsigned long type, and so when cast
>> to 64-bit in pte_mkX, it ends up &ing the pte with 0x00000000ffffffxxx,
>> with predictable results.
>>
>
> Actually I fixed some of that -- see the pgtable-nx patch on firstfloor -- but
> it still doesn't work. Or maybe my patch was not complete.
>
Yeah, that looks like the right sort of thing, but I wonder if there's
other places doing an open-coded "pte_val(pte) & ~_PAGE_FOO". My patch
changes the definition of _PAGE_FOO so it should be OK everywhere.
>> The original code just used signed constants for the _PAGE_X
>> definitions, which will sign-extend when cast to 64-bit, and so have the
>> upper bits set when masking. (Well, actually, the old code just
>> operated on pte_low, so the problem didn't arise; however, pgtable_64.h
>> also uses integers for its _PAGE_X, which has the same sign-extended
>> 32->64 casting property).
>>
>> I'll put together a fixup patch now.
>>
>
> I'm leaving now but can test later.
and below is the fix against full x86.git#mm.
Ingo
----------->
Subject: x86/pgtable: fix constant sign extension problem
From: Jeremy Fitzhardinge <jeremy@goop.org>
When the _PAGE_FOO constants are defined as (1ul << _PAGE_BIT_FOO), they
become unsigned longs. In 32-bit PAE mode, these end up being
implicitly cast to 64-bit types when used to manipulate a pte, and
because they're unsigned the top 32-bits are 0, destroying the upper
bits of the pte.
When _PAGE_FOO constants are given a signed integer type, the cast to
64-bits will sign-extend so that the upper bits are all ones,
preserving the upper pte bits in manipulations.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
include/asm-x86/pgtable.h | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
===================================================================
Index: linux-x86.q/include/asm-x86/pgtable.h
===================================================================
--- linux-x86.q.orig/include/asm-x86/pgtable.h
+++ linux-x86.q/include/asm-x86/pgtable.h
@@ -19,21 +19,26 @@
#define _PAGE_BIT_UNUSED3 11
#define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
-#define _PAGE_PRESENT (_AC(1, UL)<<_PAGE_BIT_PRESENT)
-#define _PAGE_RW (_AC(1, UL)<<_PAGE_BIT_RW)
-#define _PAGE_USER (_AC(1, UL)<<_PAGE_BIT_USER)
-#define _PAGE_PWT (_AC(1, UL)<<_PAGE_BIT_PWT)
-#define _PAGE_PCD ((_AC(1, UL)<<_PAGE_BIT_PCD) | _PAGE_PWT)
-#define _PAGE_ACCESSED (_AC(1, UL)<<_PAGE_BIT_ACCESSED)
-#define _PAGE_DIRTY (_AC(1, UL)<<_PAGE_BIT_DIRTY)
-#define _PAGE_PSE (_AC(1, UL)<<_PAGE_BIT_PSE) /* 2MB page */
-#define _PAGE_GLOBAL (_AC(1, UL)<<_PAGE_BIT_GLOBAL) /* Global TLB entry */
+/*
+ * Note: we use _AC(1, L) instead of _AC(1, UL) so that we get a
+ * sign-extended value on 32-bit with all 1's in the upper word,
+ * which preserves the upper pte values on 64-bit ptes:
+ */
+#define _PAGE_PRESENT (_AC(1, L)<<_PAGE_BIT_PRESENT)
+#define _PAGE_RW (_AC(1, L)<<_PAGE_BIT_RW)
+#define _PAGE_USER (_AC(1, L)<<_PAGE_BIT_USER)
+#define _PAGE_PWT (_AC(1, L)<<_PAGE_BIT_PWT)
+#define _PAGE_PCD ((_AC(1, L)<<_PAGE_BIT_PCD) | _PAGE_PWT)
+#define _PAGE_ACCESSED (_AC(1, L)<<_PAGE_BIT_ACCESSED)
+#define _PAGE_DIRTY (_AC(1, L)<<_PAGE_BIT_DIRTY)
+#define _PAGE_PSE (_AC(1, L)<<_PAGE_BIT_PSE) /* 2MB page */
+#define _PAGE_GLOBAL (_AC(1, L)<<_PAGE_BIT_GLOBAL) /* Global TLB entry */
/* We redefine PCD to be write combining. PAT bit is not used */
-#define _PAGE_WC ((_AC(1, UL)<<_PAGE_BIT_PCD))
+#define _PAGE_WC ((_AC(1, L)<<_PAGE_BIT_PCD))
#define _PAGE_CACHE_MASK (_PAGE_PCD)
-#define _PAGE_UNUSED1 (_AC(1, UL)<<_PAGE_BIT_UNUSED1)
-#define _PAGE_UNUSED2 (_AC(1, UL)<<_PAGE_BIT_UNUSED2)
-#define _PAGE_UNUSED3 (_AC(1, UL)<<_PAGE_BIT_UNUSED3)
+#define _PAGE_UNUSED1 (_AC(1, L)<<_PAGE_BIT_UNUSED1)
+#define _PAGE_UNUSED2 (_AC(1, L)<<_PAGE_BIT_UNUSED2)
+#define _PAGE_UNUSED3 (_AC(1, L)<<_PAGE_BIT_UNUSED3)
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
#define _PAGE_NX (_AC(1, ULL) << _PAGE_BIT_NX)
next prev parent reply other threads:[~2008-01-15 13:53 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20080114094814.GA28300@basil.nowhere.org>
2008-01-14 12:56 ` Andi Kleen
2008-01-14 13:06 ` Ingo Molnar
2008-01-14 13:58 ` Andi Kleen
2008-01-14 16:44 ` Jeremy Fitzhardinge
2008-01-14 16:56 ` Ingo Molnar
2008-01-14 17:08 ` Andi Kleen
2008-01-14 17:18 ` unify pagetable accessors patch causes double fault III Andi Kleen
2008-01-14 19:00 ` Ingo Molnar
2008-01-14 19:54 ` Jeremy Fitzhardinge
2008-01-14 20:15 ` Andi Kleen
2008-01-14 19:52 ` unify pagetable accessors patch causes double fault II Jeremy Fitzhardinge
2008-01-14 22:03 ` Jeremy Fitzhardinge
2008-01-14 22:23 ` Andi Kleen
2008-01-14 22:46 ` Jeremy Fitzhardinge
2008-01-15 1:05 ` Andi Kleen
2008-01-15 1:32 ` Jeremy Fitzhardinge
2008-01-15 1:38 ` Andi Kleen
2008-01-15 21:03 ` [patch] x86: lfence fix Ingo Molnar
2008-01-16 0:44 ` Andi Kleen
2008-01-15 12:55 ` unify pagetable accessors patch causes double fault II Ingo Molnar
2008-01-15 16:53 ` Andi Kleen
2008-01-15 13:53 ` Ingo Molnar [this message]
2008-01-15 17:16 ` Folding _PAGE_PWT into _PAGE_PCD (was Re: unify pagetable accessors patch causes double fault II) Jeremy Fitzhardinge
2008-01-15 17:23 ` Andi Kleen
2008-01-15 17:32 ` Jeremy Fitzhardinge
2008-01-15 17:39 ` Andi Kleen
2008-01-15 20:30 ` Venki Pallipadi
2008-01-15 20:45 ` Jeremy Fitzhardinge
2008-01-15 17:36 ` unify pagetable accessors patch causes double fault II Andi Kleen
2008-01-15 19:43 ` Jeremy Fitzhardinge
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=20080115135317.GA13493@elte.hu \
--to=mingo@elte.hu \
--cc=andi@firstfloor.org \
--cc=jeremy@goop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--subject='Re: unify pagetable accessors patch causes double fault II' \
/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
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).