Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ kernel/xpmem.mod.c
kernel/xpmem.mod
kernel/modules.order
kernel/Module.symvers
kernel/Kbuild
kernel/test_mods/
kernel/xpmem_kernel.h
.tmp_versions
test-driver
dkms.conf
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ EXTRA_DIST = \
echo "set ModulesVersion \"@MODULE_VERSION@\"" >> $@

dist: dist-bzip2

CLEANFILES = .version xpmem-*.tar.bz2
4 changes: 3 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ AC_CONFIG_FILES([Makefile
xpmem.spec
module
include/Makefile
kernel/Kbuild
kernel/Makefile
kernel/xpmem
lib/Makefile
Expand All @@ -96,5 +95,8 @@ AC_CONFIG_LINKS([kernel/xpmem_attach.c:kernel/xpmem_attach.c
kernel/xpmem_mmu_notifier.c:kernel/xpmem_mmu_notifier.c
kernel/xpmem_pfn.c:kernel/xpmem_pfn.c
kernel/xpmem_private.h:kernel/xpmem_private.h
kernel/Kbuild:kernel/Kbuild
include/xpmem.h:include/xpmem.h
include/xpmem_internal.h:include/xpmem_internal.h
test/share/run.sh:test/share/run.sh])
AC_OUTPUT
1 change: 0 additions & 1 deletion debian/clean
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
kernel/Kbuild
kernel/Makefile
kernel/xpmem
8 changes: 4 additions & 4 deletions dkms.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ BUILT_MODULE_NAME[0]="xpmem"
BUILT_MODULE_LOCATION[0]="kernel"
# where we put it under the kernel modules directory
DEST_MODULE_LOCATION[0]="/kernel/../updates/"
# how to build it
MAKE[0]="sh ./configure --with-kerneldir=$kernel_source_dir --with-kernelvers=$kernelver ; make"
# how to build it (only build kernel module for DKMS)
MAKE[0]='sh ./configure --with-kerneldir=$kernel_source_dir && make -C kernel KSRC=$kernel_source_dir'

# clean up command
CLEAN="make distclean"
## clean up command (only clean kernel module for DKMS)
CLEAN="env KSRC=$kernel_source_dir make -C kernel clean"

# rebuild and autoinstall automatically when dkms_autoinstaller runs
# for a new kernel
Expand Down
8 changes: 4 additions & 4 deletions kernel/Kbuild.in → kernel/Kbuild
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

obj-m := xpmem.o
xpmem-objs := xpmem_main.o xpmem_make.o xpmem_get.o \
xpmem_attach.o xpmem_pfn.o xpmem_misc.o \
xpmem_mmu_notifier.o


EXTRA_CFLAGS = -DKERNEL_3_8 \
-I$(obj)/@top_srcdir@/include

ccflags-y = -DKERNEL_3_8 \
-include $(obj)/xpmem_kernel.h \
-I$(obj)/../include
8 changes: 4 additions & 4 deletions kernel/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ init_SCRIPTS = xpmem
MODULE=xpmem.ko

module_sources = \
config_kernel \
Kbuild \
test_cases \
xpmem_attach.c \
xpmem_get.c \
xpmem_main.c \
Expand All @@ -19,10 +22,6 @@ EXTRA_DIST = ${module_sources}

module_DATA = $(MODULE)

KCPPFLAGS = -include @abs_top_builddir@/config.h -I@abs_top_srcdir@/include \
$(KFLAGS)
export KCPPFLAGS

$(MODULE): ${module_sources}
$(MAKE) -C $(KERNEL_PATH) M=$(abs_builddir)

Expand All @@ -31,5 +30,6 @@ modules_install: $(MODULE)

clean-local:
$(MAKE) -C $(KERNEL_PATH) M=$(abs_builddir) clean
rm -rf test_mods xpmem_kernel.h

.PHONY: $(MODULE)
20 changes: 20 additions & 0 deletions kernel/Makefile.dkms
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
KVERS = $(shell uname -r)
KSRC = /lib/modules/$(KVERS)/build
KMAKE = make -C $(KSRC) M=$(shell pwd) # $(PWD) may point to main dir

all:
$(KMAKE) modules

clean:
$(KMAKE) clean

.PHONY: all clean

obj-m := xpmem.o
xpmem-objs := xpmem_main.o xpmem_make.o xpmem_get.o \
xpmem_attach.o xpmem_pfn.o xpmem_misc.o \
xpmem_mmu_notifier.o

ccflags-y = -DKERNEL_3_8 \
-include $(obj)/xpmem_kernel.h \
-I$(obj)/../include
220 changes: 220 additions & 0 deletions kernel/config_kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#!/bin/sh

# shellcheck disable=SC2006,SC3043,SC3037
# Allows: local, echo -n, backtick syntax

usage() {
cat <<EOF
$0: configure kernel
Usage:
$0 # Run configuration
$0 sanity # Build and run sanity check
$0 CONFIG_NAME # re-test configuration for CONFIG_NAME

Options:

-o DIR - Output (and scratch) dir, for Out-of-tree build
-q Run quietly. Only print errors
-h Print this message

Kernel source is set by setting KSRC, KVERS or taken from uname -r
EOF
}

set_ksrc() {
KVERS="${KVERS:-`uname -r`}"
KSRC=${KSRC:-/lib/modules/$KVERS/build}
}

set_globals() {
OUTPUT_DIR="$PWD"
if [ "$opt_output_dir" != '' ]; then
OUTPUT_DIR="$opt_output_dir"
fi
cd "`dirname "$0"`" || exit 2
set_ksrc
NJOBS=$(($(nproc)+1)) # FIXME: calibrate -j
TEST_MODULES_DIR="$OUTPUT_DIR/test_mods"
TEST_CASES_DIR="$PWD/test_cases"
TEST_MOD_NAME="testmod"
TEST_RUN_LOG="$TEST_MODULES_DIR/run.log"
ERROR_FLAGS="-Werror-implicit-function-declaration -Wno-unused-variable -Wno-uninitialized"
HEADER_FILE="$OUTPUT_DIR/xpmem_kernel.h"
}

msg_checking() {
if [ "$silent" != 0 ]; then
return
fi
echo -n "Checking $*: "
}

msg_error() {
echo "Error: $*"
exit 1
}

msg_result() {
if [ "$silent" != 0 ]; then
return
fi
echo "$*"
}

msg_notice() {
if [ "$silent" != 0 ]; then
return
fi
echo "$*"
}

gen_test_case() {
local mod_name mod_dir

mod_name="$1"
mod_dir="$TEST_MODULES_DIR/$mod_name"
rm -rf "$mod_dir"
mkdir -p "$mod_dir"
cat <<EOF >"$mod_dir/$TEST_MOD_NAME.c"
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("test module for $mod_name");
`cat "$TEST_CASES_DIR/$mod_name.init"`
static int __init test_func (void) {
`cat "$TEST_CASES_DIR/$mod_name.main"`
return 0;
}
module_init(test_func);
EOF
echo "obj-m += $TEST_MOD_NAME.o" >"$mod_dir/Makefile"
echo "obj-\$(XPMEM_TEST)\$(XPMEM_TEST_$mod_name) += $mod_name/" >>"$TEST_MODULES_DIR/Makefile"
}

build_test_modules() {
msg_notice "Test-building kernel modules test-builds"
make -s -C "$KSRC" -k -j$NJOBS EXTRA_CFLAGS="$ERROR_FLAGS" "M=$TEST_MODULES_DIR" XPMEM_TEST=m modules >"$TEST_RUN_LOG" 2>&1
msg_notice ''
}

check_test_results() {
local mod_dir test_name rc

rm -f "$HEADER_FILE"
echo "#ifndef __XPMEM_KERNEL__" >>"$HEADER_FILE"
echo "#define __XPMEM_KERNEL__" >>"$HEADER_FILE"
msg_notice "Results of kernel tests:"
for mod_dir in "$TEST_MODULES_DIR"/HAVE_*; do
if test ! -d "$mod_dir"; then continue; fi
test_name="${mod_dir##*/}"
test ! -e "$mod_dir/$TEST_MOD_NAME.o"
rc=$?
desc_file="$TEST_CASES_DIR/$test_name.desc"
if [ -f "$desc_file" ]; then
echo "// $test_name: `cat "$desc_file"`" >> "$HEADER_FILE"
fi
if [ "$rc" != 0 ]; then
echo "#define $test_name 1" >>"$HEADER_FILE"
else
echo "#undef $test_name" >>"$HEADER_FILE"
fi
msg_notice "- $test_name: $rc"
done
}

# First case: The configure script passes version string as the env var
# XPMEM_VERSION .
# Second case: The configure script was already run successfully and set
# version string in dkms.conf. Get it from there. This works
# in both local and dkms builds.
get_package_version() {
if [ -n "$XPMEM_VERSION" ]; then
echo "$XPMEM_VERSION"
return
fi
# Assumes that dkms.conf is .. (see cd in set_globals). May
# break out-fo-tree builds.
awk -F'"' '/^PACKAGE_VERSION/ {print $2}' ../dkms.conf
}

# FIXME: another place where we write to the config file:
post_process() {
local version
if grep -q '^#define HAVE_PDE_DATA ' "$HEADER_FILE"; then
echo "#undef HAVE_NO_PDE_DATA_FUNC" >> "$HEADER_FILE"
else
echo "#define HAVE_NO_PDE_DATA_FUNC 1" >> "$HEADER_FILE"
fi
version=`get_package_version`
echo "#define PACKAGE_VERSION \"$version\"" >>"$HEADER_FILE"
echo "#endif" >>"$HEADER_FILE"
}

check_build_sanity() {
local rc
msg_checking "that system can build kernel modules"
gen_test_case KBUILD_WORKS "building a kernel module works"
make -s -C "$KSRC" EXTRA_CFLAGS="$ERROR_FLAGS" "M=$TEST_MODULES_DIR" XPMEM_TEST_KBUILD_WORKS=m modules 2>"$TEST_RUN_LOG"
rc=$?
if test "$rc" != 0; then
echo ''; cat "$TEST_RUN_LOG"
msg_error "Failed to build a dummy kernel module. Check compiler, kernel headers, etc."
fi
msg_result "yes"
}

get_tested_modules() {
printf '%s\n' "$TEST_CASES_DIR"/HAVE_*.init | sed 's|.*/||; s|\.init$||'
}

create_test_modules() {
local mod

rm -rf "${TEST_MODULES_DIR}"
mkdir -p "${TEST_MODULES_DIR}"

check_build_sanity

for mod in `get_tested_modules`; do
gen_test_case "$mod"
done
}

run_all() {
set_globals
create_test_modules
build_test_modules
check_test_results
post_process
}

# re-run a single test, after it was built
run_test() {
set_globals
if [ ! -d "$TEST_MODULES_DIR" ]; then
msg_error "Specific tests can only be run after an initial run built test modules."
fi
rm -f "$TEST_MODULES_DIR/$1/$TEST_MOD_NAME.o"
make -C "$KSRC" EXTRA_CFLAGS="$ERROR_FLAGS" "M=$TEST_MODULES_DIR" "XPMEM_TEST_$1=m" modules

}


silent=0
opt_output_dir=''
while getopts ho:q opt; do
case "$opt" in
h) usage; exit 0;;
o) opt_output_dir=$OPTARG;;
q) silent=1;;
\?) usage; exit 1;;
esac
done
shift $((OPTIND - 1))

