]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
4ef50cc8e15b7bbb75ac428b170d0ed7e5e4f2d4
[thirdparty/kernel/stable-queue.git] /
1 From 281ff33b7c1b1ba2a5f9b03425e5f692a94913fa Mon Sep 17 00:00:00 2001
2 From: Suresh Siddha <suresh.b.siddha@intel.com>
3 Date: Thu, 18 Feb 2010 11:51:40 -0800
4 Subject: x86_64, cpa: Don't work hard in preserving kernel 2M mappings when using 4K already
5
6 From: Suresh Siddha <suresh.b.siddha@intel.com>
7
8 commit 281ff33b7c1b1ba2a5f9b03425e5f692a94913fa upstream.
9
10 We currently enforce the !RW mapping for the kernel mapping that maps
11 holes between different text, rodata and data sections. However, kernel
12 identity mappings will have different RWX permissions to the pages mapping to
13 text and to the pages padding (which are freed) the text, rodata sections.
14 Hence kernel identity mappings will be broken to smaller pages. For 64-bit,
15 kernel text and kernel identity mappings are different, so we can enable
16 protection checks that come with CONFIG_DEBUG_RODATA, as well as retain 2MB
17 large page mappings for kernel text.
18
19 Konrad reported a boot failure with the Linux Xen paravirt guest because of
20 this. In this paravirt guest case, the kernel text mapping and the kernel
21 identity mapping share the same page-table pages. Thus forcing the !RW mapping
22 for some of the kernel mappings also cause the kernel identity mappings to be
23 read-only resulting in the boot failure. Linux Xen paravirt guest also
24 uses 4k mappings and don't use 2M mapping.
25
26 Fix this issue and retain large page performance advantage for native kernels
27 by not working hard and not enforcing !RW for the kernel text mapping,
28 if the current mapping is already using small page mapping.
29
30 Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
31 Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
32 LKML-Reference: <1266522700.2909.34.camel@sbs-t61.sc.intel.com>
33 Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
34 Signed-off-by: H. Peter Anvin <hpa@zytor.com>
35 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
36
37 ---
38 arch/x86/mm/pageattr.c | 25 +++++++++++++++++++++++--
39 1 file changed, 23 insertions(+), 2 deletions(-)
40
41 --- a/arch/x86/mm/pageattr.c
42 +++ b/arch/x86/mm/pageattr.c
43 @@ -291,8 +291,29 @@ static inline pgprot_t static_protection
44 */
45 if (kernel_set_to_readonly &&
46 within(address, (unsigned long)_text,
47 - (unsigned long)__end_rodata_hpage_align))
48 - pgprot_val(forbidden) |= _PAGE_RW;
49 + (unsigned long)__end_rodata_hpage_align)) {
50 + unsigned int level;
51 +
52 + /*
53 + * Don't enforce the !RW mapping for the kernel text mapping,
54 + * if the current mapping is already using small page mapping.
55 + * No need to work hard to preserve large page mappings in this
56 + * case.
57 + *
58 + * This also fixes the Linux Xen paravirt guest boot failure
59 + * (because of unexpected read-only mappings for kernel identity
60 + * mappings). In this paravirt guest case, the kernel text
61 + * mapping and the kernel identity mapping share the same
62 + * page-table pages. Thus we can't really use different
63 + * protections for the kernel text and identity mappings. Also,
64 + * these shared mappings are made of small page mappings.
65 + * Thus this don't enforce !RW mapping for small page kernel
66 + * text mapping logic will help Linux Xen parvirt guest boot
67 + * aswell.
68 + */
69 + if (lookup_address(address, &level) && (level != PG_LEVEL_4K))
70 + pgprot_val(forbidden) |= _PAGE_RW;
71 + }
72 #endif
73
74 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));