Skip to content

Commit da900a5

Browse files
committed
LKMC v3.0
This is a squash commit, the unsquashed development went through many unstable phases which would break bisects. The unsquashed branch is: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/v3.0-unsquash The main improvement of this release was to greatly generalize the testing system. The key addition was cli_function.py, which allows scripts such as ./run to be transparently called either from Python or from the command line. New tests scripts were created using this improved framework: test-baremetal and test-user-mode. We were lazy to port some of less important tests to the new setup, TODO's were added, and we need comes they will be fixed. Getting started is however sacred as usual and should work. Other changes include: - gem5: update to 7fa4c946386e7207ad5859e8ade0bbfc14000d91 - run: --tmux-args implies --tmux - run: add --userland-args to make userland arguments across QEMU and gem5 Get rid of --userland-before as a consequence. - bring initrd and initramfs back to life - build-userland: create --static to make build a bit easier - gem5: --gem5-worktree also set --gem5-build-id - remove --gem5, use --emulator gem5 everywhere Allow passing --emulator multiple times for transparent tests selection just like --arch. - test-userland: allow selecting just a few tests - linux: update to v4.20 - buildroot: update to 2018.08 The main motivation for this was to fix the build for Ubuntu 18.10, which has glibc 2.28, which broke the 2018.05 build at the m4-host package with: #error "Please port gnulib fseeko.c to your platform! - getvar --type input - failed xen attempt, refactor timer, failed svc attempt, aarch64 use gicv3 - build-doc: exit 1 on error, add to release testing - build: add --apt option to make things easier on other distros - build-linux: --no-modules-install
1 parent 3b0a343 commit da900a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5235
-3537
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@
2121
[submodule "submodules/qemu"]
2222
path = submodules/qemu
2323
url = https://github.com/cirosantilli/qemu
24+
[submodule "submodules/xen"]
25+
path = submodules/xen
26+
url = git://xenbits.xen.org/xen.git
27+
[submodule "submodules/boot-wrapper-aarch64"]
28+
path = submodules/boot-wrapper-aarch64
29+
url = git://git.kernel.org/pub/scm/linux/kernel/git/mark/boot-wrapper-aarch64.git

README.adoc

+658-335
Large diffs are not rendered by default.

arm

-3
This file was deleted.

baremetal/add.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#include <common.h>
22

