Skip to content

Commit 67e596a

Browse files
committed
Merge branch 'x86-nxt' into all-in-one
2 parents 3f9e39d + cbf35a3 commit 67e596a

29 files changed

+3010
-13
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*.cmd
2+
*.o
3+
*.mod.c
4+
*.ko
5+
*.order
6+
Module.symvers
7+
.tmp_versions

README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

x86/bitmap/Makefile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Makefile
2+
# Comment/uncomment the following line to disable/enable debugging
3+
# DEBUG = y
4+
5+
# Usage
6+
# make CROSS_COMPILE=<cross_compiler_prefix> KERNEL_DIR=<your_kernel_dir> KERNEL_BUID_OUTPUT=<kernel_buid_output>
7+
#
8+
# make CROSS_COMPILE=/home/zeroway/rk3399/tool/gcc-linaro-4.9.4-2017.01-i686_aarch64-linux-gnu/bin/aarch64-linux-gnu- KERNEL_DIR=/home/zeroway/rk3399/src/firefly/kernel KERNEL_BUID_OUTPUT=/home/zeroway/rk3399/src/firefly/out/target/product/rk3399_firefly_box/obj/KERNEL
9+
10+
# Add your debugging flag (or not) to CFLAGS
11+
ifeq ($(DEBUG),y)
12+
DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
13+
else
14+
DEBFLAGS = -O2
15+
endif
16+
17+
obj-m := bitmap_test.o
18+
19+
KERNEL_DIR ?= /lib/modules/`uname -r`/build
20+
KERNEL_BUID_OUTPUT ?=$(KERNEL_DIR)
21+
CC = $(CROSS_COMPILE)gcc
22+
LD = $(CROSS_COMPILE)ld
23+
PWD := $(shell pwd)
24+
ARCH := x86_64
25+
26+
modules:
27+
$(MAKE) -C $(KERNEL_DIR) ARCH=$(ARCH) M=$(PWD) O=$(KERNEL_DIR) modules
28+
29+
clean:
30+
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers
31+
32+
depend .depend dep:
33+
$(CC) $(CFLAGS) -M *.c > .depend
34+
35+
ifeq (.depend,$(wildcard .depend))
36+
include .depend
37+
endif

x86/bitmap/bitmap_test.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#include <linux/init.h>
2+
#include <linux/module.h>
3+
4+
/* https://www.cnblogs.com/schips/p/10674687.html */
5+
6+
#define BITMAP_LEN 10
7+
8+
#define USING_UNLONG
9+
#ifdef USING_UNLONG
10+
unsigned long mybm[1];
11+
#else
12+
DECLARE_BITMAP(mybm, BITMAP_LEN);
13+
#endif
14+
15+
static int bitmap_test_init(void)
16+
{
17+
int bit;
18+
19+
/* architecture specifiy API */
20+
/*
21+
* non atomic version
22+
* include/asm-generic/bitops/instrumented-non-atomic.h
23+
*/
24+
__set_bit(1, mybm);
25+
/*
26+
* arch___set_bit(nr, addr);
27+
* asm volatile(__ASM_SIZE(bts) " %1,%0" : : ADDR, "Ir" (nr) : "memory");
28+
*/
29+
if (!test_bit(1, mybm))
30+
printk(KERN_ALERT" bit 1 tested not set\n");
31+
else
32+
printk(KERN_ALERT" bit 1 tested set\n");
33+
34+
__clear_bit(1, mybm);
35+
if (!test_bit(1, mybm))
36+
printk(KERN_ALERT" bit 1 tested not set\n");
37+
else
38+
printk(KERN_ALERT" bit 1 tested set\n");
39+
40+
/*
41+
* atomic version
42+
* include/asm-generic/bitops/atomic.h
43+
* arch/x86/boot/bitops.h
44+
*/
45+
set_bit(2, mybm);
46+
if (!test_bit(2, mybm))
47+
printk(KERN_ALERT" bit 2 tested not set\n");
48+
else
49+
printk(KERN_ALERT" bit 2 tested set\n");
50+
51+
clear_bit(2, mybm);
52+
if (!test_bit(2, mybm))
53+
printk(KERN_ALERT" bit 2 tested not set\n");
54+
else
55+
printk(KERN_ALERT" bit 2 tested set\n");
56+
57+
/* Generic API */
58+
bitmap_zero(mybm, BITMAP_LEN);
59+
if (!test_bit(3, mybm))
60+
printk(KERN_ALERT" bit 3 tested not set\n");
61+
else
62+
printk(KERN_ALERT" bit 3 tested set\n");
63+
64+
bitmap_fill(mybm, BITMAP_LEN);
65+
if (!test_bit(3, mybm))
66+
printk(KERN_ALERT" bit 3 tested not set\n");
67+
else
68+
printk(KERN_ALERT" bit 3 tested set\n");
69+
70+
/* clear all before test */
71+
bitmap_zero(mybm, BITMAP_LEN);
72+
set_bit(4, mybm);
73+
set_bit(8, mybm);
74+
set_bit(9, mybm);
75+
/* iterator all the setted bit */
76+
for_each_set_bit(bit, mybm, BITMAP_LEN)
77+
printk(KERN_ALERT" %d\n", bit);
78+
printk(KERN_ALERT"===========\n");
79+
80+
/* iterator all the no setted bit */
81+
for_each_clear_bit(bit, mybm, BITMAP_LEN)
82+
printk(KERN_ALERT" %d\n", bit);
83+
printk(KERN_ALERT"===========\n");
84+
85+
printk(KERN_ALERT"BitMap test Done\n");
86+
87+
return 0;
88+
}
89+
90+
static void bitmap_test_exit(void)
91+
{
92+
printk(KERN_ALERT"BitMap test Exit\n");
93+
}
94+
95+
MODULE_LICENSE("Dual BSD/GPL");
96+
module_init(bitmap_test_init);
97+
module_exit(bitmap_test_exit);

