socsvn commit: r272396 - in soc2014/op/tests/ksp-tester: . kmod

op at FreeBSD.org op at FreeBSD.org
Thu Aug 14 11:42:26 UTC 2014


Author: op
Date: Thu Aug 14 11:42:24 2014
New Revision: 272396
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272396

Log:
  KSP: added test kernel module
  
  Signed-off-by: Oliver Pinter <oliver.pntr at gmail.com>
  
  

Added:
  soc2014/op/tests/ksp-tester/
  soc2014/op/tests/ksp-tester/Makefile
  soc2014/op/tests/ksp-tester/kmod/
  soc2014/op/tests/ksp-tester/kmod/.clang_complete
  soc2014/op/tests/ksp-tester/kmod/Makefile
  soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c

Added: soc2014/op/tests/ksp-tester/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/op/tests/ksp-tester/Makefile	Thu Aug 14 11:42:24 2014	(r272396)
@@ -0,0 +1,3 @@
+SUBDIR= kmod
+
+.include <bsd.subdir.mk>

Added: soc2014/op/tests/ksp-tester/kmod/.clang_complete
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/op/tests/ksp-tester/kmod/.clang_complete	Thu Aug 14 11:42:24 2014	(r272396)
@@ -0,0 +1,6 @@
+-D_KERNEL
+-DKERNEL
+-I/usr/src
+-I/usr/src/sys
+-I/usr/src/sys/amd64
+-I/usr/src/sys/x86

Added: soc2014/op/tests/ksp-tester/kmod/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/op/tests/ksp-tester/kmod/Makefile	Thu Aug 14 11:42:24 2014	(r272396)
@@ -0,0 +1,4 @@
+KMOD=	ksp-tester-kld
+SRCS=	ksp-tester-kld.c
+
+.include <bsd.kmod.mk>

Added: soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2014/op/tests/ksp-tester/kmod/ksp-tester-kld.c	Thu Aug 14 11:42:24 2014	(r272396)
@@ -0,0 +1,142 @@
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/uio.h>
+#include <sys/malloc.h>
+#include <vm/vm.h>
+
+#include <sys/linker.h>
+#include <sys/selfpatch.h>
+
+#include "opt_ksp.h"
+
+#ifndef	KSP_DEBUG
+#error "KSP_DEBUG must set at kernel build time to properly use this test"
+#endif
+
+#define DBG(...)				\
+	printf("%s: ", __func__);		\
+	printf(__VA_ARGS__);			\
+
+__noinline void lf_selfpatch_selftest(void);
+
+static int
+ksp_tester_kld_loader(struct module *m __unused, int what, void *arg __unused)
+{
+	int error = 0;
+
+	switch (what) {
+	case MOD_LOAD:
+		printf("KSP tester loaded.\n");
+		break;
+	case MOD_UNLOAD:
+		printf("KSP tester unloaded.\n");
+		break;
+	default:
+		error = EOPNOTSUPP;
+		break;
+	}
+	return (error);
+}
+
+__noinline void
+lf_selfpatch_selftest(void)
+{
+	printf("patch size == patchable size: ");
+	__asm __volatile(
+	"1:"
+	"	ud2; ud2; ; "
+	"2:	"
+	"	.pushsection set_selfpatch_patch_set, \"ax\" ;  "
+	"3:	"
+	"	.byte 0x90,0x90,0x90,0x90 ;"
+	"4:	"
+	"	.popsection "
+	"	.pushsection set_selfpatch_set, \"a\" ; "
+	"		.quad   1b ; "
+	"		.quad   3b ; "
+	"		.int    2b-1b ;	"
+	"		.int    4b-3b ;	"
+	"		.int    " __XSTRING(KSP_SELFTEST) " ; "
+	"		.int    " __XSTRING(KSP_FEATURE_SELFTEST) " ; "
+	"		.quad	0 ; "
+	"	.popsection ; "
+	);
+	DBG("works.\n");
+
+
+	printf("patch size < patchable size: ");
+	__asm __volatile(
+	"1:"
+	"	ud2; ud2; ; "
+	"2:	"
+	"	.pushsection set_selfpatch_patch_set, \"ax\" ;  "
+	"3:	"
+	"	.byte 0x90 ;"
+	"4:	"
+	"	.popsection "
+	"	.pushsection set_selfpatch_set, \"a\" ; "
+	"		.quad   1b ; "
+	"		.quad   3b ; "
+	"		.int    2b-1b ;	"
+	"		.int    4b-3b ;	"
+	"		.int    " __XSTRING(KSP_SELFTEST) " ; "
+	"		.int    " __XSTRING(KSP_FEATURE_SELFTEST) " ; "
+	"		.quad	0 ; "
+	"	.popsection ; "
+	);
+	DBG("works.\n");
+
+
+	printf("patch size << patchable size: ");
+	__asm __volatile(
+	"1:"
+	"	ud2; ud2; ud2; ud2; ud2; ud2 ; "
+	"2:	"
+	"	.pushsection set_selfpatch_patch_set, \"ax\" ;  "
+	"3:	"
+	"	.byte 0x90 ;"
+	"4:	"
+	"	.popsection "
+	"	.pushsection set_selfpatch_set, \"a\" ; "
+	"		.quad   1b ; "
+	"		.quad   3b ; "
+	"		.int    2b-1b ;	"
+	"		.int    4b-3b ;	"
+	"		.int    " __XSTRING(KSP_SELFTEST) " ; "
+	"		.int    " __XSTRING(KSP_FEATURE_SELFTEST) " ; "
+	"		.quad	0 ; "
+	"	.popsection ; "
+	);
+	DBG("works.\n");
+
+
+	printf("patch size > patchable size: ");
+	__asm __volatile(
+	"1:"
+	"	ud2; "
+	"2:	"
+	"	.pushsection set_selfpatch_patch_set, \"ax\" ;  "
+	"3:	"
+	"	.byte 0x90, 0x90, 0x90, 0x90, 0x90 ;"
+	"4:	"
+	"	.popsection "
+	"	.pushsection set_selfpatch_set, \"a\" ; "
+	"		.quad   1b ; "
+	"		.quad   3b ; "
+	"		.int    2b-1b ;	"
+	"		.int    4b-3b ;	"
+	"		.int    " __XSTRING(KSP_SELFTEST) " ; "
+	"		.int    " __XSTRING(KSP_FEATURE_SELFTEST) " ; "
+	"		.quad	0 ; "
+	"	.popsection ; "
+	);
+	DBG("failed. this must panic.\n");
+}
+
+DEV_MODULE(ksp_tester_kld, ksp_tester_kld_loader, NULL);


More information about the svn-soc-all mailing list