Module Name: src Committed By: maxv Date: Thu Apr 30 17:17:33 UTC 2020
Modified Files: src/sys/arch/amd64/amd64: locore.S src/sys/arch/i386/i386: locore.S src/sys/arch/x86/x86: patch.c Log Message: Switch to templates. To generate a diff of this commit: cvs rdiff -u -r1.202 -r1.203 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.180 -r1.181 src/sys/arch/i386/i386/locore.S cvs rdiff -u -r1.42 -r1.43 src/sys/arch/x86/x86/patch.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.202 src/sys/arch/amd64/amd64/locore.S:1.203 --- src/sys/arch/amd64/amd64/locore.S:1.202 Sun Apr 26 14:07:43 2020 +++ src/sys/arch/amd64/amd64/locore.S Thu Apr 30 17:17:33 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.202 2020/04/26 14:07:43 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.203 2020/04/30 17:17:33 maxv Exp $ */ /* * Copyright-o-rama! @@ -1589,6 +1589,26 @@ END(intrfastexit) .section .rodata + /* + * Hotpatch templates. + */ + +LABEL(hp_nolock) + nop +LABEL(hp_nolock_end) + +LABEL(hp_retfence) + lfence +LABEL(hp_retfence_end) + +LABEL(hp_clac) + clac +LABEL(hp_clac_end) + +LABEL(hp_stac) + stac +LABEL(hp_stac_end) + #ifdef SVS .globl svs_enter, svs_enter_end .globl svs_enter_altstack, svs_enter_altstack_end Index: src/sys/arch/i386/i386/locore.S diff -u src/sys/arch/i386/i386/locore.S:1.180 src/sys/arch/i386/i386/locore.S:1.181 --- src/sys/arch/i386/i386/locore.S:1.180 Sat Apr 25 15:26:17 2020 +++ src/sys/arch/i386/i386/locore.S Thu Apr 30 17:17:33 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.180 2020/04/25 15:26:17 bouyer Exp $ */ +/* $NetBSD: locore.S,v 1.181 2020/04/30 17:17:33 maxv Exp $ */ /* * Copyright-o-rama! @@ -128,7 +128,7 @@ */ #include <machine/asm.h> -__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.180 2020/04/25 15:26:17 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.181 2020/04/30 17:17:33 maxv Exp $"); #include "opt_copy_symtab.h" #include "opt_ddb.h" @@ -1612,3 +1612,24 @@ ENTRY(intrfastexit) iret END(intrfastexit) + .section .rodata + + /* + * Hotpatch templates. + */ + +LABEL(hp_nolock) + nop +LABEL(hp_nolock_end) + +LABEL(hp_retfence) + lfence +LABEL(hp_retfence_end) + +LABEL(hp_clac) + clac +LABEL(hp_clac_end) + +LABEL(hp_stac) + stac +LABEL(hp_stac_end) Index: src/sys/arch/x86/x86/patch.c diff -u src/sys/arch/x86/x86/patch.c:1.42 src/sys/arch/x86/x86/patch.c:1.43 --- src/sys/arch/x86/x86/patch.c:1.42 Sun Apr 26 14:49:17 2020 +++ src/sys/arch/x86/x86/patch.c Thu Apr 30 17:17:33 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: patch.c,v 1.42 2020/04/26 14:49:17 maxv Exp $ */ +/* $NetBSD: patch.c,v 1.43 2020/04/30 17:17:33 maxv Exp $ */ /*- * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.42 2020/04/26 14:49:17 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: patch.c,v 1.43 2020/04/30 17:17:33 maxv Exp $"); #include "opt_lockdebug.h" #ifdef i386 @@ -174,6 +174,8 @@ void x86_patch(bool early) { static bool first, second; + uint8_t *bytes; + size_t size; u_long psl; u_long cr0; @@ -194,12 +196,11 @@ x86_patch(bool early) /* * Uniprocessor: kill LOCK prefixes. */ - const uint8_t bytes[] = { - X86_NOP - }; + extern uint8_t hp_nolock, hp_nolock_end; - /* lock -> nop */ - x86_hotpatch(HP_NAME_NOLOCK, bytes, sizeof(bytes)); + bytes = &hp_nolock; + size = (size_t)&hp_nolock_end - (size_t)&hp_nolock; + x86_hotpatch(HP_NAME_NOLOCK, bytes, size); #endif } @@ -212,8 +213,6 @@ x86_patch(bool early) */ extern uint8_t sse2_lfence, sse2_lfence_end; extern uint8_t sse2_mfence, sse2_mfence_end; - uint8_t *bytes; - size_t size; bytes = &sse2_lfence; size = (size_t)&sse2_lfence_end - (size_t)&sse2_lfence; @@ -265,35 +264,30 @@ x86_patch(bool early) (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xe || (CPUID_TO_FAMILY(cpu_info_primary.ci_signature) == 0xf && CPUID_TO_EXTMODEL(cpu_info_primary.ci_signature) < 0x4))) { - const uint8_t bytes[] = { - 0x0F, 0xAE, 0xE8 /* lfence */ - }; + extern uint8_t hp_retfence, hp_retfence_end; - /* ret,nop,nop -> lfence */ - x86_hotpatch(HP_NAME_RETFENCE, bytes, sizeof(bytes)); + bytes = &hp_retfence; + size = (size_t)&hp_retfence_end - (size_t)&hp_retfence; + x86_hotpatch(HP_NAME_RETFENCE, bytes, size); } /* * If SMAP is present then patch the prepared holes with clac/stac * instructions. - * - * clac = 0x0f, 0x01, 0xca - * stac = 0x0f, 0x01, 0xcb */ if (!early && cpu_feature[5] & CPUID_SEF_SMAP) { - KASSERT(rcr4() & CR4_SMAP); - const uint8_t clac_bytes[] = { - 0x0F, 0x01, 0xCA /* clac */ - }; - const uint8_t stac_bytes[] = { - 0x0F, 0x01, 0xCB /* stac */ - }; + extern uint8_t hp_clac, hp_clac_end; + extern uint8_t hp_stac, hp_stac_end; - /* nop,nop,nop -> clac */ - x86_hotpatch(HP_NAME_CLAC, clac_bytes, sizeof(clac_bytes)); + KASSERT(rcr4() & CR4_SMAP); - /* nop,nop,nop -> stac */ - x86_hotpatch(HP_NAME_STAC, stac_bytes, sizeof(stac_bytes)); + bytes = &hp_clac; + size = (size_t)&hp_clac_end - (size_t)&hp_clac; + x86_hotpatch(HP_NAME_CLAC, bytes, size); + + bytes = &hp_stac; + size = (size_t)&hp_stac_end - (size_t)&hp_stac; + x86_hotpatch(HP_NAME_STAC, bytes, size); } x86_patch_window_close(psl, cr0);