Date: Wed, 23 Jul 2014 13:06:11 GMT From: op@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271269 - in soc2014/op/freebsd-base/sys: amd64/include x86/include Message-ID: <201407231306.s6ND6B8v068070@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: op Date: Wed Jul 23 13:06:11 2014 New Revision: 271269 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271269 Log: KSP: added SMAP and XSAVE related patch definitions Signed-off-by: Oliver Pinter <oliver.pntr@gmail.com> git: https://github.com/opntr/opBSD/tree/op/gsoc2014/kpatch Added: soc2014/op/freebsd-base/sys/amd64/include/selfpatch-asmacros.h soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h Added: soc2014/op/freebsd-base/sys/amd64/include/selfpatch-asmacros.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/amd64/include/selfpatch-asmacros.h Wed Jul 23 13:06:11 2014 (r271269) @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter <oliver.pntr at gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef __AMD64_SELFPATH_ASMACROS_H__ +#define __AMD64_SELFPATH_ASMACROS_H__ + +#include <x86/selfpatch-asmacros.h> + +#endif /* __AMD64_SELFPATH_ASMACROS_H__ */ Added: soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-asmacros.h Wed Jul 23 13:06:11 2014 (r271269) @@ -0,0 +1,130 @@ +/*- + * Copyright (c) 2014, by Oliver Pinter <oliver.pntr at gmail.com> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + + +#ifndef __X86_SELFPATCH_ASMACROS_H__ +#define __X86_SELFPATCH_ASMACROS_H__ + +#define KSP_CPU_FEATURE 1 +#define KSP_CPU_FEATURE2 2 +#define KSP_AMD_FEATURE 3 +#define KSP_AMD_FEATURE2 4 +#define KSP_VIA_FEATURE_RNG 5 +#define KSP_VIA_FEATURE_XCRYPT 6 +#define KSP_CPU_STDEXT_FEATURE 7 + +/* + * Intel Instruction Set Reference M-Z + * Table 4-12. recommended Multi-Byte Sequeance of NOP Instruction + */ +#define KSP_INSTR_INTEL_NOP1 .byte 0x90 +#define KSP_INSTR_INTEL_NOP2 .byte 0x66,0x90 +#define KSP_INSTR_INTEL_NOP3 .byte 0x0f,0x1f,0x00 +#define KSP_INSTR_INTEL_NOP4 .byte 0x0f,0x1f,0x40,0x00 +#define KSP_INSTR_INTEL_NOP5 .byte 0x0f,0x1f,0x44,0x00,0x00 +#define KSP_INSTR_INTEL_NOP6 .byte 0x66,0x0f,0x1f,0x44,0x00,0x00 +#define KSP_INSTR_INTEL_NOP7 .byte 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00 +#define KSP_INSTR_INTEL_NOP8 .byte 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00 +#define KSP_INSTR_INTEL_NOP9 .byte 0x66,0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00 + +#define KSP_INSTR_NOP1 KSP_INSTR_INTEL_NOP1 +#define KSP_INSTR_NOP2 KSP_INSTR_INTEL_NOP2 +#define KSP_INSTR_NOP3 KSP_INSTR_INTEL_NOP3 +#define KSP_INSTR_NOP4 KSP_INSTR_INTEL_NOP4 +#define KSP_INSTR_NOP5 KSP_INSTR_INTEL_NOP5 +#define KSP_INSTR_NOP6 KSP_INSTR_INTEL_NOP6 +#define KSP_INSTR_NOP7 KSP_INSTR_INTEL_NOP7 +#define KSP_INSTR_NOP8 KSP_INSTR_INTEL_NOP8 +#define KSP_INSTR_NOP9 KSP_INSTR_INTEL_NOP9 + +#define KSP_INSTR_XSAVE_XSAVEOPT(_ARG) \ + "0723:" \ + " xsave " _ARG " ; " \ + "0724: " \ + " .pushsection set_selfpatch_patch_set, \"ax\" ; " \ + "0725: " \ + " xsaveopt " _ARG " ;" \ + "0726: " \ + " .popsection " \ + " .pushsection set_selfpatch_set, \"a\" ; " \ + " .quad 0723b ; " \ + " .quad 0725b ; " \ + " .int 0724b-0723b ; " \ + " .int 0726b-0725b ; " \ + " .int " KSP_CPU_FEATURE2 " ; " \ + " .int " CPUID2_OSXSAVE " ; " \ + " .quad 0 ; " \ + " .popsection ; " + +#define _xsave_xsaveopt(_ARG) KSP_INSTR_XSAVE_XSAVEOPT(_ARG) + + +#define KSP_INSTR_NOP3_CLAC \ + "0723:" \ + " " KSP_INSTR_NOP3 " ; " \ + "0724: " \ + " .pushsection set_selfpatch_patch_set, \"ax\" ; " \ + "0725: " \ + " clac " ;" \ + "0726: " \ + " .popsection " \ + " .pushsection set_selfpatch_set, \"a\" ; " \ + " .quad 0723b ; " \ + " .quad 0725b ; " \ + " .int 0724b-0723b ; " \ + " .int 0726b-0725b ; " \ + " .int " KSP_CPU_STDEXT_FEATURE " ; " \ + " .int " CPUID_STDEXT_SMAP " ; " \ + " .quad 0 ; " \ + " .popsection ; " + +#define _clac KSP_INSTR_NOP3_CLAC + + +#define KSP_INSTR_NOP3_STAC \ + "0723:" \ + " " KSP_INSTR_NOP3 " ; " \ + "0724: " \ + " .pushsection set_selfpatch_patch_set, \"ax\" ; " \ + "0725: " \ + " stac " ;" \ + "0726: " \ + " .popsection " \ + " .pushsection set_selfpatch_set, \"a\" ; " \ + " .quad 0723b ; " \ + " .quad 0725b ; " \ + " .int 0724b-0723b ; " \ + " .int 0726b-0725b ; " \ + " .int " KSP_CPU_STDEXT_FEATURE " ; " \ + " .int " CPUID_STDEXT_SMAP " ; " \ + " .quad 0 ; " \ + " .popsection ; " + +#define _stac KSP_INSTR_NOP3_STAC + +#endif /* __X86_SELFPATCH_ASMACROS_H__ */ Modified: soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h ============================================================================== --- soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h Wed Jul 23 09:22:12 2014 (r271268) +++ soc2014/op/freebsd-base/sys/x86/include/selfpatch-machdep.h Wed Jul 23 13:06:11 2014 (r271269) @@ -29,14 +29,6 @@ #ifndef __X86_SELFPATH_MACHDEP_H__ #define __X86_SELFPATH_MACHDEP_H__ -#define KSP_CPU_FEATURE 1 -#define KSP_CPU_FEATURE2 2 -#define KSP_AMD_FEATURE 3 -#define KSP_AMD_FEATURE2 4 -#define KSP_VIA_FEATURE_RNG 5 -#define KSP_VIA_FEATURE_XCRYPT 6 -#define KSP_CPU_STDEXT_FEATURE 7 - struct lf_selfpatch; extern char *md_selfpatch_nop_table[];
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407231306.s6ND6B8v068070>
