From owner-svn-soc-all@FreeBSD.ORG Thu Aug 14 11:42:26 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 08DABD22 for ; Thu, 14 Aug 2014 11:42:26 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DE0B229CD for ; Thu, 14 Aug 2014 11:42:25 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7EBgPdE011482 for ; Thu, 14 Aug 2014 11:42:25 GMT (envelope-from op@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s7EBgOwx011453 for svn-soc-all@FreeBSD.org; Thu, 14 Aug 2014 11:42:24 GMT (envelope-from op@FreeBSD.org) Date: Thu, 14 Aug 2014 11:42:24 GMT Message-Id: <201408141142.s7EBgOwx011453@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to op@FreeBSD.org using -f From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272396 - in soc2014/op/tests/ksp-tester: . kmod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Aug 2014 11:42:26 -0000 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 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 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 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#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);