Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Machine specific setup for xen |
| 3 | * |
| 4 | * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007 |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/mm.h> |
| 10 | #include <linux/pm.h> |
Yinghai Lu | a9ce6bc | 2010-08-25 13:39:17 -0700 | [diff] [blame] | 11 | #include <linux/memblock.h> |
Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 12 | #include <linux/cpuidle.h> |
Konrad Rzeszutek Wilk | 48cdd82 | 2012-03-13 20:06:57 -0400 | [diff] [blame] | 13 | #include <linux/cpufreq.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/elf.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 16 | #include <asm/vdso.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 17 | #include <asm/e820.h> |
| 18 | #include <asm/setup.h> |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 19 | #include <asm/acpi.h> |
Konrad Rzeszutek Wilk | 8d54db79 | 2012-08-17 10:22:37 -0400 | [diff] [blame] | 20 | #include <asm/numa.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 21 | #include <asm/xen/hypervisor.h> |
| 22 | #include <asm/xen/hypercall.h> |
| 23 | |
Ian Campbell | 45263cb | 2010-10-25 16:32:29 -0700 | [diff] [blame] | 24 | #include <xen/xen.h> |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 25 | #include <xen/page.h> |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 26 | #include <xen/interface/callback.h> |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 27 | #include <xen/interface/memory.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 28 | #include <xen/interface/physdev.h> |
| 29 | #include <xen/features.h> |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 30 | #include "xen-ops.h" |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 31 | #include "vdso.h" |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 32 | #include "p2m.h" |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 33 | #include "mmu.h" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 34 | |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 35 | /* Amount of extra memory space we add to the e820 ranges */ |
David Vrabel | 8b5d44a | 2011-09-28 17:46:34 +0100 | [diff] [blame] | 36 | struct xen_memory_region xen_extra_mem[XEN_EXTRA_MEM_MAX_REGIONS] __initdata; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 37 | |
David Vrabel | aa24411 | 2011-09-28 17:46:32 +0100 | [diff] [blame] | 38 | /* Number of pages released from the initial allocation. */ |
| 39 | unsigned long xen_released_pages; |
| 40 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 41 | /* E820 map used during setting up memory. */ |
| 42 | static struct e820entry xen_e820_map[E820MAX] __initdata; |
| 43 | static u32 xen_e820_map_entries __initdata; |
| 44 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 45 | /* |
| 46 | * Buffer used to remap identity mapped pages. We only need the virtual space. |
| 47 | * The physical page behind this address is remapped as needed to different |
| 48 | * buffer pages. |
| 49 | */ |
| 50 | #define REMAP_SIZE (P2M_PER_PAGE - 3) |
| 51 | static struct { |
| 52 | unsigned long next_area_mfn; |
| 53 | unsigned long target_pfn; |
| 54 | unsigned long size; |
| 55 | unsigned long mfns[REMAP_SIZE]; |
| 56 | } xen_remap_buf __initdata __aligned(PAGE_SIZE); |
| 57 | static unsigned long xen_remap_mfn __initdata = INVALID_P2M_ENTRY; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 58 | |
Jeremy Fitzhardinge | 698bb8d | 2010-09-14 10:19:14 -0700 | [diff] [blame] | 59 | /* |
| 60 | * The maximum amount of extra memory compared to the base size. The |
| 61 | * main scaling factor is the size of struct page. At extreme ratios |
| 62 | * of base:extra, all the base memory can be filled with page |
| 63 | * structures for the extra memory, leaving no space for anything |
| 64 | * else. |
| 65 | * |
| 66 | * 10x seems like a reasonable balance between scaling flexibility and |
| 67 | * leaving a practically usable system. |
| 68 | */ |
| 69 | #define EXTRA_MEM_RATIO (10) |
| 70 | |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 71 | static void __init xen_add_extra_mem(phys_addr_t start, phys_addr_t size) |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 72 | { |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 73 | int i; |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 74 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 75 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
| 76 | /* Add new region. */ |
| 77 | if (xen_extra_mem[i].size == 0) { |
| 78 | xen_extra_mem[i].start = start; |
| 79 | xen_extra_mem[i].size = size; |
| 80 | break; |
| 81 | } |
| 82 | /* Append to existing region. */ |
| 83 | if (xen_extra_mem[i].start + xen_extra_mem[i].size == start) { |
| 84 | xen_extra_mem[i].size += size; |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | if (i == XEN_EXTRA_MEM_MAX_REGIONS) |
| 89 | printk(KERN_WARNING "Warning: not enough extra memory regions\n"); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 90 | |
Tejun Heo | d4bbf7e | 2011-11-28 09:46:22 -0800 | [diff] [blame] | 91 | memblock_reserve(start, size); |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 92 | } |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 93 | |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 94 | static void __init xen_del_extra_mem(phys_addr_t start, phys_addr_t size) |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 95 | { |
| 96 | int i; |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 97 | phys_addr_t start_r, size_r; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 98 | |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 99 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
| 100 | start_r = xen_extra_mem[i].start; |
| 101 | size_r = xen_extra_mem[i].size; |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 102 | |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 103 | /* Start of region. */ |
| 104 | if (start_r == start) { |
| 105 | BUG_ON(size > size_r); |
| 106 | xen_extra_mem[i].start += size; |
| 107 | xen_extra_mem[i].size -= size; |
| 108 | break; |
| 109 | } |
| 110 | /* End of region. */ |
| 111 | if (start_r + size_r == start + size) { |
| 112 | BUG_ON(size > size_r); |
| 113 | xen_extra_mem[i].size -= size; |
| 114 | break; |
| 115 | } |
| 116 | /* Mid of region. */ |
| 117 | if (start > start_r && start < start_r + size_r) { |
| 118 | BUG_ON(start + size > start_r + size_r); |
| 119 | xen_extra_mem[i].size = start - start_r; |
| 120 | /* Calling memblock_reserve() again is okay. */ |
| 121 | xen_add_extra_mem(start + size, start_r + size_r - |
| 122 | (start + size)); |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | memblock_free(start, size); |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Called during boot before the p2m list can take entries beyond the |
| 131 | * hypervisor supplied p2m list. Entries in extra mem are to be regarded as |
| 132 | * invalid. |
| 133 | */ |
| 134 | unsigned long __ref xen_chk_extra_mem(unsigned long pfn) |
| 135 | { |
| 136 | int i; |
Juergen Gross | e86f949 | 2015-01-12 06:05:09 +0100 | [diff] [blame] | 137 | phys_addr_t addr = PFN_PHYS(pfn); |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 138 | |
| 139 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
| 140 | if (addr >= xen_extra_mem[i].start && |
| 141 | addr < xen_extra_mem[i].start + xen_extra_mem[i].size) |
| 142 | return INVALID_P2M_ENTRY; |
| 143 | } |
| 144 | |
| 145 | return IDENTITY_FRAME(pfn); |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Mark all pfns of extra mem as invalid in p2m list. |
| 150 | */ |
| 151 | void __init xen_inv_extra_mem(void) |
| 152 | { |
| 153 | unsigned long pfn, pfn_s, pfn_e; |
| 154 | int i; |
| 155 | |
| 156 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
Juergen Gross | 9a17ad7 | 2015-01-12 06:05:10 +0100 | [diff] [blame] | 157 | if (!xen_extra_mem[i].size) |
| 158 | continue; |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 159 | pfn_s = PFN_DOWN(xen_extra_mem[i].start); |
| 160 | pfn_e = PFN_UP(xen_extra_mem[i].start + xen_extra_mem[i].size); |
| 161 | for (pfn = pfn_s; pfn < pfn_e; pfn++) |
| 162 | set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 163 | } |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 166 | /* |
| 167 | * Finds the next RAM pfn available in the E820 map after min_pfn. |
| 168 | * This function updates min_pfn with the pfn found and returns |
| 169 | * the size of that range or zero if not found. |
| 170 | */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 171 | static unsigned long __init xen_find_pfn_range(unsigned long *min_pfn) |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 172 | { |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 173 | const struct e820entry *entry = xen_e820_map; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 174 | unsigned int i; |
| 175 | unsigned long done = 0; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 176 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 177 | for (i = 0; i < xen_e820_map_entries; i++, entry++) { |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 178 | unsigned long s_pfn; |
| 179 | unsigned long e_pfn; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 180 | |
| 181 | if (entry->type != E820_RAM) |
| 182 | continue; |
| 183 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 184 | e_pfn = PFN_DOWN(entry->addr + entry->size); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 185 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 186 | /* We only care about E820 after this */ |
| 187 | if (e_pfn < *min_pfn) |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 188 | continue; |
| 189 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 190 | s_pfn = PFN_UP(entry->addr); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 191 | |
| 192 | /* If min_pfn falls within the E820 entry, we want to start |
| 193 | * at the min_pfn PFN. |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 194 | */ |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 195 | if (s_pfn <= *min_pfn) { |
| 196 | done = e_pfn - *min_pfn; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 197 | } else { |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 198 | done = e_pfn - s_pfn; |
| 199 | *min_pfn = s_pfn; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 200 | } |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 201 | break; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 202 | } |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 203 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 204 | return done; |
| 205 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 206 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 207 | static int __init xen_free_mfn(unsigned long mfn) |
| 208 | { |
| 209 | struct xen_memory_reservation reservation = { |
| 210 | .address_bits = 0, |
| 211 | .extent_order = 0, |
| 212 | .domid = DOMID_SELF |
| 213 | }; |
| 214 | |
| 215 | set_xen_guest_handle(reservation.extent_start, &mfn); |
| 216 | reservation.nr_extents = 1; |
| 217 | |
| 218 | return HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation); |
| 219 | } |
| 220 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 221 | /* |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 222 | * This releases a chunk of memory and then does the identity map. It's used |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 223 | * as a fallback if the remapping fails. |
| 224 | */ |
| 225 | static void __init xen_set_identity_and_release_chunk(unsigned long start_pfn, |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 226 | unsigned long end_pfn, unsigned long nr_pages, unsigned long *released) |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 227 | { |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 228 | unsigned long pfn, end; |
| 229 | int ret; |
| 230 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 231 | WARN_ON(start_pfn > end_pfn); |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 232 | |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 233 | /* Release pages first. */ |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 234 | end = min(end_pfn, nr_pages); |
| 235 | for (pfn = start_pfn; pfn < end; pfn++) { |
| 236 | unsigned long mfn = pfn_to_mfn(pfn); |
| 237 | |
| 238 | /* Make sure pfn exists to start with */ |
| 239 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) |
| 240 | continue; |
| 241 | |
| 242 | ret = xen_free_mfn(mfn); |
| 243 | WARN(ret != 1, "Failed to release pfn %lx err=%d\n", pfn, ret); |
| 244 | |
| 245 | if (ret == 1) { |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 246 | (*released)++; |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 247 | if (!__set_phys_to_machine(pfn, INVALID_P2M_ENTRY)) |
| 248 | break; |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 249 | } else |
| 250 | break; |
| 251 | } |
| 252 | |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 253 | set_phys_range_identity(start_pfn, end_pfn); |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 254 | } |
| 255 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 256 | /* |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 257 | * Helper function to update the p2m and m2p tables and kernel mapping. |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 258 | */ |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 259 | static void __init xen_update_mem_tables(unsigned long pfn, unsigned long mfn) |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 260 | { |
| 261 | struct mmu_update update = { |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 262 | .ptr = ((uint64_t)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 263 | .val = pfn |
| 264 | }; |
| 265 | |
| 266 | /* Update p2m */ |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 267 | if (!set_phys_to_machine(pfn, mfn)) { |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 268 | WARN(1, "Failed to set p2m mapping for pfn=%ld mfn=%ld\n", |
| 269 | pfn, mfn); |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 270 | BUG(); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* Update m2p */ |
| 274 | if (HYPERVISOR_mmu_update(&update, 1, NULL, DOMID_SELF) < 0) { |
| 275 | WARN(1, "Failed to set m2p mapping for mfn=%ld pfn=%ld\n", |
| 276 | mfn, pfn); |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 277 | BUG(); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 280 | /* Update kernel mapping, but not for highmem. */ |
Juergen Gross | e86f949 | 2015-01-12 06:05:09 +0100 | [diff] [blame] | 281 | if (pfn >= PFN_UP(__pa(high_memory - 1))) |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 282 | return; |
| 283 | |
| 284 | if (HYPERVISOR_update_va_mapping((unsigned long)__va(pfn << PAGE_SHIFT), |
| 285 | mfn_pte(mfn, PAGE_KERNEL), 0)) { |
| 286 | WARN(1, "Failed to update kernel mapping for mfn=%ld pfn=%ld\n", |
| 287 | mfn, pfn); |
| 288 | BUG(); |
| 289 | } |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /* |
| 293 | * This function updates the p2m and m2p tables with an identity map from |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 294 | * start_pfn to start_pfn+size and prepares remapping the underlying RAM of the |
| 295 | * original allocation at remap_pfn. The information needed for remapping is |
| 296 | * saved in the memory itself to avoid the need for allocating buffers. The |
| 297 | * complete remap information is contained in a list of MFNs each containing |
| 298 | * up to REMAP_SIZE MFNs and the start target PFN for doing the remap. |
| 299 | * This enables us to preserve the original mfn sequence while doing the |
| 300 | * remapping at a time when the memory management is capable of allocating |
| 301 | * virtual and physical memory in arbitrary amounts, see 'xen_remap_memory' and |
| 302 | * its callers. |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 303 | */ |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 304 | static void __init xen_do_set_identity_and_remap_chunk( |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 305 | unsigned long start_pfn, unsigned long size, unsigned long remap_pfn) |
| 306 | { |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 307 | unsigned long buf = (unsigned long)&xen_remap_buf; |
| 308 | unsigned long mfn_save, mfn; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 309 | unsigned long ident_pfn_iter, remap_pfn_iter; |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 310 | unsigned long ident_end_pfn = start_pfn + size; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 311 | unsigned long left = size; |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 312 | unsigned int i, chunk; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 313 | |
| 314 | WARN_ON(size == 0); |
| 315 | |
| 316 | BUG_ON(xen_feature(XENFEAT_auto_translated_physmap)); |
| 317 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 318 | mfn_save = virt_to_mfn(buf); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 319 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 320 | for (ident_pfn_iter = start_pfn, remap_pfn_iter = remap_pfn; |
| 321 | ident_pfn_iter < ident_end_pfn; |
| 322 | ident_pfn_iter += REMAP_SIZE, remap_pfn_iter += REMAP_SIZE) { |
| 323 | chunk = (left < REMAP_SIZE) ? left : REMAP_SIZE; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 324 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 325 | /* Map first pfn to xen_remap_buf */ |
| 326 | mfn = pfn_to_mfn(ident_pfn_iter); |
| 327 | set_pte_mfn(buf, mfn, PAGE_KERNEL); |
| 328 | |
| 329 | /* Save mapping information in page */ |
| 330 | xen_remap_buf.next_area_mfn = xen_remap_mfn; |
| 331 | xen_remap_buf.target_pfn = remap_pfn_iter; |
| 332 | xen_remap_buf.size = chunk; |
| 333 | for (i = 0; i < chunk; i++) |
| 334 | xen_remap_buf.mfns[i] = pfn_to_mfn(ident_pfn_iter + i); |
| 335 | |
| 336 | /* Put remap buf into list. */ |
| 337 | xen_remap_mfn = mfn; |
| 338 | |
| 339 | /* Set identity map */ |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 340 | set_phys_range_identity(ident_pfn_iter, ident_pfn_iter + chunk); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 341 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 342 | left -= chunk; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 345 | /* Restore old xen_remap_buf mapping */ |
| 346 | set_pte_mfn(buf, mfn_save, PAGE_KERNEL); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
| 350 | * This function takes a contiguous pfn range that needs to be identity mapped |
| 351 | * and: |
| 352 | * |
| 353 | * 1) Finds a new range of pfns to use to remap based on E820 and remap_pfn. |
| 354 | * 2) Calls the do_ function to actually do the mapping/remapping work. |
| 355 | * |
| 356 | * The goal is to not allocate additional memory but to remap the existing |
| 357 | * pages. In the case of an error the underlying memory is simply released back |
| 358 | * to Xen and not remapped. |
| 359 | */ |
Juergen Gross | 76f0a48 | 2014-12-08 06:32:19 +0100 | [diff] [blame] | 360 | static unsigned long __init xen_set_identity_and_remap_chunk( |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 361 | unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, |
| 362 | unsigned long remap_pfn, unsigned long *released, |
| 363 | unsigned long *remapped) |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 364 | { |
| 365 | unsigned long pfn; |
| 366 | unsigned long i = 0; |
| 367 | unsigned long n = end_pfn - start_pfn; |
| 368 | |
| 369 | while (i < n) { |
| 370 | unsigned long cur_pfn = start_pfn + i; |
| 371 | unsigned long left = n - i; |
| 372 | unsigned long size = left; |
| 373 | unsigned long remap_range_size; |
| 374 | |
| 375 | /* Do not remap pages beyond the current allocation */ |
| 376 | if (cur_pfn >= nr_pages) { |
| 377 | /* Identity map remaining pages */ |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 378 | set_phys_range_identity(cur_pfn, cur_pfn + size); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 379 | break; |
| 380 | } |
| 381 | if (cur_pfn + size > nr_pages) |
| 382 | size = nr_pages - cur_pfn; |
| 383 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 384 | remap_range_size = xen_find_pfn_range(&remap_pfn); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 385 | if (!remap_range_size) { |
| 386 | pr_warning("Unable to find available pfn range, not remapping identity pages\n"); |
| 387 | xen_set_identity_and_release_chunk(cur_pfn, |
David Vrabel | bc7142c | 2015-01-07 11:01:08 +0000 | [diff] [blame] | 388 | cur_pfn + left, nr_pages, released); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 389 | break; |
| 390 | } |
| 391 | /* Adjust size to fit in current e820 RAM region */ |
| 392 | if (size > remap_range_size) |
| 393 | size = remap_range_size; |
| 394 | |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 395 | xen_do_set_identity_and_remap_chunk(cur_pfn, size, remap_pfn); |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 396 | |
| 397 | /* Update variables to reflect new mappings. */ |
| 398 | i += size; |
| 399 | remap_pfn += size; |
David Vrabel | a97dae1 | 2015-01-07 11:21:50 +0000 | [diff] [blame] | 400 | *remapped += size; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* |
| 404 | * If the PFNs are currently mapped, the VA mapping also needs |
| 405 | * to be updated to be 1:1. |
| 406 | */ |
| 407 | for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) |
| 408 | (void)HYPERVISOR_update_va_mapping( |
| 409 | (unsigned long)__va(pfn << PAGE_SHIFT), |
| 410 | mfn_pte(pfn, PAGE_KERNEL_IO), 0); |
| 411 | |
| 412 | return remap_pfn; |
| 413 | } |
| 414 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 415 | static void __init xen_set_identity_and_remap(unsigned long nr_pages, |
| 416 | unsigned long *released, unsigned long *remapped) |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 417 | { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 418 | phys_addr_t start = 0; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 419 | unsigned long last_pfn = nr_pages; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 420 | const struct e820entry *entry = xen_e820_map; |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 421 | unsigned long num_released = 0; |
David Vrabel | a97dae1 | 2015-01-07 11:21:50 +0000 | [diff] [blame] | 422 | unsigned long num_remapped = 0; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 423 | int i; |
| 424 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 425 | /* |
| 426 | * Combine non-RAM regions and gaps until a RAM region (or the |
| 427 | * end of the map) is reached, then set the 1:1 map and |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 428 | * remap the memory in those non-RAM regions. |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 429 | * |
| 430 | * The combined non-RAM regions are rounded to a whole number |
| 431 | * of pages so any partial pages are accessible via the 1:1 |
| 432 | * mapping. This is needed for some BIOSes that put (for |
| 433 | * example) the DMI tables in a reserved region that begins on |
| 434 | * a non-page boundary. |
| 435 | */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 436 | for (i = 0; i < xen_e820_map_entries; i++, entry++) { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 437 | phys_addr_t end = entry->addr + entry->size; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 438 | if (entry->type == E820_RAM || i == xen_e820_map_entries - 1) { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 439 | unsigned long start_pfn = PFN_DOWN(start); |
| 440 | unsigned long end_pfn = PFN_UP(end); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 441 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 442 | if (entry->type == E820_RAM) |
| 443 | end_pfn = PFN_UP(entry->addr); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 444 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 445 | if (start_pfn < end_pfn) |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 446 | last_pfn = xen_set_identity_and_remap_chunk( |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 447 | start_pfn, end_pfn, nr_pages, |
| 448 | last_pfn, &num_released, |
| 449 | &num_remapped); |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 450 | start = end; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 451 | } |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 452 | } |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 453 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 454 | *released = num_released; |
David Vrabel | a97dae1 | 2015-01-07 11:21:50 +0000 | [diff] [blame] | 455 | *remapped = num_remapped; |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 456 | |
Matt Rushton | 4fbb67e3 | 2014-08-11 11:57:57 -0700 | [diff] [blame] | 457 | pr_info("Released %ld page(s)\n", num_released); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 458 | } |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 459 | |
| 460 | /* |
| 461 | * Remap the memory prepared in xen_do_set_identity_and_remap_chunk(). |
| 462 | * The remap information (which mfn remap to which pfn) is contained in the |
| 463 | * to be remapped memory itself in a linked list anchored at xen_remap_mfn. |
| 464 | * This scheme allows to remap the different chunks in arbitrary order while |
| 465 | * the resulting mapping will be independant from the order. |
| 466 | */ |
| 467 | void __init xen_remap_memory(void) |
| 468 | { |
| 469 | unsigned long buf = (unsigned long)&xen_remap_buf; |
| 470 | unsigned long mfn_save, mfn, pfn; |
| 471 | unsigned long remapped = 0; |
| 472 | unsigned int i; |
| 473 | unsigned long pfn_s = ~0UL; |
| 474 | unsigned long len = 0; |
| 475 | |
| 476 | mfn_save = virt_to_mfn(buf); |
| 477 | |
| 478 | while (xen_remap_mfn != INVALID_P2M_ENTRY) { |
| 479 | /* Map the remap information */ |
| 480 | set_pte_mfn(buf, xen_remap_mfn, PAGE_KERNEL); |
| 481 | |
| 482 | BUG_ON(xen_remap_mfn != xen_remap_buf.mfns[0]); |
| 483 | |
| 484 | pfn = xen_remap_buf.target_pfn; |
| 485 | for (i = 0; i < xen_remap_buf.size; i++) { |
| 486 | mfn = xen_remap_buf.mfns[i]; |
| 487 | xen_update_mem_tables(pfn, mfn); |
| 488 | remapped++; |
| 489 | pfn++; |
| 490 | } |
| 491 | if (pfn_s == ~0UL || pfn == pfn_s) { |
| 492 | pfn_s = xen_remap_buf.target_pfn; |
| 493 | len += xen_remap_buf.size; |
| 494 | } else if (pfn_s + len == xen_remap_buf.target_pfn) { |
| 495 | len += xen_remap_buf.size; |
| 496 | } else { |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 497 | xen_del_extra_mem(PFN_PHYS(pfn_s), PFN_PHYS(len)); |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 498 | pfn_s = xen_remap_buf.target_pfn; |
| 499 | len = xen_remap_buf.size; |
| 500 | } |
| 501 | |
| 502 | mfn = xen_remap_mfn; |
| 503 | xen_remap_mfn = xen_remap_buf.next_area_mfn; |
| 504 | } |
| 505 | |
| 506 | if (pfn_s != ~0UL && len) |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 507 | xen_del_extra_mem(PFN_PHYS(pfn_s), PFN_PHYS(len)); |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 508 | |
| 509 | set_pte_mfn(buf, mfn_save, PAGE_KERNEL); |
| 510 | |
| 511 | pr_info("Remapped %ld page(s)\n", remapped); |
| 512 | } |
| 513 | |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 514 | static unsigned long __init xen_get_max_pages(void) |
| 515 | { |
| 516 | unsigned long max_pages = MAX_DOMAIN_PAGES; |
| 517 | domid_t domid = DOMID_SELF; |
| 518 | int ret; |
| 519 | |
Ian Campbell | d3db728 | 2011-12-14 12:16:08 +0000 | [diff] [blame] | 520 | /* |
| 521 | * For the initial domain we use the maximum reservation as |
| 522 | * the maximum page. |
| 523 | * |
| 524 | * For guest domains the current maximum reservation reflects |
| 525 | * the current maximum rather than the static maximum. In this |
| 526 | * case the e820 map provided to us will cover the static |
| 527 | * maximum region. |
| 528 | */ |
| 529 | if (xen_initial_domain()) { |
| 530 | ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); |
| 531 | if (ret > 0) |
| 532 | max_pages = ret; |
| 533 | } |
| 534 | |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 535 | return min(max_pages, MAX_DOMAIN_PAGES); |
| 536 | } |
| 537 | |
Juergen Gross | a3f5239 | 2015-01-28 07:44:23 +0100 | [diff] [blame] | 538 | static void __init xen_align_and_add_e820_region(phys_addr_t start, |
| 539 | phys_addr_t size, int type) |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 540 | { |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 541 | phys_addr_t end = start + size; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 542 | |
| 543 | /* Align RAM regions to page boundaries. */ |
| 544 | if (type == E820_RAM) { |
| 545 | start = PAGE_ALIGN(start); |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 546 | end &= ~((phys_addr_t)PAGE_SIZE - 1); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | e820_add_region(start, end - start, type); |
| 550 | } |
| 551 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 552 | static void __init xen_ignore_unusable(void) |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 553 | { |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 554 | struct e820entry *entry = xen_e820_map; |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 555 | unsigned int i; |
| 556 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 557 | for (i = 0; i < xen_e820_map_entries; i++, entry++) { |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 558 | if (entry->type == E820_UNUSABLE) |
| 559 | entry->type = E820_RAM; |
| 560 | } |
| 561 | } |
| 562 | |
Juergen Gross | 8f5b0c6 | 2015-07-17 06:51:25 +0200 | [diff] [blame] | 563 | /* |
| 564 | * Reserve Xen mfn_list. |
| 565 | * See comment above "struct start_info" in <xen/interface/xen.h> |
| 566 | * We tried to make the the memblock_reserve more selective so |
| 567 | * that it would be clear what region is reserved. Sadly we ran |
| 568 | * in the problem wherein on a 64-bit hypervisor with a 32-bit |
| 569 | * initial domain, the pt_base has the cr3 value which is not |
| 570 | * neccessarily where the pagetable starts! As Jan put it: " |
| 571 | * Actually, the adjustment turns out to be correct: The page |
| 572 | * tables for a 32-on-64 dom0 get allocated in the order "first L1", |
| 573 | * "first L2", "first L3", so the offset to the page table base is |
| 574 | * indeed 2. When reading xen/include/public/xen.h's comment |
| 575 | * very strictly, this is not a violation (since there nothing is said |
| 576 | * that the first thing in the page table space is pointed to by |
| 577 | * pt_base; I admit that this seems to be implied though, namely |
| 578 | * do I think that it is implied that the page table space is the |
| 579 | * range [pt_base, pt_base + nt_pt_frames), whereas that |
| 580 | * range here indeed is [pt_base - 2, pt_base - 2 + nt_pt_frames), |
| 581 | * which - without a priori knowledge - the kernel would have |
| 582 | * difficulty to figure out)." - so lets just fall back to the |
| 583 | * easy way and reserve the whole region. |
| 584 | */ |
| 585 | static void __init xen_reserve_xen_mfnlist(void) |
| 586 | { |
| 587 | if (xen_start_info->mfn_list >= __START_KERNEL_map) { |
| 588 | memblock_reserve(__pa(xen_start_info->mfn_list), |
| 589 | xen_start_info->pt_base - |
| 590 | xen_start_info->mfn_list); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | memblock_reserve(PFN_PHYS(xen_start_info->first_p2m_pfn), |
| 595 | PFN_PHYS(xen_start_info->nr_p2m_frames)); |
| 596 | } |
| 597 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 598 | /** |
| 599 | * machine_specific_memory_setup - Hook for machine specific memory setup. |
| 600 | **/ |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 601 | char * __init xen_memory_setup(void) |
| 602 | { |
| 603 | unsigned long max_pfn = xen_start_info->nr_pages; |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 604 | phys_addr_t mem_end; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 605 | int rc; |
| 606 | struct xen_memory_map memmap; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 607 | unsigned long max_pages; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 608 | unsigned long extra_pages = 0; |
David Vrabel | a97dae1 | 2015-01-07 11:21:50 +0000 | [diff] [blame] | 609 | unsigned long remapped_pages; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 610 | int i; |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 611 | int op; |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 612 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 613 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 614 | mem_end = PFN_PHYS(max_pfn); |
| 615 | |
| 616 | memmap.nr_entries = E820MAX; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 617 | set_xen_guest_handle(memmap.buffer, xen_e820_map); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 618 | |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 619 | op = xen_initial_domain() ? |
| 620 | XENMEM_machine_memory_map : |
| 621 | XENMEM_memory_map; |
| 622 | rc = HYPERVISOR_memory_op(op, &memmap); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 623 | if (rc == -ENOSYS) { |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 624 | BUG_ON(xen_initial_domain()); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 625 | memmap.nr_entries = 1; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 626 | xen_e820_map[0].addr = 0ULL; |
| 627 | xen_e820_map[0].size = mem_end; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 628 | /* 8MB slack (to balance backend allocations). */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 629 | xen_e820_map[0].size += 8ULL << 20; |
| 630 | xen_e820_map[0].type = E820_RAM; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 631 | rc = 0; |
| 632 | } |
| 633 | BUG_ON(rc); |
Martin Kelly | 1ea644c | 2014-10-16 20:48:11 -0700 | [diff] [blame] | 634 | BUG_ON(memmap.nr_entries == 0); |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 635 | xen_e820_map_entries = memmap.nr_entries; |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 636 | |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 637 | /* |
| 638 | * Xen won't allow a 1:1 mapping to be created to UNUSABLE |
| 639 | * regions, so if we're using the machine memory map leave the |
| 640 | * region as RAM as it is in the pseudo-physical map. |
| 641 | * |
| 642 | * UNUSABLE regions in domUs are not handled and will need |
| 643 | * a patch in the future. |
| 644 | */ |
| 645 | if (xen_initial_domain()) |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 646 | xen_ignore_unusable(); |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 647 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 648 | /* Make sure the Xen-supplied memory map is well-ordered. */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 649 | sanitize_e820_map(xen_e820_map, xen_e820_map_entries, |
| 650 | &xen_e820_map_entries); |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 651 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 652 | max_pages = xen_get_max_pages(); |
| 653 | if (max_pages > max_pfn) |
| 654 | extra_pages += max_pages - max_pfn; |
Stefano Stabellini | 7cb31b7 | 2011-01-27 10:13:25 -0500 | [diff] [blame] | 655 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 656 | /* |
Juergen Gross | 1f3ac86 | 2014-11-28 11:53:53 +0100 | [diff] [blame] | 657 | * Set identity map on non-RAM pages and prepare remapping the |
| 658 | * underlying RAM. |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 659 | */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 660 | xen_set_identity_and_remap(max_pfn, &xen_released_pages, |
| 661 | &remapped_pages); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 662 | |
Konrad Rzeszutek Wilk | 58b7b53 | 2012-05-29 12:36:43 -0400 | [diff] [blame] | 663 | extra_pages += xen_released_pages; |
David Vrabel | a97dae1 | 2015-01-07 11:21:50 +0000 | [diff] [blame] | 664 | extra_pages += remapped_pages; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 665 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 666 | /* |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 667 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO |
| 668 | * factor the base size. On non-highmem systems, the base |
| 669 | * size is the full initial memory allocation; on highmem it |
| 670 | * is limited to the max size of lowmem, so that it doesn't |
| 671 | * get completely filled. |
| 672 | * |
| 673 | * In principle there could be a problem in lowmem systems if |
| 674 | * the initial memory is also very large with respect to |
| 675 | * lowmem, but we won't try to deal with that here. |
| 676 | */ |
| 677 | extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), |
| 678 | extra_pages); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 679 | i = 0; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 680 | while (i < xen_e820_map_entries) { |
| 681 | phys_addr_t addr = xen_e820_map[i].addr; |
| 682 | phys_addr_t size = xen_e820_map[i].size; |
| 683 | u32 type = xen_e820_map[i].type; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 684 | |
| 685 | if (type == E820_RAM) { |
| 686 | if (addr < mem_end) { |
| 687 | size = min(size, mem_end - addr); |
| 688 | } else if (extra_pages) { |
Juergen Gross | 3ba5c86 | 2015-01-28 07:44:22 +0100 | [diff] [blame] | 689 | size = min(size, PFN_PHYS(extra_pages)); |
| 690 | extra_pages -= PFN_DOWN(size); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 691 | xen_add_extra_mem(addr, size); |
Juergen Gross | 5b8e7d8 | 2014-11-28 11:53:55 +0100 | [diff] [blame] | 692 | xen_max_p2m_pfn = PFN_DOWN(addr + size); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 693 | } else |
| 694 | type = E820_UNUSABLE; |
Jeremy Fitzhardinge | 3654581 | 2010-09-29 16:54:33 -0700 | [diff] [blame] | 695 | } |
| 696 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 697 | xen_align_and_add_e820_region(addr, size, type); |
Jeremy Fitzhardinge | b5b43ce | 2010-09-02 17:10:12 -0700 | [diff] [blame] | 698 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 699 | xen_e820_map[i].addr += size; |
| 700 | xen_e820_map[i].size -= size; |
| 701 | if (xen_e820_map[i].size == 0) |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 702 | i++; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 703 | } |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 704 | |
| 705 | /* |
David Vrabel | 25b884a | 2014-01-03 15:46:10 +0000 | [diff] [blame] | 706 | * Set the rest as identity mapped, in case PCI BARs are |
| 707 | * located here. |
| 708 | * |
| 709 | * PFNs above MAX_P2M_PFN are considered identity mapped as |
| 710 | * well. |
| 711 | */ |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 712 | set_phys_range_identity(xen_e820_map[i - 1].addr / PAGE_SIZE, ~0ul); |
David Vrabel | 25b884a | 2014-01-03 15:46:10 +0000 | [diff] [blame] | 713 | |
| 714 | /* |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 715 | * In domU, the ISA region is normal, usable memory, but we |
| 716 | * reserve ISA memory anyway because too many things poke |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 717 | * about in there. |
| 718 | */ |
| 719 | e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, |
| 720 | E820_RESERVED); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 721 | |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 722 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); |
| 723 | |
Juergen Gross | 8f5b0c6 | 2015-07-17 06:51:25 +0200 | [diff] [blame] | 724 | xen_reserve_xen_mfnlist(); |
| 725 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 726 | return "Xen"; |
| 727 | } |
| 728 | |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 729 | /* |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 730 | * Machine specific memory setup for auto-translated guests. |
| 731 | */ |
| 732 | char * __init xen_auto_xlated_memory_setup(void) |
| 733 | { |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 734 | struct xen_memory_map memmap; |
| 735 | int i; |
| 736 | int rc; |
| 737 | |
| 738 | memmap.nr_entries = E820MAX; |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 739 | set_xen_guest_handle(memmap.buffer, xen_e820_map); |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 740 | |
| 741 | rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); |
| 742 | if (rc < 0) |
| 743 | panic("No memory map (%d)\n", rc); |
| 744 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 745 | xen_e820_map_entries = memmap.nr_entries; |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 746 | |
Juergen Gross | 69632ec | 2015-07-17 06:51:26 +0200 | [diff] [blame^] | 747 | sanitize_e820_map(xen_e820_map, ARRAY_SIZE(xen_e820_map), |
| 748 | &xen_e820_map_entries); |
| 749 | |
| 750 | for (i = 0; i < xen_e820_map_entries; i++) |
| 751 | e820_add_region(xen_e820_map[i].addr, xen_e820_map[i].size, |
| 752 | xen_e820_map[i].type); |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 753 | |
Juergen Gross | 8f5b0c6 | 2015-07-17 06:51:25 +0200 | [diff] [blame] | 754 | xen_reserve_xen_mfnlist(); |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 755 | |
| 756 | return "Xen"; |
| 757 | } |
| 758 | |
| 759 | /* |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 760 | * Set the bit indicating "nosegneg" library variants should be used. |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 761 | * We only need to bother in pure 32-bit mode; compat 32-bit processes |
| 762 | * can have un-truncated segments, so wrapping around is allowed. |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 763 | */ |
Sam Ravnborg | 08b6d29 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 764 | static void __init fiddle_vdso(void) |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 765 | { |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 766 | #ifdef CONFIG_X86_32 |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 767 | /* |
| 768 | * This could be called before selected_vdso32 is initialized, so |
| 769 | * just fiddle with both possible images. vdso_image_32_syscall |
| 770 | * can't be selected, since it only exists on 64-bit systems. |
| 771 | */ |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 772 | u32 *mask; |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 773 | mask = vdso_image_32_int80.data + |
| 774 | vdso_image_32_int80.sym_VDSO32_NOTE_MASK; |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 775 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 776 | mask = vdso_image_32_sysenter.data + |
| 777 | vdso_image_32_sysenter.sym_VDSO32_NOTE_MASK; |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 778 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 779 | #endif |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 782 | static int register_callback(unsigned type, const void *func) |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 783 | { |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 784 | struct callback_register callback = { |
| 785 | .type = type, |
| 786 | .address = XEN_CALLBACK(__KERNEL_CS, func), |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 787 | .flags = CALLBACKF_mask_events, |
| 788 | }; |
| 789 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 790 | return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); |
| 791 | } |
| 792 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 793 | void xen_enable_sysenter(void) |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 794 | { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 795 | int ret; |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 796 | unsigned sysenter_feature; |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 797 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 798 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 799 | sysenter_feature = X86_FEATURE_SEP; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 800 | #else |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 801 | sysenter_feature = X86_FEATURE_SYSENTER32; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 802 | #endif |
| 803 | |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 804 | if (!boot_cpu_has(sysenter_feature)) |
| 805 | return; |
| 806 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 807 | ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 808 | if(ret != 0) |
| 809 | setup_clear_cpu_cap(sysenter_feature); |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 812 | void xen_enable_syscall(void) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 813 | { |
| 814 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 815 | int ret; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 816 | |
| 817 | ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target); |
| 818 | if (ret != 0) { |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 819 | printk(KERN_ERR "Failed to set syscall callback: %d\n", ret); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 820 | /* Pretty fatal; 64-bit userspace has no other |
| 821 | mechanism for syscalls. */ |
| 822 | } |
| 823 | |
| 824 | if (boot_cpu_has(X86_FEATURE_SYSCALL32)) { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 825 | ret = register_callback(CALLBACKTYPE_syscall32, |
| 826 | xen_syscall32_target); |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 827 | if (ret != 0) |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 828 | setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 829 | } |
| 830 | #endif /* CONFIG_X86_64 */ |
| 831 | } |
David Vrabel | ea9f927 | 2014-06-16 13:07:00 +0200 | [diff] [blame] | 832 | |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 833 | void __init xen_pvmmu_arch_setup(void) |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 834 | { |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 835 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); |
| 836 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); |
| 837 | |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 838 | HYPERVISOR_vm_assist(VMASST_CMD_enable, |
| 839 | VMASST_TYPE_pae_extended_cr3); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 840 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 841 | if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) || |
| 842 | register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) |
| 843 | BUG(); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 844 | |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 845 | xen_enable_sysenter(); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 846 | xen_enable_syscall(); |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | /* This function is not called for HVM domains */ |
| 850 | void __init xen_arch_setup(void) |
| 851 | { |
| 852 | xen_panic_handler_init(); |
| 853 | if (!xen_feature(XENFEAT_auto_translated_physmap)) |
| 854 | xen_pvmmu_arch_setup(); |
| 855 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 856 | #ifdef CONFIG_ACPI |
| 857 | if (!(xen_start_info->flags & SIF_INITDOMAIN)) { |
| 858 | printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); |
| 859 | disable_acpi(); |
| 860 | } |
| 861 | #endif |
| 862 | |
| 863 | memcpy(boot_command_line, xen_start_info->cmd_line, |
| 864 | MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? |
| 865 | COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); |
| 866 | |
Jeremy Fitzhardinge | bc15fde | 2010-11-22 17:17:50 -0800 | [diff] [blame] | 867 | /* Set up idle, making sure it calls safe_halt() pvop */ |
Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 868 | disable_cpuidle(); |
Konrad Rzeszutek Wilk | 48cdd82 | 2012-03-13 20:06:57 -0400 | [diff] [blame] | 869 | disable_cpufreq(); |
Len Brown | 6a377dd | 2013-02-09 23:08:07 -0500 | [diff] [blame] | 870 | WARN_ON(xen_set_default_idle()); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 871 | fiddle_vdso(); |
Konrad Rzeszutek Wilk | 8d54db79 | 2012-08-17 10:22:37 -0400 | [diff] [blame] | 872 | #ifdef CONFIG_NUMA |
| 873 | numa_off = 1; |
| 874 | #endif |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 875 | } |