Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Switch to templates.
details: https://anonhg.NetBSD.org/src/rev/ffab4774b371
branches: trunk
changeset: 1009693:ffab4774b371
user: maxv <maxv%NetBSD.org@localhost>
date: Thu Apr 30 17:17:33 2020 +0000
description:
Switch to templates.
diffstat:
sys/arch/amd64/amd64/locore.S | 22 ++++++++++++++++++-
sys/arch/i386/i386/locore.S | 25 ++++++++++++++++++++-
sys/arch/x86/x86/patch.c | 48 ++++++++++++++++++------------------------
3 files changed, 65 insertions(+), 30 deletions(-)
diffs (181 lines):
diff -r bca2365f7b67 -r ffab4774b371 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S Thu Apr 30 17:16:00 2020 +0000
+++ b/sys/arch/amd64/amd64/locore.S Thu Apr 30 17:17:33 2020 +0000
@@ -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 @@
.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
diff -r bca2365f7b67 -r ffab4774b371 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S Thu Apr 30 17:16:00 2020 +0000
+++ b/sys/arch/i386/i386/locore.S Thu Apr 30 17:17:33 2020 +0000
@@ -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 @@
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)
diff -r bca2365f7b67 -r ffab4774b371 sys/arch/x86/x86/patch.c
--- a/sys/arch/x86/x86/patch.c Thu Apr 30 17:16:00 2020 +0000
+++ b/sys/arch/x86/x86/patch.c Thu Apr 30 17:17:33 2020 +0000
@@ -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 @@
x86_patch(bool early)
{
static bool first, second;
+ uint8_t *bytes;
+ size_t size;
u_long psl;
u_long cr0;
@@ -194,12 +196,11 @@
/*
* 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 @@
*/
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 @@
(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) {
+ extern uint8_t hp_clac, hp_clac_end;
+ extern uint8_t hp_stac, hp_stac_end;
+
KASSERT(rcr4() & CR4_SMAP);
- const uint8_t clac_bytes[] = {
- 0x0F, 0x01, 0xCA /* clac */
- };
- const uint8_t stac_bytes[] = {
- 0x0F, 0x01, 0xCB /* stac */
- };
- /* nop,nop,nop -> clac */
- x86_hotpatch(HP_NAME_CLAC, clac_bytes, sizeof(clac_bytes));
+ bytes = &hp_clac;
+ size = (size_t)&hp_clac_end - (size_t)&hp_clac;
+ x86_hotpatch(HP_NAME_CLAC, bytes, size);
- /* nop,nop,nop -> stac */
- x86_hotpatch(HP_NAME_STAC, stac_bytes, sizeof(stac_bytes));
+ 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);
Home |
Main Index |
Thread Index |
Old Index