Skip to content

Commit 2f9e897

Browse files
mcgrofingomolnar
authored andcommitted
x86/mm/mtrr, pat: Document Write Combining MTRR type effects on PAT / non-PAT pages
As part of the effort to phase out MTRR use document write-combining MTRR effects on pages with different non-PAT page attributes flags and different PAT entry values. Extend arch_phys_wc_add() documentation to clarify power of two sizes / boundary requirements as we phase out mtrr_add() use. Lastly hint towards ioremap_uc() for corner cases on device drivers working with devices with mixed regions where MTRR size requirements would otherwise not enable write-combining effective memory types. Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com> Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Antonino Daplas <adaplas@gmail.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: Dave Airlie <airlied@redhat.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Davidlohr Bueso <dbueso@suse.de> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Juergen Gross <jgross@suse.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Suresh Siddha <sbsiddha@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com> Cc: Ville Syrjälä <syrjala@sci.fi> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: linux-fbdev@vger.kernel.org Link: http://lkml.kernel.org/r/1430343851-967-3-git-send-email-mcgrof@do-not-panic.com Link: http://lkml.kernel.org/r/1432628901-18044-10-git-send-email-bp@alien8.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9e76561 commit 2f9e897

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎Documentation/x86/mtrr.txt‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
MTRR (Memory Type Range Register) control
2-
3 Jun 1999
3-
Richard Gooch
4-
<rgooch@atnf.csiro.au>
2+
3+
Richard Gooch <rgooch@atnf.csiro.au> - 3 Jun 1999
4+
Luis R. Rodriguez <mcgrof@do-not-panic.com> - April 9, 2015
5+
6+
===============================================================================
7+
Phasing out MTRR use
8+
9+
MTRR use is replaced on modern x86 hardware with PAT. Over time the only type
10+
of effective MTRR that is expected to be supported will be for write-combining.
11+
As MTRR use is phased out device drivers should use arch_phys_wc_add() to make
12+
MTRR effective on non-PAT systems while a no-op on PAT enabled systems.
13+
14+
For details refer to Documentation/x86/pat.txt.
15+
16+
===============================================================================
517

618
On Intel P6 family processors (Pentium Pro, Pentium II and later)
719
the Memory Type Range Registers (MTRRs) may be used to control

‎Documentation/x86/pat.txt‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ ioremap | -- | UC- | UC- |
3434
| | | |
3535
ioremap_cache | -- | WB | WB |
3636
| | | |
37+
ioremap_uc | -- | UC | UC |
38+
| | | |
3739
ioremap_nocache | -- | UC- | UC- |
3840
| | | |
3941
ioremap_wc | -- | -- | WC |
@@ -102,7 +104,38 @@ wants to export a RAM region, it has to do set_memory_uc() or set_memory_wc()
102104
as step 0 above and also track the usage of those pages and use set_memory_wb()
103105
before the page is freed to free pool.
104106

105-
107+
MTRR effects on PAT / non-PAT systems
108+
-------------------------------------
109+
110+
The following table provides the effects of using write-combining MTRRs when
111+
using ioremap*() calls on x86 for both non-PAT and PAT systems. Ideally
112+
mtrr_add() usage will be phased out in favor of arch_phys_wc_add() which will
113+
be a no-op on PAT enabled systems. The region over which a arch_phys_wc_add()
114+
is made, should already have been ioremapped with WC attributes or PAT entries,
115+
this can be done by using ioremap_wc() / set_memory_wc(). Devices which
116+
combine areas of IO memory desired to remain uncacheable with areas where
117+
write-combining is desirable should consider use of ioremap_uc() followed by
118+
set_memory_wc() to white-list effective write-combined areas. Such use is
119+
nevertheless discouraged as the effective memory type is considered
120+
implementation defined, yet this strategy can be used as last resort on devices
121+
with size-constrained regions where otherwise MTRR write-combining would
122+
otherwise not be effective.
123+
124+
----------------------------------------------------------------------
125+
MTRR Non-PAT PAT Linux ioremap value Effective memory type
126+
----------------------------------------------------------------------
127+
Non-PAT | PAT
128+
PAT
129+
|PCD
130+
||PWT
131+
|||
132+
WC 000 WB _PAGE_CACHE_MODE_WB WC | WC
133+
WC 001 WC _PAGE_CACHE_MODE_WC WC* | WC
134+
WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS WC* | UC
135+
WC 011 UC _PAGE_CACHE_MODE_UC UC | UC
136+
----------------------------------------------------------------------
137+
138+
(*) denotes implementation defined and is discouraged
106139

107140
Notes:
108141

‎arch/x86/kernel/cpu/mtrr/main.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ EXPORT_SYMBOL(mtrr_del);
538538
* attempts to add a WC MTRR covering size bytes starting at base and
539539
* logs an error if this fails.
540540
*
541+
* The called should provide a power of two size on an equivalent
542+
* power of two boundary.
543+
*
541544
* Drivers must store the return value to pass to mtrr_del_wc_if_needed,
542545
* but drivers should not try to interpret that return value.
543546
*/

0 commit comments

Comments
 (0)