From: tip-bot for Juergen Gross <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: mingo@kernel.org, stefan.bader@canonical.com, hpa@zytor.com,
jgross@suse.com, tglx@linutronix.de,
linux-kernel@vger.kernel.org
Subject: [tip:x86/mm] x86: Make page cache mode a real type
Date: Sun, 16 Nov 2014 02:54:30 -0800 [thread overview]
Message-ID: <tip-281d4078bec366d60990add9d91a952953bd0d72@git.kernel.org> (raw)
In-Reply-To: <1415019724-4317-2-git-send-email-jgross@suse.com>
Commit-ID: 281d4078bec366d60990add9d91a952953bd0d72
Gitweb: http://git.kernel.org/tip/281d4078bec366d60990add9d91a952953bd0d72
Author: Juergen Gross <jgross@suse.com>
AuthorDate: Mon, 3 Nov 2014 14:01:47 +0100
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 16 Nov 2014 11:04:24 +0100
x86: Make page cache mode a real type
At the moment there are a lot of places that handle setting or getting
the page cache mode by treating the pgprot bits equal to the cache mode.
This is only true because there are a lot of assumptions about the setup
of the PAT MSR. Otherwise the cache type needs to get translated into
pgprot bits and vice versa.
This patch tries to prepare for that by introducing a separate type
for the cache mode and adding functions to translate between those and
pgprot values.
To avoid too much performance penalty the translation between cache mode
and pgprot values is done via tables which contain the relevant
information. Write-back cache mode is hard-wired to be 0, all other
modes are configurable via those tables. For large pages there are
translation functions as the PAT bit is located at different positions
in the ptes of 4k and large pages.
Based-on-patch-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stefan.bader@canonical.com
Cc: xen-devel@lists.xensource.com
Cc: konrad.wilk@oracle.com
Cc: ville.syrjala@linux.intel.com
Cc: david.vrabel@citrix.com
Cc: jbeulich@suse.com
Cc: toshi.kani@hp.com
Cc: plagnioj@jcrosoft.com
Cc: tomi.valkeinen@ti.com
Cc: bhelgaas@google.com
Link: http://lkml.kernel.org/r/1415019724-4317-2-git-send-email-jgross@suse.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/x86/include/asm/pgtable_types.h | 73 +++++++++++++++++++++++++++++++++++-
arch/x86/mm/init.c | 29 ++++++++++++++
2 files changed, 101 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
index 0778964..5124642 100644
--- a/arch/x86/include/asm/pgtable_types.h
+++ b/arch/x86/include/asm/pgtable_types.h
@@ -128,12 +128,34 @@
_PAGE_SOFT_DIRTY | _PAGE_NUMA)
#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_NUMA)
-#define _PAGE_CACHE_MASK (_PAGE_PCD | _PAGE_PWT)
#define _PAGE_CACHE_WB (0)
#define _PAGE_CACHE_WC (_PAGE_PWT)
#define _PAGE_CACHE_UC_MINUS (_PAGE_PCD)
#define _PAGE_CACHE_UC (_PAGE_PCD | _PAGE_PWT)
+/*
+ * The cache modes defined here are used to translate between pure SW usage
+ * and the HW defined cache mode bits and/or PAT entries.
+ *
+ * The resulting bits for PWT, PCD and PAT should be chosen in a way
+ * to have the WB mode at index 0 (all bits clear). This is the default
+ * right now and likely would break too much if changed.
+ */
+#ifndef __ASSEMBLY__
+enum page_cache_mode {
+ _PAGE_CACHE_MODE_WB = 0,
+ _PAGE_CACHE_MODE_WC = 1,
+ _PAGE_CACHE_MODE_UC_MINUS = 2,
+ _PAGE_CACHE_MODE_UC = 3,
+ _PAGE_CACHE_MODE_WT = 4,
+ _PAGE_CACHE_MODE_WP = 5,
+ _PAGE_CACHE_MODE_NUM = 8
+};
+#endif
+
+#define _PAGE_CACHE_MASK (_PAGE_PAT | _PAGE_PCD | _PAGE_PWT)
+#define _PAGE_NOCACHE (cachemode2protval(_PAGE_CACHE_MODE_UC))
+
#define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
_PAGE_ACCESSED | _PAGE_NX)
@@ -341,6 +363,55 @@ static inline pmdval_t pmdnuma_flags(pmd_t pmd)
#define pgprot_val(x) ((x).pgprot)
#define __pgprot(x) ((pgprot_t) { (x) } )
+extern uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM];
+extern uint8_t __pte2cachemode_tbl[8];
+
+#define __pte2cm_idx(cb) \
+ ((((cb) >> (_PAGE_BIT_PAT - 2)) & 4) | \
+ (((cb) >> (_PAGE_BIT_PCD - 1)) & 2) | \
+ (((cb) >> _PAGE_BIT_PWT) & 1))
+
+static inline unsigned long cachemode2protval(enum page_cache_mode pcm)
+{
+ if (likely(pcm == 0))
+ return 0;
+ return __cachemode2pte_tbl[pcm];
+}
+static inline pgprot_t cachemode2pgprot(enum page_cache_mode pcm)
+{
+ return __pgprot(cachemode2protval(pcm));
+}
+static inline enum page_cache_mode pgprot2cachemode(pgprot_t pgprot)
+{
+ unsigned long masked;
+
+ masked = pgprot_val(pgprot) & _PAGE_CACHE_MASK;
+ if (likely(masked == 0))
+ return 0;
+ return __pte2cachemode_tbl[__pte2cm_idx(masked)];
+}
+static inline pgprot_t pgprot_4k_2_large(pgprot_t pgprot)
+{
+ pgprot_t new;
+ unsigned long val;
+
+ val = pgprot_val(pgprot);
+ pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
+ ((val & _PAGE_PAT) << (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
+ return new;
+}
+static inline pgprot_t pgprot_large_2_4k(pgprot_t pgprot)
+{
+ pgprot_t new;
+ unsigned long val;
+
+ val = pgprot_val(pgprot);
+ pgprot_val(new) = (val & ~(_PAGE_PAT | _PAGE_PAT_LARGE)) |
+ ((val & _PAGE_PAT_LARGE) >>
+ (_PAGE_BIT_PAT_LARGE - _PAGE_BIT_PAT));
+ return new;
+}
+
typedef struct page *pgtable_t;
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 66dba36..a9776ba 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -27,6 +27,35 @@
#include "mm_internal.h"
+/*
+ * Tables translating between page_cache_type_t and pte encoding.
+ * Minimal supported modes are defined statically, modified if more supported
+ * cache modes are available.
+ * Index into __cachemode2pte_tbl is the cachemode.
+ * Index into __pte2cachemode_tbl are the caching attribute bits of the pte
+ * (_PAGE_PWT, _PAGE_PCD, _PAGE_PAT) at index bit positions 0, 1, 2.
+ */
+uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {
+ [_PAGE_CACHE_MODE_WB] = 0,
+ [_PAGE_CACHE_MODE_WC] = _PAGE_PWT,
+ [_PAGE_CACHE_MODE_UC_MINUS] = _PAGE_PCD,
+ [_PAGE_CACHE_MODE_UC] = _PAGE_PCD | _PAGE_PWT,
+ [_PAGE_CACHE_MODE_WT] = _PAGE_PCD,
+ [_PAGE_CACHE_MODE_WP] = _PAGE_PCD,
+};
+EXPORT_SYMBOL_GPL(__cachemode2pte_tbl);
+uint8_t __pte2cachemode_tbl[8] = {
+ [__pte2cm_idx(0)] = _PAGE_CACHE_MODE_WB,
+ [__pte2cm_idx(_PAGE_PWT)] = _PAGE_CACHE_MODE_WC,
+ [__pte2cm_idx(_PAGE_PCD)] = _PAGE_CACHE_MODE_UC_MINUS,
+ [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD)] = _PAGE_CACHE_MODE_UC,
+ [__pte2cm_idx(_PAGE_PAT)] = _PAGE_CACHE_MODE_WB,
+ [__pte2cm_idx(_PAGE_PWT | _PAGE_PAT)] = _PAGE_CACHE_MODE_WC,
+ [__pte2cm_idx(_PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC_MINUS,
+ [__pte2cm_idx(_PAGE_PWT | _PAGE_PCD | _PAGE_PAT)] = _PAGE_CACHE_MODE_UC,
+};
+EXPORT_SYMBOL_GPL(__pte2cachemode_tbl);
+
static unsigned long __initdata pgt_buf_start;
static unsigned long __initdata pgt_buf_end;
static unsigned long __initdata pgt_buf_top;
next prev parent reply other threads:[~2014-11-16 10:54 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-03 13:01 [PATCH V6 00/18] x86: Full support of PAT Juergen Gross
2014-11-03 13:01 ` [PATCH V6 01/18] x86: Make page cache mode a real type Juergen Gross
2014-11-16 10:54 ` tip-bot for Juergen Gross [this message]
2015-01-22 7:11 ` Steven Noonan
2015-01-22 10:15 ` Juergen Gross
2015-01-22 11:06 ` Thomas Gleixner
2015-01-22 11:11 ` Juergen Gross
2014-11-03 13:01 ` [PATCH V6 02/18] x86: Use new cache mode type in include/asm/fb.h Juergen Gross
2014-11-16 10:54 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 03/18] x86: Use new cache mode type in drivers/video/fbdev/gbefb.c Juergen Gross
2014-11-07 8:16 ` Tomi Valkeinen
2014-11-07 8:16 ` Tomi Valkeinen
2014-11-16 10:55 ` [tip:x86/mm] x86: Use new cache mode type in drivers/video/fbdev/ gbefb.c tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 04/18] x86: Use new cache mode type in drivers/video/fbdev/vermilion Juergen Gross
2014-11-16 10:55 ` [tip:x86/mm] x86: Use new cache mode type in drivers/video/fbdev/ vermilion tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 05/18] x86: Use new cache mode type in arch/x86/pci Juergen Gross
2014-11-16 10:55 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 06/18] x86: Use new cache mode type in arch/x86/mm/init_64.c Juergen Gross
2014-11-16 10:55 ` [tip:x86/mm] x86: Use new cache mode type in arch/x86/mm/ init_64.c tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 07/18] x86: Use new cache mode type in asm/pgtable.h Juergen Gross
2014-11-16 10:56 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 08/18] x86: Use new cache mode type in mm/iomap_32.c Juergen Gross
2014-11-16 10:56 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 09/18] x86: Use new cache mode type in track_pfn_remap() and track_pfn_insert() Juergen Gross
2014-11-16 10:56 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 10/18] x86: Remove looking for setting of _PAGE_PAT_LARGE in pageattr.c Juergen Gross
2014-11-03 16:44 ` Thomas Gleixner
2014-11-16 10:57 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 11/18] x86: Use new cache mode type in setting page attributes Juergen Gross
2014-11-16 10:57 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 12/18] x86: Use new cache mode type in mm/ioremap.c Juergen Gross
2014-11-16 10:57 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:01 ` [PATCH V6 13/18] x86: Use new cache mode type in memtype related functions Juergen Gross
2014-11-16 10:57 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:02 ` [PATCH V6 14/18] x86: Clean up pgtable_types.h Juergen Gross
2014-11-16 10:58 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:02 ` [PATCH V6 15/18] x86: Support PAT bit in pagetable dump for lower levels Juergen Gross
2014-11-16 10:58 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:02 ` [PATCH V6 16/18] x86: Respect PAT bit when copying pte values between large and normal pages Juergen Gross
2014-11-16 10:58 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:02 ` [PATCH V6 17/18] x86: Enable PAT to use cache mode translation tables Juergen Gross
2014-11-16 10:58 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 13:02 ` [PATCH V6 18/18] xen: Support Xen pv-domains using PAT Juergen Gross
2014-11-16 10:59 ` [tip:x86/mm] " tip-bot for Juergen Gross
2014-11-03 16:43 ` [PATCH V6 00/18] x86: Full support of PAT Toshi Kani
2014-11-14 6:30 ` Juergen Gross
2014-11-16 13:08 ` Ingo Molnar
2014-11-17 4:42 ` Jürgen Groß
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=tip-281d4078bec366d60990add9d91a952953bd0d72@git.kernel.org \
--to=tipbot@zytor.com \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=stefan.bader@canonical.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.