blob: ad5bc9578a7336f031bf580b415fe8354780d060 [file] [log] [blame]
Rusty Russelld3561b72006-12-07 02:14:07 +01001/* Paravirtualization interfaces
2 Copyright (C) 2006 Rusty Russell IBM Corporation
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Glauber de Oliveira Costab1df07b2008-01-30 13:32:04 +010017
18 2007 - x86_64 support added by Glauber de Oliveira Costa, Red Hat Inc
Rusty Russelld3561b72006-12-07 02:14:07 +010019*/
Glauber de Oliveira Costab1df07b2008-01-30 13:32:04 +010020
Rusty Russelld3561b72006-12-07 02:14:07 +010021#include <linux/errno.h>
Paul Gortmaker186f4362016-07-13 20:18:56 -040022#include <linux/init.h>
23#include <linux/export.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010024#include <linux/efi.h>
25#include <linux/bcd.h>
Jeremy Fitzhardingece6234b2007-05-02 19:27:15 +020026#include <linux/highmem.h>
Masami Hiramatsu376e2422014-04-17 17:17:05 +090027#include <linux/kprobes.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010028
29#include <asm/bug.h>
30#include <asm/paravirt.h>
Paul Gortmaker50af5ea2012-01-20 18:35:53 -050031#include <asm/debugreg.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010032#include <asm/desc.h>
33#include <asm/setup.h>
Eduardo Habkosta312b372008-07-08 15:06:23 -070034#include <asm/pgtable.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010035#include <asm/time.h>
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -040036#include <asm/pgalloc.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010037#include <asm/irq.h>
38#include <asm/delay.h>
Rusty Russell13623d72006-12-07 02:14:08 +010039#include <asm/fixmap.h>
40#include <asm/apic.h>
Rusty Russellda181a82006-12-07 02:14:08 +010041#include <asm/tlbflush.h>
Zachary Amsden6cb9a832007-03-05 00:30:35 -080042#include <asm/timer.h>
David Howellsf05e7982012-03-28 18:11:12 +010043#include <asm/special_insns.h>
Rusty Russelld3561b72006-12-07 02:14:07 +010044
Andy Lutomirskifc57a7c2015-09-20 16:32:04 -070045/*
46 * nop stub, which must not clobber anything *including the stack* to
47 * avoid confusing the entry prologues.
48 */
49extern void _paravirt_nop(void);
50asm (".pushsection .entry.text, \"ax\"\n"
51 ".global _paravirt_nop\n"
52 "_paravirt_nop:\n\t"
53 "ret\n\t"
54 ".size _paravirt_nop, . - _paravirt_nop\n\t"
55 ".type _paravirt_nop, @function\n\t"
56 ".popsection");
Rusty Russelld3561b72006-12-07 02:14:07 +010057
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -080058/* identity function, which can be inlined */
59u32 _paravirt_ident_32(u32 x)
60{
61 return x;
62}
63
64u64 _paravirt_ident_64(u64 x)
65{
66 return x;
67}
68
Thomas Gleixner6f30c1a2009-08-20 13:19:57 +020069void __init default_banner(void)
Rusty Russelld3561b72006-12-07 02:14:07 +010070{
71 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070072 pv_info.name);
Rusty Russelld3561b72006-12-07 02:14:07 +010073}
74
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -070075/* Undefined instruction for dealing with missing ops pointers. */
76static const unsigned char ud2a[] = { 0x0f, 0x0b };
Rusty Russell139ec7c2006-12-07 02:14:08 +010077
Andi Kleen19d36cc2007-07-22 11:12:31 +020078struct branch {
79 unsigned char opcode;
80 u32 delta;
81} __attribute__((packed));
82
Andi Kleenab144f52007-08-10 22:31:03 +020083unsigned paravirt_patch_call(void *insnbuf,
84 const void *target, u16 tgt_clobbers,
85 unsigned long addr, u16 site_clobbers,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +020086 unsigned len)
87{
Andi Kleenab144f52007-08-10 22:31:03 +020088 struct branch *b = insnbuf;
89 unsigned long delta = (unsigned long)target - (addr+5);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +020090
91 if (tgt_clobbers & ~site_clobbers)
92 return len; /* target would clobber too much for this site */
93 if (len < 5)
94 return len; /* call too long for patch site */
95
Andi Kleenab144f52007-08-10 22:31:03 +020096 b->opcode = 0xe8; /* call */
97 b->delta = delta;
98 BUILD_BUG_ON(sizeof(*b) != 5);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +020099
100 return 5;
101}
102
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700103unsigned paravirt_patch_jmp(void *insnbuf, const void *target,
Andi Kleenab144f52007-08-10 22:31:03 +0200104 unsigned long addr, unsigned len)
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200105{
Andi Kleenab144f52007-08-10 22:31:03 +0200106 struct branch *b = insnbuf;
107 unsigned long delta = (unsigned long)target - (addr+5);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200108
109 if (len < 5)
110 return len; /* call too long for patch site */
111
Andi Kleenab144f52007-08-10 22:31:03 +0200112 b->opcode = 0xe9; /* jmp */
113 b->delta = delta;
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200114
115 return 5;
116}
117
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700118/* Neat trick to map patch type back to the call within the
119 * corresponding structure. */
120static void *get_call_destination(u8 type)
121{
122 struct paravirt_patch_template tmpl = {
123 .pv_init_ops = pv_init_ops,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700124 .pv_time_ops = pv_time_ops,
125 .pv_cpu_ops = pv_cpu_ops,
126 .pv_irq_ops = pv_irq_ops,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700127 .pv_mmu_ops = pv_mmu_ops,
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700128#ifdef CONFIG_PARAVIRT_SPINLOCKS
Jeremy Fitzhardinge74d4aff2008-07-07 12:07:50 -0700129 .pv_lock_ops = pv_lock_ops,
Jeremy Fitzhardingeb4ecc122009-05-13 17:16:55 -0700130#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700131 };
132 return *((void **)&tmpl + type);
133}
134
Andi Kleenab144f52007-08-10 22:31:03 +0200135unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
136 unsigned long addr, unsigned len)
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200137{
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700138 void *opfunc = get_call_destination(type);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200139 unsigned ret;
140
141 if (opfunc == NULL)
142 /* If there's no function, patch it with a ud2a (BUG) */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700143 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800144 else if (opfunc == _paravirt_nop)
Borislav Petkov79f1d832015-11-03 10:18:49 +0100145 ret = 0;
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800146
147 /* identity functions just return their single argument */
148 else if (opfunc == _paravirt_ident_32)
149 ret = paravirt_patch_ident_32(insnbuf, len);
150 else if (opfunc == _paravirt_ident_64)
151 ret = paravirt_patch_ident_64(insnbuf, len);
152
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700153 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400154 type == PARAVIRT_PATCH(pv_cpu_ops.usergs_sysret64))
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200155 /* If operation requires a jmp, then jmp */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700156 ret = paravirt_patch_jmp(insnbuf, opfunc, addr, len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200157 else
158 /* Otherwise call the function; assume target could
159 clobber any caller-save reg */
Andi Kleenab144f52007-08-10 22:31:03 +0200160 ret = paravirt_patch_call(insnbuf, opfunc, CLBR_ANY,
161 addr, clobbers, len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200162
163 return ret;
164}
165
Andi Kleenab144f52007-08-10 22:31:03 +0200166unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200167 const char *start, const char *end)
168{
169 unsigned insn_len = end - start;
170
171 if (insn_len > len || start == NULL)
172 insn_len = len;
173 else
Andi Kleenab144f52007-08-10 22:31:03 +0200174 memcpy(insnbuf, start, insn_len);
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200175
Rusty Russell139ec7c2006-12-07 02:14:08 +0100176 return insn_len;
177}
178
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100179static void native_flush_tlb(void)
Rusty Russellda181a82006-12-07 02:14:08 +0100180{
181 __native_flush_tlb();
182}
183
184/*
185 * Global pages have to be flushed a bit differently. Not a real
186 * performance problem because this does not happen often.
187 */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100188static void native_flush_tlb_global(void)
Rusty Russellda181a82006-12-07 02:14:08 +0100189{
190 __native_flush_tlb_global();
191}
192
Jeremy Fitzhardinge63f70272007-05-02 19:27:14 +0200193static void native_flush_tlb_single(unsigned long addr)
Rusty Russellda181a82006-12-07 02:14:08 +0100194{
195 __native_flush_tlb_single(addr);
196}
197
Ingo Molnarc5905af2012-02-24 08:31:31 +0100198struct static_key paravirt_steal_enabled;
199struct static_key paravirt_steal_rq_enabled;
Glauber Costa3c404b52011-07-11 15:28:15 -0400200
201static u64 native_steal_clock(int cpu)
202{
203 return 0;
204}
205
Rusty Russelld3561b72006-12-07 02:14:07 +0100206/* These are in entry.S */
Andi Kleen1a1eecd2007-02-13 13:26:25 +0100207extern void native_iret(void);
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400208extern void native_usergs_sysret64(void);
Rusty Russelld3561b72006-12-07 02:14:07 +0100209
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700210static struct resource reserve_ioports = {
211 .start = 0,
212 .end = IO_SPACE_LIMIT,
213 .name = "paravirt-ioport",
214 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
215};
216
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700217/*
218 * Reserve the whole legacy IO space to prevent any legacy drivers
219 * from wasting time probing for their hardware. This is a fairly
220 * brute-force approach to disabling all non-virtual drivers.
221 *
222 * Note that this must be called very early to have any effect.
223 */
224int paravirt_disable_iospace(void)
225{
Jeremy Fitzhardingef7743fe2008-03-27 17:28:40 -0700226 return request_resource(&ioport_resource, &reserve_ioports);
Jeremy Fitzhardinged5729292007-07-17 18:37:04 -0700227}
228
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700229static DEFINE_PER_CPU(enum paravirt_lazy_mode, paravirt_lazy_mode) = PARAVIRT_LAZY_NONE;
230
231static inline void enter_lazy(enum paravirt_lazy_mode mode)
232{
Alex Shic6ae41e2012-05-11 15:35:27 +0800233 BUG_ON(this_cpu_read(paravirt_lazy_mode) != PARAVIRT_LAZY_NONE);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700234
Alex Shic6ae41e2012-05-11 15:35:27 +0800235 this_cpu_write(paravirt_lazy_mode, mode);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700236}
237
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800238static void leave_lazy(enum paravirt_lazy_mode mode)
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700239{
Alex Shic6ae41e2012-05-11 15:35:27 +0800240 BUG_ON(this_cpu_read(paravirt_lazy_mode) != mode);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700241
Alex Shic6ae41e2012-05-11 15:35:27 +0800242 this_cpu_write(paravirt_lazy_mode, PARAVIRT_LAZY_NONE);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700243}
244
245void paravirt_enter_lazy_mmu(void)
246{
247 enter_lazy(PARAVIRT_LAZY_MMU);
248}
249
250void paravirt_leave_lazy_mmu(void)
251{
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800252 leave_lazy(PARAVIRT_LAZY_MMU);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700253}
254
Boris Ostrovsky511ba862013-03-23 09:36:36 -0400255void paravirt_flush_lazy_mmu(void)
256{
257 preempt_disable();
258
259 if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_MMU) {
260 arch_leave_lazy_mmu_mode();
261 arch_enter_lazy_mmu_mode();
262 }
263
264 preempt_enable();
265}
266
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800267void paravirt_start_context_switch(struct task_struct *prev)
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700268{
Jeremy Fitzhardinge2829b442009-02-17 23:53:19 -0800269 BUG_ON(preemptible());
270
Alex Shic6ae41e2012-05-11 15:35:27 +0800271 if (this_cpu_read(paravirt_lazy_mode) == PARAVIRT_LAZY_MMU) {
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800272 arch_leave_lazy_mmu_mode();
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800273 set_ti_thread_flag(task_thread_info(prev), TIF_LAZY_MMU_UPDATES);
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800274 }
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700275 enter_lazy(PARAVIRT_LAZY_CPU);
276}
277
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800278void paravirt_end_context_switch(struct task_struct *next)
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700279{
Jeremy Fitzhardinge2829b442009-02-17 23:53:19 -0800280 BUG_ON(preemptible());
281
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800282 leave_lazy(PARAVIRT_LAZY_CPU);
283
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800284 if (test_and_clear_ti_thread_flag(task_thread_info(next), TIF_LAZY_MMU_UPDATES))
Jeremy Fitzhardingeb407fc52009-02-17 23:46:21 -0800285 arch_enter_lazy_mmu_mode();
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700286}
287
288enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
289{
Jeremy Fitzhardingeb8bcfe92009-02-17 23:05:19 -0800290 if (in_interrupt())
291 return PARAVIRT_LAZY_NONE;
292
Alex Shic6ae41e2012-05-11 15:35:27 +0800293 return this_cpu_read(paravirt_lazy_mode);
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700294}
295
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700296struct pv_info pv_info = {
Rusty Russelld3561b72006-12-07 02:14:07 +0100297 .name = "bare hardware",
Rusty Russelld3561b72006-12-07 02:14:07 +0100298 .kernel_rpl = 0,
Jeremy Fitzhardinge5311ab62007-05-02 19:27:13 +0200299 .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
Andy Lutomirski318f5a22011-08-03 09:31:53 -0400300
301#ifdef CONFIG_X86_64
302 .extra_user_64bit_cs = __USER_CS,
303#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700304};
Rusty Russelld3561b72006-12-07 02:14:07 +0100305
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700306struct pv_init_ops pv_init_ops = {
307 .patch = native_patch,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700308};
309
310struct pv_time_ops pv_time_ops = {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700311 .sched_clock = native_sched_clock,
Glauber Costa3c404b52011-07-11 15:28:15 -0400312 .steal_clock = native_steal_clock,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700313};
Rusty Russelld3561b72006-12-07 02:14:07 +0100314
Andi Kleen9a55fdb2013-08-05 15:02:46 -0700315__visible struct pv_irq_ops pv_irq_ops = {
Jeremy Fitzhardingeecb93d12009-01-28 14:35:05 -0800316 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
317 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
318 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
319 .irq_enable = __PV_IS_CALLEE_SAVE(native_irq_enable),
Rusty Russelld3561b72006-12-07 02:14:07 +0100320 .safe_halt = native_safe_halt,
321 .halt = native_halt,
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400322#ifdef CONFIG_X86_64
323 .adjust_exception_frame = paravirt_nop,
324#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700325};
326
Andi Kleen9a55fdb2013-08-05 15:02:46 -0700327__visible struct pv_cpu_ops pv_cpu_ops = {
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700328 .cpuid = native_cpuid,
329 .get_debugreg = native_get_debugreg,
330 .set_debugreg = native_set_debugreg,
331 .clts = native_clts,
332 .read_cr0 = native_read_cr0,
333 .write_cr0 = native_write_cr0,
334 .read_cr4 = native_read_cr4,
335 .read_cr4_safe = native_read_cr4_safe,
336 .write_cr4 = native_write_cr4,
Glauber de Oliveira Costa88b47552008-01-30 13:33:19 +0100337#ifdef CONFIG_X86_64
338 .read_cr8 = native_read_cr8,
339 .write_cr8 = native_write_cr8,
340#endif
Rusty Russelld3561b72006-12-07 02:14:07 +0100341 .wbinvd = native_wbinvd,
Andy Lutomirskidd2f4a02016-04-02 07:01:38 -0700342 .read_msr = native_read_msr,
343 .write_msr = native_write_msr,
Andy Lutomirskic2ee03b2016-04-02 07:01:36 -0700344 .read_msr_safe = native_read_msr_safe,
345 .write_msr_safe = native_write_msr_safe,
Rusty Russelld3561b72006-12-07 02:14:07 +0100346 .read_pmc = native_read_pmc,
347 .load_tr_desc = native_load_tr_desc,
348 .set_ldt = native_set_ldt,
349 .load_gdt = native_load_gdt,
350 .load_idt = native_load_idt,
Rusty Russelld3561b72006-12-07 02:14:07 +0100351 .store_idt = native_store_idt,
352 .store_tr = native_store_tr,
353 .load_tls = native_load_tls,
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400354#ifdef CONFIG_X86_64
355 .load_gs_index = native_load_gs_index,
356#endif
Glauber de Oliveira Costa75b8bb32008-01-30 13:31:13 +0100357 .write_ldt_entry = native_write_ldt_entry,
Glauber de Oliveira Costa014b15b2008-01-30 13:31:13 +0100358 .write_gdt_entry = native_write_gdt_entry,
Glauber de Oliveira Costa8d947342008-01-30 13:31:12 +0100359 .write_idt_entry = native_write_idt_entry,
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700360
361 .alloc_ldt = paravirt_nop,
362 .free_ldt = paravirt_nop,
363
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100364 .load_sp0 = native_load_sp0,
Rusty Russelld3561b72006-12-07 02:14:07 +0100365
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400366#ifdef CONFIG_X86_64
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400367 .usergs_sysret64 = native_usergs_sysret64,
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400368#endif
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700369 .iret = native_iret,
Glauber de Oliveira Costae801f862008-01-30 13:32:08 +0100370 .swapgs = native_swapgs,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700371
Rusty Russelld3561b72006-12-07 02:14:07 +0100372 .set_iopl_mask = native_set_iopl_mask,
373 .io_delay = native_io_delay,
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700374
Jeremy Fitzhardinge224101e2009-02-18 11:18:57 -0800375 .start_context_switch = paravirt_nop,
376 .end_context_switch = paravirt_nop,
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700377};
Rusty Russelld3561b72006-12-07 02:14:07 +0100378
Masami Hiramatsu80271972014-04-17 17:17:19 +0900379/* At this point, native_get/set_debugreg has real function entries */
Masami Hiramatsu376e2422014-04-17 17:17:05 +0900380NOKPROBE_SYMBOL(native_get_debugreg);
Masami Hiramatsu80271972014-04-17 17:17:19 +0900381NOKPROBE_SYMBOL(native_set_debugreg);
382NOKPROBE_SYMBOL(native_load_idt);
Masami Hiramatsu376e2422014-04-17 17:17:05 +0900383
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800384#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
385/* 32-bit pagetable entries */
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800386#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800387#else
388/* 64-bit pagetable entries */
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800389#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
Jeremy Fitzhardinge41edafd2009-01-28 14:35:02 -0800390#endif
391
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700392struct pv_mmu_ops pv_mmu_ops = {
Jeremy Fitzhardingeb239fb22007-05-02 19:27:13 +0200393
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700394 .read_cr2 = native_read_cr2,
395 .write_cr2 = native_write_cr2,
396 .read_cr3 = native_read_cr3,
397 .write_cr3 = native_write_cr3,
398
Rusty Russellda181a82006-12-07 02:14:08 +0100399 .flush_tlb_user = native_flush_tlb,
400 .flush_tlb_kernel = native_flush_tlb_global,
401 .flush_tlb_single = native_flush_tlb_single,
Jeremy Fitzhardinged4c10472007-05-02 19:27:15 +0200402 .flush_tlb_others = native_flush_tlb_others,
Rusty Russellda181a82006-12-07 02:14:08 +0100403
Jeremy Fitzhardingeeba00452008-06-25 00:19:12 -0400404 .pgd_alloc = __paravirt_pgd_alloc,
405 .pgd_free = paravirt_nop,
406
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700407 .alloc_pte = paravirt_nop,
408 .alloc_pmd = paravirt_nop,
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700409 .alloc_pud = paravirt_nop,
Jeremy Fitzhardinge6944a9c2008-03-17 16:37:01 -0700410 .release_pte = paravirt_nop,
411 .release_pmd = paravirt_nop,
Jeremy Fitzhardinge2761fa02008-03-17 16:37:02 -0700412 .release_pud = paravirt_nop,
Zachary Amsdenc119ecc2007-02-13 13:26:21 +0100413
Rusty Russellda181a82006-12-07 02:14:08 +0100414 .set_pte = native_set_pte,
415 .set_pte_at = native_set_pte_at,
416 .set_pmd = native_set_pmd,
Andrea Arcangeli331127f2011-01-13 15:46:36 -0800417 .set_pmd_at = native_set_pmd_at,
Jeremy Fitzhardinge45876232007-05-02 19:27:13 +0200418 .pte_update = paravirt_nop,
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200419
Jeremy Fitzhardinge08b882c2008-06-16 04:30:01 -0700420 .ptep_modify_prot_start = __ptep_modify_prot_start,
421 .ptep_modify_prot_commit = __ptep_modify_prot_commit,
422
Kirill A. Shutemov98233362015-04-14 15:46:14 -0700423#if CONFIG_PGTABLE_LEVELS >= 3
Rusty Russellda181a82006-12-07 02:14:08 +0100424#ifdef CONFIG_X86_PAE
425 .set_pte_atomic = native_set_pte_atomic,
Rusty Russellda181a82006-12-07 02:14:08 +0100426 .pte_clear = native_pte_clear,
427 .pmd_clear = native_pmd_clear,
Eduardo Habkostf95f2f72008-01-30 13:33:20 +0100428#endif
429 .set_pud = native_set_pud,
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800430
431 .pmd_val = PTE_IDENT,
432 .make_pmd = PTE_IDENT,
Eduardo Habkostf95f2f72008-01-30 13:33:20 +0100433
Kirill A. Shutemov98233362015-04-14 15:46:14 -0700434#if CONFIG_PGTABLE_LEVELS == 4
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800435 .pud_val = PTE_IDENT,
436 .make_pud = PTE_IDENT,
437
Eduardo Habkostf95f2f72008-01-30 13:33:20 +0100438 .set_pgd = native_set_pgd,
Rusty Russellda181a82006-12-07 02:14:08 +0100439#endif
Kirill A. Shutemov98233362015-04-14 15:46:14 -0700440#endif /* CONFIG_PGTABLE_LEVELS >= 3 */
Rusty Russellda181a82006-12-07 02:14:08 +0100441
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800442 .pte_val = PTE_IDENT,
443 .pgd_val = PTE_IDENT,
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200444
Jeremy Fitzhardingeda5de7c2009-01-28 14:35:07 -0800445 .make_pte = PTE_IDENT,
446 .make_pgd = PTE_IDENT,
Jeremy Fitzhardinge3dc494e2007-05-02 19:27:13 +0200447
Jeremy Fitzhardinged6dd61c2007-05-02 19:27:14 +0200448 .dup_mmap = paravirt_nop,
449 .exit_mmap = paravirt_nop,
450 .activate_mm = paravirt_nop,
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700451
452 .lazy_mode = {
453 .enter = paravirt_nop,
454 .leave = paravirt_nop,
Boris Ostrovsky511ba862013-03-23 09:36:36 -0400455 .flush = paravirt_nop,
Jeremy Fitzhardinge8965c1c2007-10-16 11:51:29 -0700456 },
Jeremy Fitzhardingeaeaaa592008-06-17 11:42:01 -0700457
458 .set_fixmap = native_set_fixmap,
Rusty Russelld3561b72006-12-07 02:14:07 +0100459};
Ingo Molnar0dbe5a12007-01-22 20:40:36 -0800460
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700461EXPORT_SYMBOL_GPL(pv_time_ops);
Jeremy Fitzhardingef97b8952007-11-28 16:22:11 -0800462EXPORT_SYMBOL (pv_cpu_ops);
463EXPORT_SYMBOL (pv_mmu_ops);
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700464EXPORT_SYMBOL_GPL(pv_info);
465EXPORT_SYMBOL (pv_irq_ops);