33
int main(void) {
4-
int i, j, k;
5-
i = 1;
4+
int i, j, k;
5+
i = 1;
66
/* test-gdb-op1 */
7-
j = 2;
7+
j = 2;
88
/* test-gdb-op2 */
9-
k = i + j;
9+
k = i + j;
1010
/* test-gdb-result */
11-
if (k != 3)
12-
common_assert_fail();
11+
if (k != 3)
12+
common_assert_fail();
1313
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef COMMON_AARCH64_H
2+
#define COMMON_AARCH64_H
3+
4+
#include <inttypes.h>
5+
6+
#define SYSREG_READ(type, name) \
7+
type sysreg_ ## name ## _read(void) { \
8+
type name; \
9+
__asm__ __volatile__("mrs %0, " #name : "=r" (name) : : ); \
10+
return name; \
11+
}
12+
13+
#define SYSREG_WRITE(type, name) \
14+
void sysreg_ ## name ## _write(type name) { \
15+
__asm__ __volatile__("msr " #name ", %0" : : "r" (name) : ); \
16+
}
17+
18+
#define SYSREG_READ_WRITE(name, type) \
19+
SYSREG_READ(name, type) \
20+
SYSREG_WRITE(name, type)
21+
22+
#define SVC(immediate) __asm__ __volatile__("svc " #immediate : : : )
23+
24+
#endif

baremetal/arch/aarch64/el.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55

66
int main(void) {
7-
register uint64_t x0 __asm__ ("x0");
8-
__asm__ ("mrs x0, CurrentEL;" : : : "%x0");
9-
printf("%" PRIu64 "\n", x0 >> 2);
10-
return 0;
7+
uint64_t el;
8+
__asm__ ("mrs %0, CurrentEL;" : "=r" (el) : :);
9+
printf("%" PRIu64 "\n", el >> 2);
10+
return 0;
1111
}

baremetal/arch/aarch64/multicore.S

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ main:
99

1010
/* Read cpu id into x1.
1111
* TODO: cores beyond 4th?
12+
* Mnemonic: Main Processor ID Register
1213
*/
1314
mrs x1, mpidr_el1
1415
ands x1, x1, 3

baremetal/arch/aarch64/svc.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
4+
#include "common_aarch64.h"
5+
6+
/* Masks each of the 4 exception types: Synchronous, System error,
7+
* IRQ and FIQ.
8+
*/
9+
SYSREG_READ_WRITE(uint32_t, daif)
10+
11+
/* Determines if we use SP0 or SPx. Default: SP0.
12+
* See also: https://stackoverflow.com/questions/29393677/armv8-exception-vector-significance-of-el0-sp
13+
*/
14+
SYSREG_READ_WRITE(uint32_t, spsel)
15+
16+
/* Jump to this SP if spsel == SPx. */
17+
SYSREG_READ_WRITE(uint64_t, sp_el1)
18+
19+
int main(void) {
20+
printf("daif 0x%" PRIx32 "\n", sysreg_daif_read());
21+
printf("spsel 0x%" PRIx32 "\n", sysreg_spsel_read());
22+
/* TODO this breaks execution because reading system registers that end
23+
* in ELx "trap", leading into an exception on the upper EL.
24+
*/
25+
/*printf("sp_el1 0x%" PRIx64 "\n", sysreg_sp_el1_read());*/
26+
/*SVC(0);*/
27+
return 0;
28+
}

baremetal/arch/aarch64/timer.c

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include <stdio.h>
2+
#include <inttypes.h>
3+
4+
#include "common_aarch64.h"
5+
6+
#define CNTV_CTL_ENABLE (1 << 0)
7+
#define CNTV_CTL_IMASK (1 << 1)
8+
#define CNTV_CTL_ISTATUS (1 << 2)
9+
10+
/* Frequency in Hz. ? */
11+
SYSREG_READ_WRITE(uint64_t, cntfrq_el0)
12+
13+
/* Current virtual counter value. */
14+
SYSREG_READ(uint64_t, cntvct_el0)
15+
16+
/* Compare value. See: cntv_ctl_el0_enable. */
17+
SYSREG_READ_WRITE(uint64_t, cntv_cval_el0)
18+
19+
/* On write, set cntv_cval_el0 = (cntvct_el0 + cntv_tval_el0).
20+
* This means that the next interrupt will happen in cntv_tval_el0 cycles.
21+
*/
22+
SYSREG_READ_WRITE(uint64_t, cntv_tval_el0)
23+
24+
/* Control register. */
25+
SYSREG_READ_WRITE(uint32_t, cntv_ctl_el0)
26+
27+
void cntv_ctl_el0_disable(void) {
28+
sysreg_cntv_ctl_el0_write(sysreg_cntv_ctl_el0_read() & ~CNTV_CTL_ENABLE);
29+
}
30+
31+
/* If enabled, when: cntv_ctl > cntv_cval then:
32+
*
33+
* * if CNTV_CTL_IMASK is clear, raise an interrupt
34+
* * set CNTV_CTL_ISTATUS
35+
*/
36+
void cntv_ctl_el0_enable(void) {
37+
sysreg_cntv_ctl_el0_write(sysreg_cntv_ctl_el0_read() | CNTV_CTL_ENABLE);
38+
}
39+
40+
int main(void) {
41+
/* Initial state. */
42+
printf("cntv_ctl_el0 0x%" PRIx32 "\n", sysreg_cntv_ctl_el0_read());
43+
printf("cntfrq_el0 0x%" PRIx64 "\n", sysreg_cntfrq_el0_read());
44+
printf("cntv_cval_el0 0x%" PRIx64 "\n", sysreg_cntv_cval_el0_read());
45+
46+
/* Get the counter value many times to watch the time pass. */
47+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
48+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
49+
printf("cntvct_el0 0x%" PRIx64 "\n", sysreg_cntvct_el0_read());
50+
51+
#if 0
52+
/* TODO crashes gem5. */
53+
puts("cntfrq_el0 = 1");
54+
sysreg_cntfrq_el0_write(1);
55+
printf("cntfrq_el0 0x%" PRIx64 "\n", sysreg_cntfrq_el0_read());
56+
#endif
57+
58+
return 0;
59+
}

baremetal/arch/arm/el.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include <inttypes.h>
55

66
int main(void) {
7-
register uint32_t r0 __asm__ ("r0");
8-
__asm__ ("mrs r0, CPSR" : : : "%r0");
9-
printf("%" PRIu32 "\n", r0 & 0x1F);
10-
return 0;
7+
uint32_t cpsr;
8+
__asm__ ("mrs %0, CPSR" : "=r" (cpsr) : :);
9+
printf("%" PRIu32 "\n", cpsr & 0x1F);
10+
return 0;
1111
}

baremetal/exit.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
#include <stdlib.h>
33

44
int main(void) {
5-
exit(0);
5+
exit(0);
66
}
7-
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <stdio.h>
22

33
int main(void) {
4-
puts("hello");
5-
return 0;
4+
puts("hello");
5+
return 0;
66
}

baremetal/interactive/assert_fail.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <common.h>
22

33
int main(void) {
4-
common_assert_fail();
4+
common_assert_fail();
55
}
66

baremetal/interactive/exit1.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
#include <stdlib.h>
33

44
int main(void) {
5-
exit(1);
5+
exit(1);
66
}

baremetal/interactive/infinite_loop.c

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int main(void) {
2+
while(1) {}
3+
return 0;
4+
}

baremetal/lib/syscalls.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,24 @@ int _write(int file, char *ptr, int len) {
6464
void _exit(int status) {
6565
#if defined(GEM5)
6666
#if defined(__arm__)
67-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x21 << 16);");
67+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x21 << 16);");
6868
#elif defined(__aarch64__)
69-
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
69+
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
7070
#endif
7171
#else
7272
#if defined(__arm__)
7373
__asm__ __volatile__ ("mov r0, #0x18; ldr r1, =#0x20026; svc 0x00123456");
7474
#elif defined(__aarch64__)
75-
/* TODO actually use the exit value here, just for fun. */
75+
/* TODO actually use the exit value here, just for fun. */
7676
__asm__ __volatile__ (
77-
"mov x1, #0x26\n" \
78-
"movk x1, #2, lsl #16\n" \
79-
"str x1, [sp,#0]\n" \
80-
"mov x0, #0\n" \
81-
"str x0, [sp,#8]\n" \
82-
"mov x1, sp\n" \
83-
"mov w0, #0x18\n" \
84-
"hlt 0xf000\n"
77+
"mov x1, #0x26\n" \
78+
"movk x1, #2, lsl #16\n" \
79+
"str x1, [sp,#0]\n" \
80+
"mov x0, #0\n" \
81+
"str x0, [sp,#8]\n" \
82+
"mov x1, sp\n" \
83+
"mov w0, #0x18\n" \
84+
"hlt 0xf000\n"
8585
);
8686
#endif
8787
#endif

bench-all

+6-6
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,25 @@ if "$bench_gem5_build"; then
100100
common_arch="$default_arch"
101101
gem5_build_id=bench
102102
common_gem5_build_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_build_dir)"
103-
common_gem5_src_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_src_dir)"
103+
common_gem5_source_dir="$("$getvar" --arch "$common_arch" --gem5-build-id "$gem5_build_id" gem5_source_dir)"
104104
results_file="${common_gem5_build_dir}/lkmc-bench-build.txt"
105-
git -C "${common_gem5_src_dir}" clean -xdf
105+
git -C "${common_gem5_source_dir}" clean -xdf
106106
rm -f "$results_file"
107107
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
108108
# TODO understand better: --foreground required otherwise we cannot
109109
# kill the build with Ctrl+C if something goes wrong, can be minimized to:
110110
# bash -c "eval 'timeout 5 sleep 3'"
111111
"${root_dir}/bench-cmd" "timeout --foreground 900 ./build-gem5 --arch '$common_arch' --gem5-build-id '$gem5_build_id'" "$results_file"
112112
cp "$results_file" "${new_dir}/gem5-bench-build-${common_arch}.txt"
113-
git -C "${common_gem5_src_dir}" clean -xdf
113+
git -C "${common_gem5_source_dir}" clean -xdf
114114
"${root_dir}/build-gem5" --arch "$common_arch" --clean --gem5-build-id "$gem5_build_id"
115115
fi
116116

117117
if "$bench_linux_boot"; then
118118
cd "${root_dir}"
119-
"${root_dir}/build" --all
120-
"${root_dir}/bench-boot" --size 3
121-
cp "$(${root_dir}/getvar bench_boot)" "$new_dir"
119+
"${root_dir}/build" --all-archs all
120+
"${root_dir}/test-boot" --size 3
121+
cp "$(${root_dir}/getvar test_boot_benchmark_file)" "$new_dir"
122122
fi
123123

124124
if "$update_repo"; then

bench-boot

-94
This file was deleted.

0 commit comments

Comments
 (0)