diff options
Diffstat (limited to 'arch/x86/xen/setup.c')
-rw-r--r-- | arch/x86/xen/setup.c | 170 |
1 files changed, 144 insertions, 26 deletions
diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index 1ba8dff26753..a4790bf22c59 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c | |||
@@ -26,7 +26,6 @@ | |||
26 | #include <xen/interface/memory.h> | 26 | #include <xen/interface/memory.h> |
27 | #include <xen/interface/physdev.h> | 27 | #include <xen/interface/physdev.h> |
28 | #include <xen/features.h> | 28 | #include <xen/features.h> |
29 | |||
30 | #include "xen-ops.h" | 29 | #include "xen-ops.h" |
31 | #include "vdso.h" | 30 | #include "vdso.h" |
32 | 31 | ||
@@ -84,8 +83,8 @@ static void __init xen_add_extra_mem(u64 start, u64 size) | |||
84 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); | 83 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
85 | } | 84 | } |
86 | 85 | ||
87 | static unsigned long __init xen_release_chunk(unsigned long start, | 86 | static unsigned long __init xen_do_chunk(unsigned long start, |
88 | unsigned long end) | 87 | unsigned long end, bool release) |
89 | { | 88 | { |
90 | struct xen_memory_reservation reservation = { | 89 | struct xen_memory_reservation reservation = { |
91 | .address_bits = 0, | 90 | .address_bits = 0, |
@@ -96,30 +95,138 @@ static unsigned long __init xen_release_chunk(unsigned long start, | |||
96 | unsigned long pfn; | 95 | unsigned long pfn; |
97 | int ret; | 96 | int ret; |
98 | 97 | ||
99 | for(pfn = start; pfn < end; pfn++) { | 98 | for (pfn = start; pfn < end; pfn++) { |
99 | unsigned long frame; | ||
100 | unsigned long mfn = pfn_to_mfn(pfn); | 100 | unsigned long mfn = pfn_to_mfn(pfn); |
101 | 101 | ||
102 | /* Make sure pfn exists to start with */ | 102 | if (release) { |
103 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) | 103 | /* Make sure pfn exists to start with */ |
104 | continue; | 104 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) |
105 | 105 | continue; | |
106 | set_xen_guest_handle(reservation.extent_start, &mfn); | 106 | frame = mfn; |
107 | } else { | ||
108 | if (mfn != INVALID_P2M_ENTRY) | ||
109 | continue; | ||
110 | frame = pfn; | ||
111 | } | ||
112 | set_xen_guest_handle(reservation.extent_start, &frame); | ||
107 | reservation.nr_extents = 1; | 113 | reservation.nr_extents = 1; |
108 | 114 | ||
109 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, | 115 | ret = HYPERVISOR_memory_op(release ? XENMEM_decrease_reservation : XENMEM_populate_physmap, |
110 | &reservation); | 116 | &reservation); |
111 | WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret); | 117 | WARN(ret != 1, "Failed to %s pfn %lx err=%d\n", |
118 | release ? "release" : "populate", pfn, ret); | ||
119 | |||
112 | if (ret == 1) { | 120 | if (ret == 1) { |
113 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); | 121 | if (!early_set_phys_to_machine(pfn, release ? INVALID_P2M_ENTRY : frame)) { |
122 | if (release) | ||
123 | break; | ||
124 | set_xen_guest_handle(reservation.extent_start, &frame); | ||
125 | reservation.nr_extents = 1; | ||
126 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, | ||
127 | &reservation); | ||
128 | break; | ||
129 | } | ||
114 | len++; | 130 | len++; |
115 | } | 131 | } else |
132 | break; | ||
116 | } | 133 | } |
117 | printk(KERN_INFO "Freeing %lx-%lx pfn range: %lu pages freed\n", | 134 | if (len) |
118 | start, end, len); | 135 | printk(KERN_INFO "%s %lx-%lx pfn range: %lu pages %s\n", |
136 | release ? "Freeing" : "Populating", | ||
137 | start, end, len, | ||
138 | release ? "freed" : "added"); | ||
119 | 139 | ||
120 | return len; | 140 | return len; |
121 | } | 141 | } |
122 | 142 | ||
143 | static unsigned long __init xen_release_chunk(unsigned long start, | ||
144 | unsigned long end) | ||
145 | { | ||
146 | return xen_do_chunk(start, end, true); | ||
147 | } | ||
148 | |||
149 | static unsigned long __init xen_populate_chunk( | ||
150 | const struct e820entry *list, size_t map_size, | ||
151 | unsigned long max_pfn, unsigned long *last_pfn, | ||
152 | unsigned long credits_left) | ||
153 | { | ||
154 | const struct e820entry *entry; | ||
155 | unsigned int i; | ||
156 | unsigned long done = 0; | ||
157 | unsigned long dest_pfn; | ||
158 | |||
159 | for (i = 0, entry = list; i < map_size; i++, entry++) { | ||
160 | unsigned long credits = credits_left; | ||
161 | unsigned long s_pfn; | ||
162 | unsigned long e_pfn; | ||
163 | unsigned long pfns; | ||
164 | long capacity; | ||
165 | |||
166 | if (credits <= 0) | ||
167 | break; | ||
168 | |||
169 | if (entry->type != E820_RAM) | ||
170 | continue; | ||
171 | |||
172 | e_pfn = PFN_UP(entry->addr + entry->size); | ||
173 | |||
174 | /* We only care about E820 after the xen_start_info->nr_pages */ | ||
175 | if (e_pfn <= max_pfn) | ||
176 | continue; | ||
177 | |||
178 | s_pfn = PFN_DOWN(entry->addr); | ||
179 | /* If the E820 falls within the nr_pages, we want to start | ||
180 | * at the nr_pages PFN. | ||
181 | * If that would mean going past the E820 entry, skip it | ||
182 | */ | ||
183 | if (s_pfn <= max_pfn) { | ||
184 | capacity = e_pfn - max_pfn; | ||
185 | dest_pfn = max_pfn; | ||
186 | } else { | ||
187 | /* last_pfn MUST be within E820_RAM regions */ | ||
188 | if (*last_pfn && e_pfn >= *last_pfn) | ||
189 | s_pfn = *last_pfn; | ||
190 | capacity = e_pfn - s_pfn; | ||
191 | dest_pfn = s_pfn; | ||
192 | } | ||
193 | /* If we had filled this E820_RAM entry, go to the next one. */ | ||
194 | if (capacity <= 0) | ||
195 | continue; | ||
196 | |||
197 | if (credits > capacity) | ||
198 | credits = capacity; | ||
199 | |||
200 | pfns = xen_do_chunk(dest_pfn, dest_pfn + credits, false); | ||
201 | done += pfns; | ||
202 | credits_left -= pfns; | ||
203 | *last_pfn = (dest_pfn + pfns); | ||
204 | } | ||
205 | return done; | ||
206 | } | ||
207 | |||
208 | static void __init xen_set_identity_and_release_chunk( | ||
209 | unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, | ||
210 | unsigned long *released, unsigned long *identity) | ||
211 | { | ||
212 | unsigned long pfn; | ||
213 | |||
214 | /* | ||
215 | * If the PFNs are currently mapped, the VA mapping also needs | ||
216 | * to be updated to be 1:1. | ||
217 | */ | ||
218 | for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) | ||
219 | (void)HYPERVISOR_update_va_mapping( | ||
220 | (unsigned long)__va(pfn << PAGE_SHIFT), | ||
221 | mfn_pte(pfn, PAGE_KERNEL_IO), 0); | ||
222 | |||
223 | if (start_pfn < nr_pages) | ||
224 | *released += xen_release_chunk( | ||
225 | start_pfn, min(end_pfn, nr_pages)); | ||
226 | |||
227 | *identity += set_phys_range_identity(start_pfn, end_pfn); | ||
228 | } | ||
229 | |||
123 | static unsigned long __init xen_set_identity_and_release( | 230 | static unsigned long __init xen_set_identity_and_release( |
124 | const struct e820entry *list, size_t map_size, unsigned long nr_pages) | 231 | const struct e820entry *list, size_t map_size, unsigned long nr_pages) |
125 | { | 232 | { |
@@ -142,7 +249,6 @@ static unsigned long __init xen_set_identity_and_release( | |||
142 | */ | 249 | */ |
143 | for (i = 0, entry = list; i < map_size; i++, entry++) { | 250 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
144 | phys_addr_t end = entry->addr + entry->size; | 251 | phys_addr_t end = entry->addr + entry->size; |
145 | |||
146 | if (entry->type == E820_RAM || i == map_size - 1) { | 252 | if (entry->type == E820_RAM || i == map_size - 1) { |
147 | unsigned long start_pfn = PFN_DOWN(start); | 253 | unsigned long start_pfn = PFN_DOWN(start); |
148 | unsigned long end_pfn = PFN_UP(end); | 254 | unsigned long end_pfn = PFN_UP(end); |
@@ -150,20 +256,19 @@ static unsigned long __init xen_set_identity_and_release( | |||
150 | if (entry->type == E820_RAM) | 256 | if (entry->type == E820_RAM) |
151 | end_pfn = PFN_UP(entry->addr); | 257 | end_pfn = PFN_UP(entry->addr); |
152 | 258 | ||
153 | if (start_pfn < end_pfn) { | 259 | if (start_pfn < end_pfn) |
154 | if (start_pfn < nr_pages) | 260 | xen_set_identity_and_release_chunk( |
155 | released += xen_release_chunk( | 261 | start_pfn, end_pfn, nr_pages, |
156 | start_pfn, min(end_pfn, nr_pages)); | 262 | &released, &identity); |
157 | 263 | ||
158 | identity += set_phys_range_identity( | ||
159 | start_pfn, end_pfn); | ||
160 | } | ||
161 | start = end; | 264 | start = end; |
162 | } | 265 | } |
163 | } | 266 | } |
164 | 267 | ||
165 | printk(KERN_INFO "Released %lu pages of unused memory\n", released); | 268 | if (released) |
166 | printk(KERN_INFO "Set %ld page(s) to 1-1 mapping\n", identity); | 269 | printk(KERN_INFO "Released %lu pages of unused memory\n", released); |
270 | if (identity) | ||
271 | printk(KERN_INFO "Set %ld page(s) to 1-1 mapping\n", identity); | ||
167 | 272 | ||
168 | return released; | 273 | return released; |
169 | } | 274 | } |
@@ -217,7 +322,9 @@ char * __init xen_memory_setup(void) | |||
217 | int rc; | 322 | int rc; |
218 | struct xen_memory_map memmap; | 323 | struct xen_memory_map memmap; |
219 | unsigned long max_pages; | 324 | unsigned long max_pages; |
325 | unsigned long last_pfn = 0; | ||
220 | unsigned long extra_pages = 0; | 326 | unsigned long extra_pages = 0; |
327 | unsigned long populated; | ||
221 | int i; | 328 | int i; |
222 | int op; | 329 | int op; |
223 | 330 | ||
@@ -257,8 +364,20 @@ char * __init xen_memory_setup(void) | |||
257 | */ | 364 | */ |
258 | xen_released_pages = xen_set_identity_and_release( | 365 | xen_released_pages = xen_set_identity_and_release( |
259 | map, memmap.nr_entries, max_pfn); | 366 | map, memmap.nr_entries, max_pfn); |
367 | |||
368 | /* | ||
369 | * Populate back the non-RAM pages and E820 gaps that had been | ||
370 | * released. */ | ||
371 | populated = xen_populate_chunk(map, memmap.nr_entries, | ||
372 | max_pfn, &last_pfn, xen_released_pages); | ||
373 | |||
374 | xen_released_pages -= populated; | ||
260 | extra_pages += xen_released_pages; | 375 | extra_pages += xen_released_pages; |
261 | 376 | ||
377 | if (last_pfn > max_pfn) { | ||
378 | max_pfn = min(MAX_DOMAIN_PAGES, last_pfn); | ||
379 | mem_end = PFN_PHYS(max_pfn); | ||
380 | } | ||
262 | /* | 381 | /* |
263 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO | 382 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO |
264 | * factor the base size. On non-highmem systems, the base | 383 | * factor the base size. On non-highmem systems, the base |
@@ -272,7 +391,6 @@ char * __init xen_memory_setup(void) | |||
272 | */ | 391 | */ |
273 | extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), | 392 | extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), |
274 | extra_pages); | 393 | extra_pages); |
275 | |||
276 | i = 0; | 394 | i = 0; |
277 | while (i < memmap.nr_entries) { | 395 | while (i < memmap.nr_entries) { |
278 | u64 addr = map[i].addr; | 396 | u64 addr = map[i].addr; |