blob: 83a59a67757a77b46f7b7788074294a3a3c8a10c [file] [log] [blame]
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -07001/*
2 * Handle caching attributes in page tables (PAT)
3 *
4 * Authors: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Suresh B Siddha <suresh.b.siddha@intel.com>
6 *
7 * Loosely based on earlier PAT patchset from Eric Biederman and Andi Kleen.
8 */
9
Ingo Molnarad2cde12008-09-30 13:20:45 +020010#include <linux/seq_file.h>
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -070011#include <linux/bootmem.h>
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -070012#include <linux/debugfs.h>
Ingo Molnar9de94db2017-01-27 13:08:42 +010013#include <linux/ioport.h>
Ingo Molnarad2cde12008-09-30 13:20:45 +020014#include <linux/kernel.h>
Dan Williamsf25748e32016-01-15 16:56:43 -080015#include <linux/pfn_t.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090016#include <linux/slab.h>
Ingo Molnarad2cde12008-09-30 13:20:45 +020017#include <linux/mm.h>
18#include <linux/fs.h>
Venkatesh Pallipadi335ef892009-07-10 09:57:36 -070019#include <linux/rbtree.h>
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070020
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070021#include <asm/cacheflush.h>
Ingo Molnarad2cde12008-09-30 13:20:45 +020022#include <asm/processor.h>
23#include <asm/tlbflush.h>
Jack Steinerfd12a0d2009-11-19 14:23:41 -060024#include <asm/x86_init.h>
Ingo Molnarad2cde12008-09-30 13:20:45 +020025#include <asm/pgtable.h>
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070026#include <asm/fcntl.h>
Ingo Molnar66441bd2017-01-27 10:27:10 +010027#include <asm/e820/api.h>
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070028#include <asm/mtrr.h>
Ingo Molnarad2cde12008-09-30 13:20:45 +020029#include <asm/page.h>
30#include <asm/msr.h>
31#include <asm/pat.h>
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -070032#include <asm/io.h>
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070033
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -080034#include "pat_internal.h"
Juergen Grossbd809af2014-11-03 14:02:03 +010035#include "mm_internal.h"
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -080036
Luis R. Rodriguez9e765612015-05-26 10:28:11 +020037#undef pr_fmt
38#define pr_fmt(fmt) "" fmt
39
Borislav Petkov9dac6292015-06-04 18:55:09 +020040static bool boot_cpu_done;
41
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +020042static int __read_mostly __pat_enabled = IS_ENABLED(CONFIG_X86_PAT);
Toshi Kani224bb1e2016-03-23 15:41:58 -060043static void init_cache_modes(void);
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070044
Toshi Kani224bb1e2016-03-23 15:41:58 -060045void pat_disable(const char *reason)
Thomas Gleixner8d4a4302008-05-08 09:18:43 +020046{
Toshi Kani224bb1e2016-03-23 15:41:58 -060047 if (!__pat_enabled)
48 return;
49
50 if (boot_cpu_done) {
51 WARN_ONCE(1, "x86/PAT: PAT cannot be disabled after initialization\n");
52 return;
53 }
54
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +020055 __pat_enabled = 0;
Luis R. Rodriguez9e765612015-05-26 10:28:11 +020056 pr_info("x86/PAT: %s\n", reason);
Toshi Kani224bb1e2016-03-23 15:41:58 -060057
58 init_cache_modes();
Thomas Gleixner8d4a4302008-05-08 09:18:43 +020059}
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070060
Andrew Mortonbe524fb2008-05-29 00:01:28 -070061static int __init nopat(char *str)
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070062{
Thomas Gleixner8d4a4302008-05-08 09:18:43 +020063 pat_disable("PAT support disabled.");
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -070064 return 0;
65}
66early_param("nopat", nopat);
67
Mikulas Patockacbed27c2017-04-18 15:07:11 -040068static bool __read_mostly __pat_initialized = false;
69
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +020070bool pat_enabled(void)
71{
Mikulas Patockacbed27c2017-04-18 15:07:11 -040072 return __pat_initialized;
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +020073}
Luis R. Rodriguezfbe71932015-05-26 10:28:16 +020074EXPORT_SYMBOL_GPL(pat_enabled);
Venki Pallipadi77b52b42008-05-05 19:09:10 -070075
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -080076int pat_debug_enable;
Ingo Molnarad2cde12008-09-30 13:20:45 +020077
Venki Pallipadi77b52b42008-05-05 19:09:10 -070078static int __init pat_debug_setup(char *str)
79{
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -080080 pat_debug_enable = 1;
Venki Pallipadi77b52b42008-05-05 19:09:10 -070081 return 0;
82}
83__setup("debugpat", pat_debug_setup);
84
Thomas Gleixner0dbcae82014-11-16 18:59:19 +010085#ifdef CONFIG_X86_PAT
86/*
Toshi Kani35a5a102015-06-04 18:55:19 +020087 * X86 PAT uses page flags arch_1 and uncached together to keep track of
88 * memory type of pages that have backing page struct.
89 *
90 * X86 PAT supports 4 different memory types:
91 * - _PAGE_CACHE_MODE_WB
92 * - _PAGE_CACHE_MODE_WC
93 * - _PAGE_CACHE_MODE_UC_MINUS
94 * - _PAGE_CACHE_MODE_WT
95 *
96 * _PAGE_CACHE_MODE_WB is the default type.
Thomas Gleixner0dbcae82014-11-16 18:59:19 +010097 */
98
Toshi Kani35a5a102015-06-04 18:55:19 +020099#define _PGMT_WB 0
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100100#define _PGMT_WC (1UL << PG_arch_1)
101#define _PGMT_UC_MINUS (1UL << PG_uncached)
Toshi Kani35a5a102015-06-04 18:55:19 +0200102#define _PGMT_WT (1UL << PG_uncached | 1UL << PG_arch_1)
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100103#define _PGMT_MASK (1UL << PG_uncached | 1UL << PG_arch_1)
104#define _PGMT_CLEAR_MASK (~_PGMT_MASK)
105
106static inline enum page_cache_mode get_page_memtype(struct page *pg)
107{
108 unsigned long pg_flags = pg->flags & _PGMT_MASK;
109
Toshi Kani35a5a102015-06-04 18:55:19 +0200110 if (pg_flags == _PGMT_WB)
111 return _PAGE_CACHE_MODE_WB;
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100112 else if (pg_flags == _PGMT_WC)
113 return _PAGE_CACHE_MODE_WC;
114 else if (pg_flags == _PGMT_UC_MINUS)
115 return _PAGE_CACHE_MODE_UC_MINUS;
116 else
Toshi Kani35a5a102015-06-04 18:55:19 +0200117 return _PAGE_CACHE_MODE_WT;
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100118}
119
120static inline void set_page_memtype(struct page *pg,
121 enum page_cache_mode memtype)
122{
123 unsigned long memtype_flags;
124 unsigned long old_flags;
125 unsigned long new_flags;
126
127 switch (memtype) {
128 case _PAGE_CACHE_MODE_WC:
129 memtype_flags = _PGMT_WC;
130 break;
131 case _PAGE_CACHE_MODE_UC_MINUS:
132 memtype_flags = _PGMT_UC_MINUS;
133 break;
Toshi Kani35a5a102015-06-04 18:55:19 +0200134 case _PAGE_CACHE_MODE_WT:
135 memtype_flags = _PGMT_WT;
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100136 break;
Toshi Kani35a5a102015-06-04 18:55:19 +0200137 case _PAGE_CACHE_MODE_WB:
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100138 default:
Toshi Kani35a5a102015-06-04 18:55:19 +0200139 memtype_flags = _PGMT_WB;
Thomas Gleixner0dbcae82014-11-16 18:59:19 +0100140 break;
141 }
142
143 do {
144 old_flags = pg->flags;
145 new_flags = (old_flags & _PGMT_CLEAR_MASK) | memtype_flags;
146 } while (cmpxchg(&pg->flags, old_flags, new_flags) != old_flags);
147}
148#else
149static inline enum page_cache_mode get_page_memtype(struct page *pg)
150{
151 return -1;
152}
153static inline void set_page_memtype(struct page *pg,
154 enum page_cache_mode memtype)
155{
156}
157#endif
158
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700159enum {
160 PAT_UC = 0, /* uncached */
161 PAT_WC = 1, /* Write combining */
162 PAT_WT = 4, /* Write Through */
163 PAT_WP = 5, /* Write Protected */
164 PAT_WB = 6, /* Write Back (default) */
Adam Buchbinder6a6256f2016-02-23 15:34:30 -0800165 PAT_UC_MINUS = 7, /* UC, but can be overridden by MTRR */
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700166};
167
Juergen Grossbd809af2014-11-03 14:02:03 +0100168#define CM(c) (_PAGE_CACHE_MODE_ ## c)
169
170static enum page_cache_mode pat_get_cache_mode(unsigned pat_val, char *msg)
171{
172 enum page_cache_mode cache;
173 char *cache_mode;
174
175 switch (pat_val) {
176 case PAT_UC: cache = CM(UC); cache_mode = "UC "; break;
177 case PAT_WC: cache = CM(WC); cache_mode = "WC "; break;
178 case PAT_WT: cache = CM(WT); cache_mode = "WT "; break;
179 case PAT_WP: cache = CM(WP); cache_mode = "WP "; break;
180 case PAT_WB: cache = CM(WB); cache_mode = "WB "; break;
181 case PAT_UC_MINUS: cache = CM(UC_MINUS); cache_mode = "UC- "; break;
182 default: cache = CM(WB); cache_mode = "WB "; break;
183 }
184
185 memcpy(msg, cache_mode, 4);
186
187 return cache;
188}
189
190#undef CM
191
192/*
193 * Update the cache mode to pgprot translation tables according to PAT
194 * configuration.
195 * Using lower indices is preferred, so we start with highest index.
196 */
Toshi Kani88ba2812016-03-23 15:42:02 -0600197static void __init_cache_modes(u64 pat)
Juergen Grossbd809af2014-11-03 14:02:03 +0100198{
Juergen Grossbd809af2014-11-03 14:02:03 +0100199 enum page_cache_mode cache;
200 char pat_msg[33];
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200201 int i;
Juergen Grossbd809af2014-11-03 14:02:03 +0100202
Juergen Grossbd809af2014-11-03 14:02:03 +0100203 pat_msg[32] = 0;
204 for (i = 7; i >= 0; i--) {
205 cache = pat_get_cache_mode((pat >> (i * 8)) & 7,
206 pat_msg + 4 * i);
207 update_cache_mode_entry(i, cache);
208 }
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200209 pr_info("x86/PAT: Configuration [0-7]: %s\n", pat_msg);
Juergen Grossbd809af2014-11-03 14:02:03 +0100210}
211
Andreas Herrmanncd7a4e92008-06-10 16:05:39 +0200212#define PAT(x, y) ((u64)PAT_ ## y << ((x)*8))
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700213
Borislav Petkov9dac6292015-06-04 18:55:09 +0200214static void pat_bsp_init(u64 pat)
215{
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200216 u64 tmp_pat;
217
Toshi Kanid63dcf42016-03-23 15:41:59 -0600218 if (!boot_cpu_has(X86_FEATURE_PAT)) {
Borislav Petkov9dac6292015-06-04 18:55:09 +0200219 pat_disable("PAT not supported by CPU.");
220 return;
221 }
222
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200223 rdmsrl(MSR_IA32_CR_PAT, tmp_pat);
224 if (!tmp_pat) {
Borislav Petkov9dac6292015-06-04 18:55:09 +0200225 pat_disable("PAT MSR is 0, disabled.");
226 return;
227 }
228
229 wrmsrl(MSR_IA32_CR_PAT, pat);
Mikulas Patockacbed27c2017-04-18 15:07:11 -0400230 __pat_initialized = true;
Borislav Petkov9dac6292015-06-04 18:55:09 +0200231
Toshi Kani02f037d2016-03-23 15:41:57 -0600232 __init_cache_modes(pat);
Borislav Petkov9dac6292015-06-04 18:55:09 +0200233}
234
235static void pat_ap_init(u64 pat)
236{
Mikulas Patockacbed27c2017-04-18 15:07:11 -0400237 if (!this_cpu_has(X86_FEATURE_PAT)) {
Borislav Petkov9dac6292015-06-04 18:55:09 +0200238 /*
239 * If this happens we are on a secondary CPU, but switched to
240 * PAT on the boot CPU. We have no way to undo PAT.
241 */
242 panic("x86/PAT: PAT enabled, but not supported by secondary CPU\n");
243 }
244
245 wrmsrl(MSR_IA32_CR_PAT, pat);
246}
247
Toshi Kani02f037d2016-03-23 15:41:57 -0600248static void init_cache_modes(void)
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700249{
Toshi Kani02f037d2016-03-23 15:41:57 -0600250 u64 pat = 0;
251 static int init_cm_done;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700252
Toshi Kani02f037d2016-03-23 15:41:57 -0600253 if (init_cm_done)
254 return;
255
256 if (boot_cpu_has(X86_FEATURE_PAT)) {
257 /*
258 * CPU supports PAT. Set PAT table to be consistent with
259 * PAT MSR. This case supports "nopat" boot option, and
260 * virtual machine environments which support PAT without
261 * MTRRs. In specific, Xen has unique setup to PAT MSR.
262 *
263 * If PAT MSR returns 0, it is considered invalid and emulates
264 * as No PAT.
265 */
266 rdmsrl(MSR_IA32_CR_PAT, pat);
267 }
268
269 if (!pat) {
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200270 /*
271 * No PAT. Emulate the PAT table that corresponds to the two
Toshi Kani02f037d2016-03-23 15:41:57 -0600272 * cache bits, PWT (Write Through) and PCD (Cache Disable).
273 * This setup is also the same as the BIOS default setup.
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200274 *
Toshi Kanid79a40c2015-06-04 18:55:12 +0200275 * PTE encoding:
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200276 *
277 * PCD
278 * |PWT PAT
279 * || slot
280 * 00 0 WB : _PAGE_CACHE_MODE_WB
281 * 01 1 WT : _PAGE_CACHE_MODE_WT
282 * 10 2 UC-: _PAGE_CACHE_MODE_UC_MINUS
283 * 11 3 UC : _PAGE_CACHE_MODE_UC
284 *
285 * NOTE: When WC or WP is used, it is redirected to UC- per
286 * the default setup in __cachemode2pte_tbl[].
287 */
288 pat = PAT(0, WB) | PAT(1, WT) | PAT(2, UC_MINUS) | PAT(3, UC) |
289 PAT(4, WB) | PAT(5, WT) | PAT(6, UC_MINUS) | PAT(7, UC);
Toshi Kani02f037d2016-03-23 15:41:57 -0600290 }
Toshi Kanid79a40c2015-06-04 18:55:12 +0200291
Toshi Kani02f037d2016-03-23 15:41:57 -0600292 __init_cache_modes(pat);
293
294 init_cm_done = 1;
295}
296
297/**
298 * pat_init - Initialize PAT MSR and PAT table
299 *
300 * This function initializes PAT MSR and PAT table with an OS-defined value
301 * to enable additional cache attributes, WC and WT.
302 *
303 * This function must be called on all CPUs using the specific sequence of
304 * operations defined in Intel SDM. mtrr_rendezvous_handler() provides this
305 * procedure for PAT.
306 */
307void pat_init(void)
308{
309 u64 pat;
310 struct cpuinfo_x86 *c = &boot_cpu_data;
311
Mikulas Patockacbed27c2017-04-18 15:07:11 -0400312 if (!__pat_enabled) {
Toshi Kani02f037d2016-03-23 15:41:57 -0600313 init_cache_modes();
314 return;
315 }
316
317 if ((c->x86_vendor == X86_VENDOR_INTEL) &&
318 (((c->x86 == 0x6) && (c->x86_model <= 0xd)) ||
319 ((c->x86 == 0xf) && (c->x86_model <= 0x6)))) {
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200320 /*
Toshi Kanid79a40c2015-06-04 18:55:12 +0200321 * PAT support with the lower four entries. Intel Pentium 2,
322 * 3, M, and 4 are affected by PAT errata, which makes the
323 * upper four entries unusable. To be on the safe side, we don't
324 * use those.
325 *
326 * PTE encoding:
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200327 * PAT
328 * |PCD
Toshi Kanid79a40c2015-06-04 18:55:12 +0200329 * ||PWT PAT
330 * ||| slot
331 * 000 0 WB : _PAGE_CACHE_MODE_WB
332 * 001 1 WC : _PAGE_CACHE_MODE_WC
333 * 010 2 UC-: _PAGE_CACHE_MODE_UC_MINUS
334 * 011 3 UC : _PAGE_CACHE_MODE_UC
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200335 * PAT bit unused
Toshi Kanid79a40c2015-06-04 18:55:12 +0200336 *
337 * NOTE: When WT or WP is used, it is redirected to UC- per
338 * the default setup in __cachemode2pte_tbl[].
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200339 */
340 pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) |
341 PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, UC);
Toshi Kanid79a40c2015-06-04 18:55:12 +0200342 } else {
343 /*
344 * Full PAT support. We put WT in slot 7 to improve
345 * robustness in the presence of errata that might cause
346 * the high PAT bit to be ignored. This way, a buggy slot 7
347 * access will hit slot 3, and slot 3 is UC, so at worst
348 * we lose performance without causing a correctness issue.
349 * Pentium 4 erratum N46 is an example for such an erratum,
350 * although we try not to use PAT at all on affected CPUs.
351 *
352 * PTE encoding:
353 * PAT
354 * |PCD
355 * ||PWT PAT
356 * ||| slot
357 * 000 0 WB : _PAGE_CACHE_MODE_WB
358 * 001 1 WC : _PAGE_CACHE_MODE_WC
359 * 010 2 UC-: _PAGE_CACHE_MODE_UC_MINUS
360 * 011 3 UC : _PAGE_CACHE_MODE_UC
361 * 100 4 WB : Reserved
362 * 101 5 WC : Reserved
363 * 110 6 UC-: Reserved
364 * 111 7 WT : _PAGE_CACHE_MODE_WT
365 *
366 * The reserved slots are unused, but mapped to their
367 * corresponding types in the presence of PAT errata.
368 */
369 pat = PAT(0, WB) | PAT(1, WC) | PAT(2, UC_MINUS) | PAT(3, UC) |
370 PAT(4, WB) | PAT(5, WC) | PAT(6, UC_MINUS) | PAT(7, WT);
Borislav Petkov9cd25aa2015-06-04 18:55:10 +0200371 }
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700372
Borislav Petkov9dac6292015-06-04 18:55:09 +0200373 if (!boot_cpu_done) {
374 pat_bsp_init(pat);
375 boot_cpu_done = true;
376 } else {
377 pat_ap_init(pat);
Juergen Gross9d34cfd2015-01-12 06:15:45 +0100378 }
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700379}
380
381#undef PAT
382
Pallipadi, Venkatesh9e41a492010-02-10 15:26:07 -0800383static DEFINE_SPINLOCK(memtype_lock); /* protects memtype accesses */
Venkatesh Pallipadi335ef892009-07-10 09:57:36 -0700384
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700385/*
386 * Does intersection of PAT memory type and MTRR memory type and returns
387 * the resulting memory type as PAT understands it.
388 * (Type in pat and mtrr will not have same value)
389 * The intersection is based on "Effective Memory Type" tables in IA-32
390 * SDM vol 3a
391 */
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100392static unsigned long pat_x_mtrr_type(u64 start, u64 end,
393 enum page_cache_mode req_type)
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700394{
Venki Pallipadic26421d2008-05-29 12:01:44 -0700395 /*
396 * Look for MTRR hint to get the effective type in case where PAT
397 * request is for WB.
398 */
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100399 if (req_type == _PAGE_CACHE_MODE_WB) {
Toshi Kanib73522e2015-05-26 10:28:10 +0200400 u8 mtrr_type, uniform;
Andreas Herrmanndd0c7c42008-06-18 15:38:57 +0200401
Toshi Kanib73522e2015-05-26 10:28:10 +0200402 mtrr_type = mtrr_type_lookup(start, end, &uniform);
Suresh Siddhab6ff32d2009-04-09 14:26:51 -0700403 if (mtrr_type != MTRR_TYPE_WRBACK)
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100404 return _PAGE_CACHE_MODE_UC_MINUS;
Suresh Siddhab6ff32d2009-04-09 14:26:51 -0700405
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100406 return _PAGE_CACHE_MODE_WB;
Andreas Herrmanndd0c7c42008-06-18 15:38:57 +0200407 }
408
409 return req_type;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700410}
411
John Dykstrafa835232012-05-25 16:12:46 -0500412struct pagerange_state {
413 unsigned long cur_pfn;
414 int ram;
415 int not_ram;
416};
417
418static int
419pagerange_is_ram_callback(unsigned long initial_pfn, unsigned long total_nr_pages, void *arg)
420{
421 struct pagerange_state *state = arg;
422
423 state->not_ram |= initial_pfn > state->cur_pfn;
424 state->ram |= total_nr_pages > 0;
425 state->cur_pfn = initial_pfn + total_nr_pages;
426
427 return state->ram && state->not_ram;
428}
429
Yasuaki Ishimatsu3709c852010-07-22 14:57:35 +0900430static int pat_pagerange_is_ram(resource_size_t start, resource_size_t end)
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800431{
John Dykstrafa835232012-05-25 16:12:46 -0500432 int ret = 0;
433 unsigned long start_pfn = start >> PAGE_SHIFT;
434 unsigned long end_pfn = (end + PAGE_SIZE - 1) >> PAGE_SHIFT;
435 struct pagerange_state state = {start_pfn, 0, 0};
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800436
John Dykstrafa835232012-05-25 16:12:46 -0500437 /*
438 * For legacy reasons, physical address range in the legacy ISA
439 * region is tracked as non-RAM. This will allow users of
440 * /dev/mem to map portions of legacy ISA region, even when
441 * some of those portions are listed(or not even listed) with
442 * different e820 types(RAM/reserved/..)
443 */
444 if (start_pfn < ISA_END_ADDRESS >> PAGE_SHIFT)
445 start_pfn = ISA_END_ADDRESS >> PAGE_SHIFT;
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800446
John Dykstrafa835232012-05-25 16:12:46 -0500447 if (start_pfn < end_pfn) {
448 ret = walk_system_ram_range(start_pfn, end_pfn - start_pfn,
449 &state, pagerange_is_ram_callback);
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800450 }
451
John Dykstrafa835232012-05-25 16:12:46 -0500452 return (ret > 0) ? -1 : (state.ram ? 1 : 0);
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800453}
454
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700455/*
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700456 * For RAM pages, we use page flags to mark the pages with appropriate type.
Toshi Kani35a5a102015-06-04 18:55:19 +0200457 * The page flags are limited to four types, WB (default), WC, WT and UC-.
458 * WP request fails with -EINVAL, and UC gets redirected to UC-. Setting
459 * a new memory type is only allowed for a page mapped with the default WB
460 * type.
Toshi Kani0d69bdf2015-06-04 18:55:13 +0200461 *
462 * Here we do two passes:
463 * - Find the memtype of all the pages in the range, look for any conflicts.
464 * - In case of no conflicts, set the new memtype for pages in the range.
Suresh Siddha9542ada2008-09-24 08:53:33 -0700465 */
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100466static int reserve_ram_pages_type(u64 start, u64 end,
467 enum page_cache_mode req_type,
468 enum page_cache_mode *new_type)
Suresh Siddha9542ada2008-09-24 08:53:33 -0700469{
470 struct page *page;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700471 u64 pfn;
472
Toshi Kani35a5a102015-06-04 18:55:19 +0200473 if (req_type == _PAGE_CACHE_MODE_WP) {
Toshi Kani0d69bdf2015-06-04 18:55:13 +0200474 if (new_type)
475 *new_type = _PAGE_CACHE_MODE_UC_MINUS;
476 return -EINVAL;
477 }
478
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100479 if (req_type == _PAGE_CACHE_MODE_UC) {
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700480 /* We do not support strong UC */
481 WARN_ON_ONCE(1);
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100482 req_type = _PAGE_CACHE_MODE_UC_MINUS;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700483 }
484
485 for (pfn = (start >> PAGE_SHIFT); pfn < (end >> PAGE_SHIFT); ++pfn) {
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100486 enum page_cache_mode type;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700487
488 page = pfn_to_page(pfn);
489 type = get_page_memtype(page);
Toshi Kani35a5a102015-06-04 18:55:19 +0200490 if (type != _PAGE_CACHE_MODE_WB) {
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200491 pr_info("x86/PAT: reserve_ram_pages_type failed [mem %#010Lx-%#010Lx], track 0x%x, req 0x%x\n",
Bjorn Helgaas365811d2012-05-29 15:06:29 -0700492 start, end - 1, type, req_type);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700493 if (new_type)
494 *new_type = type;
495
496 return -EBUSY;
497 }
498 }
499
500 if (new_type)
501 *new_type = req_type;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700502
503 for (pfn = (start >> PAGE_SHIFT); pfn < (end >> PAGE_SHIFT); ++pfn) {
504 page = pfn_to_page(pfn);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700505 set_page_memtype(page, req_type);
Suresh Siddha9542ada2008-09-24 08:53:33 -0700506 }
507 return 0;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700508}
509
510static int free_ram_pages_type(u64 start, u64 end)
511{
512 struct page *page;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700513 u64 pfn;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700514
515 for (pfn = (start >> PAGE_SHIFT); pfn < (end >> PAGE_SHIFT); ++pfn) {
516 page = pfn_to_page(pfn);
Toshi Kani35a5a102015-06-04 18:55:19 +0200517 set_page_memtype(page, _PAGE_CACHE_MODE_WB);
Suresh Siddha9542ada2008-09-24 08:53:33 -0700518 }
519 return 0;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700520}
521
522/*
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700523 * req_type typically has one of the:
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100524 * - _PAGE_CACHE_MODE_WB
525 * - _PAGE_CACHE_MODE_WC
526 * - _PAGE_CACHE_MODE_UC_MINUS
527 * - _PAGE_CACHE_MODE_UC
Toshi Kani0d69bdf2015-06-04 18:55:13 +0200528 * - _PAGE_CACHE_MODE_WT
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700529 *
Andreas Herrmannac979912008-06-20 22:01:49 +0200530 * If new_type is NULL, function will return an error if it cannot reserve the
531 * region with req_type. If new_type is non-NULL, function will return
532 * available type in new_type in case of no error. In case of any error
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700533 * it will return a negative return value.
534 */
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100535int reserve_memtype(u64 start, u64 end, enum page_cache_mode req_type,
536 enum page_cache_mode *new_type)
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700537{
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -0800538 struct memtype *new;
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100539 enum page_cache_mode actual_type;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700540 int is_range_ram;
Ingo Molnarad2cde12008-09-30 13:20:45 +0200541 int err = 0;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700542
Ingo Molnarad2cde12008-09-30 13:20:45 +0200543 BUG_ON(start >= end); /* end is exclusive */
Andreas Herrmann69e26be2008-06-20 22:03:06 +0200544
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200545 if (!pat_enabled()) {
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700546 /* This is identical to page table setting without PAT */
Borislav Petkov7202fdb2015-06-04 18:55:11 +0200547 if (new_type)
548 *new_type = req_type;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700549 return 0;
550 }
551
552 /* Low ISA region is always mapped WB in page table. No need to track */
H. Peter Anvin8a271382009-11-23 14:49:20 -0800553 if (x86_platform.is_untracked_pat_range(start, end)) {
Andreas Herrmannac979912008-06-20 22:01:49 +0200554 if (new_type)
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100555 *new_type = _PAGE_CACHE_MODE_WB;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700556 return 0;
557 }
558
Suresh Siddhab6ff32d2009-04-09 14:26:51 -0700559 /*
560 * Call mtrr_lookup to get the type hint. This is an
561 * optimization for /dev/mem mmap'ers into WB memory (BIOS
562 * tools and ACPI tools). Use WB request for WB memory and use
563 * UC_MINUS otherwise.
564 */
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100565 actual_type = pat_x_mtrr_type(start, end, req_type);
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700566
Suresh Siddha95971342009-01-13 10:21:30 -0800567 if (new_type)
568 *new_type = actual_type;
569
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800570 is_range_ram = pat_pagerange_is_ram(start, end);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700571 if (is_range_ram == 1) {
572
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700573 err = reserve_ram_pages_type(start, end, req_type, new_type);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700574
575 return err;
576 } else if (is_range_ram < 0) {
Suresh Siddha9542ada2008-09-24 08:53:33 -0700577 return -EINVAL;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700578 }
Suresh Siddha9542ada2008-09-24 08:53:33 -0700579
Venkatesh Pallipadi6a4f3b52010-06-10 17:45:01 -0700580 new = kzalloc(sizeof(struct memtype), GFP_KERNEL);
Andreas Herrmannac979912008-06-20 22:01:49 +0200581 if (!new)
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700582 return -ENOMEM;
583
Ingo Molnarad2cde12008-09-30 13:20:45 +0200584 new->start = start;
585 new->end = end;
586 new->type = actual_type;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700587
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700588 spin_lock(&memtype_lock);
589
Pallipadi, Venkatesh9e41a492010-02-10 15:26:07 -0800590 err = rbt_memtype_check_insert(new, new_type);
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700591 if (err) {
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200592 pr_info("x86/PAT: reserve_memtype failed [mem %#010Lx-%#010Lx], track %s, req %s\n",
593 start, end - 1,
594 cattr_name(new->type), cattr_name(req_type));
Andreas Herrmannac979912008-06-20 22:01:49 +0200595 kfree(new);
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700596 spin_unlock(&memtype_lock);
Ingo Molnarad2cde12008-09-30 13:20:45 +0200597
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700598 return err;
599 }
600
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700601 spin_unlock(&memtype_lock);
Andreas Herrmann3e9c83b2008-06-20 22:04:02 +0200602
Bjorn Helgaas365811d2012-05-29 15:06:29 -0700603 dprintk("reserve_memtype added [mem %#010Lx-%#010Lx], track %s, req %s, ret %s\n",
604 start, end - 1, cattr_name(new->type), cattr_name(req_type),
Andreas Herrmann3e9c83b2008-06-20 22:04:02 +0200605 new_type ? cattr_name(*new_type) : "-");
606
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700607 return err;
608}
609
610int free_memtype(u64 start, u64 end)
611{
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700612 int err = -EINVAL;
Suresh Siddha9542ada2008-09-24 08:53:33 -0700613 int is_range_ram;
Xiaotian Feng20413f22010-05-26 09:51:10 +0800614 struct memtype *entry;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700615
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200616 if (!pat_enabled())
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700617 return 0;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700618
619 /* Low ISA region is always mapped WB. No need to track */
H. Peter Anvin8a271382009-11-23 14:49:20 -0800620 if (x86_platform.is_untracked_pat_range(start, end))
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700621 return 0;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700622
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800623 is_range_ram = pat_pagerange_is_ram(start, end);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700624 if (is_range_ram == 1) {
625
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700626 err = free_ram_pages_type(start, end);
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700627
628 return err;
629 } else if (is_range_ram < 0) {
Suresh Siddha9542ada2008-09-24 08:53:33 -0700630 return -EINVAL;
Venkatesh Pallipadif5841742009-07-10 09:57:38 -0700631 }
Suresh Siddha9542ada2008-09-24 08:53:33 -0700632
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700633 spin_lock(&memtype_lock);
Xiaotian Feng20413f22010-05-26 09:51:10 +0800634 entry = rbt_memtype_erase(start, end);
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700635 spin_unlock(&memtype_lock);
636
Toshi Kani2039e6a2015-12-22 17:54:24 -0700637 if (IS_ERR(entry)) {
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200638 pr_info("x86/PAT: %s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
639 current->comm, current->pid, start, end - 1);
Xiaotian Feng20413f22010-05-26 09:51:10 +0800640 return -EINVAL;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700641 }
venkatesh.pallipadi@intel.com6997ab42008-03-18 17:00:25 -0700642
Xiaotian Feng20413f22010-05-26 09:51:10 +0800643 kfree(entry);
644
Bjorn Helgaas365811d2012-05-29 15:06:29 -0700645 dprintk("free_memtype request [mem %#010Lx-%#010Lx]\n", start, end - 1);
Ingo Molnarad2cde12008-09-30 13:20:45 +0200646
Xiaotian Feng20413f22010-05-26 09:51:10 +0800647 return 0;
venkatesh.pallipadi@intel.com2e5d9c82008-03-18 17:00:14 -0700648}
649
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700650
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700651/**
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700652 * lookup_memtype - Looksup the memory type for a physical address
653 * @paddr: physical address of which memory type needs to be looked up
654 *
655 * Only to be called when PAT is enabled
656 *
Juergen Gross2a374692014-11-03 14:01:55 +0100657 * Returns _PAGE_CACHE_MODE_WB, _PAGE_CACHE_MODE_WC, _PAGE_CACHE_MODE_UC_MINUS
Toshi Kani35a5a102015-06-04 18:55:19 +0200658 * or _PAGE_CACHE_MODE_WT.
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700659 */
Juergen Gross2a374692014-11-03 14:01:55 +0100660static enum page_cache_mode lookup_memtype(u64 paddr)
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700661{
Juergen Gross2a374692014-11-03 14:01:55 +0100662 enum page_cache_mode rettype = _PAGE_CACHE_MODE_WB;
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700663 struct memtype *entry;
664
H. Peter Anvin8a271382009-11-23 14:49:20 -0800665 if (x86_platform.is_untracked_pat_range(paddr, paddr + PAGE_SIZE))
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700666 return rettype;
667
668 if (pat_pagerange_is_ram(paddr, paddr + PAGE_SIZE)) {
669 struct page *page;
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700670
Toshi Kani35a5a102015-06-04 18:55:19 +0200671 page = pfn_to_page(paddr >> PAGE_SHIFT);
672 return get_page_memtype(page);
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700673 }
674
675 spin_lock(&memtype_lock);
676
Pallipadi, Venkatesh9e41a492010-02-10 15:26:07 -0800677 entry = rbt_memtype_lookup(paddr);
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700678 if (entry != NULL)
679 rettype = entry->type;
680 else
Juergen Gross2a374692014-11-03 14:01:55 +0100681 rettype = _PAGE_CACHE_MODE_UC_MINUS;
Venkatesh Pallipadi637b86e2009-07-10 09:57:39 -0700682
683 spin_unlock(&memtype_lock);
684 return rettype;
685}
686
687/**
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700688 * io_reserve_memtype - Request a memory type mapping for a region of memory
689 * @start: start (physical address) of the region
690 * @end: end (physical address) of the region
691 * @type: A pointer to memtype, with requested type. On success, requested
692 * or any other compatible type that was available for the region is returned
693 *
694 * On success, returns 0
695 * On failure, returns non-zero
696 */
697int io_reserve_memtype(resource_size_t start, resource_size_t end,
Juergen Gross49a3b3c2014-11-03 14:01:54 +0100698 enum page_cache_mode *type)
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700699{
H. Peter Anvinb8551922009-08-26 17:17:51 -0700700 resource_size_t size = end - start;
Juergen Gross49a3b3c2014-11-03 14:01:54 +0100701 enum page_cache_mode req_type = *type;
702 enum page_cache_mode new_type;
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700703 int ret;
704
H. Peter Anvinb8551922009-08-26 17:17:51 -0700705 WARN_ON_ONCE(iomem_map_sanity_check(start, size));
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700706
707 ret = reserve_memtype(start, end, req_type, &new_type);
708 if (ret)
709 goto out_err;
710
H. Peter Anvinb8551922009-08-26 17:17:51 -0700711 if (!is_new_memtype_allowed(start, size, req_type, new_type))
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700712 goto out_free;
713
H. Peter Anvinb8551922009-08-26 17:17:51 -0700714 if (kernel_map_sync_memtype(start, size, new_type) < 0)
Venkatesh Pallipadi9fd126bc2009-07-10 09:57:34 -0700715 goto out_free;
716
717 *type = new_type;
718 return 0;
719
720out_free:
721 free_memtype(start, end);
722 ret = -EBUSY;
723out_err:
724 return ret;
725}
726
727/**
728 * io_free_memtype - Release a memory type mapping for a region of memory
729 * @start: start (physical address) of the region
730 * @end: end (physical address) of the region
731 */
732void io_free_memtype(resource_size_t start, resource_size_t end)
733{
734 free_memtype(start, end);
735}
736
Dave Airlie8ef42272016-10-24 15:27:59 +1000737int arch_io_reserve_memtype_wc(resource_size_t start, resource_size_t size)
738{
739 enum page_cache_mode type = _PAGE_CACHE_MODE_WC;
740
741 return io_reserve_memtype(start, start + size, &type);
742}
743EXPORT_SYMBOL(arch_io_reserve_memtype_wc);
744
745void arch_io_free_memtype_wc(resource_size_t start, resource_size_t size)
746{
747 io_free_memtype(start, start + size);
748}
749EXPORT_SYMBOL(arch_io_free_memtype_wc);
750
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700751pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
752 unsigned long size, pgprot_t vma_prot)
753{
754 return vma_prot;
755}
756
Ingo Molnard0926332008-07-18 00:26:59 +0200757#ifdef CONFIG_STRICT_DEVMEM
Pavel Machek1f40a8b2014-12-28 17:15:24 +0100758/* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM */
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700759static inline int range_is_allowed(unsigned long pfn, unsigned long size)
760{
761 return 1;
762}
763#else
Ravikiran G Thirumalai9e41bff2008-10-30 13:59:21 -0700764/* This check is needed to avoid cache aliasing when PAT is enabled */
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700765static inline int range_is_allowed(unsigned long pfn, unsigned long size)
766{
767 u64 from = ((u64)pfn) << PAGE_SHIFT;
768 u64 to = from + size;
769 u64 cursor = from;
770
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200771 if (!pat_enabled())
Ravikiran G Thirumalai9e41bff2008-10-30 13:59:21 -0700772 return 1;
773
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700774 while (cursor < to) {
Jiri Kosina39380b82016-07-08 11:38:28 +0200775 if (!devmem_is_allowed(pfn))
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700776 return 0;
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700777 cursor += PAGE_SIZE;
778 pfn++;
779 }
780 return 1;
781}
Ingo Molnard0926332008-07-18 00:26:59 +0200782#endif /* CONFIG_STRICT_DEVMEM */
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700783
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700784int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
785 unsigned long size, pgprot_t *vma_prot)
786{
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100787 enum page_cache_mode pcm = _PAGE_CACHE_MODE_WB;
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700788
Venki Pallipadi0124cec2008-04-26 11:32:12 -0700789 if (!range_is_allowed(pfn, size))
790 return 0;
791
Christoph Hellwig6b2f3d12009-10-27 11:05:28 +0100792 if (file->f_flags & O_DSYNC)
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100793 pcm = _PAGE_CACHE_MODE_UC_MINUS;
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700794
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700795 *vma_prot = __pgprot((pgprot_val(*vma_prot) & ~_PAGE_CACHE_MASK) |
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100796 cachemode2protval(pcm));
venkatesh.pallipadi@intel.comf0970c12008-03-18 17:00:20 -0700797 return 1;
798}
venkatesh.pallipadi@intel.come7f260a2008-03-18 17:00:21 -0700799
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800800/*
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800801 * Change the memory type for the physial address range in kernel identity
802 * mapping space if that range is a part of identity map.
803 */
Juergen Grossb14097b2014-11-03 14:01:58 +0100804int kernel_map_sync_memtype(u64 base, unsigned long size,
805 enum page_cache_mode pcm)
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800806{
807 unsigned long id_sz;
808
Dave Hansena25b9312013-01-22 13:24:30 -0800809 if (base > __pa(high_memory-1))
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800810 return 0;
811
Dave Hansen60f583d2013-03-07 08:31:51 -0800812 /*
813 * some areas in the middle of the kernel identity range
814 * are not mapped, like the PCI space.
815 */
816 if (!page_is_ram(base >> PAGE_SHIFT))
817 return 0;
818
Dave Hansena25b9312013-01-22 13:24:30 -0800819 id_sz = (__pa(high_memory-1) <= base + size) ?
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800820 __pa(high_memory) - base :
821 size;
822
Juergen Grossb14097b2014-11-03 14:01:58 +0100823 if (ioremap_change_attr((unsigned long)__va(base), id_sz, pcm) < 0) {
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200824 pr_info("x86/PAT: %s:%d ioremap_change_attr failed %s for [mem %#010Lx-%#010Lx]\n",
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800825 current->comm, current->pid,
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100826 cattr_name(pcm),
Bjorn Helgaas365811d2012-05-29 15:06:29 -0700827 base, (unsigned long long)(base + size-1));
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800828 return -EINVAL;
829 }
830 return 0;
831}
832
833/*
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800834 * Internal interface to reserve a range of physical memory with prot.
835 * Reserved non RAM regions only and after successful reserve_memtype,
836 * this func also keeps identity mapping (if any) in sync with this new prot.
837 */
venkatesh.pallipadi@intel.comcdecff62009-01-09 16:13:12 -0800838static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
839 int strict_prot)
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800840{
841 int is_ram = 0;
Venkatesh Pallipadi7880f742009-02-24 17:35:13 -0800842 int ret;
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100843 enum page_cache_mode want_pcm = pgprot2cachemode(*vma_prot);
844 enum page_cache_mode pcm = want_pcm;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800845
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800846 is_ram = pat_pagerange_is_ram(paddr, paddr + size);
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800847
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800848 /*
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700849 * reserve_pfn_range() for RAM pages. We do not refcount to keep
850 * track of number of mappings of RAM pages. We can assert that
851 * the type requested matches the type of first page in the range.
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800852 */
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700853 if (is_ram) {
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200854 if (!pat_enabled())
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700855 return 0;
856
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100857 pcm = lookup_memtype(paddr);
858 if (want_pcm != pcm) {
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200859 pr_warn("x86/PAT: %s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700860 current->comm, current->pid,
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100861 cattr_name(want_pcm),
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700862 (unsigned long long)paddr,
Bjorn Helgaas365811d2012-05-29 15:06:29 -0700863 (unsigned long long)(paddr + size - 1),
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100864 cattr_name(pcm));
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700865 *vma_prot = __pgprot((pgprot_val(*vma_prot) &
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100866 (~_PAGE_CACHE_MASK)) |
867 cachemode2protval(pcm));
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700868 }
Pallipadi, Venkatesh4bb9c5c2009-03-12 17:45:27 -0700869 return 0;
Venkatesh Pallipadid886c732009-07-10 09:57:41 -0700870 }
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800871
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100872 ret = reserve_memtype(paddr, paddr + size, want_pcm, &pcm);
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800873 if (ret)
874 return ret;
875
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100876 if (pcm != want_pcm) {
Suresh Siddha1adcaaf2009-08-17 13:23:50 -0700877 if (strict_prot ||
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100878 !is_new_memtype_allowed(paddr, size, want_pcm, pcm)) {
venkatesh.pallipadi@intel.comcdecff62009-01-09 16:13:12 -0800879 free_memtype(paddr, paddr + size);
Luis R. Rodriguez9e765612015-05-26 10:28:11 +0200880 pr_err("x86/PAT: %s:%d map pfn expected mapping type %s for [mem %#010Lx-%#010Lx], got %s\n",
881 current->comm, current->pid,
882 cattr_name(want_pcm),
883 (unsigned long long)paddr,
884 (unsigned long long)(paddr + size - 1),
885 cattr_name(pcm));
venkatesh.pallipadi@intel.comcdecff62009-01-09 16:13:12 -0800886 return -EINVAL;
887 }
888 /*
889 * We allow returning different type than the one requested in
890 * non strict case.
891 */
892 *vma_prot = __pgprot((pgprot_val(*vma_prot) &
893 (~_PAGE_CACHE_MASK)) |
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100894 cachemode2protval(pcm));
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800895 }
896
Juergen Grosse00c8cc2014-11-03 14:01:59 +0100897 if (kernel_map_sync_memtype(paddr, size, pcm) < 0) {
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800898 free_memtype(paddr, paddr + size);
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800899 return -EINVAL;
900 }
901 return 0;
902}
903
904/*
905 * Internal interface to free a range of physical memory.
906 * Frees non RAM regions only.
907 */
908static void free_pfn_range(u64 paddr, unsigned long size)
909{
910 int is_ram;
911
Suresh Siddhabe03d9e2009-02-11 11:20:23 -0800912 is_ram = pat_pagerange_is_ram(paddr, paddr + size);
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800913 if (is_ram == 0)
914 free_memtype(paddr, paddr + size);
915}
916
917/*
Suresh Siddha5180da42012-10-08 16:28:29 -0700918 * track_pfn_copy is called when vma that is covering the pfnmap gets
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800919 * copied through copy_page_range().
920 *
921 * If the vma has a linear pfn mapping for the entire range, we get the prot
922 * from pte and reserve the entire vma range with single reserve_pfn_range call.
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800923 */
Suresh Siddha5180da42012-10-08 16:28:29 -0700924int track_pfn_copy(struct vm_area_struct *vma)
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800925{
H. Peter Anvinc1c15b62008-12-23 10:10:40 -0800926 resource_size_t paddr;
venkatesh.pallipadi@intel.com982d7892008-12-19 13:47:28 -0800927 unsigned long prot;
Pallipadi, Venkatesh4b065042009-04-08 15:37:16 -0700928 unsigned long vma_size = vma->vm_end - vma->vm_start;
venkatesh.pallipadi@intel.comcdecff62009-01-09 16:13:12 -0800929 pgprot_t pgprot;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800930
Konstantin Khlebnikovb3b9c292012-10-08 16:28:34 -0700931 if (vma->vm_flags & VM_PAT) {
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800932 /*
venkatesh.pallipadi@intel.com982d7892008-12-19 13:47:28 -0800933 * reserve the whole chunk covered by vma. We need the
934 * starting address and protection from pte.
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800935 */
Pallipadi, Venkatesh4b065042009-04-08 15:37:16 -0700936 if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) {
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800937 WARN_ON_ONCE(1);
venkatesh.pallipadi@intel.com982d7892008-12-19 13:47:28 -0800938 return -EINVAL;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800939 }
venkatesh.pallipadi@intel.comcdecff62009-01-09 16:13:12 -0800940 pgprot = __pgprot(prot);
941 return reserve_pfn_range(paddr, vma_size, &pgprot, 1);
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800942 }
943
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800944 return 0;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800945}
946
947/*
Dan Williams90497712016-09-07 08:51:21 -0700948 * prot is passed in as a parameter for the new mapping. If the vma has
949 * a linear pfn mapping for the entire range, or no vma is provided,
950 * reserve the entire pfn + size range with single reserve_pfn_range
951 * call.
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800952 */
Suresh Siddha5180da42012-10-08 16:28:29 -0700953int track_pfn_remap(struct vm_area_struct *vma, pgprot_t *prot,
Konstantin Khlebnikovb3b9c292012-10-08 16:28:34 -0700954 unsigned long pfn, unsigned long addr, unsigned long size)
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800955{
Suresh Siddhab1a86e12012-10-08 16:28:23 -0700956 resource_size_t paddr = (resource_size_t)pfn << PAGE_SHIFT;
Juergen Gross2a374692014-11-03 14:01:55 +0100957 enum page_cache_mode pcm;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800958
Suresh Siddhab1a86e12012-10-08 16:28:23 -0700959 /* reserve the whole chunk starting from paddr */
Dan Williams90497712016-09-07 08:51:21 -0700960 if (!vma || (addr == vma->vm_start
961 && size == (vma->vm_end - vma->vm_start))) {
Konstantin Khlebnikovb3b9c292012-10-08 16:28:34 -0700962 int ret;
963
964 ret = reserve_pfn_range(paddr, size, prot, 0);
Dan Williams90497712016-09-07 08:51:21 -0700965 if (ret == 0 && vma)
Konstantin Khlebnikovb3b9c292012-10-08 16:28:34 -0700966 vma->vm_flags |= VM_PAT;
967 return ret;
968 }
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -0800969
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200970 if (!pat_enabled())
Venkatesh Pallipadi108763762009-07-10 09:57:40 -0700971 return 0;
972
Suresh Siddha5180da42012-10-08 16:28:29 -0700973 /*
974 * For anything smaller than the vma size we set prot based on the
975 * lookup.
976 */
Juergen Gross2a374692014-11-03 14:01:55 +0100977 pcm = lookup_memtype(paddr);
Suresh Siddha5180da42012-10-08 16:28:29 -0700978
979 /* Check memtype for the remaining pages */
980 while (size > PAGE_SIZE) {
981 size -= PAGE_SIZE;
982 paddr += PAGE_SIZE;
Juergen Gross2a374692014-11-03 14:01:55 +0100983 if (pcm != lookup_memtype(paddr))
Suresh Siddha5180da42012-10-08 16:28:29 -0700984 return -EINVAL;
985 }
986
Matthew Wilcoxdd7b6842016-01-25 12:25:15 -0500987 *prot = __pgprot((pgprot_val(*prot) & (~_PAGE_CACHE_MASK)) |
Juergen Gross2a374692014-11-03 14:01:55 +0100988 cachemode2protval(pcm));
Suresh Siddha5180da42012-10-08 16:28:29 -0700989
990 return 0;
991}
992
Borislav Petkov308a0472016-10-26 19:43:43 +0200993void track_pfn_insert(struct vm_area_struct *vma, pgprot_t *prot, pfn_t pfn)
Suresh Siddha5180da42012-10-08 16:28:29 -0700994{
Juergen Gross2a374692014-11-03 14:01:55 +0100995 enum page_cache_mode pcm;
Suresh Siddha5180da42012-10-08 16:28:29 -0700996
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +0200997 if (!pat_enabled())
Borislav Petkov308a0472016-10-26 19:43:43 +0200998 return;
Suresh Siddha5180da42012-10-08 16:28:29 -0700999
1000 /* Set prot based on lookup */
Dan Williamsf25748e32016-01-15 16:56:43 -08001001 pcm = lookup_memtype(pfn_t_to_phys(pfn));
Matthew Wilcoxdd7b6842016-01-25 12:25:15 -05001002 *prot = __pgprot((pgprot_val(*prot) & (~_PAGE_CACHE_MASK)) |
Juergen Gross2a374692014-11-03 14:01:55 +01001003 cachemode2protval(pcm));
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001004}
1005
1006/*
Suresh Siddha5180da42012-10-08 16:28:29 -07001007 * untrack_pfn is called while unmapping a pfnmap for a region.
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001008 * untrack can be called for a specific region indicated by pfn and size or
Suresh Siddhab1a86e12012-10-08 16:28:23 -07001009 * can be for the entire vma (in which case pfn, size are zero).
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001010 */
Suresh Siddha5180da42012-10-08 16:28:29 -07001011void untrack_pfn(struct vm_area_struct *vma, unsigned long pfn,
1012 unsigned long size)
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001013{
H. Peter Anvinc1c15b62008-12-23 10:10:40 -08001014 resource_size_t paddr;
Suresh Siddhab1a86e12012-10-08 16:28:23 -07001015 unsigned long prot;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001016
Dan Williams90497712016-09-07 08:51:21 -07001017 if (vma && !(vma->vm_flags & VM_PAT))
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001018 return;
Suresh Siddhab1a86e12012-10-08 16:28:23 -07001019
1020 /* free the chunk starting from pfn or the whole chunk */
1021 paddr = (resource_size_t)pfn << PAGE_SHIFT;
1022 if (!paddr && !size) {
1023 if (follow_phys(vma, vma->vm_start, 0, &prot, &paddr)) {
1024 WARN_ON_ONCE(1);
1025 return;
1026 }
1027
1028 size = vma->vm_end - vma->vm_start;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001029 }
Suresh Siddhab1a86e12012-10-08 16:28:23 -07001030 free_pfn_range(paddr, size);
Dan Williams90497712016-09-07 08:51:21 -07001031 if (vma)
1032 vma->vm_flags &= ~VM_PAT;
venkatesh.pallipadi@intel.com58993292008-12-18 11:41:30 -08001033}
1034
Toshi Kanid9fe4fa2015-12-22 17:54:23 -07001035/*
1036 * untrack_pfn_moved is called, while mremapping a pfnmap for a new region,
1037 * with the old vma after its pfnmap page table has been removed. The new
1038 * vma has a new pfnmap to the same pfn & cache type with VM_PAT set.
1039 */
1040void untrack_pfn_moved(struct vm_area_struct *vma)
1041{
1042 vma->vm_flags &= ~VM_PAT;
1043}
1044
venkatesh.pallipadi@intel.com2520bd32008-12-18 11:41:32 -08001045pgprot_t pgprot_writecombine(pgprot_t prot)
1046{
Borislav Petkov7202fdb2015-06-04 18:55:11 +02001047 return __pgprot(pgprot_val(prot) |
Juergen Grosse00c8cc2014-11-03 14:01:59 +01001048 cachemode2protval(_PAGE_CACHE_MODE_WC));
venkatesh.pallipadi@intel.com2520bd32008-12-18 11:41:32 -08001049}
Ingo Molnar92b9af92009-02-28 14:09:27 +01001050EXPORT_SYMBOL_GPL(pgprot_writecombine);
venkatesh.pallipadi@intel.com2520bd32008-12-18 11:41:32 -08001051
Toshi Kanid1b4bfb2015-06-04 18:55:18 +02001052pgprot_t pgprot_writethrough(pgprot_t prot)
1053{
1054 return __pgprot(pgprot_val(prot) |
1055 cachemode2protval(_PAGE_CACHE_MODE_WT));
1056}
1057EXPORT_SYMBOL_GPL(pgprot_writethrough);
1058
Andreas Herrmann012f09e2008-08-06 16:23:08 +02001059#if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT)
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001060
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001061static struct memtype *memtype_get_idx(loff_t pos)
1062{
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -08001063 struct memtype *print_entry;
1064 int ret;
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001065
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -08001066 print_entry = kzalloc(sizeof(struct memtype), GFP_KERNEL);
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001067 if (!print_entry)
1068 return NULL;
1069
1070 spin_lock(&memtype_lock);
Pallipadi, Venkatesh9e41a492010-02-10 15:26:07 -08001071 ret = rbt_memtype_copy_nth_element(print_entry, pos);
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001072 spin_unlock(&memtype_lock);
Ingo Molnarad2cde12008-09-30 13:20:45 +02001073
venkatesh.pallipadi@intel.combe5a0c12010-02-10 11:57:06 -08001074 if (!ret) {
1075 return print_entry;
1076 } else {
1077 kfree(print_entry);
1078 return NULL;
1079 }
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001080}
1081
1082static void *memtype_seq_start(struct seq_file *seq, loff_t *pos)
1083{
1084 if (*pos == 0) {
1085 ++*pos;
Rasmus Villemoes37367082014-11-28 22:03:41 +01001086 seq_puts(seq, "PAT memtype list:\n");
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001087 }
1088
1089 return memtype_get_idx(*pos);
1090}
1091
1092static void *memtype_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1093{
1094 ++*pos;
1095 return memtype_get_idx(*pos);
1096}
1097
1098static void memtype_seq_stop(struct seq_file *seq, void *v)
1099{
1100}
1101
1102static int memtype_seq_show(struct seq_file *seq, void *v)
1103{
1104 struct memtype *print_entry = (struct memtype *)v;
1105
1106 seq_printf(seq, "%s @ 0x%Lx-0x%Lx\n", cattr_name(print_entry->type),
1107 print_entry->start, print_entry->end);
1108 kfree(print_entry);
Ingo Molnarad2cde12008-09-30 13:20:45 +02001109
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001110 return 0;
1111}
1112
Tobias Klauserd535e432009-09-04 15:53:09 +02001113static const struct seq_operations memtype_seq_ops = {
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001114 .start = memtype_seq_start,
1115 .next = memtype_seq_next,
1116 .stop = memtype_seq_stop,
1117 .show = memtype_seq_show,
1118};
1119
1120static int memtype_seq_open(struct inode *inode, struct file *file)
1121{
1122 return seq_open(file, &memtype_seq_ops);
1123}
1124
1125static const struct file_operations memtype_fops = {
1126 .open = memtype_seq_open,
1127 .read = seq_read,
1128 .llseek = seq_lseek,
1129 .release = seq_release,
1130};
1131
1132static int __init pat_memtype_list_init(void)
1133{
Luis R. Rodriguezcb32edf2015-05-26 10:28:15 +02001134 if (pat_enabled()) {
Xiaotian Fengdd4377b2009-11-26 19:53:48 +08001135 debugfs_create_file("pat_memtype_list", S_IRUSR,
1136 arch_debugfs_dir, NULL, &memtype_fops);
1137 }
venkatesh.pallipadi@intel.comfec09622008-07-18 16:08:14 -07001138 return 0;
1139}
1140
1141late_initcall(pat_memtype_list_init);
1142
Andreas Herrmann012f09e2008-08-06 16:23:08 +02001143#endif /* CONFIG_DEBUG_FS && CONFIG_X86_PAT */