forked from clearlinux-pkgs/linux-iot-lts2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0012-x86-mm-cpa-Avoid-the-4k-pages-check-completely.patch
171 lines (155 loc) · 6.19 KB
/
0012-x86-mm-cpa-Avoid-the-4k-pages-check-completely.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From bb1e569b89ee3b9f5128d5eb6ac15e5a41b084cd Mon Sep 17 00:00:00 2001
From: Thomas Gleixner <[email protected]>
Date: Mon, 17 Sep 2018 16:29:17 +0200
Subject: [PATCH 12/12] x86/mm/cpa: Avoid the 4k pages check completely
The extra loop which tries hard to preserve large pages in case of conflicts
with static protection regions turns out to be not preserving anything, at
least not in the experiments which have been conducted.
There might be corner cases in which the code would be able to preserve a
large page oaccsionally, but it's really not worth the extra code and the
cycles wasted in the common case.
Before:
1G pages checked: 2
1G pages sameprot: 0
1G pages preserved: 0
2M pages checked: 541
2M pages sameprot: 466
2M pages preserved: 47
4K pages checked: 514
4K pages set-checked: 7668
After:
1G pages checked: 2
1G pages sameprot: 0
1G pages preserved: 0
2M pages checked: 538
2M pages sameprot: 466
2M pages preserved: 47
4K pages set-checked: 7668
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Dave Hansen <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Bin Yang <[email protected]>
Cc: Mark Gross <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Cc: Zhang Ning <[email protected]>
Signed-off-by: Lili Li <[email protected]>
---
arch/x86/mm/pageattr.c | 64 +++++++++++-------------------------------
1 file changed, 16 insertions(+), 48 deletions(-)
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index bbc5eb5cbc9d..4e55ded01be5 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -111,7 +111,6 @@ static unsigned long cpa_1g_preserved;
static unsigned long cpa_2m_checked;
static unsigned long cpa_2m_sameprot;
static unsigned long cpa_2m_preserved;
-static unsigned long cpa_4k_checked;
static unsigned long cpa_4k_install;
static inline void cpa_inc_1g_checked(void)
@@ -124,11 +123,6 @@ static inline void cpa_inc_2m_checked(void)
cpa_2m_checked++;
}
-static inline void cpa_inc_4k_checked(void)
-{
- cpa_4k_checked++;
-}
-
static inline void cpa_inc_4k_install(void)
{
cpa_4k_install++;
@@ -158,7 +152,6 @@ static int cpastats_show(struct seq_file *m, void *p)
seq_printf(m, "2M pages checked: %16lu\n", cpa_2m_checked);
seq_printf(m, "2M pages sameprot: %16lu\n", cpa_2m_sameprot);
seq_printf(m, "2M pages preserved: %16lu\n", cpa_2m_preserved);
- seq_printf(m, "4K pages checked: %16lu\n", cpa_4k_checked);
seq_printf(m, "4K pages set-checked: %16lu\n", cpa_4k_install);
return 0;
}
@@ -185,7 +178,6 @@ late_initcall(cpa_stats_init);
#else
static inline void cpa_inc_1g_checked(void) { }
static inline void cpa_inc_2m_checked(void) { }
-static inline void cpa_inc_4k_checked(void) { }
static inline void cpa_inc_4k_install(void) { }
static inline void cpa_inc_lp_sameprot(int level) { }
static inline void cpa_inc_lp_preserved(int level) { }
@@ -745,11 +737,10 @@ static pgprot_t pgprot_clear_protnone_bits(pgprot_t prot)
static int __should_split_large_page(pte_t *kpte, unsigned long address,
struct cpa_data *cpa)
{
- unsigned long numpages, pmask, psize, lpaddr, addr, pfn, old_pfn;
+ unsigned long numpages, pmask, psize, lpaddr, pfn, old_pfn;
pgprot_t old_prot, new_prot, req_prot, chk_prot;
pte_t new_pte, old_pte, *tmp;
enum pg_level level;
- int i;
/*
* Check for races, another CPU might have split this page
@@ -854,53 +845,30 @@ static int __should_split_large_page(pte_t *kpte, unsigned long address,
}
/*
- * Optimization: Check whether the requested pgprot is conflicting
- * with a static protection requirement in the large page. If not,
- * then checking whether the requested range is fully covering the
- * large page can be done right here.
+ * If the requested range does not cover the full page, split it up
*/
- new_prot = static_protections(req_prot, lpaddr, old_pfn, numpages,
- CPA_DETECT);
-
- if (pgprot_val(req_prot) == pgprot_val(new_prot)) {
- if (address != lpaddr || cpa->numpages != numpages)
- return 1;
- goto setlp;
- }
+ if (address != lpaddr || cpa->numpages != numpages)
+ return 1;
/*
- * Slow path. The full large page check above established that the
- * requested pgprot cannot be applied to the full large page due to
- * conflicting requirements of static protection regions. It might
- * turn out that the whole requested range is covered by the
- * modified protection of the first 4k segment at @address. This
- * might result in the ability to preserve the large page
- * nevertheless.
+ * Check whether the requested pgprot is conflicting with a static
+ * protection requirement in the large page.
*/
- new_prot = static_protections(req_prot, address, pfn, 1, CPA_DETECT);
- pfn = old_pfn;
- for (i = 0, addr = lpaddr; i < numpages; i++, addr += PAGE_SIZE, pfn++) {
- chk_prot = static_protections(req_prot, addr, pfn, 1,
- CPA_DETECT);
- cpa_inc_4k_checked();
- if (pgprot_val(chk_prot) != pgprot_val(new_prot))
- return 1;
- }
-
- /* If there are no changes, return. */
- if (pgprot_val(new_prot) == pgprot_val(old_prot)) {
- cpa_inc_lp_sameprot(level);
- return 0;
- }
+ new_prot = static_protections(req_prot, lpaddr, old_pfn, numpages,
+ CPA_DETECT);
/*
- * Verify that the address is aligned and the number of pages
- * covers the full page.
+ * If there is a conflict, split the large page.
+ *
+ * There used to be a 4k wise evaluation trying really hard to
+ * preserve the large pages, but experimentation has shown, that this
+ * does not help at all. There might be corner cases which would
+ * preserve one large page occasionally, but it's really not worth the
+ * extra code and cycles for the common case.
*/
- if (address != lpaddr || cpa->numpages != numpages)
+ if (pgprot_val(req_prot) != pgprot_val(new_prot))
return 1;
-setlp:
/* All checks passed. Update the large page mapping. */
new_pte = pfn_pte(old_pfn, new_prot);
__set_pmd_pte(kpte, address, new_pte);
--
2.19.1