case "$1" in
HAVE_* | KBUILD_WORKS) run_test "$1";;
sanity) run_test KBUILD_WORKS;;
'') run_all;;
*) usage; exit 1;;
esac
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_DECL_VMA_ITER_INIT.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm_types.h>
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_DECL_VMA_ITER_INIT.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(void) vma_iter_init;
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_DECL_VM_FLAGS_SET.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_DECL_VM_FLAGS_SET.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(void) vm_flags_set;
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_GUP_4_10.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
4 changes: 4 additions & 0 deletions kernel/test_cases/HAVE_GUP_4_10.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
unsigned int gup_flags, struct page **pages,
struct vm_area_struct **vmas, int *locked);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_GUP_4_8.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
4 changes: 4 additions & 0 deletions kernel/test_cases/HAVE_GUP_4_8.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
int write, int force, struct page **pages,
struct vm_area_struct **vmas);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_GUP_4_9.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
4 changes: 4 additions & 0 deletions kernel/test_cases/HAVE_GUP_4_9.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long get_user_pages_remote(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
unsigned int gup_flags, struct page **pages,
struct vm_area_struct **vmas);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_GUP_5_9.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
4 changes: 4 additions & 0 deletions kernel/test_cases/HAVE_GUP_5_9.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long get_user_pages_remote(struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
unsigned int gup_flags, struct page **pages,
struct vm_area_struct **vmas, int *locked);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_GUP_6_5.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
4 changes: 4 additions & 0 deletions kernel/test_cases/HAVE_GUP_6_5.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
long get_user_pages_remote(struct mm_struct *mm,
unsigned long start, unsigned long nr_pages,
unsigned int gup_flags, struct page **pages,
int *locked);
2 changes: 2 additions & 0 deletions kernel/test_cases/HAVE_LATEST_APPLY_TO_PAGE_RANGE.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <linux/mm.h>
extern pte_fn_t callback;
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_LATEST_APPLY_TO_PAGE_RANGE.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int a = callback(NULL, 1, NULL);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PDE_DATA.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Used to calculate HAVE_NO_PDE_DATA_FUNC at post-process
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PDE_DATA.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/proc_fs.h>
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PDE_DATA.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pde_data(NULL);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PDE_DATA_MACRO.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/proc_fs.h>
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PDE_DATA_MACRO.main
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PDE_DATA(NULL);
1 change: 1 addition & 0 deletions kernel/test_cases/HAVE_PMD_LEAF_MACRO.init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <linux/mm.h>
Loading