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" |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 32 | |
| 33 | /* These are code, but not functions. Defined in entry.S */ |
| 34 | extern const char xen_hypervisor_callback[]; |
| 35 | extern const char xen_failsafe_callback[]; |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 36 | #ifdef CONFIG_X86_64 |
Andi Kleen | 07ba06d | 2013-10-22 09:07:59 -0700 | [diff] [blame] | 37 | extern asmlinkage void nmi(void); |
Konrad Rzeszutek Wilk | 6efa20e | 2013-07-19 11:51:31 -0400 | [diff] [blame] | 38 | #endif |
Tej | f63c2f2 | 2008-12-16 11:56:06 -0800 | [diff] [blame] | 39 | extern void xen_sysenter_target(void); |
| 40 | extern void xen_syscall_target(void); |
| 41 | extern void xen_syscall32_target(void); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 42 | |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 43 | /* Amount of extra memory space we add to the e820 ranges */ |
David Vrabel | 8b5d44a | 2011-09-28 17:46:34 +0100 | [diff] [blame] | 44 | 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] | 45 | |
David Vrabel | aa24411 | 2011-09-28 17:46:32 +0100 | [diff] [blame] | 46 | /* Number of pages released from the initial allocation. */ |
| 47 | unsigned long xen_released_pages; |
| 48 | |
Jeremy Fitzhardinge | 698bb8d | 2010-09-14 10:19:14 -0700 | [diff] [blame] | 49 | /* |
| 50 | * The maximum amount of extra memory compared to the base size. The |
| 51 | * main scaling factor is the size of struct page. At extreme ratios |
| 52 | * of base:extra, all the base memory can be filled with page |
| 53 | * structures for the extra memory, leaving no space for anything |
| 54 | * else. |
| 55 | * |
| 56 | * 10x seems like a reasonable balance between scaling flexibility and |
| 57 | * leaving a practically usable system. |
| 58 | */ |
| 59 | #define EXTRA_MEM_RATIO (10) |
| 60 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 61 | static void __init xen_add_extra_mem(u64 start, u64 size) |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 62 | { |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 63 | unsigned long pfn; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 64 | int i; |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 65 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 66 | for (i = 0; i < XEN_EXTRA_MEM_MAX_REGIONS; i++) { |
| 67 | /* Add new region. */ |
| 68 | if (xen_extra_mem[i].size == 0) { |
| 69 | xen_extra_mem[i].start = start; |
| 70 | xen_extra_mem[i].size = size; |
| 71 | break; |
| 72 | } |
| 73 | /* Append to existing region. */ |
| 74 | if (xen_extra_mem[i].start + xen_extra_mem[i].size == start) { |
| 75 | xen_extra_mem[i].size += size; |
| 76 | break; |
| 77 | } |
| 78 | } |
| 79 | if (i == XEN_EXTRA_MEM_MAX_REGIONS) |
| 80 | printk(KERN_WARNING "Warning: not enough extra memory regions\n"); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 81 | |
Tejun Heo | d4bbf7e | 2011-11-28 09:46:22 -0800 | [diff] [blame] | 82 | memblock_reserve(start, size); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 83 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 84 | xen_max_p2m_pfn = PFN_DOWN(start + size); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 85 | for (pfn = PFN_DOWN(start); pfn < xen_max_p2m_pfn; pfn++) { |
| 86 | unsigned long mfn = pfn_to_mfn(pfn); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 87 | |
David Vrabel | 2dcc9a3 | 2014-01-07 11:36:53 +0000 | [diff] [blame] | 88 | if (WARN_ONCE(mfn == pfn, "Trying to over-write 1-1 mapping (pfn: %lx)\n", pfn)) |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 89 | continue; |
David Vrabel | 2dcc9a3 | 2014-01-07 11:36:53 +0000 | [diff] [blame] | 90 | WARN_ONCE(mfn != INVALID_P2M_ENTRY, "Trying to remove %lx which has %lx mfn!\n", |
| 91 | pfn, mfn); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 92 | |
Konrad Rzeszutek Wilk | 6eaa412 | 2011-01-18 20:09:41 -0500 | [diff] [blame] | 93 | __set_phys_to_machine(pfn, INVALID_P2M_ENTRY); |
Konrad Rzeszutek Wilk | c96aae1 | 2012-08-17 16:43:28 -0400 | [diff] [blame] | 94 | } |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 97 | static unsigned long __init xen_do_chunk(unsigned long start, |
| 98 | unsigned long end, bool release) |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 99 | { |
| 100 | struct xen_memory_reservation reservation = { |
| 101 | .address_bits = 0, |
| 102 | .extent_order = 0, |
| 103 | .domid = DOMID_SELF |
| 104 | }; |
Jeremy Fitzhardinge | f89e048 | 2009-09-16 12:38:33 -0700 | [diff] [blame] | 105 | unsigned long len = 0; |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 106 | unsigned long pfn; |
| 107 | int ret; |
| 108 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 109 | for (pfn = start; pfn < end; pfn++) { |
| 110 | unsigned long frame; |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 111 | unsigned long mfn = pfn_to_mfn(pfn); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 112 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 113 | if (release) { |
| 114 | /* Make sure pfn exists to start with */ |
| 115 | if (mfn == INVALID_P2M_ENTRY || mfn_to_pfn(mfn) != pfn) |
| 116 | continue; |
| 117 | frame = mfn; |
| 118 | } else { |
David Vrabel | 562658f | 2014-06-02 17:53:06 +0100 | [diff] [blame] | 119 | if (mfn != INVALID_P2M_ENTRY) |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 120 | continue; |
| 121 | frame = pfn; |
| 122 | } |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 123 | set_xen_guest_handle(reservation.extent_start, &frame); |
| 124 | reservation.nr_extents = 1; |
| 125 | |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 126 | ret = HYPERVISOR_memory_op(release ? XENMEM_decrease_reservation : XENMEM_populate_physmap, |
| 127 | &reservation); |
| 128 | WARN(ret != 1, "Failed to %s pfn %lx err=%d\n", |
| 129 | release ? "release" : "populate", pfn, ret); |
| 130 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 131 | if (ret == 1) { |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 132 | if (!early_set_phys_to_machine(pfn, release ? INVALID_P2M_ENTRY : frame)) { |
| 133 | if (release) |
| 134 | break; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 135 | set_xen_guest_handle(reservation.extent_start, &frame); |
| 136 | reservation.nr_extents = 1; |
| 137 | ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 138 | &reservation); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 139 | break; |
| 140 | } |
| 141 | len++; |
| 142 | } else |
| 143 | break; |
| 144 | } |
| 145 | if (len) |
Konrad Rzeszutek Wilk | 96dc08b | 2012-04-06 16:10:20 -0400 | [diff] [blame] | 146 | printk(KERN_INFO "%s %lx-%lx pfn range: %lu pages %s\n", |
| 147 | release ? "Freeing" : "Populating", |
| 148 | start, end, len, |
| 149 | release ? "freed" : "added"); |
| 150 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 151 | return len; |
| 152 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 153 | |
| 154 | static unsigned long __init xen_release_chunk(unsigned long start, |
| 155 | unsigned long end) |
| 156 | { |
| 157 | return xen_do_chunk(start, end, true); |
| 158 | } |
| 159 | |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 160 | static unsigned long __init xen_populate_chunk( |
| 161 | const struct e820entry *list, size_t map_size, |
| 162 | unsigned long max_pfn, unsigned long *last_pfn, |
| 163 | unsigned long credits_left) |
| 164 | { |
| 165 | const struct e820entry *entry; |
| 166 | unsigned int i; |
| 167 | unsigned long done = 0; |
| 168 | unsigned long dest_pfn; |
| 169 | |
| 170 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 171 | unsigned long s_pfn; |
| 172 | unsigned long e_pfn; |
| 173 | unsigned long pfns; |
| 174 | long capacity; |
| 175 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 176 | if (credits_left <= 0) |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 177 | break; |
| 178 | |
| 179 | if (entry->type != E820_RAM) |
| 180 | continue; |
| 181 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 182 | e_pfn = PFN_DOWN(entry->addr + entry->size); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 183 | |
| 184 | /* We only care about E820 after the xen_start_info->nr_pages */ |
| 185 | if (e_pfn <= max_pfn) |
| 186 | continue; |
| 187 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 188 | s_pfn = PFN_UP(entry->addr); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 189 | /* If the E820 falls within the nr_pages, we want to start |
| 190 | * at the nr_pages PFN. |
| 191 | * If that would mean going past the E820 entry, skip it |
| 192 | */ |
| 193 | if (s_pfn <= max_pfn) { |
| 194 | capacity = e_pfn - max_pfn; |
| 195 | dest_pfn = max_pfn; |
| 196 | } else { |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 197 | capacity = e_pfn - s_pfn; |
| 198 | dest_pfn = s_pfn; |
| 199 | } |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 200 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 201 | if (credits_left < capacity) |
| 202 | capacity = credits_left; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 203 | |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 204 | pfns = xen_do_chunk(dest_pfn, dest_pfn + capacity, false); |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 205 | done += pfns; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 206 | *last_pfn = (dest_pfn + pfns); |
zhenzhong.duan | c3d93f8 | 2012-07-18 13:06:39 +0800 | [diff] [blame] | 207 | if (pfns < capacity) |
| 208 | break; |
| 209 | credits_left -= pfns; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 210 | } |
| 211 | return done; |
| 212 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 213 | |
| 214 | static void __init xen_set_identity_and_release_chunk( |
| 215 | unsigned long start_pfn, unsigned long end_pfn, unsigned long nr_pages, |
| 216 | unsigned long *released, unsigned long *identity) |
| 217 | { |
| 218 | unsigned long pfn; |
| 219 | |
| 220 | /* |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 221 | * If the PFNs are currently mapped, clear the mappings |
| 222 | * (except for the ISA region which must be 1:1 mapped) to |
| 223 | * release the refcounts (in Xen) on the original frames. |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 224 | */ |
David Vrabel | 562658f | 2014-06-02 17:53:06 +0100 | [diff] [blame] | 225 | for (pfn = start_pfn; pfn <= max_pfn_mapped && pfn < end_pfn; pfn++) { |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 226 | pte_t pte = __pte_ma(0); |
| 227 | |
| 228 | if (pfn < PFN_UP(ISA_END_ADDRESS)) |
| 229 | pte = mfn_pte(pfn, PAGE_KERNEL_IO); |
| 230 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 231 | (void)HYPERVISOR_update_va_mapping( |
David Vrabel | e201bfc | 2013-07-22 15:29:00 +0100 | [diff] [blame] | 232 | (unsigned long)__va(pfn << PAGE_SHIFT), pte, 0); |
| 233 | } |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 234 | |
| 235 | if (start_pfn < nr_pages) |
| 236 | *released += xen_release_chunk( |
| 237 | start_pfn, min(end_pfn, nr_pages)); |
| 238 | |
| 239 | *identity += set_phys_range_identity(start_pfn, end_pfn); |
| 240 | } |
| 241 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 242 | static unsigned long __init xen_set_identity_and_release( |
| 243 | const struct e820entry *list, size_t map_size, unsigned long nr_pages) |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 244 | { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 245 | phys_addr_t start = 0; |
Miroslav Rezanina | 093d7b4 | 2009-09-16 03:56:17 -0400 | [diff] [blame] | 246 | unsigned long released = 0; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 247 | unsigned long identity = 0; |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 248 | const struct e820entry *entry; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 249 | int i; |
| 250 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 251 | /* |
| 252 | * Combine non-RAM regions and gaps until a RAM region (or the |
| 253 | * end of the map) is reached, then set the 1:1 map and |
| 254 | * release the pages (if available) in those non-RAM regions. |
| 255 | * |
| 256 | * The combined non-RAM regions are rounded to a whole number |
| 257 | * of pages so any partial pages are accessible via the 1:1 |
| 258 | * mapping. This is needed for some BIOSes that put (for |
| 259 | * example) the DMI tables in a reserved region that begins on |
| 260 | * a non-page boundary. |
| 261 | */ |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 262 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 263 | phys_addr_t end = entry->addr + entry->size; |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 264 | if (entry->type == E820_RAM || i == map_size - 1) { |
| 265 | unsigned long start_pfn = PFN_DOWN(start); |
| 266 | unsigned long end_pfn = PFN_UP(end); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 267 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 268 | if (entry->type == E820_RAM) |
| 269 | end_pfn = PFN_UP(entry->addr); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 270 | |
David Vrabel | 83d51ab | 2012-05-03 16:15:42 +0100 | [diff] [blame] | 271 | if (start_pfn < end_pfn) |
| 272 | xen_set_identity_and_release_chunk( |
| 273 | start_pfn, end_pfn, nr_pages, |
| 274 | &released, &identity); |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 275 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 276 | start = end; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 277 | } |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 278 | } |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 279 | |
Konrad Rzeszutek Wilk | ca11823 | 2012-03-30 15:37:07 -0400 | [diff] [blame] | 280 | if (released) |
| 281 | printk(KERN_INFO "Released %lu pages of unused memory\n", released); |
| 282 | if (identity) |
| 283 | printk(KERN_INFO "Set %ld page(s) to 1-1 mapping\n", identity); |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 284 | |
| 285 | return released; |
Konrad Rzeszutek Wilk | 68df0da | 2011-02-01 17:15:30 -0500 | [diff] [blame] | 286 | } |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 287 | |
| 288 | static unsigned long __init xen_get_max_pages(void) |
| 289 | { |
| 290 | unsigned long max_pages = MAX_DOMAIN_PAGES; |
| 291 | domid_t domid = DOMID_SELF; |
| 292 | int ret; |
| 293 | |
Ian Campbell | d3db728 | 2011-12-14 12:16:08 +0000 | [diff] [blame] | 294 | /* |
| 295 | * For the initial domain we use the maximum reservation as |
| 296 | * the maximum page. |
| 297 | * |
| 298 | * For guest domains the current maximum reservation reflects |
| 299 | * the current maximum rather than the static maximum. In this |
| 300 | * case the e820 map provided to us will cover the static |
| 301 | * maximum region. |
| 302 | */ |
| 303 | if (xen_initial_domain()) { |
| 304 | ret = HYPERVISOR_memory_op(XENMEM_maximum_reservation, &domid); |
| 305 | if (ret > 0) |
| 306 | max_pages = ret; |
| 307 | } |
| 308 | |
David Vrabel | d312ae87 | 2011-08-19 15:57:16 +0100 | [diff] [blame] | 309 | return min(max_pages, MAX_DOMAIN_PAGES); |
| 310 | } |
| 311 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 312 | static void xen_align_and_add_e820_region(u64 start, u64 size, int type) |
| 313 | { |
| 314 | u64 end = start + size; |
| 315 | |
| 316 | /* Align RAM regions to page boundaries. */ |
| 317 | if (type == E820_RAM) { |
| 318 | start = PAGE_ALIGN(start); |
| 319 | end &= ~((u64)PAGE_SIZE - 1); |
| 320 | } |
| 321 | |
| 322 | e820_add_region(start, end - start, type); |
| 323 | } |
| 324 | |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 325 | void xen_ignore_unusable(struct e820entry *list, size_t map_size) |
| 326 | { |
| 327 | struct e820entry *entry; |
| 328 | unsigned int i; |
| 329 | |
| 330 | for (i = 0, entry = list; i < map_size; i++, entry++) { |
| 331 | if (entry->type == E820_UNUSABLE) |
| 332 | entry->type = E820_RAM; |
| 333 | } |
| 334 | } |
| 335 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 336 | /** |
| 337 | * machine_specific_memory_setup - Hook for machine specific memory setup. |
| 338 | **/ |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 339 | char * __init xen_memory_setup(void) |
| 340 | { |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 341 | static struct e820entry map[E820MAX] __initdata; |
| 342 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 343 | unsigned long max_pfn = xen_start_info->nr_pages; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 344 | unsigned long long mem_end; |
| 345 | int rc; |
| 346 | struct xen_memory_map memmap; |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 347 | unsigned long max_pages; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 348 | unsigned long last_pfn = 0; |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 349 | unsigned long extra_pages = 0; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 350 | unsigned long populated; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 351 | int i; |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 352 | int op; |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 353 | |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 354 | max_pfn = min(MAX_DOMAIN_PAGES, max_pfn); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 355 | mem_end = PFN_PHYS(max_pfn); |
| 356 | |
| 357 | memmap.nr_entries = E820MAX; |
| 358 | set_xen_guest_handle(memmap.buffer, map); |
| 359 | |
Ian Campbell | 9e9a5fc | 2010-09-02 16:16:00 +0100 | [diff] [blame] | 360 | op = xen_initial_domain() ? |
| 361 | XENMEM_machine_memory_map : |
| 362 | XENMEM_memory_map; |
| 363 | rc = HYPERVISOR_memory_op(op, &memmap); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 364 | if (rc == -ENOSYS) { |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 365 | BUG_ON(xen_initial_domain()); |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 366 | memmap.nr_entries = 1; |
| 367 | map[0].addr = 0ULL; |
| 368 | map[0].size = mem_end; |
| 369 | /* 8MB slack (to balance backend allocations). */ |
| 370 | map[0].size += 8ULL << 20; |
| 371 | map[0].type = E820_RAM; |
| 372 | rc = 0; |
| 373 | } |
| 374 | BUG_ON(rc); |
Jeremy Fitzhardinge | 8006ec3 | 2008-05-26 23:31:19 +0100 | [diff] [blame] | 375 | |
David Vrabel | 3bc38cb | 2013-08-16 15:42:55 +0100 | [diff] [blame] | 376 | /* |
| 377 | * Xen won't allow a 1:1 mapping to be created to UNUSABLE |
| 378 | * regions, so if we're using the machine memory map leave the |
| 379 | * region as RAM as it is in the pseudo-physical map. |
| 380 | * |
| 381 | * UNUSABLE regions in domUs are not handled and will need |
| 382 | * a patch in the future. |
| 383 | */ |
| 384 | if (xen_initial_domain()) |
| 385 | xen_ignore_unusable(map, memmap.nr_entries); |
| 386 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 387 | /* Make sure the Xen-supplied memory map is well-ordered. */ |
| 388 | sanitize_e820_map(map, memmap.nr_entries, &memmap.nr_entries); |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 389 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 390 | max_pages = xen_get_max_pages(); |
| 391 | if (max_pages > max_pfn) |
| 392 | extra_pages += max_pages - max_pfn; |
Stefano Stabellini | 7cb31b7 | 2011-01-27 10:13:25 -0500 | [diff] [blame] | 393 | |
David Vrabel | f3f436e | 2011-09-28 17:46:36 +0100 | [diff] [blame] | 394 | /* |
| 395 | * Set P2M for all non-RAM pages and E820 gaps to be identity |
| 396 | * type PFNs. Any RAM pages that would be made inaccesible by |
| 397 | * this are first released. |
| 398 | */ |
| 399 | xen_released_pages = xen_set_identity_and_release( |
| 400 | map, memmap.nr_entries, max_pfn); |
Jeremy Fitzhardinge | 42ee147 | 2010-08-30 16:41:02 -0700 | [diff] [blame] | 401 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 402 | /* |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 403 | * Populate back the non-RAM pages and E820 gaps that had been |
| 404 | * released. */ |
| 405 | populated = xen_populate_chunk(map, memmap.nr_entries, |
| 406 | max_pfn, &last_pfn, xen_released_pages); |
| 407 | |
Konrad Rzeszutek Wilk | 58b7b53 | 2012-05-29 12:36:43 -0400 | [diff] [blame] | 408 | xen_released_pages -= populated; |
| 409 | extra_pages += xen_released_pages; |
Konrad Rzeszutek Wilk | 2e2fb75 | 2012-04-06 10:07:11 -0400 | [diff] [blame] | 410 | |
| 411 | if (last_pfn > max_pfn) { |
| 412 | max_pfn = min(MAX_DOMAIN_PAGES, last_pfn); |
| 413 | mem_end = PFN_PHYS(max_pfn); |
| 414 | } |
| 415 | /* |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 416 | * Clamp the amount of extra memory to a EXTRA_MEM_RATIO |
| 417 | * factor the base size. On non-highmem systems, the base |
| 418 | * size is the full initial memory allocation; on highmem it |
| 419 | * is limited to the max size of lowmem, so that it doesn't |
| 420 | * get completely filled. |
| 421 | * |
| 422 | * In principle there could be a problem in lowmem systems if |
| 423 | * the initial memory is also very large with respect to |
| 424 | * lowmem, but we won't try to deal with that here. |
| 425 | */ |
| 426 | extra_pages = min(EXTRA_MEM_RATIO * min(max_pfn, PFN_DOWN(MAXMEM)), |
| 427 | extra_pages); |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 428 | i = 0; |
| 429 | while (i < memmap.nr_entries) { |
| 430 | u64 addr = map[i].addr; |
| 431 | u64 size = map[i].size; |
| 432 | u32 type = map[i].type; |
| 433 | |
| 434 | if (type == E820_RAM) { |
| 435 | if (addr < mem_end) { |
| 436 | size = min(size, mem_end - addr); |
| 437 | } else if (extra_pages) { |
| 438 | size = min(size, (u64)extra_pages * PAGE_SIZE); |
| 439 | extra_pages -= size / PAGE_SIZE; |
| 440 | xen_add_extra_mem(addr, size); |
| 441 | } else |
| 442 | type = E820_UNUSABLE; |
Jeremy Fitzhardinge | 3654581 | 2010-09-29 16:54:33 -0700 | [diff] [blame] | 443 | } |
| 444 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 445 | xen_align_and_add_e820_region(addr, size, type); |
Jeremy Fitzhardinge | b5b43ce | 2010-09-02 17:10:12 -0700 | [diff] [blame] | 446 | |
David Vrabel | dc91c72 | 2011-09-29 12:26:19 +0100 | [diff] [blame] | 447 | map[i].addr += size; |
| 448 | map[i].size -= size; |
| 449 | if (map[i].size == 0) |
| 450 | i++; |
Ian Campbell | 35ae11f | 2009-02-06 19:09:48 -0800 | [diff] [blame] | 451 | } |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 452 | |
| 453 | /* |
David Vrabel | 25b884a | 2014-01-03 15:46:10 +0000 | [diff] [blame] | 454 | * Set the rest as identity mapped, in case PCI BARs are |
| 455 | * located here. |
| 456 | * |
| 457 | * PFNs above MAX_P2M_PFN are considered identity mapped as |
| 458 | * well. |
| 459 | */ |
| 460 | set_phys_range_identity(map[i-1].addr / PAGE_SIZE, ~0ul); |
| 461 | |
| 462 | /* |
Ian Campbell | 9ec23a7f | 2010-10-28 11:32:29 -0700 | [diff] [blame] | 463 | * In domU, the ISA region is normal, usable memory, but we |
| 464 | * reserve ISA memory anyway because too many things poke |
Jeremy Fitzhardinge | b792c75 | 2008-06-16 14:54:49 -0700 | [diff] [blame] | 465 | * about in there. |
| 466 | */ |
| 467 | e820_add_region(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, |
| 468 | E820_RESERVED); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 469 | |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 470 | /* |
| 471 | * Reserve Xen bits: |
| 472 | * - mfn_list |
| 473 | * - xen_start_info |
| 474 | * See comment above "struct start_info" in <xen/interface/xen.h> |
Konrad Rzeszutek Wilk | 51faaf2 | 2012-08-22 13:00:10 -0400 | [diff] [blame] | 475 | * We tried to make the the memblock_reserve more selective so |
| 476 | * that it would be clear what region is reserved. Sadly we ran |
| 477 | * in the problem wherein on a 64-bit hypervisor with a 32-bit |
| 478 | * initial domain, the pt_base has the cr3 value which is not |
| 479 | * neccessarily where the pagetable starts! As Jan put it: " |
| 480 | * Actually, the adjustment turns out to be correct: The page |
| 481 | * tables for a 32-on-64 dom0 get allocated in the order "first L1", |
| 482 | * "first L2", "first L3", so the offset to the page table base is |
| 483 | * indeed 2. When reading xen/include/public/xen.h's comment |
| 484 | * very strictly, this is not a violation (since there nothing is said |
| 485 | * that the first thing in the page table space is pointed to by |
| 486 | * pt_base; I admit that this seems to be implied though, namely |
| 487 | * do I think that it is implied that the page table space is the |
| 488 | * range [pt_base, pt_base + nt_pt_frames), whereas that |
| 489 | * range here indeed is [pt_base - 2, pt_base - 2 + nt_pt_frames), |
| 490 | * which - without a priori knowledge - the kernel would have |
| 491 | * difficulty to figure out)." - so lets just fall back to the |
| 492 | * easy way and reserve the whole region. |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 493 | */ |
Tejun Heo | 24aa078 | 2011-07-12 11:16:06 +0200 | [diff] [blame] | 494 | memblock_reserve(__pa(xen_start_info->mfn_list), |
| 495 | xen_start_info->pt_base - xen_start_info->mfn_list); |
Jeremy Fitzhardinge | be5bf9f | 2008-06-16 14:54:46 -0700 | [diff] [blame] | 496 | |
| 497 | sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map); |
| 498 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 499 | return "Xen"; |
| 500 | } |
| 501 | |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 502 | /* |
David Vrabel | abacaad | 2014-06-02 17:58:01 +0100 | [diff] [blame] | 503 | * Machine specific memory setup for auto-translated guests. |
| 504 | */ |
| 505 | char * __init xen_auto_xlated_memory_setup(void) |
| 506 | { |
| 507 | static struct e820entry map[E820MAX] __initdata; |
| 508 | |
| 509 | struct xen_memory_map memmap; |
| 510 | int i; |
| 511 | int rc; |
| 512 | |
| 513 | memmap.nr_entries = E820MAX; |
| 514 | set_xen_guest_handle(memmap.buffer, map); |
| 515 | |
| 516 | rc = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap); |
| 517 | if (rc < 0) |
| 518 | panic("No memory map (%d)\n", rc); |
| 519 | |
| 520 | sanitize_e820_map(map, ARRAY_SIZE(map), &memmap.nr_entries); |
| 521 | |
| 522 | for (i = 0; i < memmap.nr_entries; i++) |
| 523 | e820_add_region(map[i].addr, map[i].size, map[i].type); |
| 524 | |
| 525 | memblock_reserve(__pa(xen_start_info->mfn_list), |
| 526 | xen_start_info->pt_base - xen_start_info->mfn_list); |
| 527 | |
| 528 | return "Xen"; |
| 529 | } |
| 530 | |
| 531 | /* |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 532 | * Set the bit indicating "nosegneg" library variants should be used. |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 533 | * We only need to bother in pure 32-bit mode; compat 32-bit processes |
| 534 | * can have un-truncated segments, so wrapping around is allowed. |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 535 | */ |
Sam Ravnborg | 08b6d29 | 2008-01-30 13:33:25 +0100 | [diff] [blame] | 536 | static void __init fiddle_vdso(void) |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 537 | { |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 538 | #ifdef CONFIG_X86_32 |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 539 | /* |
| 540 | * This could be called before selected_vdso32 is initialized, so |
| 541 | * just fiddle with both possible images. vdso_image_32_syscall |
| 542 | * can't be selected, since it only exists on 64-bit systems. |
| 543 | */ |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 544 | u32 *mask; |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 545 | mask = vdso_image_32_int80.data + |
| 546 | vdso_image_32_int80.sym_VDSO32_NOTE_MASK; |
Jeremy Fitzhardinge | 6a52e4b | 2008-07-12 02:22:00 -0700 | [diff] [blame] | 547 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Andy Lutomirski | 6f121e5 | 2014-05-05 12:19:34 -0700 | [diff] [blame] | 548 | mask = vdso_image_32_sysenter.data + |
| 549 | vdso_image_32_sysenter.sym_VDSO32_NOTE_MASK; |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 550 | *mask |= 1 << VDSO_NOTE_NONEGSEG_BIT; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 551 | #endif |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 554 | static int register_callback(unsigned type, const void *func) |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 555 | { |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 556 | struct callback_register callback = { |
| 557 | .type = type, |
| 558 | .address = XEN_CALLBACK(__KERNEL_CS, func), |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 559 | .flags = CALLBACKF_mask_events, |
| 560 | }; |
| 561 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 562 | return HYPERVISOR_callback_op(CALLBACKOP_register, &callback); |
| 563 | } |
| 564 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 565 | void xen_enable_sysenter(void) |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 566 | { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 567 | int ret; |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 568 | unsigned sysenter_feature; |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 569 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 570 | #ifdef CONFIG_X86_32 |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 571 | sysenter_feature = X86_FEATURE_SEP; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 572 | #else |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 573 | sysenter_feature = X86_FEATURE_SYSENTER32; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 574 | #endif |
| 575 | |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 576 | if (!boot_cpu_has(sysenter_feature)) |
| 577 | return; |
| 578 | |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 579 | ret = register_callback(CALLBACKTYPE_sysenter, xen_sysenter_target); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 580 | if(ret != 0) |
| 581 | setup_clear_cpu_cap(sysenter_feature); |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 584 | void xen_enable_syscall(void) |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 585 | { |
| 586 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 587 | int ret; |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 588 | |
| 589 | ret = register_callback(CALLBACKTYPE_syscall, xen_syscall_target); |
| 590 | if (ret != 0) { |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 591 | printk(KERN_ERR "Failed to set syscall callback: %d\n", ret); |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 592 | /* Pretty fatal; 64-bit userspace has no other |
| 593 | mechanism for syscalls. */ |
| 594 | } |
| 595 | |
| 596 | if (boot_cpu_has(X86_FEATURE_SYSCALL32)) { |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 597 | ret = register_callback(CALLBACKTYPE_syscall32, |
| 598 | xen_syscall32_target); |
Jeremy Fitzhardinge | d5303b8 | 2008-07-12 02:22:06 -0700 | [diff] [blame] | 599 | if (ret != 0) |
Jeremy Fitzhardinge | 62541c3 | 2008-07-10 16:24:08 -0700 | [diff] [blame] | 600 | setup_clear_cpu_cap(X86_FEATURE_SYSCALL32); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 601 | } |
| 602 | #endif /* CONFIG_X86_64 */ |
| 603 | } |
David Vrabel | ea9f927 | 2014-06-16 13:07:00 +0200 | [diff] [blame] | 604 | |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 605 | void __init xen_pvmmu_arch_setup(void) |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 606 | { |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 607 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments); |
| 608 | HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables); |
| 609 | |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 610 | HYPERVISOR_vm_assist(VMASST_CMD_enable, |
| 611 | VMASST_TYPE_pae_extended_cr3); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 612 | |
Jeremy Fitzhardinge | 88459d4 | 2008-07-08 15:07:02 -0700 | [diff] [blame] | 613 | if (register_callback(CALLBACKTYPE_event, xen_hypervisor_callback) || |
| 614 | register_callback(CALLBACKTYPE_failsafe, xen_failsafe_callback)) |
| 615 | BUG(); |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 616 | |
Jeremy Fitzhardinge | e2a81ba | 2008-03-17 16:37:17 -0700 | [diff] [blame] | 617 | xen_enable_sysenter(); |
Jeremy Fitzhardinge | 6fcac6d | 2008-07-08 15:07:14 -0700 | [diff] [blame] | 618 | xen_enable_syscall(); |
Mukesh Rathor | d285d68 | 2013-12-13 12:45:31 -0500 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /* This function is not called for HVM domains */ |
| 622 | void __init xen_arch_setup(void) |
| 623 | { |
| 624 | xen_panic_handler_init(); |
| 625 | if (!xen_feature(XENFEAT_auto_translated_physmap)) |
| 626 | xen_pvmmu_arch_setup(); |
| 627 | |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 628 | #ifdef CONFIG_ACPI |
| 629 | if (!(xen_start_info->flags & SIF_INITDOMAIN)) { |
| 630 | printk(KERN_INFO "ACPI in unprivileged domain disabled\n"); |
| 631 | disable_acpi(); |
| 632 | } |
| 633 | #endif |
| 634 | |
| 635 | memcpy(boot_command_line, xen_start_info->cmd_line, |
| 636 | MAX_GUEST_CMDLINE > COMMAND_LINE_SIZE ? |
| 637 | COMMAND_LINE_SIZE : MAX_GUEST_CMDLINE); |
| 638 | |
Jeremy Fitzhardinge | bc15fde | 2010-11-22 17:17:50 -0800 | [diff] [blame] | 639 | /* Set up idle, making sure it calls safe_halt() pvop */ |
Len Brown | d91ee58 | 2011-04-01 18:28:35 -0400 | [diff] [blame] | 640 | disable_cpuidle(); |
Konrad Rzeszutek Wilk | 48cdd82 | 2012-03-13 20:06:57 -0400 | [diff] [blame] | 641 | disable_cpufreq(); |
Len Brown | 6a377dd | 2013-02-09 23:08:07 -0500 | [diff] [blame] | 642 | WARN_ON(xen_set_default_idle()); |
Roland McGrath | d2eea68 | 2007-07-20 00:31:43 -0700 | [diff] [blame] | 643 | fiddle_vdso(); |
Konrad Rzeszutek Wilk | 8d54db79 | 2012-08-17 10:22:37 -0400 | [diff] [blame] | 644 | #ifdef CONFIG_NUMA |
| 645 | numa_off = 1; |
| 646 | #endif |
Jeremy Fitzhardinge | 5ead97c | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 647 | } |