-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjailhouse.patch
320 lines (285 loc) · 11.3 KB
/
jailhouse.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
diff --git a/Kbuild b/Kbuild
index 71c232d4..8b8aff3f 100644
--- a/Kbuild
+++ b/Kbuild
@@ -41,7 +41,9 @@ GEN_VERSION_H := $(obj)/hypervisor/include/generated/version.h
$(GEN_VERSION_H): $(src)/Makefile FORCE
$(call filechk,version)
-subdir-y := driver hypervisor configs inmates tools
+subdir-y := hypervisor configs inmates tools
+
+obj-m := driver/
subdir-ccflags-y := -Werror
diff --git a/configs/Makefile b/configs/Makefile
index 1e59840e..62d263e3 100644
--- a/configs/Makefile
+++ b/configs/Makefile
@@ -15,13 +15,13 @@
LINUXINCLUDE := -I$(src)/../hypervisor/arch/$(SRCARCH)/include \
-I$(src)/../hypervisor/include \
-I$(src)/../include
-KBUILD_CFLAGS := -Wextra -D__LINUX_COMPILER_TYPES_H
+KBUILD_CFLAGS := -Werror -Wall -Wextra -D__LINUX_COMPILER_TYPES_H
ifneq ($(wildcard $(obj)/../include/jailhouse/config.h),)
KBUILD_CFLAGS += -include $(obj)/../include/jailhouse/config.h
endif
-OBJCOPYFLAGS := -O binary
+OBJCOPYFLAGS := -O binary --remove-section=.note.gnu.property
CONFIGS = $(shell cd $(src); ls $(SRCARCH)/*.c)
diff --git a/driver/main.c b/driver/main.c
index fe752753..0fad50d2 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -58,15 +58,22 @@
#error 64-bit kernel required!
#endif
+#ifndef MSR_IA32_FEAT_CTL
+#define MSR_IA32_FEAT_CTL MSR_IA32_FEATURE_CONTROL
+#endif
+#ifndef FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX
+#define FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX
+#endif
+
#if JAILHOUSE_CELL_ID_NAMELEN != JAILHOUSE_CELL_NAME_MAXLEN
# warning JAILHOUSE_CELL_ID_NAMELEN and JAILHOUSE_CELL_NAME_MAXLEN out of sync!
#endif
#ifdef CONFIG_X86
-#define JAILHOUSE_AMD_FW_NAME "jailhouse-amd.bin"
-#define JAILHOUSE_INTEL_FW_NAME "jailhouse-intel.bin"
+#define JAILHOUSE_AMD_FW_NAME "rvm-amd.bin"
+#define JAILHOUSE_INTEL_FW_NAME "rvm-intel.bin"
#else
-#define JAILHOUSE_FW_NAME "jailhouse.bin"
+#define JAILHOUSE_FW_NAME "rvm.bin"
#endif
MODULE_DESCRIPTION("Management driver for Jailhouse partitioning hypervisor");
@@ -100,7 +107,11 @@ static struct resource *hypervisor_mem_res;
static typeof(ioremap_page_range) *ioremap_page_range_sym;
#ifdef CONFIG_X86
-static typeof(lapic_timer_frequency) *lapic_timer_frequency_sym;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0)
+#define lapic_timer_period lapic_timer_frequency
+#define lapic_timer_period_sym lapic_timer_frequency_sym
+#endif
+static typeof(lapic_timer_period) *lapic_timer_period_sym;
#endif
#ifdef CONFIG_ARM
static typeof(__boot_cpu_mode) *__boot_cpu_mode_sym;
@@ -402,9 +413,8 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
if (boot_cpu_has(X86_FEATURE_VMX)) {
u64 features;
- rdmsrl(MSR_IA32_FEATURE_CONTROL, features);
- if ((features &
- FEATURE_CONTROL_VMXON_ENABLED_OUTSIDE_SMX) == 0) {
+ rdmsrl(MSR_IA32_FEAT_CTL, features);
+ if ((features & FEAT_CTL_VMX_ENABLED_OUTSIDE_SMX) == 0) {
pr_err("jailhouse: VT-x disabled by Firmware/BIOS\n");
err = -ENODEV;
goto error_put_module;
@@ -550,7 +560,7 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
config->platform_info.x86.tsc_khz = tsc_khz;
if (config->platform_info.x86.apic_khz == 0)
config->platform_info.x86.apic_khz =
- *lapic_timer_frequency_sym / (1000 / HZ);
+ *lapic_timer_period_sym / (1000 / HZ);
#endif
err = jailhouse_cell_prepare_root(&config->root_cell);
@@ -695,10 +705,9 @@ static int jailhouse_cmd_disable(void)
preempt_enable();
err = error_code;
- if (err)
- goto unlock_out;
-
- update_last_console();
+ if (err) {
+ pr_warn("jailhouse: Failed to disable hypervisor: %d\n", err);
+ }
jailhouse_cell_delete_root();
jailhouse_enabled = false;
@@ -885,19 +894,20 @@ static int __init jailhouse_init(void)
{
int err;
-#ifdef CONFIG_KALLSYMS_ALL
-#define RESOLVE_EXTERNAL_SYMBOL(symbol) \
+#if defined(CONFIG_KALLSYMS_ALL) && LINUX_VERSION_CODE < KERNEL_VERSION(5,7,0)
+#define __RESOLVE_EXTERNAL_SYMBOL(symbol) \
symbol##_sym = (void *)kallsyms_lookup_name(#symbol); \
if (!symbol##_sym) \
return -EINVAL
#else
-#define RESOLVE_EXTERNAL_SYMBOL(symbol) \
+#define __RESOLVE_EXTERNAL_SYMBOL(symbol) \
symbol##_sym = &symbol
#endif
+#define RESOLVE_EXTERNAL_SYMBOL(symbol...) __RESOLVE_EXTERNAL_SYMBOL(symbol)
RESOLVE_EXTERNAL_SYMBOL(ioremap_page_range);
#ifdef CONFIG_X86
- RESOLVE_EXTERNAL_SYMBOL(lapic_timer_frequency);
+ RESOLVE_EXTERNAL_SYMBOL(lapic_timer_period);
#endif
#ifdef CONFIG_ARM
RESOLVE_EXTERNAL_SYMBOL(__boot_cpu_mode);
diff --git a/gen-config.sh b/gen-config.sh
new file mode 100755
index 00000000..6f9dc246
--- /dev/null
+++ b/gen-config.sh
@@ -0,0 +1,12 @@
+# Generate system configuration
+sudo python3 ./tools/jailhouse-config-create --mem-hv 256M ./configs/x86/qemu-ubuntu.c
+sudo chown $(whoami) ./configs/x86/qemu-ubuntu.c
+echo "Created config file at './configs/x86/qemu-ubuntu.c'"
+
+# Extract kernel command line
+cmdline=$(cat ./configs/x86/qemu-ubuntu.c | grep memmap | tr -d " \*" | sed 's/\$/\\\\\\\\\\$/g')
+
+# Update grub config
+cmdline=$(echo $cmdline | sed 's/\\/\\\\/g')
+sudo sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=$cmdline/" /etc/default/grub
+echo "Appended kernel cmdline: $cmdline, see '/etc/default/grub'"
diff --git a/hypervisor/arch/x86/include/asm/jailhouse_header.h b/hypervisor/arch/x86/include/asm/jailhouse_header.h
index 020af029..92ee115c 100644
--- a/hypervisor/arch/x86/include/asm/jailhouse_header.h
+++ b/hypervisor/arch/x86/include/asm/jailhouse_header.h
@@ -10,5 +10,5 @@
* the COPYING file in the top-level directory.
*/
-#define JAILHOUSE_BASE __JH_CONST_UL(0xfffffffff0000000)
+#define JAILHOUSE_BASE __JH_CONST_UL(0xffffff0000000000)
#define JAILHOUSE_BORROW_ROOT_PT 1
diff --git a/hypervisor/include/jailhouse/header.h b/hypervisor/include/jailhouse/header.h
index 518bc5cb..5fddda56 100644
--- a/hypervisor/include/jailhouse/header.h
+++ b/hypervisor/include/jailhouse/header.h
@@ -12,7 +12,7 @@
#include <asm/jailhouse_header.h>
-#define JAILHOUSE_SIGNATURE "JAILHOUS"
+#define JAILHOUSE_SIGNATURE "RVMIMAGE"
#define HYP_STUB_ABI_LEGACY 0
#define HYP_STUB_ABI_OPCODE 1
diff --git a/include/jailhouse/cell-config.h b/include/jailhouse/cell-config.h
index 66e13c3d..51c8531c 100644
--- a/include/jailhouse/cell-config.h
+++ b/include/jailhouse/cell-config.h
@@ -67,7 +67,7 @@
#define CELL_FLAGS_VIRTUAL_CONSOLE_PERMITTED(flags) \
!!((flags) & JAILHOUSE_CELL_VIRTUAL_CONSOLE_PERMITTED)
-#define JAILHOUSE_CELL_DESC_SIGNATURE "JHCELL"
+#define JAILHOUSE_CELL_DESC_SIGNATURE "RVMCEL"
/**
* The jailhouse cell configuration.
@@ -200,7 +200,7 @@ struct jailhouse_iommu {
__u32 amd_features;
} __attribute__((packed));
-#define JAILHOUSE_SYSTEM_SIGNATURE "JHSYST"
+#define JAILHOUSE_SYSTEM_SIGNATURE "RVMSYS"
/*
* The flag JAILHOUSE_SYS_VIRTUAL_DEBUG_CONSOLE allows the root cell to read
diff --git a/pyjailhouse/sysfs_parser.py b/pyjailhouse/sysfs_parser.py
index c4154736..e1a6efca 100644
--- a/pyjailhouse/sysfs_parser.py
+++ b/pyjailhouse/sysfs_parser.py
@@ -100,19 +100,19 @@ def parse_iomem(pcidevices):
dmar_regions = []
for r in regions:
append_r = True
- # filter the list for MSI-X pages
- for d in pcidevices:
- if d.msix_address >= r.start and d.msix_address <= r.stop:
- if d.msix_address > r.start:
- head_r = MemRegion(r.start, d.msix_address - 1,
- r.typestr, r.comments)
- ret.append(head_r)
- if d.msix_address + d.msix_region_size < r.stop:
- tail_r = MemRegion(d.msix_address + d.msix_region_size,
- r.stop, r.typestr, r.comments)
- ret.append(tail_r)
- append_r = False
- break
+ # # filter the list for MSI-X pages
+ # for d in pcidevices:
+ # if d.msix_address >= r.start and d.msix_address <= r.stop:
+ # if d.msix_address > r.start:
+ # head_r = MemRegion(r.start, d.msix_address - 1,
+ # r.typestr, r.comments)
+ # ret.append(head_r)
+ # if d.msix_address + d.msix_region_size < r.stop:
+ # tail_r = MemRegion(d.msix_address + d.msix_region_size,
+ # r.stop, r.typestr, r.comments)
+ # ret.append(tail_r)
+ # append_r = False
+ # break
# filter out the ROMs
if (r.start >= rom_region.start and r.stop <= rom_region.stop):
add_rom_region = True
@@ -202,6 +202,7 @@ def parse_dmar_devscope(f):
# parsing of DMAR ACPI Table
# see Intel VT-d Spec chapter 8
def parse_dmar(pcidevices, ioapics, dmar_regions):
+ return [], []
f = input_open('/sys/firmware/acpi/tables/DMAR', 'rb')
signature = f.read(4)
if signature != b'DMAR':
@@ -315,6 +316,7 @@ def parse_dmar(pcidevices, ioapics, dmar_regions):
def parse_ivrs(pcidevices, ioapics):
+ return [], []
def format_bdf(bdf):
bus, dev, fun = (bdf >> 8) & 0xff, (bdf >> 3) & 0x1f, bdf & 0x7
return '%02x:%02x.%x' % (bus, dev, fun)
@@ -889,12 +891,12 @@ class IOMemRegionTree:
regions.extend(tree.regions_split_by_kernel())
continue
- # blacklisted on all levels
- if (
- (s.find('PCI MMCONFIG') >= 0) or
- (s.find('APIC') >= 0) # covers both APIC and IOAPIC
- ):
- continue
+ # # blacklisted on all levels
+ # if (
+ # (s.find('PCI MMCONFIG') >= 0) or
+ # (s.find('APIC') >= 0) # covers both APIC and IOAPIC
+ # ):
+ # continue
# generally blacklisted, unless we find an HPET behind it
if (s.lower() == 'reserved'):
diff --git a/tools/jailhouse-config-create b/tools/jailhouse-config-create
index 6673f46c..6b8a0227 100755
--- a/tools/jailhouse-config-create
+++ b/tools/jailhouse-config-create
@@ -239,7 +239,7 @@ if options.generate_collector:
f.close()
sys.exit(0)
-if ((options.root is '/') and (os.geteuid() is not 0)):
+if options.root == '/' and os.geteuid() != 0:
print('ERROR: You have to be root to work on "/"!', file=sys.stderr)
sys.exit(1)
@@ -266,7 +266,7 @@ product = [input_readline('/sys/class/dmi/id/sys_vendor',
True).rstrip()
]
-inmatemem = kmg_multiply_str(options.mem_inmates)
+inmatemem = 0 # kmg_multiply_str(options.mem_inmates)
hvmem = [0, kmg_multiply_str(options.mem_hv)]
(regions, dmar_regions) = sysfs_parser.parse_iomem(pcidevices)
@@ -298,7 +298,9 @@ hvmem[0] = ourmem[0]
inmatereg = sysfs_parser.MemRegion(ourmem[0] + hvmem[1],
ourmem[0] + hvmem[1] + inmatemem - 1,
'JAILHOUSE Inmate Memory')
-regions.append(inmatereg)
+
+for r in regions:
+ print(r)
cpucount = count_cpus()
diff --git a/tools/root-cell-config.c.tmpl b/tools/root-cell-config.c.tmpl
index 5a8e1412..9b016c80 100644
--- a/tools/root-cell-config.c.tmpl
+++ b/tools/root-cell-config.c.tmpl
@@ -56,7 +56,7 @@ struct {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
- .flags = JAILHOUSE_SYS_VIRTUAL_DEBUG_CONSOLE,
+ .flags = 0,
.hypervisor_memory = {
.phys_start = ${hex(hvmem[0])},
.size = ${hex(hvmem[1])},