x86/bpf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
demo

x86/bpf/Makefile

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
KERNEL_DIR ?= /lib/modules/`uname -r`/build
4+
KERNEL_BUID_OUTPUT ?=$(KERNEL_DIR)
5+
srctree ?=$(KERNEL_DIR)
6+
7+
BPF_SAMPLES_PATH ?= $(KERNEL_DIR)/samples/bpf
8+
TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
9+
10+
# List of programs to build
11+
tprogs-y := demo
12+
tprogs-y += vmexit
13+
14+
# Libbpf dependencies
15+
LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
16+
17+
demo-objs := trace_helpers.o
18+
demo-objs += demo_user.o
19+
20+
vmexit-objs := trace_helpers.o
21+
vmexit-objs += vmexit_user.o
22+
23+
# Tell kbuild to always build the programs
24+
always-y := $(tprogs-y)
25+
always-y += demo_kern.o
26+
always-y += vmexit_kern.o
27+
28+
ifeq ($(ARCH), arm)
29+
# Strip all except -D__LINUX_ARM_ARCH__ option needed to handle linux
30+
# headers when arm instruction set identification is requested.
31+
ARM_ARCH_SELECTOR := $(filter -D__LINUX_ARM_ARCH__%, $(KBUILD_CFLAGS))
32+
BPF_EXTRA_CFLAGS := $(ARM_ARCH_SELECTOR)
33+
TPROGS_CFLAGS += $(ARM_ARCH_SELECTOR)
34+
endif
35+
36+
ifeq ($(ARCH), mips)
37+
TPROGS_CFLAGS += -D__SANE_USERSPACE_TYPES__
38+
ifdef CONFIG_MACH_LOONGSON64
39+
BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-loongson64
40+
BPF_EXTRA_CFLAGS += -I$(srctree)/arch/mips/include/asm/mach-generic
41+
endif
42+
endif
43+
44+
TPROGS_CFLAGS += -Wall -O2
45+
TPROGS_CFLAGS += -Wmissing-prototypes
46+
TPROGS_CFLAGS += -Wstrict-prototypes
47+
48+
TPROGS_CFLAGS += -I$(objtree)/usr/include
49+
TPROGS_CFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
50+
TPROGS_CFLAGS += -I$(srctree)/tools/lib/
51+
TPROGS_CFLAGS += -I$(srctree)/tools/include
52+
TPROGS_CFLAGS += -I$(srctree)/tools/perf
53+
TPROGS_CFLAGS += -DHAVE_ATTR_TEST=0
54+
55+
ifdef SYSROOT
56+
TPROGS_CFLAGS += --sysroot=$(SYSROOT)
57+
TPROGS_LDFLAGS := -L$(SYSROOT)/usr/lib
58+
endif
59+
60+
TPROGS_LDLIBS += $(LIBBPF) -lelf -lz
61+
TPROGLDLIBS_tracex4 += -lrt
62+
TPROGLDLIBS_trace_output += -lrt
63+
TPROGLDLIBS_map_perf_test += -lrt
64+
TPROGLDLIBS_test_overhead += -lrt
65+
TPROGLDLIBS_xdpsock += -pthread -lcap
66+
TPROGLDLIBS_xsk_fwd += -pthread
67+
68+
# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
69+
# make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang
70+
LLC ?= llc
71+
CLANG ?= clang
72+
OPT ?= opt
73+
LLVM_DIS ?= llvm-dis
74+
LLVM_OBJCOPY ?= llvm-objcopy
75+
BTF_PAHOLE ?= pahole
76+
77+
# Detect that we're cross compiling and use the cross compiler
78+
ifdef CROSS_COMPILE
79+
CLANG_ARCH_ARGS = --target=$(notdir $(CROSS_COMPILE:%-=%))
80+
endif
81+
82+
# Don't evaluate probes and warnings if we need to run make recursively
83+
ifneq ($(src),)
84+
HDR_PROBE := $(shell printf "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
85+
$(CC) $(TPROGS_CFLAGS) $(TPROGS_LDFLAGS) -x c - \
86+
-o /dev/null 2>/dev/null && echo okay)
87+
88+
ifeq ($(HDR_PROBE),)
89+
$(warning WARNING: Detected possible issues with include path.)
90+
$(warning WARNING: Please install kernel headers locally (make headers_install).)
91+
endif
92+
93+
BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
94+
BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
95+
BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
96+
BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
97+
$(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
98+
readelf -S ./llvm_btf_verify.o | grep BTF; \
99+
/bin/rm -f ./llvm_btf_verify.o)
100+
101+
BPF_EXTRA_CFLAGS += -fno-stack-protector
102+
ifneq ($(BTF_LLVM_PROBE),)
103+
BPF_EXTRA_CFLAGS += -g
104+
else
105+
ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
106+
BPF_EXTRA_CFLAGS += -g
107+
LLC_FLAGS += -mattr=dwarfris
108+
DWARF2BTF = y
109+
endif
110+
endif
111+
endif
112+
113+
# Trick to allow make to be run from this directory
114+
all:
115+
$(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) BPF_SAMPLES_PATH=$(BPF_SAMPLES_PATH)
116+
117+
clean:
118+
$(MAKE) -C $(KERNEL_DIR) M=$(CURDIR) clean
119+
@find $(CURDIR) -type f -name '*~' -delete
120+
121+
$(LIBBPF): FORCE
122+
# Fix up variables inherited from Kbuild that tools/ build system won't like
123+
$(MAKE) -C $(dir $@) RM='rm -rf' EXTRA_CFLAGS="$(TPROGS_CFLAGS)" \
124+
LDFLAGS=$(TPROGS_LDFLAGS) srctree=$(BPF_SAMPLES_PATH)/../../ O=
125+
126+
$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
127+
$(call filechk,offsets,__SYSCALL_NRS_H__)
128+
129+
targets += syscall_nrs.s
130+
clean-files += syscall_nrs.h
131+
132+
FORCE:
133+
134+
135+
# Verify LLVM compiler tools are available and bpf target is supported by llc
136+
.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
137+
138+
verify_cmds: $(CLANG) $(LLC)
139+
@for TOOL in $^ ; do \
140+
if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
141+
echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
142+
exit 1; \
143+
else true; fi; \
144+
done
145+
146+
verify_target_bpf: verify_cmds
147+
@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
148+
echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
149+
echo " NOTICE: LLVM version >= 3.7.1 required" ;\
150+
exit 2; \
151+
else true; fi
152+
153+
$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
154+
$(src)/*.c: verify_target_bpf $(LIBBPF)
155+
156+
$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
157+
$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
158+
$(obj)/hbm.o: $(src)/hbm.h
159+
$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
160+
161+
-include $(BPF_SAMPLES_PATH)/Makefile.target
162+
163+
# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
164+
# But, there is no easy way to fix it, so just exclude it since it is
165+
# useless for BPF samples.
166+
# below we use long chain of commands, clang | opt | llvm-dis | llc,
167+
# to generate final object file. 'clang' compiles the source into IR
168+
# with native target, e.g., x64, arm64, etc. 'opt' does bpf CORE IR builtin
169+
# processing (llvm12) and IR optimizations. 'llvm-dis' converts
170+
# 'opt' output to IR, and finally 'llc' generates bpf byte code.
171+
$(obj)/%.o: $(src)/%.c
172+
@echo " CLANG-bpf " $@
173+
$(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(BPF_EXTRA_CFLAGS) \
174+
-I$(obj) -I$(srctree)/tools/testing/selftests/bpf/ \
175+
-I$(srctree)/tools/lib/ \
176+
-D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
177+
-D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
178+
-Wno-gnu-variable-sized-type-not-at-end \
179+
-Wno-address-of-packed-member -Wno-tautological-compare \
180+
-Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
181+
-I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
182+
-O2 -emit-llvm -Xclang -disable-llvm-passes -c $< -o - | \
183+
$(OPT) -O2 -mtriple=bpf-pc-linux | $(LLVM_DIS) | \
184+
$(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
185+
ifeq ($(DWARF2BTF),y)
186+
$(BTF_PAHOLE) -J $@
187+
endif

0 commit comments

Comments
 (0)