.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2010 SUSE Linux Products GmbH. All rights reserved. |
---|
3 | 4 | * Copyright 2010-2011 Freescale Semiconductor, Inc. |
---|
4 | 5 | * |
---|
5 | 6 | * Authors: |
---|
6 | 7 | * Alexander Graf <agraf@suse.de> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License, version 2, as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | | - * |
---|
12 | | - * This program is distributed in the hope that it will be useful, |
---|
13 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | | - * GNU General Public License for more details. |
---|
16 | | - * |
---|
17 | | - * You should have received a copy of the GNU General Public License |
---|
18 | | - * along with this program; if not, write to the Free Software |
---|
19 | | - * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
20 | 8 | */ |
---|
21 | 9 | |
---|
22 | 10 | #include <linux/kvm_host.h> |
---|
.. | .. |
---|
76 | 64 | #define KVM_INST_MTSRIN 0x7c0001e4 |
---|
77 | 65 | |
---|
78 | 66 | static bool kvm_patching_worked = true; |
---|
79 | | -char kvm_tmp[1024 * 1024]; |
---|
| 67 | +extern char kvm_tmp[]; |
---|
| 68 | +extern char kvm_tmp_end[]; |
---|
80 | 69 | static int kvm_tmp_index; |
---|
81 | 70 | |
---|
82 | | -static inline void kvm_patch_ins(u32 *inst, u32 new_inst) |
---|
| 71 | +static void __init kvm_patch_ins(u32 *inst, u32 new_inst) |
---|
83 | 72 | { |
---|
84 | 73 | *inst = new_inst; |
---|
85 | 74 | flush_icache_range((ulong)inst, (ulong)inst + 4); |
---|
86 | 75 | } |
---|
87 | 76 | |
---|
88 | | -static void kvm_patch_ins_ll(u32 *inst, long addr, u32 rt) |
---|
| 77 | +static void __init kvm_patch_ins_ll(u32 *inst, long addr, u32 rt) |
---|
89 | 78 | { |
---|
90 | 79 | #ifdef CONFIG_64BIT |
---|
91 | 80 | kvm_patch_ins(inst, KVM_INST_LD | rt | (addr & 0x0000fffc)); |
---|
.. | .. |
---|
94 | 83 | #endif |
---|
95 | 84 | } |
---|
96 | 85 | |
---|
97 | | -static void kvm_patch_ins_ld(u32 *inst, long addr, u32 rt) |
---|
| 86 | +static void __init kvm_patch_ins_ld(u32 *inst, long addr, u32 rt) |
---|
98 | 87 | { |
---|
99 | 88 | #ifdef CONFIG_64BIT |
---|
100 | 89 | kvm_patch_ins(inst, KVM_INST_LD | rt | (addr & 0x0000fffc)); |
---|
.. | .. |
---|
103 | 92 | #endif |
---|
104 | 93 | } |
---|
105 | 94 | |
---|
106 | | -static void kvm_patch_ins_lwz(u32 *inst, long addr, u32 rt) |
---|
| 95 | +static void __init kvm_patch_ins_lwz(u32 *inst, long addr, u32 rt) |
---|
107 | 96 | { |
---|
108 | 97 | kvm_patch_ins(inst, KVM_INST_LWZ | rt | (addr & 0x0000ffff)); |
---|
109 | 98 | } |
---|
110 | 99 | |
---|
111 | | -static void kvm_patch_ins_std(u32 *inst, long addr, u32 rt) |
---|
| 100 | +static void __init kvm_patch_ins_std(u32 *inst, long addr, u32 rt) |
---|
112 | 101 | { |
---|
113 | 102 | #ifdef CONFIG_64BIT |
---|
114 | 103 | kvm_patch_ins(inst, KVM_INST_STD | rt | (addr & 0x0000fffc)); |
---|
.. | .. |
---|
117 | 106 | #endif |
---|
118 | 107 | } |
---|
119 | 108 | |
---|
120 | | -static void kvm_patch_ins_stw(u32 *inst, long addr, u32 rt) |
---|
| 109 | +static void __init kvm_patch_ins_stw(u32 *inst, long addr, u32 rt) |
---|
121 | 110 | { |
---|
122 | 111 | kvm_patch_ins(inst, KVM_INST_STW | rt | (addr & 0x0000fffc)); |
---|
123 | 112 | } |
---|
124 | 113 | |
---|
125 | | -static void kvm_patch_ins_nop(u32 *inst) |
---|
| 114 | +static void __init kvm_patch_ins_nop(u32 *inst) |
---|
126 | 115 | { |
---|
127 | 116 | kvm_patch_ins(inst, KVM_INST_NOP); |
---|
128 | 117 | } |
---|
129 | 118 | |
---|
130 | | -static void kvm_patch_ins_b(u32 *inst, int addr) |
---|
| 119 | +static void __init kvm_patch_ins_b(u32 *inst, int addr) |
---|
131 | 120 | { |
---|
132 | 121 | #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_PPC_BOOK3S) |
---|
133 | 122 | /* On relocatable kernels interrupts handlers and our code |
---|
.. | .. |
---|
140 | 129 | kvm_patch_ins(inst, KVM_INST_B | (addr & KVM_INST_B_MASK)); |
---|
141 | 130 | } |
---|
142 | 131 | |
---|
143 | | -static u32 *kvm_alloc(int len) |
---|
| 132 | +static u32 * __init kvm_alloc(int len) |
---|
144 | 133 | { |
---|
145 | 134 | u32 *p; |
---|
146 | 135 | |
---|
147 | | - if ((kvm_tmp_index + len) > ARRAY_SIZE(kvm_tmp)) { |
---|
| 136 | + if ((kvm_tmp_index + len) > (kvm_tmp_end - kvm_tmp)) { |
---|
148 | 137 | printk(KERN_ERR "KVM: No more space (%d + %d)\n", |
---|
149 | 138 | kvm_tmp_index, len); |
---|
150 | 139 | kvm_patching_worked = false; |
---|
.. | .. |
---|
163 | 152 | extern u32 kvm_emulate_mtmsrd_len; |
---|
164 | 153 | extern u32 kvm_emulate_mtmsrd[]; |
---|
165 | 154 | |
---|
166 | | -static void kvm_patch_ins_mtmsrd(u32 *inst, u32 rt) |
---|
| 155 | +static void __init kvm_patch_ins_mtmsrd(u32 *inst, u32 rt) |
---|
167 | 156 | { |
---|
168 | 157 | u32 *p; |
---|
169 | 158 | int distance_start; |
---|
.. | .. |
---|
216 | 205 | extern u32 kvm_emulate_mtmsr_len; |
---|
217 | 206 | extern u32 kvm_emulate_mtmsr[]; |
---|
218 | 207 | |
---|
219 | | -static void kvm_patch_ins_mtmsr(u32 *inst, u32 rt) |
---|
| 208 | +static void __init kvm_patch_ins_mtmsr(u32 *inst, u32 rt) |
---|
220 | 209 | { |
---|
221 | 210 | u32 *p; |
---|
222 | 211 | int distance_start; |
---|
.. | .. |
---|
277 | 266 | extern u32 kvm_emulate_wrtee_len; |
---|
278 | 267 | extern u32 kvm_emulate_wrtee[]; |
---|
279 | 268 | |
---|
280 | | -static void kvm_patch_ins_wrtee(u32 *inst, u32 rt, int imm_one) |
---|
| 269 | +static void __init kvm_patch_ins_wrtee(u32 *inst, u32 rt, int imm_one) |
---|
281 | 270 | { |
---|
282 | 271 | u32 *p; |
---|
283 | 272 | int distance_start; |
---|
.. | .. |
---|
334 | 323 | extern u32 kvm_emulate_wrteei_0_len; |
---|
335 | 324 | extern u32 kvm_emulate_wrteei_0[]; |
---|
336 | 325 | |
---|
337 | | -static void kvm_patch_ins_wrteei_0(u32 *inst) |
---|
| 326 | +static void __init kvm_patch_ins_wrteei_0(u32 *inst) |
---|
338 | 327 | { |
---|
339 | 328 | u32 *p; |
---|
340 | 329 | int distance_start; |
---|
.. | .. |
---|
375 | 364 | extern u32 kvm_emulate_mtsrin_len; |
---|
376 | 365 | extern u32 kvm_emulate_mtsrin[]; |
---|
377 | 366 | |
---|
378 | | -static void kvm_patch_ins_mtsrin(u32 *inst, u32 rt, u32 rb) |
---|
| 367 | +static void __init kvm_patch_ins_mtsrin(u32 *inst, u32 rt, u32 rb) |
---|
379 | 368 | { |
---|
380 | 369 | u32 *p; |
---|
381 | 370 | int distance_start; |
---|
.. | .. |
---|
411 | 400 | |
---|
412 | 401 | #endif |
---|
413 | 402 | |
---|
414 | | -static void kvm_map_magic_page(void *data) |
---|
| 403 | +static void __init kvm_map_magic_page(void *data) |
---|
415 | 404 | { |
---|
416 | 405 | u32 *features = data; |
---|
417 | 406 | |
---|
.. | .. |
---|
426 | 415 | *features = out[0]; |
---|
427 | 416 | } |
---|
428 | 417 | |
---|
429 | | -static void kvm_check_ins(u32 *inst, u32 features) |
---|
| 418 | +static void __init kvm_check_ins(u32 *inst, u32 features) |
---|
430 | 419 | { |
---|
431 | 420 | u32 _inst = *inst; |
---|
432 | 421 | u32 inst_no_rt = _inst & ~KVM_MASK_RT; |
---|
.. | .. |
---|
670 | 659 | extern u32 kvm_template_start[]; |
---|
671 | 660 | extern u32 kvm_template_end[]; |
---|
672 | 661 | |
---|
673 | | -static void kvm_use_magic_page(void) |
---|
| 662 | +static void __init kvm_use_magic_page(void) |
---|
674 | 663 | { |
---|
675 | 664 | u32 *p; |
---|
676 | 665 | u32 *start, *end; |
---|
.. | .. |
---|
680 | 669 | on_each_cpu(kvm_map_magic_page, &features, 1); |
---|
681 | 670 | |
---|
682 | 671 | /* Quick self-test to see if the mapping works */ |
---|
683 | | - if (!fault_in_pages_readable((const char *)KVM_MAGIC_PAGE, sizeof(u32))) { |
---|
| 672 | + if (fault_in_pages_readable((const char *)KVM_MAGIC_PAGE, sizeof(u32))) { |
---|
684 | 673 | kvm_patching_worked = false; |
---|
685 | 674 | return; |
---|
686 | 675 | } |
---|
.. | .. |
---|
711 | 700 | kvm_patching_worked ? "worked" : "failed"); |
---|
712 | 701 | } |
---|
713 | 702 | |
---|
714 | | -static __init void kvm_free_tmp(void) |
---|
715 | | -{ |
---|
716 | | - /* |
---|
717 | | - * Inform kmemleak about the hole in the .bss section since the |
---|
718 | | - * corresponding pages will be unmapped with DEBUG_PAGEALLOC=y. |
---|
719 | | - */ |
---|
720 | | - kmemleak_free_part(&kvm_tmp[kvm_tmp_index], |
---|
721 | | - ARRAY_SIZE(kvm_tmp) - kvm_tmp_index); |
---|
722 | | - free_reserved_area(&kvm_tmp[kvm_tmp_index], |
---|
723 | | - &kvm_tmp[ARRAY_SIZE(kvm_tmp)], -1, NULL); |
---|
724 | | -} |
---|
725 | | - |
---|
726 | 703 | static int __init kvm_guest_init(void) |
---|
727 | 704 | { |
---|
728 | 705 | if (!kvm_para_available()) |
---|
729 | | - goto free_tmp; |
---|
| 706 | + return 0; |
---|
730 | 707 | |
---|
731 | 708 | if (!epapr_paravirt_enabled) |
---|
732 | | - goto free_tmp; |
---|
| 709 | + return 0; |
---|
733 | 710 | |
---|
734 | 711 | if (kvm_para_has_feature(KVM_FEATURE_MAGIC_PAGE)) |
---|
735 | 712 | kvm_use_magic_page(); |
---|
.. | .. |
---|
738 | 715 | /* Enable napping */ |
---|
739 | 716 | powersave_nap = 1; |
---|
740 | 717 | #endif |
---|
741 | | - |
---|
742 | | -free_tmp: |
---|
743 | | - kvm_free_tmp(); |
---|
744 | 718 | |
---|
745 | 719 | return 0; |
---|
746 | 720 | } |
---|